diff options
| author | Sam Ravnborg <sam@mars.ravnborg.org> | 2004-10-27 04:07:03 +0200 |
|---|---|---|
| committer | Sam Ravnborg <sam@mars.ravnborg.org> | 2004-10-27 04:07:03 +0200 |
| commit | 298039e7b2dc1bd12cb2944707ede23c8af770c4 (patch) | |
| tree | 2a5e7c2b681f7c97d64c276c91184bcc7406fadf | |
| parent | 6a7cb7739139cd5994a2be73e9c4088a70a568c2 (diff) | |
kbuild/usr: initramfs list fixed and simplified
Moving logic to scripts/gen_initramfs_list.sh make a nice cleanup in
usr/Makefile.
A new initramfs image will be generated if the initramfs_list file changes.
This patch also fixes the bug with make O=..
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
| -rw-r--r-- | scripts/Makefile.lib | 27 | ||||
| -rw-r--r-- | scripts/gen_initramfs_list.sh | 51 | ||||
| -rw-r--r-- | usr/Makefile | 29 | ||||
| -rw-r--r-- | usr/initramfs_list | 5 |
4 files changed, 71 insertions, 41 deletions
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 3a7663b901f0..6e75ced8b583 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -232,3 +232,30 @@ descend =$(Q)$(MAKE) -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build ob # Usage: # $(Q)$(MAKE) $(build)=dir build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj + +# filechk is used to check if the content of a generated file is updated. +# Sample usage: +# define filechk_sample +# echo $KERNELRELEASE +# endef +# version.h : Makefile +# $(call filechk,sample) +# The rule defined shall write to stdout the content of the new file. +# The existing file will be compared with the new one. +# - If no file exist it is created +# - If the content differ the new file is used +# - If they are equal no change, and no timestamp update + +define filechk + $(Q)set -e; \ + echo ' CHK $@'; \ + mkdir -p $(dir $@); \ + $(filechk_$(1)) $(2) > $@.tmp; \ + if [ -r $@ ] && cmp -s $@ $@.tmp; then \ + rm -f $@.tmp; \ + else \ + echo ' UPD $@'; \ + mv -f $@.tmp $@; \ + fi +endef + diff --git a/scripts/gen_initramfs_list.sh b/scripts/gen_initramfs_list.sh index 59b810396c7b..1d415792ac78 100644 --- a/scripts/gen_initramfs_list.sh +++ b/scripts/gen_initramfs_list.sh @@ -2,24 +2,25 @@ # Copyright (C) Martin Schlemmer <azarah@nosferatu.za.org> # Released under the terms of the GNU GPL # -# A script to generate newline separated entries (to stdout) from a directory's -# contents suitable for use as a cpio_list for gen_init_cpio. +# Generate a newline separated list of entries from the file/directory pointed +# out by the environment variable: CONFIG_INITRAMFS_SOURCE # -# Arguements: $1 -- the source directory +# If CONFIG_INITRAMFS_SOURCE is non-existing then generate a small dummy file. +# +# The output is suitable for gen_init_cpio as found in usr/Makefile. # # TODO: Add support for symlinks, sockets and pipes when gen_init_cpio # supports them. -usage() { - echo "Usage: $0 initramfs-source-dir" - exit 1 -} - -srcdir=$(echo "$1" | sed -e 's://*:/:g') +simple_initramfs() { + cat <<-EOF + # This is a very simple initramfs -if [ "$#" -gt 1 -o ! -d "${srcdir}" ]; then - usage -fi + dir /dev 0755 0 0 + nod /dev/console 0600 0 0 c 5 1 + dir /root 0700 0 0 + EOF +} filetype() { local argv1="$1" @@ -76,9 +77,27 @@ parse() { return 0 } -find "${srcdir}" -printf "%p %m %U %G\n" | \ -while read x; do - parse ${x} -done +if [ -z $1 ]; then + simple_initramfs +elif [ -f $1 ]; then + cat $1 +elif [ -d $1 ]; then + srcdir=$(echo "$1" | sed -e 's://*:/:g') + dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" 2>/dev/null) + + # If $dirlist is only one line, then the directory is empty + if [ "$(echo "${dirlist}" | wc -l)" -gt 1 ]; then + echo "${dirlist}" | \ + while read x; do + parse ${x} + done + else + # Failsafe in case directory is empty + simple_initramfs + fi +else + echo " $0: Cannot open '$1' (CONFIG_INITRAMFS_SOURCE)" >&2 + exit 1 +fi exit 0 diff --git a/usr/Makefile b/usr/Makefile index 96fe2c336da8..f269a5f7701f 100644 --- a/usr/Makefile +++ b/usr/Makefile @@ -3,7 +3,7 @@ obj-y := initramfs_data.o hostprogs-y := gen_init_cpio -clean-files := initramfs_data.cpio.gz +clean-files := initramfs_data.cpio.gz initramfs_list # If you want a different list of files in the initramfs_data.cpio # then you can either overwrite the cpio_list in this directory @@ -23,28 +23,17 @@ $(obj)/initramfs_data.o: $(obj)/initramfs_data.cpio.gz FORCE # Commented out for now # initramfs-y := $(obj)/root/hello -quiet_cmd_gen_list = GEN_INITRAMFS_LIST $@ - cmd_gen_list = $(shell \ - if test -f $(CONFIG_INITRAMFS_SOURCE); then \ - if [ $(CONFIG_INITRAMFS_SOURCE) != $@ ]; then \ - echo 'cp -f $(CONFIG_INITRAMFS_SOURCE) $@'; \ - else \ - echo 'echo Using shipped $@'; \ - fi; \ - elif test -d $(CONFIG_INITRAMFS_SOURCE); then \ - echo 'scripts/gen_initramfs_list.sh $(CONFIG_INITRAMFS_SOURCE) > $@'; \ - else \ - echo 'echo Using shipped $@'; \ - fi) - - -$(INITRAMFS_LIST): FORCE - $(call cmd,gen_list) +filechk_initramfs_list = $(CONFIG_SHELL) \ + $(srctree)/scripts/gen_initramfs_list.sh $(CONFIG_INITRAMFS_SOURCE) + +$(obj)/initramfs_list: FORCE + $(call filechk,initramfs_list) quiet_cmd_cpio = CPIO $@ - cmd_cpio = ./$< $(INITRAMFS_LIST) > $@ + cmd_cpio = ./$< $(obj)/initramfs_list > $@ -$(obj)/initramfs_data.cpio: $(obj)/gen_init_cpio $(initramfs-y) $(INITRAMFS_LIST) FORCE +$(obj)/initramfs_data.cpio: $(obj)/gen_init_cpio \ + $(initramfs-y) $(obj)/initramfs_list FORCE $(call if_changed,cpio) targets += initramfs_data.cpio diff --git a/usr/initramfs_list b/usr/initramfs_list deleted file mode 100644 index e631e61191b4..000000000000 --- a/usr/initramfs_list +++ /dev/null @@ -1,5 +0,0 @@ -# This is a very simple initramfs - mostly preliminary for future expansion - -dir /dev 0755 0 0 -nod /dev/console 0600 0 0 c 5 1 -dir /root 0700 0 0 |
