Commit ea52ca1b authored by Kai Germaschewski's avatar Kai Germaschewski

kbuild: Restore build nr, improve vmlinux link

People relied on the build generation number to find out if they actually
booted the right kernel, only incrementing it on config changes isn't
enough for them. So this patch goes back to the old behavior, only done
right this time:

We now don't increment the generation number on every invocation of make, 
but on every link of vmlinux. At the same time, this patch fixes the
Makefile to only relink vmlinux if any of its prequisite object files
(or the command line) changed. Incrementing the version number
happens *after* we decided to relink vmlinux.
parent 5b281f91
...@@ -159,14 +159,25 @@ export CPPFLAGS CFLAGS CFLAGS_KERNEL AFLAGS AFLAGS_KERNEL ...@@ -159,14 +159,25 @@ export CPPFLAGS CFLAGS CFLAGS_KERNEL AFLAGS AFLAGS_KERNEL
export NETWORKS DRIVERS LIBS HEAD LDFLAGS LINKFLAGS MAKEBOOT ASFLAGS export NETWORKS DRIVERS LIBS HEAD LDFLAGS LINKFLAGS MAKEBOOT ASFLAGS
# Build vmlinux / boot target # boot target
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
boot: vmlinux boot: vmlinux
@$(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" AFLAGS="$(AFLAGS) $(AFLAGS_KERNEL)" -C arch/$(ARCH)/boot @$(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" AFLAGS="$(AFLAGS) $(AFLAGS_KERNEL)" -C arch/$(ARCH)/boot
vmlinux: include/linux/version.h $(CONFIGURATION) linuxsubdirs # Build vmlinux
$(LD) $(LINKFLAGS) $(HEAD) $(INIT) \ # ---------------------------------------------------------------------------
# This is a bit tricky: If we need to relink vmlinux, we want
# the version number incremented, which means recompile init/version.o
# and relink init/init.o. However, we cannot do this during the
# normal descending-into-subdirs phase, since at that time
# we cannot yet know if we will need to relink vmlinux.
# So we descend into init/ inside the rule for vmlinux again.
vmlinux-objs := $(HEAD) $(INIT) $(CORE_FILES) $(LIBS) $(DRIVERS) $(NETWORKS)
cmd_link_vmlinux = $(LD) $(LINKFLAGS) $(HEAD) $(INIT) \
--start-group \ --start-group \
$(CORE_FILES) \ $(CORE_FILES) \
$(LIBS) \ $(LIBS) \
...@@ -174,10 +185,33 @@ vmlinux: include/linux/version.h $(CONFIGURATION) linuxsubdirs ...@@ -174,10 +185,33 @@ vmlinux: include/linux/version.h $(CONFIGURATION) linuxsubdirs
$(NETWORKS) \ $(NETWORKS) \
--end-group \ --end-group \
-o vmlinux -o vmlinux
# set -e makes the rule exit immediately on error
define rule_link_vmlinux
set -e
echo Generating build number
. scripts/mkversion > .tmpversion
mv -f .tmpversion .version
$(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" AFLAGS="$(AFLAGS) $(AFLAGS_KERNEL)" -C init
echo $(cmd_link_vmlinux)
$(cmd_link_vmlinux)
echo 'cmd_$@ := $(cmd_link_vmlinux)' > $(@D)/.$(@F).cmd
$(NM) vmlinux | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map $(NM) vmlinux | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map
endef
vmlinux: $(CONFIGURATION) $(vmlinux-objs) dummy
$(call if_changed_rule,link_vmlinux)
# The actual objects are generated when descending, make sure
# no implicit rule kicks in
$(sort $(vmlinux-objs)): linuxsubdirs
@
# Handle descending into subdirectories listed in $(SUBDIRS) # Handle descending into subdirectories listed in $(SUBDIRS)
.PHONY: linuxsubdirs
linuxsubdirs: $(patsubst %, _dir_%, $(SUBDIRS)) linuxsubdirs: $(patsubst %, _dir_%, $(SUBDIRS))
$(patsubst %, _dir_%, $(SUBDIRS)) : dummy include/linux/version.h include/config/MARKER $(patsubst %, _dir_%, $(SUBDIRS)) : dummy include/linux/version.h include/config/MARKER
...@@ -214,8 +248,6 @@ symlinks: ...@@ -214,8 +248,6 @@ symlinks:
include/config/MARKER: scripts/split-include include/linux/autoconf.h include/config/MARKER: scripts/split-include include/linux/autoconf.h
scripts/split-include include/linux/autoconf.h include/config scripts/split-include include/linux/autoconf.h include/config
@ touch include/config/MARKER @ touch include/config/MARKER
. scripts/mkversion > .tmpversion
@mv -f .tmpversion .version
# Generate some files # Generate some files
...@@ -470,3 +502,12 @@ backup: mrproper ...@@ -470,3 +502,12 @@ backup: mrproper
sums: sums:
find . -type f -print | sort | xargs sum > .SUMS find . -type f -print | sort | xargs sum > .SUMS
# FIXME Should go into a make.lib or something
# ---------------------------------------------------------------------------
if_changed_rule = $(if $(strip $? \
$(filter-out $(cmd_$(1)),$(cmd_$(@F)))\
$(filter-out $(cmd_$(@F)),$(cmd_$(1)))),\
@$(rule_$(1)))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment