Skip to content

Commit

Permalink
[build] Include version number within only a single object file
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Nov 2, 2012
1 parent 0932bc5 commit 4867085
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 21 deletions.
5 changes: 0 additions & 5 deletions src/Makefile
Expand Up @@ -169,11 +169,6 @@ GITVERSION := $(shell git describe --always --abbrev=1 --match "" 2>/dev/null)
ifneq ($(GITVERSION),)
VERSION += ($(GITVERSION))
endif
CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) \
-DVERSION_MINOR=$(VERSION_MINOR) \
-DVERSION_PATCH=$(VERSION_PATCH) \
-DVERSION="\"$(VERSION)\""
IDENT = '$(@F) $(VERSION) (GPL) ipxe.org'
version :
@$(ECHO) "$(VERSION)"

Expand Down
7 changes: 7 additions & 0 deletions src/Makefile.housekeeping
Expand Up @@ -653,6 +653,13 @@ $(BIN)/embedded.o : override CC := env CCACHE_DISABLE=1 $(CC)

$(BIN)/clientcert.o : override CC := env CCACHE_DISABLE=1 $(CC)

# Version number
#
CFLAGS_version += -DVERSION_MAJOR=$(VERSION_MAJOR) \
-DVERSION_MINOR=$(VERSION_MINOR) \
-DVERSION_PATCH=$(VERSION_PATCH) \
-DVERSION="\"$(VERSION)\""

# We automatically generate rules for any file mentioned in AUTO_SRCS
# using the following set of templates. It would be cleaner to use
# $(eval ...), but this function exists only in GNU make >= 3.80.
Expand Down
5 changes: 4 additions & 1 deletion src/arch/i386/image/multiboot.c
Expand Up @@ -39,6 +39,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/init.h>
#include <ipxe/features.h>
#include <ipxe/uri.h>
#include <ipxe/version.h>

FEATURE ( FEATURE_IMAGE, "MBOOT", DHCP_EB_FEATURE_MULTIBOOT, 1 );

Expand Down Expand Up @@ -247,7 +248,7 @@ static struct multiboot_info __bss16 ( mbinfo );
#define mbinfo __use_data16 ( mbinfo )

/** The multiboot bootloader name */
static char __data16_array ( mb_bootloader_name, [] ) = "iPXE " VERSION;
static char __bss16_array ( mb_bootloader_name, [32] );
#define mb_bootloader_name __use_data16 ( mb_bootloader_name )

/** The multiboot memory map */
Expand Down Expand Up @@ -420,6 +421,8 @@ static int multiboot_exec ( struct image *image ) {
mbinfo.cmdline = multiboot_add_cmdline ( image );
mbinfo.mods_addr = virt_to_phys ( mbmodules );
mbinfo.mmap_addr = virt_to_phys ( mbmemmap );
snprintf ( mb_bootloader_name, sizeof ( mb_bootloader_name ),
"iPXE %s", product_version );
mbinfo.boot_loader_name = virt_to_phys ( mb_bootloader_name );
if ( ( rc = multiboot_add_modules ( image, max, &mbinfo, mbmodules,
( sizeof ( mbmodules ) /
Expand Down
11 changes: 5 additions & 6 deletions src/arch/i386/image/nbi.c
Expand Up @@ -10,6 +10,7 @@
#include <ipxe/fakedhcp.h>
#include <ipxe/image.h>
#include <ipxe/features.h>
#include <ipxe/version.h>

/** @file
*
Expand Down Expand Up @@ -94,12 +95,6 @@ struct ebinfo {
uint16_t flags; /* Bit flags */
};

/** Info passed to NBI image */
static struct ebinfo loaderinfo = {
VERSION_MAJOR, VERSION_MINOR,
0
};

/**
* Prepare a segment for an NBI image
*
Expand Down Expand Up @@ -281,6 +276,10 @@ static int nbi_boot16 ( struct image *image, struct imgheader *imgheader ) {
* @ret rc Return status code, if image returns
*/
static int nbi_boot32 ( struct image *image, struct imgheader *imgheader ) {
struct ebinfo loaderinfo = {
product_major_version, product_minor_version,
0
};
int discard_D, discard_S, discard_b;
int rc;

Expand Down
7 changes: 6 additions & 1 deletion src/arch/i386/interface/syslinux/comboot_call.c
Expand Up @@ -39,12 +39,13 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/serial.h>
#include <ipxe/init.h>
#include <ipxe/image.h>
#include <ipxe/version.h>
#include <usr/imgmgmt.h>
#include "config/console.h"
#include "config/serial.h"

/** The "SYSLINUX" version string */
static char __data16_array ( syslinux_version, [] ) = "\r\niPXE " VERSION;
static char __bss16_array ( syslinux_version, [32] );
#define syslinux_version __use_data16 ( syslinux_version )

/** The "SYSLINUX" copyright string */
Expand Down Expand Up @@ -326,6 +327,10 @@ static __asmcall void int22 ( struct i386_all_regs *ix86 ) {
/* SYSLINUX derivative ID */
ix86->regs.dl = BZI_LOADER_TYPE_IPXE;

/* SYSLINUX version */
snprintf ( syslinux_version, sizeof ( syslinux_version ),
"\r\niPXE %s", product_version );

/* SYSLINUX version and copyright strings */
ix86->segs.es = rm_ds;
ix86->regs.si = ( ( unsigned ) __from_data16 ( syslinux_version ) );
Expand Down
5 changes: 3 additions & 2 deletions src/core/main.c
Expand Up @@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/shell.h>
#include <ipxe/image.h>
#include <ipxe/keys.h>
#include <ipxe/version.h>
#include <usr/prompt.h>
#include <usr/autoboot.h>
#include <config/general.h>
Expand Down Expand Up @@ -82,10 +83,10 @@ __asmcall int main ( void ) {
* do so.
*
*/
printf ( NORMAL "\n\n" PRODUCT_NAME "\n" BOLD "iPXE " VERSION
printf ( NORMAL "\n\n" PRODUCT_NAME "\n" BOLD "iPXE %s"
NORMAL " -- Open Source Network Boot Firmware -- "
CYAN "http://ipxe.org" NORMAL "\n"
"Features:" );
"Features:", product_version );
for_each_table_entry ( feature, FEATURES )
printf ( " %s", feature->name );
printf ( "\n" );
Expand Down
41 changes: 41 additions & 0 deletions src/core/version.c
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/

FILE_LICENCE ( GPL2_OR_LATER );

/** @file
*
* Version number
*
*/

#include <ipxe/features.h>
#include <ipxe/version.h>

/** Version number feature */
FEATURE_VERSION ( VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH );

/** Product major version */
const int product_major_version = VERSION_MAJOR;

/** Product minor version */
const int product_minor_version = VERSION_MINOR;

/** Product version string */
const char *product_version = VERSION;
16 changes: 16 additions & 0 deletions src/include/ipxe/version.h
@@ -0,0 +1,16 @@
#ifndef _IPXE_VERSION_H
#define _IPXE_VERSION_H

/** @file
*
* Version number
*
*/

FILE_LICENCE ( GPL2_OR_LATER );

extern const int product_major_version;
extern const int product_minor_version;
extern const char *product_version;

#endif /* _IPXE_VERSION_H */
3 changes: 2 additions & 1 deletion src/interface/efi/efi_snp_hii.c
Expand Up @@ -54,6 +54,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/nvo.h>
#include <ipxe/device.h>
#include <ipxe/netdevice.h>
#include <ipxe/version.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_hii.h>
#include <ipxe/efi/efi_snp.h>
Expand Down Expand Up @@ -196,7 +197,7 @@ efi_snp_hii_package_list ( struct efi_snp_device *snpdev ) {
efi_ifr_text_op ( &ifr,
efi_ifr_string ( &ifr, "Version" ),
efi_ifr_string ( &ifr, "Firmware version" ),
efi_ifr_string ( &ifr, VERSION ) );
efi_ifr_string ( &ifr, "%s", product_version ) );
efi_ifr_text_op ( &ifr,
efi_ifr_string ( &ifr, "Driver" ),
efi_ifr_string ( &ifr, "Firmware driver" ),
Expand Down
5 changes: 3 additions & 2 deletions src/net/tcp/httpcore.c
Expand Up @@ -48,6 +48,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/md5.h>
#include <ipxe/blockdev.h>
#include <ipxe/acpi.h>
#include <ipxe/version.h>
#include <ipxe/http.h>

/* Disambiguate the various error causes */
Expand Down Expand Up @@ -1141,11 +1142,11 @@ static void http_step ( struct http_request *http ) {
/* Send request */
if ( ( rc = xfer_printf ( &http->socket,
"%s %s HTTP/1.1\r\n"
"User-Agent: iPXE/" VERSION "\r\n"
"User-Agent: iPXE/%s\r\n"
"Host: %s%s%s\r\n"
"%s%s%s"
"\r\n",
method, uri, http->uri->host,
method, uri, product_version, http->uri->host,
( http->uri->port ?
":" : "" ),
( http->uri->port ?
Expand Down
3 changes: 0 additions & 3 deletions src/net/udp/dhcp.c
Expand Up @@ -91,9 +91,6 @@ static uint8_t dhcp_request_options_data[] = {
DHCP_END
};

/** Version number feature */
FEATURE_VERSION ( VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH );

/** DHCP server address setting */
struct setting dhcp_server_setting __setting ( SETTING_MISC ) = {
.name = "dhcp-server",
Expand Down

0 comments on commit 4867085

Please sign in to comment.