Added makefile machinary to generate the build information data
authorDavide Libenzi <dlibenzi@google.com>
Tue, 15 Dec 2015 03:15:35 +0000 (19:15 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 17 Dec 2015 20:42:28 +0000 (15:42 -0500)
Added makefile machinary to generate the build information data.
A kern/src/build_info.c is automatically generated, exporting build
information.

Signed-off-by: Davide Libenzi <dlibenzi@google.com>
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
.gitignore
Makefile
kern/arch/riscv/Makefile
kern/arch/x86/Makefile
kern/include/build_info.h [new file with mode: 0644]
kern/src/Kbuild

index 3dd25bd..20c022f 100644 (file)
@@ -19,6 +19,8 @@ ros-project.tmproj
 kern/boot
 kern/include/arch
 kern/src/arch
+kern/src/build_info.c
+kern/src/error.c
 user/parlib/include/arch
 Documentation/doxygen/rosdoc
 sim/
index 2bdcf79..bd19cad 100644 (file)
--- a/Makefile
+++ b/Makefile
 # their Makelocal. This is useful, for example, to allow emacs to find the
 # correct file when errors are encountered using its builtin 'M-x compile'
 # command.
+VERSION = 0
+PATCHLEVEL = 1
+SUBLEVEL = 0
+EXTRAVERSION =
+VERNAME = Nanwan
+
+KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
+
+export KERNELVERSION VERNAME
+
 NO_PRINT_DIRECTORY ?= --no-print-directory
 
 # Save the ability to export the parent's original environment for future use
@@ -83,6 +93,10 @@ export AKAROS_ROOT
 # generate for non-kbuild targets
 OBJDIR ?= obj
 
+# Don't need to export these, since the Makelocal is included.
+KERNEL_OBJ := $(OBJDIR)/kern/akaros-kernel
+CMP_KERNEL_OBJ := $(KERNEL_OBJ).gz
+
 # Symlinks
 # =========================================================================
 # We have a few symlinks so that code can include <arch/whatever.h>.  This
@@ -389,9 +403,8 @@ export CFLAGS_USER CXXFLAGS_USER CFLAGS_USER_LIBS
 # kernel build output.  Right now, it's only passed down to tests/
 dummy-1 := $(shell mkdir -p $(OBJDIR)/kern/)
 
-# Don't need to export these, since the Makelocal is included.
-KERNEL_OBJ := $(OBJDIR)/kern/akaros-kernel
-CMP_KERNEL_OBJ := $(KERNEL_OBJ).gz
+# Machinery to create the kernel build info source
+export BUILD_INFO_FILE
 
 # Since we're doing this outside of the dot-config part, some targets, such as
 # clean, won't read in our .config/auto.conf, and won't know about the
@@ -610,21 +623,11 @@ utestclean:
        @$(MAKE) -C user/utest clean
 
 # KFS related stuff
-PHONY += fill-kfs unfill-kfs create-build-file
+PHONY += fill-kfs unfill-kfs
 xcc-gcc-libs = $(XCC_TARGET_ROOT)/../lib/
 xcc-so-files = $(addprefix $(XCC_TARGET_LIB), *.so*) \
                $(addprefix $(xcc-gcc-libs), *.so*)
 
-KERNEL_ELF_PATH=$(abspath $(KERNEL_OBJ))-64b
-create-build-file:
-ifneq ($(INVARIANT_BUILD),1)
-               @echo "KernelPath: $(KERNEL_ELF_PATH)" > kern/kfs/etc/build.info
-               @echo "KernelSize: $(shell stat -c %s $(KERNEL_ELF_PATH))" >> \
-                       kern/kfs/etc/build.info
-               @echo "Date: `date`" >> kern/kfs/etc/build.info
-               @echo "Host: `hostname`" >> kern/kfs/etc/build.info
-endif
-
 $(OBJDIR)/.dont-force-fill-kfs:
        $(Q)rm -rf $(addprefix $(FIRST_KFS_PATH)/lib/, $(notdir $(xcc-so-files)))
        @echo "Cross Compiler 'so' files removed from KFS"
@@ -634,7 +637,7 @@ $(OBJDIR)/.dont-force-fill-kfs:
        @echo "User space tests removed from KFS"
        @touch $(OBJDIR)/.dont-force-fill-kfs
 
-fill-kfs: $(OBJDIR)/.dont-force-fill-kfs install-libs tests create-build-file
+fill-kfs: $(OBJDIR)/.dont-force-fill-kfs install-libs tests
        @mkdir -p $(FIRST_KFS_PATH)/lib
        $(Q)cp -uP $(xcc-so-files) $(FIRST_KFS_PATH)/lib
        @echo "Cross Compiler 'so' files installed to KFS"
index 2bd6e7e..4bbb35c 100644 (file)
@@ -1,3 +1,7 @@
 CROSS_COMPILE := riscv-ucb-akaros-
 # basically a nop.  this runs post-link of the kernel
 ARCH_POST_LINK_CMD = echo -n
+
+# Machinery to create the kernel build info source
+KERNEL_ELF_PATH := $(abspath $(KERNEL_OBJ))
+export KERNEL_ELF_PATH
index e1fdaaa..2d121f6 100644 (file)
@@ -8,5 +8,9 @@ LDFLAGS_KERNEL += -z max-page-size=0x1000
 # Need to change the format to 32 bit, to trick multiboot/grub1 into loading
 ARCH_POST_LINK_CMD = cp $@ $@-64b; $(OBJCOPY) -I elf64-x86-64 -O elf32-i386 $@
 
+# Machinery to create the kernel build info source
+KERNEL_ELF_PATH := $(abspath $(KERNEL_OBJ))-64b
+export KERNEL_ELF_PATH
+
 # BITS is used in Kbuilds, so we can select bit-specific source files.
 export BITS
diff --git a/kern/include/build_info.h b/kern/include/build_info.h
new file mode 100644 (file)
index 0000000..bc44f35
--- /dev/null
@@ -0,0 +1,15 @@
+/* Copyright (c) 2015 Google Inc
+ * Davide Libenzi <dlibenzi@google.com>
+ * See LICENSE for details.
+ */
+
+#pragma once
+
+#include <compiler.h>
+
+extern const char __weak build_info_kernel_path[];
+extern const char __weak build_info_date[];
+extern const char __weak build_info_host[];
+extern const char __weak build_info_commitid[];
+extern const char __weak build_info_version[];
+extern const char __weak build_info_version_name[];
index 939a914..c3af054 100644 (file)
@@ -7,12 +7,35 @@ $(src)/error.c: $(AKAROS_ROOT)/include/ros/errno.h
        @echo "};"                             >> $(@)
        @echo "const int MAX_ERRNO = sizeof(errno_strings)/sizeof(errno_strings[0]);" >> $(@)
 
+$(src)/build_info.c:
+ifeq ($(BUILD_INFO_FILE),)
+               @echo "/* Automatically generated. DO NOT EDIT! */" > $(@)
+               @echo "" >> $(@)
+               @echo "const char build_info_kernel_path[] = { \"$(KERNEL_ELF_PATH)\" };"\
+                       >> $(@)
+               @echo "const char build_info_date[] = { \"`date`\" };"\
+                       >> $(@)
+               @echo "const char build_info_host[] = { \"`hostname`\" };"\
+                       >> $(@)
+               @echo "const char build_info_commitid[] = { \"`git rev-parse HEAD`\" };"\
+                       >> $(@)
+               @echo "const char build_info_version[] = { \"$(KERNELVERSION)\" };"\
+                       >> $(@)
+               @echo "const char build_info_version_name[] = { \"$(VERNAME)\" };"\
+                       >> $(@)
+else
+               @cp $(BUILD_INFO_FILE) $(@)
+endif
+
+clean-files += build_info.c error.c
+
 obj-y                                          += alarm.o
 obj-y                                          += apipe.o
 obj-y                                          += arsc.o
 obj-y                                          += atomic.o
 obj-y                                          += bitmap.o
 obj-y                                          += blockdev.o
+obj-y                                          += build_info.o
 obj-y                                          += ceq.o
 obj-y                                          += colored_caches.o
 obj-y                                          += completion.o