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
# this 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/
# ---------------------------------------------------------------------------
......@@ -339,6 +344,7 @@ ifdef CONFIG_MODVERSIONS
include/linux/modversions.h: scripts/fixdep prepare FORCE
@rm -rf .tmp_export-objs
@$(MAKE) $(patsubst %,_sfdep_%,$(SUBDIRS))
@echo -n 'Generating $@'
@( echo "#ifndef _LINUX_MODVERSIONS_H";\
echo "#define _LINUX_MODVERSIONS_H"; \
echo "#include <linux/modsetver.h>"; \
......@@ -346,15 +352,8 @@ include/linux/modversions.h: scripts/fixdep prepare FORCE
echo "#include <linux/$${f}>"; \
done; \
echo "#endif"; \
) > $@.tmp
@rm -rf .tmp_export-objs
@if [ -r $@ ] && cmp -s $@ $@.tmp; then \
echo $@ was not updated; \
rm -f $@.tmp; \
else \
echo $@ was updated; \
mv -f $@.tmp $@; \
fi
) > $@.tmp; \
$(update-if-changed)
$(patsubst %,_sfdep_%,$(SUBDIRS)): FORCE
@$(MAKE) -C $(patsubst _sfdep_%, %, $@) fastdep
......@@ -660,5 +659,15 @@ if_changed_rule = $(if $(strip $? \
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:
......@@ -5,7 +5,7 @@
# The following temporary rule will make sure that people's
# trees get updated to the right permissions, since patch(1)
# 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)
......
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