Commit 1e5a8730 authored by Kai Germaschewski's avatar Kai Germaschewski

kbuild: Use a standard "update-if-changed"

For some cases, we cannot decide if a target would change just by looking
at its prequisites, i.e. it's quite likely that it remains the same
even though a prequisite changed. The updated timestamp would cause
a lot of unnecessary recompiles. In this case, we actually generate
a temporary file, compare it to the old file and only the contents
are different do overwrite the old file.

The "update-if-changed" snippet remains always the same, so let's
put it into a macro instead of duplicating it. After that change,
scripts/mkversion_h is so small that we rather put the three remaining
lines directly into the Makefile.
parent 4e30f812
...@@ -301,7 +301,12 @@ include/linux/autoconf.h: .config ...@@ -301,7 +301,12 @@ include/linux/autoconf.h: .config
# this Makefile # this Makefile
include/linux/version.h: Makefile include/linux/version.h: Makefile
@scripts/mkversion_h $@ $(KERNELRELEASE) $(VERSION) $(PATCHLEVEL) $(SUBLEVEL) @echo -n 'Generating $@'
@(echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"; \
echo \#define LINUX_VERSION_CODE `expr $(VERSION) \\* 65536 + $(PATCHLEVEL) \\* 256 + $(SUBLEVEL)`; \
echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))'; \
) > $@.tmp
@$(update-if-changed)
# Helpers built in scripts/ # Helpers built in scripts/
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
...@@ -339,6 +344,7 @@ ifdef CONFIG_MODVERSIONS ...@@ -339,6 +344,7 @@ ifdef CONFIG_MODVERSIONS
include/linux/modversions.h: scripts/fixdep prepare FORCE include/linux/modversions.h: scripts/fixdep prepare FORCE
@rm -rf .tmp_export-objs @rm -rf .tmp_export-objs
@$(MAKE) $(patsubst %,_sfdep_%,$(SUBDIRS)) @$(MAKE) $(patsubst %,_sfdep_%,$(SUBDIRS))
@echo -n 'Generating $@'
@( echo "#ifndef _LINUX_MODVERSIONS_H";\ @( echo "#ifndef _LINUX_MODVERSIONS_H";\
echo "#define _LINUX_MODVERSIONS_H"; \ echo "#define _LINUX_MODVERSIONS_H"; \
echo "#include <linux/modsetver.h>"; \ echo "#include <linux/modsetver.h>"; \
...@@ -346,15 +352,8 @@ include/linux/modversions.h: scripts/fixdep prepare FORCE ...@@ -346,15 +352,8 @@ include/linux/modversions.h: scripts/fixdep prepare FORCE
echo "#include <linux/$${f}>"; \ echo "#include <linux/$${f}>"; \
done; \ done; \
echo "#endif"; \ echo "#endif"; \
) > $@.tmp ) > $@.tmp; \
@rm -rf .tmp_export-objs $(update-if-changed)
@if [ -r $@ ] && cmp -s $@ $@.tmp; then \
echo $@ was not updated; \
rm -f $@.tmp; \
else \
echo $@ was updated; \
mv -f $@.tmp $@; \
fi
$(patsubst %,_sfdep_%,$(SUBDIRS)): FORCE $(patsubst %,_sfdep_%,$(SUBDIRS)): FORCE
@$(MAKE) -C $(patsubst _sfdep_%, %, $@) fastdep @$(MAKE) -C $(patsubst _sfdep_%, %, $@) fastdep
...@@ -660,5 +659,15 @@ if_changed_rule = $(if $(strip $? \ ...@@ -660,5 +659,15 @@ if_changed_rule = $(if $(strip $? \
cmd = @$(if $($(quiet)$(1)),echo ' $($(quiet)$(1))' &&) $($(1)) cmd = @$(if $($(quiet)$(1)),echo ' $($(quiet)$(1))' &&) $($(1))
define update-if-changed
if [ -r $@ ] && cmp -s $@ $@.tmp; then \
echo ' (unchanged)'; \
rm -f $@.tmp; \
else \
echo ' (updated)'; \
mv -f $@.tmp $@; \
fi
endef
FORCE: FORCE:
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# The following temporary rule will make sure that people's # The following temporary rule will make sure that people's
# trees get updated to the right permissions, since patch(1) # trees get updated to the right permissions, since patch(1)
# can't do it # can't do it
CHMOD_FILES := docgen gen-all-syms kernel-doc mkcompile_h mkversion_h makelst CHMOD_FILES := docgen gen-all-syms kernel-doc mkcompile_h makelst
all: fixdep split-include $(CHMOD_FILES) all: fixdep split-include $(CHMOD_FILES)
......
TARGET=$1
KERNELRELEASE=$2
VERSION=$3
PATCHLEVEL=$4
SUBLEVEL=$5
# Generate a temporary version.h
( echo \#define UTS_RELEASE \"$KERNELRELEASE\"
echo \#define LINUX_VERSION_CODE `expr $VERSION \\* 65536 + $PATCHLEVEL \\* 256 + $SUBLEVEL`
echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))'
) > .tmpversion
# Only replace the real version.h if the new one is different
# in order to preserve the timestamp and avoid unnecessary
# recompilations.
if [ -r $TARGET ] && \
cmp -s $TARGET .tmpversion; then
echo $TARGET was not updated;
rm -f .tmpversion
else
echo $TARGET was updated;
mv -f .tmpversion $TARGET
fi
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