Add support for multiple microarchitectures in single binary
[vpp.git] / vpp / app / version.c
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <vlib/vlib.h>
16 #include <vppinfra/cpu.h>
17 #include <app/version.h>
18
19 #if DPDK > 0
20 #include <rte_version.h>
21 #include <vnet/vnet.h>
22 #include <vnet/devices/dpdk/dpdk.h>
23 #endif /* DPDK */
24
25 static char * vpe_version_string = 
26     "vpp v" VPP_BUILD_VER 
27     " built by " VPP_BUILD_USER 
28     " on " VPP_BUILD_HOST 
29     " at " VPP_BUILD_DATE;
30
31 static char * vpe_compiler =
32 #if defined(__INTEL_COMPILER)
33 #define __(x) #x
34 #define _(x) __(x)
35         "icc " _(__INTEL_COMPILER) " (" __VERSION__ ")";
36 #undef _
37 #undef __
38 #elif defined(__clang__)
39         "Clang/LLVM " __clang_version__;
40 #elif defined (__GNUC__)
41         "GCC " __VERSION__;
42 #else
43         "unknown compiler";
44 #endif
45
46 static clib_error_t *
47 show_vpe_version_command_fn (vlib_main_t * vm,
48                  unformat_input_t * input,
49                  vlib_cli_command_t * cmd)
50 {
51   if (unformat (input, "verbose"))
52     {
53 #define _(a,b,c) vlib_cli_output (vm, "%-25s " b, a ":", c);
54       _("Version", "%s", "v" VPP_BUILD_VER);
55       _("Compiled by", "%s", VPP_BUILD_USER);
56       _("Compile host", "%s", VPP_BUILD_HOST);
57       _("Compile date", "%s", VPP_BUILD_DATE);
58       _("Compile location", "%s", VPP_BUILD_TOPDIR);
59       _("Compiler", "%s", vpe_compiler);
60       _("CPU model name", "%U", format_cpu_model_name);
61       _("CPU microarchitecture", "%U", format_cpu_uarch);
62       _("CPU flags", "%U", format_cpu_flags);
63       _("Current PID", "%d", getpid());
64 #if DPDK > 0
65       _("DPDK Version", "%s", rte_version());
66       _("DPDK EAL init args", "%s", dpdk_main.eal_init_args_str);
67 #endif
68 #undef _
69     }
70   else
71     vlib_cli_output (vm, "%s", vpe_version_string);
72   return 0;
73 }
74
75 VLIB_CLI_COMMAND (show_vpe_version_command, static) = {
76   .path = "show version",
77   .short_help = "show version information",
78   .function = show_vpe_version_command_fn,
79 };
80
81 char * vpe_api_get_build_directory (void) 
82 {
83   return VPP_BUILD_TOPDIR;
84 }
85
86 char * vpe_api_get_version (void) 
87 {
88   return VPP_BUILD_VER;
89 }
90 char * vpe_api_get_build_date (void) 
91 {
92   return VPP_BUILD_DATE;
93 }