ソースを参照

[build] Expose build timestamp, build name, and product names

Expose the build timestamp (measured in seconds since the Epoch) and
the build name (e.g. "rtl8139.rom" or "ipxe.efi"), and provide the
product name and product short name in a single centralised location.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10年前
コミット
8290a95513

+ 1
- 0
src/Makefile ファイルの表示

@@ -96,6 +96,7 @@ SRCDIRS		+= config
96 96
 # automatic build system.
97 97
 #
98 98
 NON_AUTO_SRCS	:=
99
+NON_AUTO_SRCS	+= core/version.c
99 100
 NON_AUTO_SRCS	+= drivers/net/prism2.c
100 101
 
101 102
 # INCDIRS lists the include path

+ 21
- 16
src/Makefile.housekeeping ファイルの表示

@@ -697,19 +697,6 @@ $(BIN)/embedded.% : override CC := env CCACHE_DISABLE=1 $(CC)
697 697
 $(BIN)/certstore.% : override CC := env CCACHE_DISABLE=1 $(CC)
698 698
 $(BIN)/privkey.% : override CC := env CCACHE_DISABLE=1 $(CC)
699 699
 
700
-# Version number
701
-#
702
-CFLAGS_version += -DVERSION_MAJOR=$(VERSION_MAJOR) \
703
-		  -DVERSION_MINOR=$(VERSION_MINOR) \
704
-		  -DVERSION_PATCH=$(VERSION_PATCH) \
705
-		  -DVERSION="\"$(VERSION)\""
706
-# Make sure the version number gets updated on every git checkout
707
-ifneq ($(GITVERSION),)
708
-ifneq ($(wildcard ../.git/index),)
709
-$(BIN)/version.o : ../.git/index
710
-endif
711
-endif
712
-
713 700
 # Debug message autocolourisation range
714 701
 #
715 702
 DBGCOL_LIST	:= $(BIN)/.dbgcol.list
@@ -1004,13 +991,31 @@ blib : $(BLIB)
1004 991
 #
1005 992
 BUILD_ID_CMD	:= perl -e 'printf "0x%08x", int ( rand ( 0xffffffff ) );'
1006 993
 
994
+# Build timestamp
995
+#
996
+BUILD_TIMESTAMP := $(shell date +%s)
997
+
998
+# Build version
999
+#
1000
+GIT_INDEX := $(if $(GITVERSION),$(if $(wildcard ../.git/index),../.git/index))
1001
+$(BIN)/%.version.o : core/version.c $(MAKEDEPS) $(GIT_INDEX)
1002
+	$(QM)$(ECHO) "  [VERSION] $@"
1003
+	$(Q)$(COMPILE_c) -DBUILD_NAME="\"$*\"" \
1004
+		-DVERSION_MAJOR=$(VERSION_MAJOR) \
1005
+		-DVERSION_MINOR=$(VERSION_MINOR) \
1006
+		-DVERSION_PATCH=$(VERSION_PATCH) \
1007
+		-DVERSION="\"$(VERSION)\"" \
1008
+		-c $< -o $@
1009
+
1007 1010
 # Build an intermediate object file from the objects required for the
1008 1011
 # specified target.
1009 1012
 #
1010
-$(BIN)/%.tmp : $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
1013
+$(BIN)/%.tmp : $(BIN)/%.version.o $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
1011 1014
 	$(QM)$(ECHO) "  [LD] $@"
1012
-	$(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $(BLIB) -o $@ \
1013
-		--defsym _build_id=`$(BUILD_ID_CMD)` -Map $(BIN)/$*.tmp.map
1015
+	$(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $< $(BLIB) -o $@ \
1016
+		--defsym _build_id=`$(BUILD_ID_CMD)` \
1017
+		--defsym _build_timestamp=$(BUILD_TIMESTAMP) \
1018
+		-Map $(BIN)/$*.tmp.map
1014 1019
 	$(Q)$(OBJDUMP) -ht $@ | $(PERL) $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
1015 1020
 
1016 1021
 # Keep intermediate object file (useful for debugging)

+ 2
- 2
src/core/main.c ファイルの表示

@@ -17,8 +17,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
17 17
 #include <stddef.h>
18 18
 #include <stdio.h>
19 19
 #include <ipxe/init.h>
20
+#include <ipxe/version.h>
20 21
 #include <usr/autoboot.h>
21
-#include <config/general.h>
22 22
 
23 23
 /**
24 24
  * Main entry point
@@ -31,7 +31,7 @@ __asmcall int main ( void ) {
31 31
 	initialise();
32 32
 
33 33
 	/* Some devices take an unreasonably long time to initialise */
34
-	printf ( PRODUCT_SHORT_NAME " initialising devices..." );
34
+	printf ( "%s initialising devices...", product_short_name );
35 35
 	startup();
36 36
 	printf ( "ok\n" );
37 37
 

+ 49
- 1
src/core/version.c ファイルの表示

@@ -25,12 +25,35 @@ FILE_LICENCE ( GPL2_OR_LATER );
25 25
  *
26 26
  */
27 27
 
28
+#include <wchar.h>
28 29
 #include <ipxe/features.h>
29 30
 #include <ipxe/version.h>
31
+#include <config/general.h>
32
+
33
+/**
34
+ * Create wide-character version of string
35
+ *
36
+ * @v string		String
37
+ * @ret wstring		Wide-character version of string
38
+ */
39
+#define WSTRING( string ) _WSTRING ( string )
40
+#define _WSTRING( string ) L ## string
30 41
 
31 42
 /** Version number feature */
32 43
 FEATURE_VERSION ( VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH );
33 44
 
45
+/** Build timestamp (generated by linker) */
46
+extern char _build_timestamp[];
47
+
48
+/** Build ID (generated by linker) */
49
+extern char _build_id[];
50
+
51
+/** Build timestamp */
52
+unsigned long build_timestamp = ( ( unsigned long ) _build_timestamp );
53
+
54
+/** Build ID */
55
+unsigned long build_id = ( ( unsigned long ) _build_id );
56
+
34 57
 /** Product major version */
35 58
 const int product_major_version = VERSION_MAJOR;
36 59
 
@@ -38,4 +61,29 @@ const int product_major_version = VERSION_MAJOR;
38 61
 const int product_minor_version = VERSION_MINOR;
39 62
 
40 63
 /** Product version string */
41
-const char *product_version = VERSION;
64
+const char product_version[] = VERSION;
65
+
66
+/** Product name string */
67
+const char product_name[] = PRODUCT_NAME;
68
+
69
+/** Product short name string */
70
+const char product_short_name[] = PRODUCT_SHORT_NAME;
71
+
72
+/** Build name string */
73
+const char build_name[] = BUILD_NAME;
74
+
75
+/** Wide-character product version string */
76
+const wchar_t product_wversion[] = WSTRING ( VERSION );
77
+
78
+/** Wide-character product name string */
79
+const wchar_t product_wname[] = WSTRING ( PRODUCT_NAME );
80
+
81
+/** Wide-character product short name string */
82
+const wchar_t product_short_wname[] = WSTRING ( PRODUCT_SHORT_NAME );
83
+
84
+/** Wide-character build name string */
85
+const wchar_t build_wname[] = WSTRING ( BUILD_NAME );
86
+
87
+/** Copy of build name string within ".prefix" */
88
+const char build_name_prefix[] __attribute__ (( section ( ".prefix.name" ) ))
89
+	= BUILD_NAME;

+ 12
- 1
src/include/ipxe/version.h ファイルの表示

@@ -9,8 +9,19 @@
9 9
 
10 10
 FILE_LICENCE ( GPL2_OR_LATER );
11 11
 
12
+#include <wchar.h>
13
+
14
+extern unsigned long build_timestamp;
15
+extern unsigned long build_id;
12 16
 extern const int product_major_version;
13 17
 extern const int product_minor_version;
14
-extern const char *product_version;
18
+extern const char product_version[];
19
+extern const char product_name[];
20
+extern const char product_short_name[];
21
+extern const char build_name[];
22
+extern const wchar_t product_wversion[];
23
+extern const wchar_t product_wname[];
24
+extern const wchar_t product_short_wname[];
25
+extern const wchar_t build_wname[];
15 26
 
16 27
 #endif /* _IPXE_VERSION_H */

+ 2
- 2
src/interface/efi/efi_driver.c ファイルの表示

@@ -23,12 +23,12 @@ FILE_LICENCE ( GPL2_OR_LATER );
23 23
 #include <stdio.h>
24 24
 #include <string.h>
25 25
 #include <errno.h>
26
+#include <ipxe/version.h>
26 27
 #include <ipxe/efi/efi.h>
27 28
 #include <ipxe/efi/Protocol/DriverBinding.h>
28 29
 #include <ipxe/efi/Protocol/ComponentName2.h>
29 30
 #include <ipxe/efi/efi_strings.h>
30 31
 #include <ipxe/efi/efi_driver.h>
31
-#include <config/general.h>
32 32
 
33 33
 /** @file
34 34
  *
@@ -207,7 +207,7 @@ int efi_driver_install ( struct efi_driver *efidrv ) {
207 207
 	efi_snprintf ( efidrv->wname,
208 208
 		       ( sizeof ( efidrv->wname ) /
209 209
 			 sizeof ( efidrv->wname[0] ) ),
210
-		       PRODUCT_SHORT_NAME "%s%s",
210
+		       "%s%s%s", product_short_name,
211 211
 		       ( efidrv->name ? " - " : "" ),
212 212
 		       ( efidrv->name ? efidrv->name : "" ) );
213 213
 

+ 4
- 4
src/interface/efi/efi_snp.c ファイルの表示

@@ -28,12 +28,12 @@ FILE_LICENCE ( GPL2_OR_LATER );
28 28
 #include <ipxe/iobuf.h>
29 29
 #include <ipxe/in.h>
30 30
 #include <ipxe/pci.h>
31
+#include <ipxe/version.h>
31 32
 #include <ipxe/efi/efi.h>
32 33
 #include <ipxe/efi/efi_pci.h>
33 34
 #include <ipxe/efi/efi_driver.h>
34 35
 #include <ipxe/efi/efi_strings.h>
35 36
 #include <ipxe/efi/efi_snp.h>
36
-#include <config/general.h>
37 37
 #include <usr/autoboot.h>
38 38
 
39 39
 /** EFI simple network protocol GUID */
@@ -988,12 +988,12 @@ static int efi_snp_probe ( struct net_device *netdev ) {
988 988
 	efi_snprintf ( snpdev->driver_name,
989 989
 		       ( sizeof ( snpdev->driver_name ) /
990 990
 			 sizeof ( snpdev->driver_name[0] ) ),
991
-		       PRODUCT_SHORT_NAME " %s", netdev->dev->driver_name );
991
+		       "%s %s", product_short_name, netdev->dev->driver_name );
992 992
 	efi_snprintf ( snpdev->controller_name,
993 993
 		       ( sizeof ( snpdev->controller_name ) /
994 994
 			 sizeof ( snpdev->controller_name[0] ) ),
995
-		       PRODUCT_SHORT_NAME " %s (%s)",
996
-		       netdev->name, netdev_addr ( netdev ) );
995
+		       "%s %s (%s)", product_short_name, netdev->name,
996
+		       netdev_addr ( netdev ) );
997 997
 	snpdev->name2.GetDriverName = efi_snp_get_driver_name;
998 998
 	snpdev->name2.GetControllerName = efi_snp_get_controller_name;
999 999
 	snpdev->name2.SupportedLanguages = "en";

+ 6
- 7
src/interface/efi/efi_snp_hii.c ファイルの表示

@@ -59,7 +59,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
59 59
 #include <ipxe/efi/efi_hii.h>
60 60
 #include <ipxe/efi/efi_snp.h>
61 61
 #include <ipxe/efi/efi_strings.h>
62
-#include <config/general.h>
63 62
 
64 63
 /** EFI configuration access protocol GUID */
65 64
 static EFI_GUID efi_hii_config_access_protocol_guid
@@ -162,7 +161,7 @@ efi_snp_hii_package_list ( struct efi_snp_device *snpdev ) {
162 161
 	struct device *dev = netdev->dev;
163 162
 	struct efi_ifr_builder ifr;
164 163
 	EFI_HII_PACKAGE_LIST_HEADER *package;
165
-	const char *product_name;
164
+	const char *name;
166 165
 	EFI_GUID package_guid;
167 166
 	EFI_GUID formset_guid;
168 167
 	EFI_GUID varstore_guid;
@@ -173,7 +172,7 @@ efi_snp_hii_package_list ( struct efi_snp_device *snpdev ) {
173 172
 	efi_ifr_init ( &ifr );
174 173
 
175 174
 	/* Determine product name */
176
-	product_name = ( PRODUCT_NAME[0] ? PRODUCT_NAME : PRODUCT_SHORT_NAME );
175
+	name = ( product_name[0] ? product_name : product_short_name );
177 176
 
178 177
 	/* Generate GUIDs */
179 178
 	efi_snp_hii_random_guid ( &package_guid );
@@ -181,13 +180,13 @@ efi_snp_hii_package_list ( struct efi_snp_device *snpdev ) {
181 180
 	efi_snp_hii_random_guid ( &varstore_guid );
182 181
 
183 182
 	/* Generate title string (used more than once) */
184
-	title_id = efi_ifr_string ( &ifr, "%s (%s)", product_name,
183
+	title_id = efi_ifr_string ( &ifr, "%s (%s)", name,
185 184
 				    netdev_addr ( netdev ) );
186 185
 
187 186
 	/* Generate opcodes */
188 187
 	efi_ifr_form_set_op ( &ifr, &formset_guid, title_id,
189
-			      efi_ifr_string ( &ifr,
190
-					       "Configure " PRODUCT_SHORT_NAME),
188
+			      efi_ifr_string ( &ifr, "Configure %s",
189
+					       product_short_name ),
191 190
 			      &efi_hii_platform_setup_formset_guid,
192 191
 			      &efi_hii_ibm_ucm_compliant_formset_guid, NULL );
193 192
 	efi_ifr_guid_class_op ( &ifr, EFI_NETWORK_DEVICE_CLASS );
@@ -197,7 +196,7 @@ efi_snp_hii_package_list ( struct efi_snp_device *snpdev ) {
197 196
 	efi_ifr_text_op ( &ifr,
198 197
 			  efi_ifr_string ( &ifr, "Name" ),
199 198
 			  efi_ifr_string ( &ifr, "Firmware product name" ),
200
-			  efi_ifr_string ( &ifr, "%s", product_name ) );
199
+			  efi_ifr_string ( &ifr, "%s", name ) );
201 200
 	efi_ifr_text_op ( &ifr,
202 201
 			  efi_ifr_string ( &ifr, "Version" ),
203 202
 			  efi_ifr_string ( &ifr, "Firmware version" ),

+ 2
- 2
src/net/tcp/oncrpc.c ファイルの表示

@@ -37,7 +37,7 @@
37 37
 #include <ipxe/oncrpc_iob.h>
38 38
 #include <ipxe/init.h>
39 39
 #include <ipxe/settings.h>
40
-#include <config/general.h>
40
+#include <ipxe/version.h>
41 41
 
42 42
 /** @file
43 43
  *
@@ -88,7 +88,7 @@ int oncrpc_init_cred_sys ( struct oncrpc_cred_sys *auth_sys ) {
88 88
 	fetch_string_setting_copy ( NULL, &hostname_setting,
89 89
 	                            &auth_sys->hostname );
90 90
 	if ( ! auth_sys->hostname )
91
-		if ( ! ( auth_sys->hostname = strdup ( PRODUCT_SHORT_NAME ) ) )
91
+		if ( ! ( auth_sys->hostname = strdup ( product_short_name ) ) )
92 92
 			return -ENOMEM;
93 93
 
94 94
 	auth_sys->uid         = fetch_uintz_setting ( NULL, &uid_setting );

+ 2
- 2
src/usr/autoboot.c ファイルの表示

@@ -499,10 +499,10 @@ void ipxe ( struct net_device *netdev ) {
499 499
 	 * do so.
500 500
 	 *
501 501
 	 */
502
-	printf ( NORMAL "\n\n" PRODUCT_NAME "\n" BOLD "iPXE %s"
502
+	printf ( NORMAL "\n\n%s\n" BOLD "iPXE %s"
503 503
 		 NORMAL " -- Open Source Network Boot Firmware -- "
504 504
 		 CYAN "http://ipxe.org" NORMAL "\n"
505
-		 "Features:", product_version );
505
+		 "Features:", product_name, product_version );
506 506
 	for_each_table_entry ( feature, FEATURES )
507 507
 		printf ( " %s", feature->name );
508 508
 	printf ( "\n" );

読み込み中…
キャンセル
保存