Hi Peter & others. Here are three patches that does the following: #1 - Update kbuild part of klibc so make clean works Adds gzip including a sample kbuild file #2 - Factor out definition of usr/ to two variables #3 - Move kbuild files to reflect location in the kernel As requested in earlier mail I need a bit of guidiance of what you expect from the kernel integrated parts of klibc. My plan is over time to kbuildtify klibc so only one buildsystem needs to be maintained. The challenge here is to include most of the features in current system without sacrifing the simplicity of the current syntax. This plan needs Peter's blessing before I continue though - and mainstream kernel integration is more fun - so that will be done first. Sam
Sam Ravnborg
2005-Jul-30 13:25 UTC
[klibc] kbuild: Update to latest kbuild tree changes, fix make clean, add gzip to kernel
This update requires the latest changes from the kbuild tree to be fully operational. The changes are planned to hit mainstream kernel when 2.6.14 opens up. This patch should work with older kernels too, except for the make clean functionality. Included in this patch: - Fixes so make clean is now working - Added gzip to kernel tree (in cp-to-kernel) including a small Kbuild file - Updated to latest Kbuild.include - Modified CFLAGS to match the klibc supplied values Signed-off-by: Sam Ravnborg <sam@ravnborg.org> --- commit 3d669f9229cb75affb2c13df3fff98f3c71dd94c tree dfc007f4217ee3499a8fbb4caac9efeb5a6eaf0d parent 5691e96ebfccd21a1f75d3518dd55a96b311d1aa author Sam Ravnborg <sam@mars.(none)> Sat, 30 Jul 2005 21:54:33 +0200 committer Sam Ravnborg <sam@mars.(none)> Sat, 30 Jul 2005 21:54:33 +0200 cp-to-kernel.sh | 14 ++++++- gzip/Kbuild | 49 ++++++++++++++++++++++++++ kernel/Kbuild | 13 ++++++- kernel/Kbuild.include | 86 +++++++++++++++++++++++++++++++++++----------- kernel/Kbuild.klibc | 12 ++++-- klibc/Kbuild | 5 ++- klibc/socketcalls/Kbuild | 4 ++ klibc/syscalls/Kbuild | 2 + 8 files changed, 153 insertions(+), 32 deletions(-) diff --git a/cp-to-kernel.sh b/cp-to-kernel.sh --- a/cp-to-kernel.sh +++ b/cp-to-kernel.sh @@ -12,7 +12,7 @@ fi kernel=$1 if [ ! -d $kernel ]; then - echo "$kernel is not a kernel directory" + echo "$kernel is not a directory" exit 1 fi @@ -32,8 +32,18 @@ if [ -z $2 ]; then cp -R include/* $kernel/usr/include fi +echo "Copying gzip" +if [ ! -d $kernel/usr/gzip ]; then + mkdir -p $kernel/usr/gzip +fi +cp -R gzip/* $kernel/usr/gzip + echo "Copying kbuild files" -cp kernel/Kbuild.* $kernel/scripts +cp kernel/Kbuild.klibc $kernel/scripts +# Newer kernel versions have Kbuild.include, so do not overwrite it +if [ ! -f $kernel/scripts/Kbuild.include ]; then + cp kernel/Kbuild.include $kernel/scripts +fi cp kernel/Kbuild $kernel/usr cp klibc/Kbuild $kernel/usr/klibc cp klibc/syscalls/Kbuild $kernel/usr/klibc/syscalls diff --git a/gzip/Kbuild b/gzip/Kbuild new file mode 100644 --- /dev/null +++ b/gzip/Kbuild @@ -0,0 +1,49 @@ + +user-progs := gzip +gzip-y := gzip.o util.o unzip.o inflate.o + +ifeq (a,b) + +Kept for convinience +ZIPSRCS = zip.c deflate.c trees.c bits.c +UNZIPSRCS = unzip.c inflate.c + +SRCS = gzip.c util.c $(UNZIPSRCS) +OBJS = $(SRCS:.c=.o) +HDRS = gzip.h tailor.h revision.h +LIBS = $(KLIBC) $(LIBGCC) + +ifeq ($(ZIP),y) +DEFS += -DSUPPORT_ZIP +SRCS += $(ZIPSRCS) +endif + +all: gzip gunzip zcat gzip.stripped + +# Actual build-related targets + +gzip: Makefile $(OBJS) $(CRT0) $(LIBS) + $(LD) $(LDFLAGS) -o $@ $(CRT0) $(OBJS) $(LIBS) + +gunzip: gzip + rm -f $@ + ln $< $@ + +zcat: gzip + rm -f $@ + ln $< $@ + +gzip.stripped: gzip + $(STRIP) $< -o $@ + +clean: + $(RM) -f core *.o gzip gunzip zcat gzip.stripped .*.d + +spotless: clean + rm -f *~ + +# These should presumably be shared... +install: all + $(INSTALL_EXEC) gzip gunzip zcat $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)bin + +endif diff --git a/kernel/Kbuild b/kernel/Kbuild --- a/kernel/Kbuild +++ b/kernel/Kbuild @@ -7,15 +7,26 @@ always := klibc/libc.a hostprogs-y := gen_init_cpio clean-files := initramfs_data.cpio.gz initramfs_list +# Descend down into klibc when cleaning +subdir- := klibc + # Build klibc library $(obj)/klibc/libc.a: FORCE $(Q)$(MAKE) -rR -f $(srctree)/scripts/Kbuild.klibc obj=$(obj)/klibc +initramfs-y += gzip + +initramfs-y := $(addprefix $(obj)/,$(initramfs-y)) +.PHONY: $(initramfs-y) + # initramfs_data.o contains the initramfs_data.cpio.gz image. # The image is included using .incbin, a dependency which is not # tracked automatically. $(obj)/initramfs_data.o: $(obj)/initramfs_data.cpio.gz FORCE +$(initramfs-y): $(obj)/klibc/libc.a + $(Q)$(MAKE) -f $(srctree)/scripts/Kbuild.klibc obj=$@ + ifdef CONFIG_INITRAMFS_ROOT_UID gen_initramfs_args += -u $(CONFIG_INITRAMFS_ROOT_UID) endif @@ -34,7 +45,7 @@ filechk_initramfs_list = $(CONFIG_SHELL) $(srctree)/scripts/gen_initramfs_list.sh $(gen_initramfs_args) \ $(quotefixed_initramfs_source) -$(obj)/initramfs_list: FORCE +$(obj)/initramfs_list: $(src)/Kbuild FORCE $(call filechk,initramfs_list) quiet_cmd_cpio = CPIO $@ diff --git a/kernel/Kbuild.include b/kernel/Kbuild.include --- a/kernel/Kbuild.include +++ b/kernel/Kbuild.include @@ -1,52 +1,96 @@ -# -# Generic kbuild routines -# +#### +# kbuild: Generic definitions +# Convinient variables +comma := , +empty :+space := $(empty) $(empty) + +### # The temporary file to save gcc -MD generated dependencies must not # contain a comma depfile = $(subst $(comma),_,$(@D)/.$(@F).d) +### +# 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 +# - stdin is piped in from the first prerequisite ($<) so one has +# to specify a valid file as first prerequisite (often the kbuild file) +define filechk + $(Q)set -e; \ + echo ' CHK $@'; \ + mkdir -p $(dir $@); \ + $(filechk_$(1)) < $< > $@.tmp; \ + if [ -r $@ ] && cmp -s $@ $@.tmp; then \ + rm -f $@.tmp; \ + else \ + echo ' UPD $@'; \ + mv -f $@.tmp $@; \ + fi +endef + +### +# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj+# Usage: +# $(Q)$(MAKE) $(build)=dir +build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj + +# If quiet is set, only print short version of command +cmd = @$(if $($(quiet)cmd_$(1)),\ + echo ' $(subst ','\'',$($(quiet)cmd_$(1)))' &&) $(cmd_$(1)) + +### +# if_changed - execute command if any prerequisite is newer than +# target, or command line has changed +# if_changed_dep - as if_changed, but uses fixdep to reveal dependencies +# including used config symbols +# if_changed_rule - as if_changed but execute rule instead +# See Documentation/kbuild/makefiles.txt for more info ifneq ($(KBUILD_NOCMDDEP),1) # Check if both arguments has same arguments. Result in empty string if equal # User may override this check using make KBUILD_NOCMDDEP=1 arg-check = $(strip $(filter-out $(1), $(2)) $(filter-out $(2), $(1)) ) - endif -# If quiet is set, only print short version of command -cmd = @$(if $($(quiet)cmd_$(1)),\ - echo ' $(subst ','\'',$($(quiet)cmd_$(1)))' &&) $(cmd_$(1)) - - # echo command. Short version is $(quiet) equals quiet, otherwise full command echo-cmd = $(if $($(quiet)cmd_$(1)), \ echo ' $(subst ','\'',$($(quiet)cmd_$(1)))';) # function to only execute the passed command if necessary -# >'< substitution is for echo to work, -# >$< substitution to preserve $ when reloading .cmd file -# note: when using inline perl scripts [perl -e '...$$t=1;...'] in -# $(cmd_xxx) double $$ your perl vars +# >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file +# note: when using inline perl scripts [perl -e '...$$t=1;...'] in $(cmd_xxx) double $$ your perl vars # if_changed = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ @set -e; \ $(echo-cmd) \ $(cmd_$(1)); \ - echo 'cmd_$@ := $(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' \ - > $(@D)/.$(@F).cmd) - + echo 'cmd_$@ := $(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).cmd) # execute the command and also postprocess generated .d dependencies # file -if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^) \ - $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ +if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\ + $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ @set -e; \ $(echo-cmd) \ $(cmd_$(1)); \ - scripts/basic/fixdep $(depfile) $@ \ - '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \ + scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \ rm -f $(depfile); \ mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd) - +# Usage: $(call if_changed_rule,foo) +# will check if $(cmd_foo) changed, or any of the prequisites changed, +# and if so will execute $(rule_foo) +if_changed_rule = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),\ + @set -e; \ + $(rule_$(1))) diff --git a/kernel/Kbuild.klibc b/kernel/Kbuild.klibc --- a/kernel/Kbuild.klibc +++ b/kernel/Kbuild.klibc @@ -31,8 +31,7 @@ KLIBSRC := usr/klibc # Arch specific definitions for klibc include $(KLIBSRC)/arch/$(ARCH)/MCONFIG -USERWARNFLAGS := -Wall -Wpointer-arith -Wwrite-strings \ - -Wstrict-prototypes -Winline +USERWARNFLAGS := -W -Wall -Wsign-compare USERCROSS := $(CROSS_COMPILE) @@ -48,9 +47,10 @@ USERCPPFLAGS := -I$(srctree)/usr/incl -I$(srctree)/usr/include \ -Iinclude \ $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) \ - -D__KLIBC__ -DBITSIZE=$(BITSIZE) -USERCFLAGS := $(USERCPPFLAGS) $(ARCHREQFLAGS) $(OPTFLAGS) \ - $(USERWARNFLAGS) + -D__KLIBC__=1 -D__KLIBC_MINOR__=0 \ + -DBITSIZE=$(BITSIZE) +USERCFLAGS := $(USERCPPFLAGS) $(REQFLAGS) $(ARCHREQFLAGS) \ + $(OPTFLAGS) $(USERWARNFLAGS) USERAFLAGS := -D__ASSEMBLY__ $(USERCPPFLAGS) USERSTRIPFLAGS := --strip-all -R .comment -R .note @@ -201,6 +201,7 @@ __build : $(user-dirs) $(user-progs) # Descend if needed $(sort $(addsuffix /built-in.o,$(user-dirs))): $(user-dirs) ; +# link program that has only a single .o file quiet_cmd_user-ld-single = USERLD $@ cmd_user-ld-single = $(USERLD) $(USERLDFLAGS) -o $@ \ $(USERCRT0) $< \ @@ -214,6 +215,7 @@ $(user-single): %: %.o $(USERCRT0) $(USE targets += $(user-single) $(user-single:=.o) +# link programs that consist of more than one .o file multi-deps = $($(subst $(obj)/,,$@-y)) link-multi-deps = $(addprefix $(obj)/, \ $(patsubst %/, %/built-in.o, $(multi-deps))) diff --git a/klibc/Kbuild b/klibc/Kbuild --- a/klibc/Kbuild +++ b/klibc/Kbuild @@ -119,6 +119,7 @@ $(SOLIB): $(CRT0) $(call objectify,__sha # Build sha1 hash values targets += klibc.so libc.so.hash hostprogs-y := sha1hash +clean-files += klibc-???????????????????????????.so quiet_cmd_solibhash = HASH $@ cmd_solibhash = $(USERNM) $< | egrep '^[0-9a-fA-F]+ [ADRTW] ' | \ @@ -129,7 +130,7 @@ $(SOLIB).hash: $(SOLIB) $(obj)/sha1hash quiet_cmd_sohash = GEN $@ cmd_sohash = cat $< > $@; \ $(USERSTRIP) $(USERSTRIPFLAGS) $@; \ - rm -f $(obj)/klibc-??????????????????????.so; \ + rm -f $(obj)/klibc-???????????????????????????.so; \ ln -f $@ $(obj)/klibc-`cat $(SOLIB).hash`.so $(SOHASH): $(SOLIB) $(SOLIB).hash $(call cmd,sohash) @@ -139,7 +140,7 @@ $(SOHASH): $(SOLIB) $(SOLIB).hash # build interp.o targets += interp.o -quiet_cmd_interp = BUILD $@ +quiet_cmd_interp = BUILD $@ cmd_interp = $(USERCC) $(usercflags) -D__ASSEMBLY__ \ -DLIBDIR=\"$(SHLIBDIR)\" \ -DSOHASH=\"`cat $(SOLIB).hash`\" \ diff --git a/klibc/socketcalls/Kbuild b/klibc/socketcalls/Kbuild --- a/klibc/socketcalls/Kbuild +++ b/klibc/socketcalls/Kbuild @@ -4,7 +4,9 @@ # Include automatically generated Makefile fragment. # It contains definition of socketcall-objs specifying name of all .o files +ifeq ($(clean),) -include $(obj)/socketcalls.mk +endif # Composite object containing all .o file always := socketcalls.o @@ -17,7 +19,7 @@ klibc-dir := $(srctree)/usr/klibc targets := socketcalls.o targets += socketcalls.mk targets += $(socketcall-objs) -clean-files += *.o +clean-files += *.S *.o # Create reloctable composite object file $(obj)/socketcalls.o: $(call objectify,$(socketcall-objs)) FORCE diff --git a/klibc/syscalls/Kbuild b/klibc/syscalls/Kbuild --- a/klibc/syscalls/Kbuild +++ b/klibc/syscalls/Kbuild @@ -4,7 +4,9 @@ # Include automatically generated Makefile fragment. # It contains definition of syscall-objs specifying name of all .o files +ifeq ($(clean),) -include $(obj)/syscalls.mk +endif # Composite object containing all .o file always := syscalls.o
Sam Ravnborg
2005-Jul-30 13:26 UTC
[klibc] [patch 2/3] kbuild: use KLIBSRC + KLIBINC consistent in kbuild files
Using KLIBSRC + KLIBINC all over the place allow os to centralize to a single place where we hardcode where in the kernel tree klibc is placed. While visiting the files alignment was fixed in a few spots. Signed-off-by: Sam Ravnborg <sam@ravnborg.org> --- commit 6327408a6bf07cf284adb344e982cb91b6eed4a7 tree 11a1bfe0719c8ebc39cfb95fce0bc0f8fa2a6d18 parent 3d669f9229cb75affb2c13df3fff98f3c71dd94c author Sam Ravnborg <sam@mars.(none)> Sat, 30 Jul 2005 22:07:11 +0200 committer Sam Ravnborg <sam@mars.(none)> Sat, 30 Jul 2005 22:07:11 +0200 kernel/Kbuild | 4 ++++ kernel/Kbuild.klibc | 11 +++++------ klibc/socketcalls/Kbuild | 14 ++++++-------- klibc/syscalls/Kbuild | 30 ++++++++++++++---------------- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/kernel/Kbuild b/kernel/Kbuild --- a/kernel/Kbuild +++ b/kernel/Kbuild @@ -2,6 +2,10 @@ # kbuild file for usr/ - including initramfs image and klibc # +klibc definitions - to be moved to top-level Makefile later +export KLIBSRC := $(srctree)/$(src)/klibc +export KLIBINC := $(srctree)/$(src)/include + obj-y := initramfs_data.o always := klibc/libc.a hostprogs-y := gen_init_cpio diff --git a/kernel/Kbuild.klibc b/kernel/Kbuild.klibc --- a/kernel/Kbuild.klibc +++ b/kernel/Kbuild.klibc @@ -26,7 +26,6 @@ include $(srctree)/scripts/Kbuild.includ # Defines used when compiling early userspace (klibc programs) # --------------------------------------------------------------------------- -KLIBSRC := usr/klibc # Arch specific definitions for klibc include $(KLIBSRC)/arch/$(ARCH)/MCONFIG @@ -42,9 +41,9 @@ USERRANLIB := $(USERCROSS)ranlib USERSTRIP := $(USERCROSS)strip USERNM := $(USERCROSS)nm -USERCPPFLAGS := -I$(srctree)/usr/include/arch/$(ARCH) \ - -I$(srctree)/usr/include/bits$(BITSIZE) \ - -I$(srctree)/usr/include \ +USERCPPFLAGS := -I$(KLIBINC)/arch/$(ARCH) \ + -I$(KLIBINC)/bits$(BITSIZE) \ + -I$(KLIBINC) \ -Iinclude \ $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) \ -D__KLIBC__=1 -D__KLIBC_MINOR__=0 \ @@ -56,8 +55,8 @@ USERSTRIPFLAGS := --strip-all -R .comme USERLIBGCC := $(shell $(USERCC) --print-libgcc) USERSHAREDFLAGS := $(SHAREDFLAGS) -USERCRT0 := $(objtree)/$(KLIBSRC)/arch/$(ARCH)/crt0.o -USERLIBC := $(objtree)/$(KLIBSRC)/libc.a +USERCRT0 := $(KLIBSRC)/arch/$(ARCH)/crt0.o +USERLIBC := $(KLIBSRC)/libc.a # # This indicates the location of the final version of the shared library. diff --git a/klibc/socketcalls/Kbuild b/klibc/socketcalls/Kbuild --- a/klibc/socketcalls/Kbuild +++ b/klibc/socketcalls/Kbuild @@ -11,8 +11,6 @@ endif # Composite object containing all .o file always := socketcalls.o -klibc-dir := $(srctree)/usr/klibc - ##### # Generate socket calls stubs # Based on input from SOCKETCALLS.def generate socket call stubs @@ -26,15 +24,15 @@ $(obj)/socketcalls.o: $(call objectify,$ $(call if_changed,userld) quiet_cmd_socketcalls = GEN $@ - cmd_socketcalls = $(PERL) $(klibc-dir)/socketcalls.pl \ - $(klibc-dir)/SOCKETCALLS.def \ + cmd_socketcalls = $(PERL) $(KLIBSRC)/socketcalls.pl \ + $(KLIBSRC)/SOCKETCALLS.def \ $(ARCH) $(obj) > $@ || rm -f $@ # Generate socketcall stubs -$(obj)/socketcalls.mk: $(klibc-dir)/socketcalls.pl \ - $(klibc-dir)/SOCKETCALLS.def \ - $(call objectify, $(socketcall-objs:.o=.S)) \ - $(klibc-dir)/socketcommon.h +$(obj)/socketcalls.mk: $(KLIBSRC)/socketcalls.pl \ + $(KLIBSRC)/SOCKETCALLS.def \ + $(call objectify, $(socketcall-objs:.o=.S)) \ + $(KLIBSRC)/socketcommon.h $(call cmd,socketcalls) diff --git a/klibc/syscalls/Kbuild b/klibc/syscalls/Kbuild --- a/klibc/syscalls/Kbuild +++ b/klibc/syscalls/Kbuild @@ -11,8 +11,6 @@ endif # Composite object containing all .o file always := syscalls.o -klibc-dir := $(srctree)/usr/klibc - ##### # Generate syscalls stubs @@ -24,7 +22,7 @@ targets += SYSCALLS.i syscalls.nrs targets += $(syscall-objs) # Side effect of running syscalls.pl -clean-files += $(objtree)/usr/include/klibc/havesyscall.h +clean-files += $(KLIBINC)/klibc/havesyscall.h # All the syscall stubs clean-files += *.o *.S *.c @@ -37,29 +35,29 @@ $(obj)/syscalls.o: $(call objectify,$(sy quiet_cmd_syscall.i = GEN $@ cmd_syscall.i = $(USERCC) $(usercflags) -D__ASSEMBLY__ \ -ansi -x assembler-with-cpp -E -o $@ $< -$(obj)/SYSCALLS.i: $(klibc-dir)/SYSCALLS.def FORCE +$(obj)/SYSCALLS.i: $(KLIBSRC)/SYSCALLS.def FORCE $(call if_changed_dep,syscall.i) # Get syscalls numbers quiet_cmd_syscall.nrs = GEN $@ cmd_syscall.nrs = $(USERCC) $(usercflags) -Wp,-dM -x c -E -o $@ $< -$(obj)/syscalls.nrs: $(srctree)/usr/include/sys/syscall.h FORCE +$(obj)/syscalls.nrs: $(KLIBINC)/sys/syscall.h FORCE $(call if_changed_dep,syscall.nrs) -# Generate usr/include/klibc/havesyscall.h + makefile fragment +# Generate $(KLIBINC)/klibc/havesyscall.h + makefile fragment # Using sysstub.pl in arch dir generate all .S files quiet_cmd_syscalls = GEN $@ - cmd_syscalls = mkdir -p $(objtree)/usr/include/klibc/; \ - $(PERL) $(klibc-dir)/syscalls.pl $(obj)/SYSCALLS.i \ - $(klibc-dir)/arch/$(ARCH)/sysstub.ph \ - $(ARCH) $(BITSIZE) $(obj)/syscalls.nrs \ - $(obj) \ - $(objtree)/usr/include/klibc/havesyscall.h > $@ \ + cmd_syscalls = mkdir -p $(KLIBINC)/klibc/; \ + $(PERL) $(KLIBSRC)/syscalls.pl $(obj)/SYSCALLS.i \ + $(KLIBSRC)/arch/$(ARCH)/sysstub.ph \ + $(ARCH) $(BITSIZE) $(obj)/syscalls.nrs \ + $(obj) \ + $(KLIBINC)/klibc/havesyscall.h > $@ \ || rm -f $@ -$(obj)/syscalls.mk: $(klibc-dir)/syscalls.pl $(obj)/SYSCALLS.i \ - $(klibc-dir)/arch/$(ARCH)/sysstub.ph \ - $(call objectify, $(syscall-objs:.o=.S)) \ - $(klibc-dir)/syscommon.h $(obj)/syscalls.nrs +$(obj)/syscalls.mk: $(KLIBSRC)/syscalls.pl $(obj)/SYSCALLS.i \ + $(KLIBSRC)/arch/$(ARCH)/sysstub.ph \ + $(call objectify, $(syscall-objs:.o=.S)) \ + $(KLIBSRC)/syscommon.h $(obj)/syscalls.nrs $(call cmd,syscalls)
Sam Ravnborg
2005-Jul-30 13:27 UTC
[klibc] [patch 3/3] kbuild: move kbuild files to reflects directory structure in the kernel
To make it more obvious where the files are supposed to end up move files so they reflect the directory structure in the kernel. mkdir usr mv kernel/Kbuild usr mkdir scripts mv kernel/* scripts/ rmdir kernel Furthermore updated cp-to-kernel to refelct new directory layout And added '#' in front of comment in usr/Kbuild Signed-off-by: Sam Ravnborg <sam@ravnborg.org> --- commit 6b1838e0265930a078ab79815dfa8fe86102a562 tree a704f20950106726a2c91b4882ac8ed60a971e81 parent 6327408a6bf07cf284adb344e982cb91b6eed4a7 author Sam Ravnborg <sam@mars.(none)> Sat, 30 Jul 2005 22:19:06 +0200 committer Sam Ravnborg <sam@mars.(none)> Sat, 30 Jul 2005 22:19:06 +0200 cp-to-kernel.sh | 6 + kernel/Kbuild | 87 --------------- kernel/Kbuild.include | 96 ---------------- kernel/Kbuild.klibc | 282 ------------------------------------------------ scripts/Kbuild.include | 96 ++++++++++++++++ scripts/Kbuild.klibc | 282 ++++++++++++++++++++++++++++++++++++++++++++++++ usr/Kbuild | 87 +++++++++++++++ 7 files changed, 468 insertions(+), 468 deletions(-) diff --git a/cp-to-kernel.sh b/cp-to-kernel.sh --- a/cp-to-kernel.sh +++ b/cp-to-kernel.sh @@ -39,12 +39,12 @@ fi cp -R gzip/* $kernel/usr/gzip echo "Copying kbuild files" -cp kernel/Kbuild.klibc $kernel/scripts +cp scripts/Kbuild.klibc $kernel/scripts # Newer kernel versions have Kbuild.include, so do not overwrite it if [ ! -f $kernel/scripts/Kbuild.include ]; then - cp kernel/Kbuild.include $kernel/scripts + cp scripts/Kbuild.include $kernel/scripts fi -cp kernel/Kbuild $kernel/usr +cp usr/Kbuild $kernel/usr cp klibc/Kbuild $kernel/usr/klibc cp klibc/syscalls/Kbuild $kernel/usr/klibc/syscalls cp klibc/socketcalls/Kbuild $kernel/usr/klibc/socketcalls diff --git a/kernel/Kbuild b/kernel/Kbuild deleted file mode 100644 --- a/kernel/Kbuild +++ /dev/null @@ -1,87 +0,0 @@ -# -# kbuild file for usr/ - including initramfs image and klibc -# - -klibc definitions - to be moved to top-level Makefile later -export KLIBSRC := $(srctree)/$(src)/klibc -export KLIBINC := $(srctree)/$(src)/include - -obj-y := initramfs_data.o -always := klibc/libc.a -hostprogs-y := gen_init_cpio -clean-files := initramfs_data.cpio.gz initramfs_list - -# Descend down into klibc when cleaning -subdir- := klibc - -# Build klibc library -$(obj)/klibc/libc.a: FORCE - $(Q)$(MAKE) -rR -f $(srctree)/scripts/Kbuild.klibc obj=$(obj)/klibc - -initramfs-y += gzip - -initramfs-y := $(addprefix $(obj)/,$(initramfs-y)) -.PHONY: $(initramfs-y) - -# initramfs_data.o contains the initramfs_data.cpio.gz image. -# The image is included using .incbin, a dependency which is not -# tracked automatically. -$(obj)/initramfs_data.o: $(obj)/initramfs_data.cpio.gz FORCE - -$(initramfs-y): $(obj)/klibc/libc.a - $(Q)$(MAKE) -f $(srctree)/scripts/Kbuild.klibc obj=$@ - -ifdef CONFIG_INITRAMFS_ROOT_UID -gen_initramfs_args += -u $(CONFIG_INITRAMFS_ROOT_UID) -endif - -ifdef CONFIG_INITRAMFS_ROOT_GID -gen_initramfs_args += -g $(CONFIG_INITRAMFS_ROOT_GID) -endif - -# The $(shell echo $(CONFIG_INITRAMFS_SOURCE)) is to remove the -# gratuitous begin and end quotes from the Kconfig string type. -# Internal, escaped quotes in the Kconfig string will loose the -# escape and become active quotes. -quotefixed_initramfs_source := $(shell echo $(CONFIG_INITRAMFS_SOURCE)) - -filechk_initramfs_list = $(CONFIG_SHELL) \ - $(srctree)/scripts/gen_initramfs_list.sh $(gen_initramfs_args) \ - $(quotefixed_initramfs_source) - -$(obj)/initramfs_list: $(src)/Kbuild FORCE - $(call filechk,initramfs_list) - -quiet_cmd_cpio = CPIO $@ - cmd_cpio = ./$< $(obj)/initramfs_list > $@ - - -# Check if the INITRAMFS_SOURCE is a cpio archive -ifneq (,$(findstring .cpio,$(quotefixed_initramfs_source))) - -# INITRAMFS_SOURCE has a cpio archive - verify that it's a single file -ifneq (1,$(words $(quotefixed_initramfs_source))) -$(error Only a single file may be specified in CONFIG_INITRAMFS_SOURCE (="$(quotefixed_initramfs_source)") when a cpio archive is directly specified.) -endif -# Now use the cpio archive directly -initramfs_data_cpio = $(quotefixed_initramfs_source) -targets += $(quotefixed_initramfs_source) - -else - -# INITRAMFS_SOURCE is not a cpio archive - create one -$(obj)/initramfs_data.cpio: $(obj)/gen_init_cpio \ - $(initramfs-y) $(obj)/initramfs_list FORCE - $(call if_changed,cpio) - -targets += initramfs_data.cpio -initramfs_data_cpio = $(obj)/initramfs_data.cpio - -endif - - -$(obj)/initramfs_data.cpio.gz: $(initramfs_data_cpio) FORCE - $(call if_changed,gzip) - -targets += initramfs_data.cpio.gz - diff --git a/kernel/Kbuild.include b/kernel/Kbuild.include deleted file mode 100644 --- a/kernel/Kbuild.include +++ /dev/null @@ -1,96 +0,0 @@ -#### -# kbuild: Generic definitions - -# Convinient variables -comma := , -empty :-space := $(empty) $(empty) - -### -# The temporary file to save gcc -MD generated dependencies must not -# contain a comma -depfile = $(subst $(comma),_,$(@D)/.$(@F).d) - -### -# 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 -# - stdin is piped in from the first prerequisite ($<) so one has -# to specify a valid file as first prerequisite (often the kbuild file) -define filechk - $(Q)set -e; \ - echo ' CHK $@'; \ - mkdir -p $(dir $@); \ - $(filechk_$(1)) < $< > $@.tmp; \ - if [ -r $@ ] && cmp -s $@ $@.tmp; then \ - rm -f $@.tmp; \ - else \ - echo ' UPD $@'; \ - mv -f $@.tmp $@; \ - fi -endef - -### -# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj-# Usage: -# $(Q)$(MAKE) $(build)=dir -build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj - -# If quiet is set, only print short version of command -cmd = @$(if $($(quiet)cmd_$(1)),\ - echo ' $(subst ','\'',$($(quiet)cmd_$(1)))' &&) $(cmd_$(1)) - -### -# if_changed - execute command if any prerequisite is newer than -# target, or command line has changed -# if_changed_dep - as if_changed, but uses fixdep to reveal dependencies -# including used config symbols -# if_changed_rule - as if_changed but execute rule instead -# See Documentation/kbuild/makefiles.txt for more info - -ifneq ($(KBUILD_NOCMDDEP),1) -# Check if both arguments has same arguments. Result in empty string if equal -# User may override this check using make KBUILD_NOCMDDEP=1 -arg-check = $(strip $(filter-out $(1), $(2)) $(filter-out $(2), $(1)) ) -endif - -# echo command. Short version is $(quiet) equals quiet, otherwise full command -echo-cmd = $(if $($(quiet)cmd_$(1)), \ - echo ' $(subst ','\'',$($(quiet)cmd_$(1)))';) - -# function to only execute the passed command if necessary -# >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file -# note: when using inline perl scripts [perl -e '...$$t=1;...'] in $(cmd_xxx) double $$ your perl vars -# -if_changed = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ - @set -e; \ - $(echo-cmd) \ - $(cmd_$(1)); \ - echo 'cmd_$@ := $(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).cmd) - -# execute the command and also postprocess generated .d dependencies -# file -if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\ - $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ - @set -e; \ - $(echo-cmd) \ - $(cmd_$(1)); \ - scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \ - rm -f $(depfile); \ - mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd) - -# Usage: $(call if_changed_rule,foo) -# will check if $(cmd_foo) changed, or any of the prequisites changed, -# and if so will execute $(rule_foo) -if_changed_rule = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),\ - @set -e; \ - $(rule_$(1))) diff --git a/kernel/Kbuild.klibc b/kernel/Kbuild.klibc deleted file mode 100644 --- a/kernel/Kbuild.klibc +++ /dev/null @@ -1,282 +0,0 @@ -# =========================================================================-# Support for building klibc and related programs -# =========================================================================-# -# To create a kbuild file for a userspace program do the following: -# -# Kbuild: -# -# user-progs := cat -# -# This will compile a file named cat.c -> the executable 'cat' -# -# If the user space program consist of more files do the following: -# Kbuild: -# -# user-progs := ipconfig -# ipconfig-y := main.o netdev.c - -src := $(obj) - -.phony: __build -__build: - -# Generic Kbuild routines -include $(srctree)/scripts/Kbuild.include - -# Defines used when compiling early userspace (klibc programs) -# --------------------------------------------------------------------------- - -# Arch specific definitions for klibc -include $(KLIBSRC)/arch/$(ARCH)/MCONFIG - -USERWARNFLAGS := -W -Wall -Wsign-compare - -USERCROSS := $(CROSS_COMPILE) - -USERLD := $(USERCROSS)ld -USERCC := $(USERCROSS)gcc -USERAR := $(USERCROSS)ar -USERRANLIB := $(USERCROSS)ranlib -USERSTRIP := $(USERCROSS)strip -USERNM := $(USERCROSS)nm - -USERCPPFLAGS := -I$(KLIBINC)/arch/$(ARCH) \ - -I$(KLIBINC)/bits$(BITSIZE) \ - -I$(KLIBINC) \ - -Iinclude \ - $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) \ - -D__KLIBC__=1 -D__KLIBC_MINOR__=0 \ - -DBITSIZE=$(BITSIZE) -USERCFLAGS := $(USERCPPFLAGS) $(REQFLAGS) $(ARCHREQFLAGS) \ - $(OPTFLAGS) $(USERWARNFLAGS) -USERAFLAGS := -D__ASSEMBLY__ $(USERCPPFLAGS) -USERSTRIPFLAGS := --strip-all -R .comment -R .note - -USERLIBGCC := $(shell $(USERCC) --print-libgcc) -USERSHAREDFLAGS := $(SHAREDFLAGS) -USERCRT0 := $(KLIBSRC)/arch/$(ARCH)/crt0.o -USERLIBC := $(KLIBSRC)/libc.a - -# -# This indicates the location of the final version of the shared library. -# THIS MUST BE AN ABSOLUTE PATH WITH NO FINAL SLASH. -# Leave this empty to make it the root. -# -SHLIBDIR = /lib - -export USERLD USERCC USERAR USERSTRIP USERNM -export USERCFLAGS USERAFLAGS USERLIBGCC USERSHAREDFLAGS USERSTRIPFLAGS -export USERCRT0 USERLIBC SHLIBDIR - -# kernel configuration -include .config - -# Add $(obj)/ for paths that is not absolute -objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o))) - -# Kbuild file in the directory that is being build -include $(obj)/Kbuild - -##### -# user-progs := handling - -# user-progs based on a single .c file (with same name) -user-single := $(foreach p, $(user-progs), $(if $($(p)-y),,$(p))) - -# user-progs which is based on several .o files -user-multi := $(foreach p, $(user-progs), $(if $($(p)-y),$(p))) -# objects used for user-progs with more then one .o file -user-multi-objs := $(foreach p, $(user-multi), $($(p)-y)) -# objects build in this dir -user-real-objs := $(patsubst %/,,$(user-multi-objs)) -# Directories we need to visit before user-multi-obs are up-to-date -user-dirs := $(patsubst %/,%,$(filter %/, $(user-multi-objs))) -# replace all dir/ with dir/built-in.o -user-multi-objs := $(patsubst %/, %/built-in.o, $(user-multi-objs)) - -# $(output-dirs) are a list of directories that contain object files -output-dirs := $(dir $(user-dirs)) -output-dirs += $(foreach f, $(hostprogs-y) $(targets), \ - $(if $(dir $(f)), $(dir $(f)))) -output-dirs := $(strip $(sort $(filter-out ./,$(output-dirs)))) - -# prefix so we get full dir -user-progs := $(addprefix $(obj)/,$(user-progs)) -user-single := $(addprefix $(obj)/,$(user-single)) -user-multi := $(addprefix $(obj)/,$(user-multi)) -user-multi-objs := $(addprefix $(obj)/,$(user-multi-objs)) -user-real-objs := $(addprefix $(obj)/,$(user-real-objs)) -output-dirs := $(addprefix $(obj)/,$(output-dirs)) -user-dirs := $(addprefix $(obj)/,$(user-dirs)) -subdir-y := $(addprefix $(obj)/,$(subdir-y)) -always := $(addprefix $(obj)/,$(always)) -targets := $(addprefix $(obj)/,$(targets)) - - -_usercflags = $(USERCFLAGS) $(EXTRA_USERCFLAGS) $(USERCFLAGS_$(*F).o) -_useraflags = $(USERAFLAGS) $(EXTRA_USERAFLAGS) $(USERAFLAGS_$(*F).o) - -usercflags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(_usercflags) -useraflags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(_useraflags) - -ifneq ($(KBUILD_SRC),) -# Create output directory if not already present -_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj)) - -# Create directories for object files if directory does not exist -# Needed when obj-y := dir/file.o syntax is used -_dummy := $(foreach d,$(output-dirs), $(shell [ -d $(d) ] || mkdir -p $(d))) -endif - -# Do we have to make a built-in.o in this dir? -ifneq ($(strip $(obj-y) $(obj-n) $(obj-)),) -builtin-target := $(obj)/built-in.o -endif - -__build: $(subdir-y) $(builtin-target) $(always) - @: - -# Compile C sources (.c) -# --------------------------------------------------------------------------- - -quiet_cmd_cc_s_c = USERCC $@ - cmd_cc_s_c = $(USERCC) $(usercflags) -S -o $@ $< - -%.s: %.c FORCE - $(call if_changed_dep,cc_s_c) - -quiet_cmd_cc_i_c = USERCPP $@ - cmd_cc_i_c = $(USERCPP) $(usercflags) -o $@ $< - -%.i: %.c FORCE - $(call if_changed_dep,cc_i_c) - -quiet_cmd_cc_o_c = USERCC $@ - cmd_cc_o_c = $(USERCC) $(usercflags) -c -o $@ $< - -%.o: %.c FORCE - $(call if_changed_dep,cc_o_c) - -# Compile assembler sources (.S) -# --------------------------------------------------------------------------- - -quiet_cmd_as_s_S = USERCPP $@ - cmd_as_s_S = $(USERCPP) $(useraflags) -o $@ $< - -%.s: %.S FORCE - $(call if_changed_dep,as_s_S) - -quiet_cmd_as_o_S = USERAS $@ - cmd_as_o_S = $(USERCC) $(useraflags) -c -o $@ $< - -%.o: %.S FORCE - $(call if_changed_dep,as_o_S) - -targets += $(real-objs-y) - -# -# Rule to compile a set of .o files into one .o file -# -ifdef builtin-target -quiet_cmd_link_o_target = LD $@ -# If the list of objects to link is empty, just create an empty built-in.o -cmd_link_o_target = $(if $(strip $(obj-y)),\ - $(USERLD) $(USERLDFLAGS) -r -o $@ $(filter $(obj-y), $^),\ - rm -f $@; $(AR) rcs $@) - -$(builtin-target): $(obj-y) FORCE - $(call if_changed,link_o_target) -targets += $(builtin-target) -endif # builtin-target - - -ifdef user-progs -# Compile userspace programs for the target -# ==========================================================================- -__build : $(user-dirs) $(user-progs) - -# Descend if needed -$(sort $(addsuffix /built-in.o,$(user-dirs))): $(user-dirs) ; - -# link program that has only a single .o file -quiet_cmd_user-ld-single = USERLD $@ - cmd_user-ld-single = $(USERLD) $(USERLDFLAGS) -o $@ \ - $(USERCRT0) $< \ - $(filter-out FORCE,$^) \ - $(USERLIBC) $(USERLIBGCC) \ - $(USERLIBGCC); \ - $(USERSTRIP) $(USERSTRIPFLAGS) $@ - -$(user-single): %: %.o $(USERCRT0) $(USERLIBC) FORCE - $(call if_changed,user-ld-single) - -targets += $(user-single) $(user-single:=.o) - -# link programs that consist of more than one .o file -multi-deps = $($(subst $(obj)/,,$@-y)) -link-multi-deps = $(addprefix $(obj)/, \ - $(patsubst %/, %/built-in.o, $(multi-deps))) - -quiet_cmd_user-ld-multi = USERLD $@ - cmd_user-ld-multi = $(USERLD) $(USERLDFLAGS) -o $@ \ - $(USERCRT0) \ - $(link-multi-deps) \ - $(USERLIBC) $(USERLIBGCC) \ - $(USERLIBGCC); \ - $(USERSTRIP) $(USERSTRIPFLAGS) $@ - -$(user-multi): $(user-multi-objs) FORCE - $(call if_changed,user-ld-multi) - -targets += $(user-multi) $(user-real-objs) -endif - - -# Compile programs on the host -# ==========================================================================-ifdef hostprogs-y -include $(srctree)/scripts/Makefile.host -endif - -# Descending -# --------------------------------------------------------------------------- - -.PHONY: $(subdir-y) $(user-dirs) -$(subdir-y) $(user-dirs): - $(Q)$(MAKE) $(klibc)=$@ - -# Add FORCE to the prequisites of a target to force it to be always rebuilt. -# --------------------------------------------------------------------------- - -.PHONY: FORCE - -FORCE: - -# Linking -# Create a reloctable composite object file -# --------------------------------------------------------------------------- -quiet_cmd_userld = USERLD $@ - cmd_userld = $(USERLD) -r $(USERLDFLAGS) \ - $(EXTRA_USERLDFLAGS) $(USERLDFLAGS_$(@F)) \ - $(filter-out FORCE,$^) -o $@ - - -# Read all saved command lines and dependencies for the $(targets) we -# may be building above, using $(if_changed{,_dep}). As an -# optimization, we don't need to read them if the target does not -# exist, we will rebuild anyway in that case. - -targets := $(wildcard $(sort $(targets))) -cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) - -ifneq ($(cmd_files),) - include $(cmd_files) -endif - -# Shorthand for $(Q)$(MAKE) -f scripts/Kbuild.klibc obj -# Usage: -# $(Q)$(MAKE) $(klibc)=dir -klibc := -rR -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Kbuild.klibc obj - diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include new file mode 100644 --- /dev/null +++ b/scripts/Kbuild.include @@ -0,0 +1,96 @@ +#### +# kbuild: Generic definitions + +# Convinient variables +comma := , +empty :+space := $(empty) $(empty) + +### +# The temporary file to save gcc -MD generated dependencies must not +# contain a comma +depfile = $(subst $(comma),_,$(@D)/.$(@F).d) + +### +# 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 +# - stdin is piped in from the first prerequisite ($<) so one has +# to specify a valid file as first prerequisite (often the kbuild file) +define filechk + $(Q)set -e; \ + echo ' CHK $@'; \ + mkdir -p $(dir $@); \ + $(filechk_$(1)) < $< > $@.tmp; \ + if [ -r $@ ] && cmp -s $@ $@.tmp; then \ + rm -f $@.tmp; \ + else \ + echo ' UPD $@'; \ + mv -f $@.tmp $@; \ + fi +endef + +### +# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj+# Usage: +# $(Q)$(MAKE) $(build)=dir +build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj + +# If quiet is set, only print short version of command +cmd = @$(if $($(quiet)cmd_$(1)),\ + echo ' $(subst ','\'',$($(quiet)cmd_$(1)))' &&) $(cmd_$(1)) + +### +# if_changed - execute command if any prerequisite is newer than +# target, or command line has changed +# if_changed_dep - as if_changed, but uses fixdep to reveal dependencies +# including used config symbols +# if_changed_rule - as if_changed but execute rule instead +# See Documentation/kbuild/makefiles.txt for more info + +ifneq ($(KBUILD_NOCMDDEP),1) +# Check if both arguments has same arguments. Result in empty string if equal +# User may override this check using make KBUILD_NOCMDDEP=1 +arg-check = $(strip $(filter-out $(1), $(2)) $(filter-out $(2), $(1)) ) +endif + +# echo command. Short version is $(quiet) equals quiet, otherwise full command +echo-cmd = $(if $($(quiet)cmd_$(1)), \ + echo ' $(subst ','\'',$($(quiet)cmd_$(1)))';) + +# function to only execute the passed command if necessary +# >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file +# note: when using inline perl scripts [perl -e '...$$t=1;...'] in $(cmd_xxx) double $$ your perl vars +# +if_changed = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ + @set -e; \ + $(echo-cmd) \ + $(cmd_$(1)); \ + echo 'cmd_$@ := $(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).cmd) + +# execute the command and also postprocess generated .d dependencies +# file +if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\ + $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ + @set -e; \ + $(echo-cmd) \ + $(cmd_$(1)); \ + scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \ + rm -f $(depfile); \ + mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd) + +# Usage: $(call if_changed_rule,foo) +# will check if $(cmd_foo) changed, or any of the prequisites changed, +# and if so will execute $(rule_foo) +if_changed_rule = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),\ + @set -e; \ + $(rule_$(1))) diff --git a/scripts/Kbuild.klibc b/scripts/Kbuild.klibc new file mode 100644 --- /dev/null +++ b/scripts/Kbuild.klibc @@ -0,0 +1,282 @@ +# =========================================================================+# Support for building klibc and related programs +# =========================================================================+# +# To create a kbuild file for a userspace program do the following: +# +# Kbuild: +# +# user-progs := cat +# +# This will compile a file named cat.c -> the executable 'cat' +# +# If the user space program consist of more files do the following: +# Kbuild: +# +# user-progs := ipconfig +# ipconfig-y := main.o netdev.c + +src := $(obj) + +.phony: __build +__build: + +# Generic Kbuild routines +include $(srctree)/scripts/Kbuild.include + +# Defines used when compiling early userspace (klibc programs) +# --------------------------------------------------------------------------- + +# Arch specific definitions for klibc +include $(KLIBSRC)/arch/$(ARCH)/MCONFIG + +USERWARNFLAGS := -W -Wall -Wsign-compare + +USERCROSS := $(CROSS_COMPILE) + +USERLD := $(USERCROSS)ld +USERCC := $(USERCROSS)gcc +USERAR := $(USERCROSS)ar +USERRANLIB := $(USERCROSS)ranlib +USERSTRIP := $(USERCROSS)strip +USERNM := $(USERCROSS)nm + +USERCPPFLAGS := -I$(KLIBINC)/arch/$(ARCH) \ + -I$(KLIBINC)/bits$(BITSIZE) \ + -I$(KLIBINC) \ + -Iinclude \ + $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) \ + -D__KLIBC__=1 -D__KLIBC_MINOR__=0 \ + -DBITSIZE=$(BITSIZE) +USERCFLAGS := $(USERCPPFLAGS) $(REQFLAGS) $(ARCHREQFLAGS) \ + $(OPTFLAGS) $(USERWARNFLAGS) +USERAFLAGS := -D__ASSEMBLY__ $(USERCPPFLAGS) +USERSTRIPFLAGS := --strip-all -R .comment -R .note + +USERLIBGCC := $(shell $(USERCC) --print-libgcc) +USERSHAREDFLAGS := $(SHAREDFLAGS) +USERCRT0 := $(KLIBSRC)/arch/$(ARCH)/crt0.o +USERLIBC := $(KLIBSRC)/libc.a + +# +# This indicates the location of the final version of the shared library. +# THIS MUST BE AN ABSOLUTE PATH WITH NO FINAL SLASH. +# Leave this empty to make it the root. +# +SHLIBDIR = /lib + +export USERLD USERCC USERAR USERSTRIP USERNM +export USERCFLAGS USERAFLAGS USERLIBGCC USERSHAREDFLAGS USERSTRIPFLAGS +export USERCRT0 USERLIBC SHLIBDIR + +# kernel configuration +include .config + +# Add $(obj)/ for paths that is not absolute +objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o))) + +# Kbuild file in the directory that is being build +include $(obj)/Kbuild + +##### +# user-progs := handling + +# user-progs based on a single .c file (with same name) +user-single := $(foreach p, $(user-progs), $(if $($(p)-y),,$(p))) + +# user-progs which is based on several .o files +user-multi := $(foreach p, $(user-progs), $(if $($(p)-y),$(p))) +# objects used for user-progs with more then one .o file +user-multi-objs := $(foreach p, $(user-multi), $($(p)-y)) +# objects build in this dir +user-real-objs := $(patsubst %/,,$(user-multi-objs)) +# Directories we need to visit before user-multi-obs are up-to-date +user-dirs := $(patsubst %/,%,$(filter %/, $(user-multi-objs))) +# replace all dir/ with dir/built-in.o +user-multi-objs := $(patsubst %/, %/built-in.o, $(user-multi-objs)) + +# $(output-dirs) are a list of directories that contain object files +output-dirs := $(dir $(user-dirs)) +output-dirs += $(foreach f, $(hostprogs-y) $(targets), \ + $(if $(dir $(f)), $(dir $(f)))) +output-dirs := $(strip $(sort $(filter-out ./,$(output-dirs)))) + +# prefix so we get full dir +user-progs := $(addprefix $(obj)/,$(user-progs)) +user-single := $(addprefix $(obj)/,$(user-single)) +user-multi := $(addprefix $(obj)/,$(user-multi)) +user-multi-objs := $(addprefix $(obj)/,$(user-multi-objs)) +user-real-objs := $(addprefix $(obj)/,$(user-real-objs)) +output-dirs := $(addprefix $(obj)/,$(output-dirs)) +user-dirs := $(addprefix $(obj)/,$(user-dirs)) +subdir-y := $(addprefix $(obj)/,$(subdir-y)) +always := $(addprefix $(obj)/,$(always)) +targets := $(addprefix $(obj)/,$(targets)) + + +_usercflags = $(USERCFLAGS) $(EXTRA_USERCFLAGS) $(USERCFLAGS_$(*F).o) +_useraflags = $(USERAFLAGS) $(EXTRA_USERAFLAGS) $(USERAFLAGS_$(*F).o) + +usercflags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(_usercflags) +useraflags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(_useraflags) + +ifneq ($(KBUILD_SRC),) +# Create output directory if not already present +_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj)) + +# Create directories for object files if directory does not exist +# Needed when obj-y := dir/file.o syntax is used +_dummy := $(foreach d,$(output-dirs), $(shell [ -d $(d) ] || mkdir -p $(d))) +endif + +# Do we have to make a built-in.o in this dir? +ifneq ($(strip $(obj-y) $(obj-n) $(obj-)),) +builtin-target := $(obj)/built-in.o +endif + +__build: $(subdir-y) $(builtin-target) $(always) + @: + +# Compile C sources (.c) +# --------------------------------------------------------------------------- + +quiet_cmd_cc_s_c = USERCC $@ + cmd_cc_s_c = $(USERCC) $(usercflags) -S -o $@ $< + +%.s: %.c FORCE + $(call if_changed_dep,cc_s_c) + +quiet_cmd_cc_i_c = USERCPP $@ + cmd_cc_i_c = $(USERCPP) $(usercflags) -o $@ $< + +%.i: %.c FORCE + $(call if_changed_dep,cc_i_c) + +quiet_cmd_cc_o_c = USERCC $@ + cmd_cc_o_c = $(USERCC) $(usercflags) -c -o $@ $< + +%.o: %.c FORCE + $(call if_changed_dep,cc_o_c) + +# Compile assembler sources (.S) +# --------------------------------------------------------------------------- + +quiet_cmd_as_s_S = USERCPP $@ + cmd_as_s_S = $(USERCPP) $(useraflags) -o $@ $< + +%.s: %.S FORCE + $(call if_changed_dep,as_s_S) + +quiet_cmd_as_o_S = USERAS $@ + cmd_as_o_S = $(USERCC) $(useraflags) -c -o $@ $< + +%.o: %.S FORCE + $(call if_changed_dep,as_o_S) + +targets += $(real-objs-y) + +# +# Rule to compile a set of .o files into one .o file +# +ifdef builtin-target +quiet_cmd_link_o_target = LD $@ +# If the list of objects to link is empty, just create an empty built-in.o +cmd_link_o_target = $(if $(strip $(obj-y)),\ + $(USERLD) $(USERLDFLAGS) -r -o $@ $(filter $(obj-y), $^),\ + rm -f $@; $(AR) rcs $@) + +$(builtin-target): $(obj-y) FORCE + $(call if_changed,link_o_target) +targets += $(builtin-target) +endif # builtin-target + + +ifdef user-progs +# Compile userspace programs for the target +# ==========================================================================+ +__build : $(user-dirs) $(user-progs) + +# Descend if needed +$(sort $(addsuffix /built-in.o,$(user-dirs))): $(user-dirs) ; + +# link program that has only a single .o file +quiet_cmd_user-ld-single = USERLD $@ + cmd_user-ld-single = $(USERLD) $(USERLDFLAGS) -o $@ \ + $(USERCRT0) $< \ + $(filter-out FORCE,$^) \ + $(USERLIBC) $(USERLIBGCC) \ + $(USERLIBGCC); \ + $(USERSTRIP) $(USERSTRIPFLAGS) $@ + +$(user-single): %: %.o $(USERCRT0) $(USERLIBC) FORCE + $(call if_changed,user-ld-single) + +targets += $(user-single) $(user-single:=.o) + +# link programs that consist of more than one .o file +multi-deps = $($(subst $(obj)/,,$@-y)) +link-multi-deps = $(addprefix $(obj)/, \ + $(patsubst %/, %/built-in.o, $(multi-deps))) + +quiet_cmd_user-ld-multi = USERLD $@ + cmd_user-ld-multi = $(USERLD) $(USERLDFLAGS) -o $@ \ + $(USERCRT0) \ + $(link-multi-deps) \ + $(USERLIBC) $(USERLIBGCC) \ + $(USERLIBGCC); \ + $(USERSTRIP) $(USERSTRIPFLAGS) $@ + +$(user-multi): $(user-multi-objs) FORCE + $(call if_changed,user-ld-multi) + +targets += $(user-multi) $(user-real-objs) +endif + + +# Compile programs on the host +# ==========================================================================+ifdef hostprogs-y +include $(srctree)/scripts/Makefile.host +endif + +# Descending +# --------------------------------------------------------------------------- + +.PHONY: $(subdir-y) $(user-dirs) +$(subdir-y) $(user-dirs): + $(Q)$(MAKE) $(klibc)=$@ + +# Add FORCE to the prequisites of a target to force it to be always rebuilt. +# --------------------------------------------------------------------------- + +.PHONY: FORCE + +FORCE: + +# Linking +# Create a reloctable composite object file +# --------------------------------------------------------------------------- +quiet_cmd_userld = USERLD $@ + cmd_userld = $(USERLD) -r $(USERLDFLAGS) \ + $(EXTRA_USERLDFLAGS) $(USERLDFLAGS_$(@F)) \ + $(filter-out FORCE,$^) -o $@ + + +# Read all saved command lines and dependencies for the $(targets) we +# may be building above, using $(if_changed{,_dep}). As an +# optimization, we don't need to read them if the target does not +# exist, we will rebuild anyway in that case. + +targets := $(wildcard $(sort $(targets))) +cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) + +ifneq ($(cmd_files),) + include $(cmd_files) +endif + +# Shorthand for $(Q)$(MAKE) -f scripts/Kbuild.klibc obj +# Usage: +# $(Q)$(MAKE) $(klibc)=dir +klibc := -rR -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Kbuild.klibc obj + diff --git a/usr/Kbuild b/usr/Kbuild new file mode 100644 --- /dev/null +++ b/usr/Kbuild @@ -0,0 +1,87 @@ +# +# kbuild file for usr/ - including initramfs image and klibc +# + +# klibc definitions - to be moved to top-level Makefile later +export KLIBSRC := $(srctree)/$(src)/klibc +export KLIBINC := $(srctree)/$(src)/include + +obj-y := initramfs_data.o +always := klibc/libc.a +hostprogs-y := gen_init_cpio +clean-files := initramfs_data.cpio.gz initramfs_list + +# Descend down into klibc when cleaning +subdir- := klibc + +# Build klibc library +$(obj)/klibc/libc.a: FORCE + $(Q)$(MAKE) -rR -f $(srctree)/scripts/Kbuild.klibc obj=$(obj)/klibc + +initramfs-y += gzip + +initramfs-y := $(addprefix $(obj)/,$(initramfs-y)) +.PHONY: $(initramfs-y) + +# initramfs_data.o contains the initramfs_data.cpio.gz image. +# The image is included using .incbin, a dependency which is not +# tracked automatically. +$(obj)/initramfs_data.o: $(obj)/initramfs_data.cpio.gz FORCE + +$(initramfs-y): $(obj)/klibc/libc.a + $(Q)$(MAKE) -f $(srctree)/scripts/Kbuild.klibc obj=$@ + +ifdef CONFIG_INITRAMFS_ROOT_UID +gen_initramfs_args += -u $(CONFIG_INITRAMFS_ROOT_UID) +endif + +ifdef CONFIG_INITRAMFS_ROOT_GID +gen_initramfs_args += -g $(CONFIG_INITRAMFS_ROOT_GID) +endif + +# The $(shell echo $(CONFIG_INITRAMFS_SOURCE)) is to remove the +# gratuitous begin and end quotes from the Kconfig string type. +# Internal, escaped quotes in the Kconfig string will loose the +# escape and become active quotes. +quotefixed_initramfs_source := $(shell echo $(CONFIG_INITRAMFS_SOURCE)) + +filechk_initramfs_list = $(CONFIG_SHELL) \ + $(srctree)/scripts/gen_initramfs_list.sh $(gen_initramfs_args) \ + $(quotefixed_initramfs_source) + +$(obj)/initramfs_list: $(src)/Kbuild FORCE + $(call filechk,initramfs_list) + +quiet_cmd_cpio = CPIO $@ + cmd_cpio = ./$< $(obj)/initramfs_list > $@ + + +# Check if the INITRAMFS_SOURCE is a cpio archive +ifneq (,$(findstring .cpio,$(quotefixed_initramfs_source))) + +# INITRAMFS_SOURCE has a cpio archive - verify that it's a single file +ifneq (1,$(words $(quotefixed_initramfs_source))) +$(error Only a single file may be specified in CONFIG_INITRAMFS_SOURCE (="$(quotefixed_initramfs_source)") when a cpio archive is directly specified.) +endif +# Now use the cpio archive directly +initramfs_data_cpio = $(quotefixed_initramfs_source) +targets += $(quotefixed_initramfs_source) + +else + +# INITRAMFS_SOURCE is not a cpio archive - create one +$(obj)/initramfs_data.cpio: $(obj)/gen_init_cpio \ + $(initramfs-y) $(obj)/initramfs_list FORCE + $(call if_changed,cpio) + +targets += initramfs_data.cpio +initramfs_data_cpio = $(obj)/initramfs_data.cpio + +endif + + +$(obj)/initramfs_data.cpio.gz: $(initramfs_data_cpio) FORCE + $(call if_changed,gzip) + +targets += initramfs_data.cpio.gz +