Sam Ravnborg
2006-Apr-17 07:11 UTC
[klibc] [PATCH] klibc: rebuild cpio image when content changes
Generate dependencies almost like done by fixdep in the kernel. This teaches make to rebuild cpio image when content has changed. Also restructured usr/Kbuild a little so we better utilise parallel makes (dash, gzip, utils and kinit are now build in parallel). Signed-off-by: Sam Ravnborg <sam@ravnborg.org> --- patch is on top of hpa's linux tree, so path differ if applied to the klibc tree. This one has passed all my trivial testing. touch usr/kinit/kinit.o && make usr/ will regenerate cpio image. But with all the troubles this simple issue has caused me I woul not be suprised if there are some untested cornercase. Sam scripts/gen_initramfs_list.sh | 8 ++++++ usr/Kbuild | 52 ++++++++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/scripts/gen_initramfs_list.sh b/scripts/gen_initramfs_list.sh index 45c81b0..a609970 100644 --- a/scripts/gen_initramfs_list.sh +++ b/scripts/gen_initramfs_list.sh @@ -268,6 +268,14 @@ while [ $# -gt 0 ]; do esac done +# trailer of dependency list +if [ ! -z ${dep_list} ]; then + echo "" + echo "initramfs: \$(deps_initramfs)" + echo "\$(deps_initramfs): ;" + echo "" +fi + # If output_file is set we will generate cpio archive and gzip it # we are carefull to delete tmp files if [ ! -z ${output_file} ]; then diff --git a/usr/Kbuild b/usr/Kbuild index c4f5be2..e338cf9 100644 --- a/usr/Kbuild +++ b/usr/Kbuild @@ -8,21 +8,38 @@ export KLIBCINC := $(srctree)/$(src)/inc export KLIBCOBJ := $(objtree)/$(obj)/klibc CONFIG_KLIBC := 1 +klibc-subdir := klibc +usr-subdirs := kinit utils dash gzip +subdir- := $(klibc-subdir) $(usr-subdirs) + +usr-subdirs := $(addprefix _usr_,$(usr-subdirs)) +klibc-subdir := $(addprefix _usr_,$(klibc-subdir)) + # Klibc binaries ifdef CONFIG_KLIBC klibc := -f $(srctree)/scripts/Kbuild.klibc obj + +# .initramfs_data.cpio.gz.d is used to identify all files included +# in initramfs and to detect if any files are added/removed. +# Removed files are identified by directory timestamp being updated +# The dependency list is generated by gen_initramfs.sh -l +ifneq ($(wildcard $(obj)/.initramfs_data.cpio.gz.d),) + include $(obj)/.initramfs_data.cpio.gz.d +endif -.PHONY: klibcdirs -$(obj)/initramfs_list: klibcdirs +# build klibc library before the klibc programs +# build klibc programs before cpio.gz +.PHONY: initramfs $(usr-subdirs) $(klibc-subdir) +initramfs: $(usr-subdirs) $(klibc-subdir) +$(deps_initramfs): $(usr-subdirs) $(klibc-subdir) -klibcdirs: FORCE - $(Q)$(MAKE) $(klibc)=$(src)/klibc - $(Q)$(MAKE) $(klibc)=$(src)/kinit - $(Q)$(MAKE) $(klibc)=$(src)/utils - $(Q)$(MAKE) $(klibc)=$(src)/dash - $(Q)$(MAKE) $(klibc)=$(src)/gzip +$(usr-subdirs): $(klibc-subdir) + $(Q)$(MAKE) $(klibc)=$(src)/$(patsubst _usr_%,%,$(@)) + +$(klibc-subdir): + $(Q)$(MAKE) $(klibc)=$(src)/$(patsubst _usr_%,%,$(@)) endif -subdir- := klibc kinit utils dash gzip + # Generate builtin.o based on initramfs_data.o obj-y := initramfs_data.o @@ -36,7 +53,7 @@ ##### # Generate the initramfs cpio archive hostprogs-y := gen_init_cpio -initramfs := $(CONFIG_SHELL) $(srctree)/scripts/gen_initramfs_list.sh +ginitramfs := $(CONFIG_SHELL) $(srctree)/scripts/gen_initramfs_list.sh ramfs-input := $(shell echo $(CONFIG_INITRAMFS_SOURCE)) ramfs-input := $(if $(ramfs-input), $(ramfs-input), -d) @@ -44,26 +61,17 @@ ramfs-args := \ $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \ $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID)) \ $(ramfs-input) - -# .initramfs_data.cpio.gz.d is used to identify all files included -# in initramfs and to detect if any files are added/removed. -# Removed files are identified by directory timestamp being updated -# The dependency list is generated by gen_initramfs.sh -l -ifneq ($(wildcard $(obj)/.initramfs_data.cpio.gz.d),) - include $(obj)/.initramfs_data.cpio.gz.d -endif quiet_cmd_initfs = GEN $@ - cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input) + cmd_initfs = $(ginitramfs) -o $@ $(ramfs-args) $(ramfs-input) targets := initramfs_data.cpio.gz -$(deps_initramfs): klibcdirs # We rebuild initramfs_data.cpio.gz if: # 1) Any included file is newer then initramfs_data.cpio.gz # 2) There are changes in which files are included (added or deleted) # 3) If gen_init_cpio are newer than initramfs_data.cpio.gz # 4) arguments to gen_initramfs.sh changes -$(obj)/initramfs_data.cpio.gz: $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs - $(Q)$(initramfs) -l $(ramfs-input) > $(obj)/.initramfs_data.cpio.gz.d +$(obj)/initramfs_data.cpio.gz: $(obj)/gen_init_cpio $(deps_initramfs) initramfs + $(Q)$(ginitramfs) -l $(ramfs-input) > $(obj)/.initramfs_data.cpio.gz.d $(call if_changed,initfs)
Reasonably Related Threads
- [klibc 19/43] klibc basic build infrastructure
- [WIP] rebuild initramfs when content changes
- [PATCH] klibc: default initramfs content stored in usr/initramfs.default
- [PATCH] kbuild: fix usr/Kbuild to use new usr/gen_initramfs.sh
- [PATCH] kbuild: rebuild initramfs if included files changes