Hi Bryan and other klibc people. I have taken a stamp on the Makefiles for klibc, this is what I came up with. 1) No longer recompile on every invocation 2) Correct checking on dependencies 3) Simpler makefile syntax (almost all over the place) I compile-time tested it only. Two open issues: a) Do we realy use .a files for initramfs. I renemed that to the executable. b) I renamed nfsmount/main.c to nfsmount/nfsmount.c Similar for ipconfig. THIS IS NOT IN THE PATCH. I have it in bk, but this is mainly for review - whatever. I will push it when have made a few more changes. Are there any plans to upgrade to lastest -test soon? It may cause some problems in the top-level Makefile, and usr/Makefile. I will be happy to sort any kbuild problems out if needed. PS. Not subscribed to klibc@zytor.com - how do I do that? Already tried majordome@zytor.com - no luck. Sam ===== Makefile 1.415 vs edited ====--- 1.415/Makefile Thu Jul 31 22:15:44 2003 +++ edited/Makefile Sat Oct 4 06:51:19 2003 @@ -255,7 +255,7 @@ include $(KLIBSRC)/arch/$(ARCH)/MCONFIG -export USERLD USERCC USERAR USERSTRIP USERNM \ +export KLIBSRC USERLD USERCC USERAR USERSTRIP USERNM \ USERCFLAGS USERAFLAGS USERLIBGCC USERSHAREDFLAGS USERSTRIPFLAGS \ USERCRT0 USERLIBC ===== scripts/Makefile.user 1.3 vs edited ====--- 1.3/scripts/Makefile.user Tue Jun 10 05:56:56 2003 +++ edited/scripts/Makefile.user Sat Oct 4 22:47:02 2003 @@ -13,7 +13,7 @@ objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o))) -build-multi := $(foreach o,$(build-targets),$(if $(deps_$(o)),$(o))) +build-multi := $(foreach o,$(targets),$(if $(deps_$(o)),$(o))) build-y := $(foreach o,$(build-multi),$(deps_$(o))) include scripts/Makefile.lib @@ -22,7 +22,7 @@ build-y := $(call objectify,$(build-y)) real-objs-y += $(build-y) -__build: $(subdir-ym) $(build-targets) +__build: $(subdir-ym) $(always) @: # Compile C sources (.c) @@ -32,19 +32,19 @@ $(NOSTDINC_FLAGS) quiet_cmd_cc_s_c = USERCC $@ -cmd_cc_s_c = $(USERCC) $(usercflags) -S -o $@ $< + 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 $@ $< + 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 $@ $< + cmd_cc_o_c = $(USERCC) $(usercflags) -c -o $@ $< %.o: %.c FORCE $(call if_changed_dep,cc_o_c) @@ -55,23 +55,23 @@ useraflags = -Wp,-MD,$(depfile) $(USERAFLAGS) $(NOSTDINC_FLAGS) quiet_cmd_as_s_S = USERCPP $@ -cmd_as_s_S = $(USERCPP) $(useraflags) -o $@ $< + 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 $@ $< + cmd_as_o_S = $(USERCC) $(useraflags) -c -o $@ $< %.o: %.S FORCE $(call if_changed_dep,as_o_S) -targets += $(real-objs-y) $(build-targets) +targets += $(real-objs-y) $(targets) # User defined commands... # ========================================================================= -$(build-multi) : %: $(build-y) FORCE +$(build-multi): FORCE $(call if_changed,$(subst $(obj)/,,$@)) # Compile userspace programs for the target @@ -81,18 +81,38 @@ user-progs := $(addprefix $(obj)/,$(user-progs)) user-single := $(user-progs) +__build : $(user-progs) quiet_cmd_user-ld-single = USERLD $@ cmd_user-ld-single = $(USERLD) $(USERLDFLAGS) -o $@ \ - $(USERCRT0) $< $(USERLIBC) $(USERLIBGCC); \ + --start-group \ + $(filter-out FORCE,$^) \ + --end-group $(USERLIBGCC); \ $(USERSTRIP) $(USERSTRIPFLAGS) $@ -$(user-single): %: %.o FORCE +$(user-single): %: %.o $(USERCRT0) $(USERLIBC) FORCE $(call if_changed,user-ld-single) targets += $(user-single) $(user-single:=.o) endif + +ifdef user-libs + +user-libs := $(addprefix $(obj)/,$(user-libs)) +user-lib-single := $(user-libs) +__build : $(user-libs) + +quiet_cmd_user-ar-single = USERAR $@ + cmd_user-ar-single = $(USERAR) cru $@ $(filter-out FORCE,$^) + +$(user-lib-single): %.a: %.o FORCE + $(call if_changed,user-ar-single) + +targets += $(user-lib-single) + +endif + # Compile programs on the host # =============================================================================== usr/Makefile 1.11 vs edited ====--- 1.11/usr/Makefile Thu Jul 31 22:19:05 2003 +++ edited/usr/Makefile Sat Oct 4 22:40:56 2003 @@ -2,8 +2,6 @@ host-progs := gen_init_cpio -HOSTCC += -I$(TOPDIR)/include - clean-files := initramfs_data.cpio.gz # initramfs_data.o contains the initramfs_data.cpio.gz image. @@ -16,9 +14,16 @@ # but we need the information for the build as well, so it's duplicated # here. -initramfs-$(CONFIG_USR_KINIT) := $(obj)/kinit/kinit -initramfs-$(CONFIG_IP_PNP) += $(obj)/ipconfig/libipconfig.a -initramfs-$(CONFIG_ROOT_NFS) += $(obj)/nfsmount/libnfsmount.a +initramfs-$(CONFIG_IP_PNP) := $(obj)/ipconfig/ipconfig +usr_sdirs-$(CONFIG_IP_PNP) := $(obj)/ipconfig + +initramfs-$(CONFIG_ROOT_NFS) += $(obj)/nfsmount/nfsmount +usr_sdirs-$(CONFIG_ROOT_NFS) += $(obj)/nfsmount + +# kinit uses .a files from nfsmount and ipconfig +$(obj)/kinit/kinit: $(usr_sdirs-y) +initramfs-$(CONFIG_USR_KINIT) += $(obj)/kinit/kinit +usr_sdirs-$(CONFIG_USR_KINIT) += $(obj)/kinit quiet_cmd_cpio = CPIO $@ cmd_cpio = ./$< $(obj) > $@ @@ -28,23 +33,21 @@ targets += initramfs_data.cpio -usr_subdirs-y :-usr_subdirs-$(CONFIG_ROOT_NFS) += $(obj)/nfsmount -usr_subdirs-$(CONFIG_IP_PNP) += $(obj)/ipconfig -usr_subdirs-$(CONFIG_USR_KINIT) += $(obj)/kinit +$(obj)/initramfs_data.cpio.gz: $(obj)/initramfs_data.cpio FORCE + $(call if_changed,gzip) + +targets += initramfs_data.cpio.gz -ifdef CONFIG_USR_KINIT -$(initramfs-y): $(usr_subdirs-y) -$(usr_subdirs-y): $(obj)/lib +# Which targets do we need to update before building the initramfs +$(initramfs-y): $(usr_sdirs-y) -.PHONY: $(obj)/lib $(usr_subdirs-y) +# Traverse subdirectorie first, but make sure lib/ is build before +# all others - they need it -$(obj)/lib $(usr_subdirs-y): - $(Q)$(MAKE) $(user)=$@ -endif +.PHONY: $(obj)/lib $(usr_sdirs-y) +$(usr_sdirs-y): $(obj)/lib -$(obj)/initramfs_data.cpio.gz: $(obj)/initramfs_data.cpio FORCE - $(call if_changed,gzip) +$(obj)/lib $(usr_sdirs-y): FORCE + $(Q)$(MAKE) $(user)=$@ -targets += initramfs_data.cpio.gz ===== usr/gen_init_cpio.c 1.6 vs edited ====--- 1.6/usr/gen_init_cpio.c Wed Jul 9 07:35:07 2003 +++ edited/usr/gen_init_cpio.c Sat Oct 4 07:39:26 2003 @@ -8,10 +8,7 @@ #include <time.h> #include <fcntl.h> -#include <config/usr/klibc.h> -#ifdef CONFIG_USR_KLIBC -#include <config/usr/kinit.h> -#endif +#include <linux/config.h> static unsigned int offset; static unsigned int ino = 721; ===== usr/ipconfig/Makefile 1.3 vs edited ====--- 1.3/usr/ipconfig/Makefile Mon May 26 07:20:31 2003 +++ edited/usr/ipconfig/Makefile Sat Oct 4 22:03:13 2003 @@ -1,18 +1,11 @@ -user-progs := $(obj)/ipconfig -build-targets := $(obj)/ipconfig $(obj)/ipconfig.a -objs := main.o netdev.o packet.o dhcp_proto.o bootp_proto.o -LIBS := $(USERLIBC) $(USERLIBGCC) +user-progs := ipconfig +user-libs := ipconfig.a -OBJS := $(objs:%=$(obj)/%) +#Objects build in local directory +objs := netdev.o packet.o dhcp_proto.o bootp_proto.o -quiet_cmd_ipconfig = USERLD $@ - cmd_ipconfig = $(USERLD) $(USERLDFLAGS) -o $@ $^ +targets := $(objs) +objs := $(addprefix $(obj)/,$(objs)) -$(obj)/ipconfig: $(USERCRT0) $(OBJS) $(LIBS) - $(call if_changed,ipconfig) - -quiet_cmd_ipconfig.a = USERAR $@ - cmd_ipconfig.a = $(USERAR) cru $@ $^ - -$(obj)/ipconfig.a: $(OBJS) - $(call if_changed,ipconfig.a) +$(obj)/ipconfig : $(objs) +$(obj)/ipconfig.a : $(objs) ===== usr/kinit/Makefile 1.4 vs edited ====--- 1.4/usr/kinit/Makefile Tue Jun 10 05:56:57 2003 +++ edited/usr/kinit/Makefile Sat Oct 4 22:01:55 2003 @@ -1,17 +1,17 @@ -user-progs := $(obj)/kinit -build-targets := $(obj)/kinit -objs := kinit.o nfsroot.o do_mounts.o -USERCFLAGS += -I$(src)/../ipconfig -I$(src)/../nfsmount +# Makefile for kinit - tiny init program +user-progs := kinit -LIBS-y :-LIBS-$(CONFIG_IP_PNP) += $(obj)/../ipconfig/ipconfig.a -LIBS-$(CONFIG_ROOT_NFS) += $(obj)/../nfsmount/nfsmount.a -LIBS-y += $(USERLIBC) $(USERLIBGCC) +# Needs header files here +USERCFLAGS += -I$(obj)/../ipconfig -I$(obj)/../nfsmount -OBJS := $(objs:%=$(obj)/%) +# objects build in this directory +objs := nfsroot.o do_mounts.o -quiet_cmd_kinit = USERLD $@ - cmd_kinit = $(USERLD) $(USERLDFLAGS) -o $@ $^ +targets := $(objs) +objs := $(addprefix $(obj)/,$(objs)) -$(obj)/kinit: $(USERCRT0) $(OBJS) $(LIBS-y) - $(call if_changed,kinit) +libs-$(CONFIG_IP_PNP) += $(obj)/../ipconfig/ipconfig.a +libs-$(CONFIG_ROOT_NFS) += $(obj)/../nfsmount/nfsmount.a + +# Must list local dependencies here +$(obj)/kinit: $(objs) $(libs-y) ===== usr/lib/Makefile 1.8 vs edited ====--- 1.8/usr/lib/Makefile Mon May 26 06:50:43 2003 +++ edited/usr/lib/Makefile Fri Oct 3 23:33:54 2003 @@ -28,11 +28,6 @@ inet/inet_ntoa.o inet/inet_aton.o inet/inet_addr.o \ inet/inet_ntop.o inet/inet_pton.o inet/bindresvport.o \ send.o recv.o -SOLIB = libc.so -SOHASH = klibc.so - -CRT0 = crt0.o -LIB = libc.a # Add any architecture-specific rules include $(src)/arch/$(ARCH)/Makefile.inc @@ -44,73 +39,76 @@ quiet_cmd_objs.mk = GEN $@ cmd_objs.mk = $(PERL) $(word 2,$^) $(ARCH) $(obj) $< > $@ +clean-files += syscalls.mk syscalls/*.[cS] $(obj)/syscalls.mk: $(src)/SYSCALLS $(src)/syscalls.pl - $(call if_changed,objs.mk) + $(call cmd,objs.mk) +clean-files += socketcalls.mk socketcalls/*.[cS] $(obj)/socketcalls.mk: $(src)/SOCKETCALLS $(src)/socketcalls.pl - $(call if_changed,objs.mk) + $(call cmd,objs.mk) # That's what we're supposed to build -build-targets := $(obj)/crt0.o $(obj)/libc.a $(obj)/libc.so $(obj)/klibc.so +always := crt0.o libc.a libc.so klibc.so +host-progs := sha1hash -host-progs := $(obj)/sha1hash - -$(obj)/sha1hash: $(src)/sha1hash.c - $(HOSTCC) -o $@ $^ +defdep = $(obj)/$(1): $(addprefix $(obj)/,$(deps_$(1))) # crt0.o - -quiet_cmd_cp = CP $@ - cmd_cp = cp $< $@ - -$(obj)/crt0.o: $(obj)/arch/$(ARCH)/crt0.o - $(call if_changed,cp) - -targets += $(obj)/crt0.o $(obj)/arch/$(ARCH)/crt0.o +targets += crt0.o +deps_crt0.o := arch/$(ARCH)/crt0.o +$(call defdep,crt0.o) +quiet_cmd_crt0.o = CP $@ + cmd_crt0.o = cp $(word 2,$^) $@ # static lib +dep_libc = $(LIBOBJS) $(ARCHOBJS) $(syscall-objs) $(socketcall-objs) -deps_libc.a = __static_init.o $(LIBOBJS) $(ARCHOBJS) \ - $(syscall-objs) $(socketcall-objs) -quiet_cmd_libc.a = USERAR $@ - cmd_libc.a = rm -f $@; $(USERAR) rcs $@ $^ - -$(obj)/libc.a: $(deps_libc.a:%=$(obj)/%) - $(call if_changed,libc.a) +targets += libc.a +deps_libc.a := __static_init.o $(dep_libc) +$(call defdep,libc.a) +quiet_cmd_libc.a = USERAR $@ + cmd_libc.a = rm -f $@; $(USERAR) rcs $@ $(filter-out FORCE,$^) # shared lib +targets += libc.so +deps_libc.so := crt0.o __shared_init.o $(dep_libc) +$(call defdep,libc.so) +quiet_cmd_libc.so = LD $@ + cmd_libc.so = $(USERLD) $(USERLDFLAGS) $(USERSHAREDFLAGS) -o $@ $(filter-out FORCE,$^) + +targets += klibc.so +deps_klibc.so := libc.so libc.so.hash +$(call defdep,klibc.so) +quiet_cmd_klibc.so = GEN $@ + cmd_klibc.so = cp $(word 2,$^) $@;$(USERSTRIP) $(USERSTRIPFLAGS) $@; \ + rm -f $(obj)/klibc-??????????????????????.so; \ + ln -f $@ $(obj)/klibc-`cat $(obj)/libc.so.hash`.so + +# Hash variant of libc + +targets += libc.so.hash +deps_libc.so.hash := libc.so sha1hash +$(call defdep,libc.so.hash) +quiet_cmd_libc.so.hash = HASH $@ + cmd_libc.so.hash = $(USERNM) $(word 2,$^) | egrep '^[0-9a-fA-F]+ [ADRTW] ' | \ + sort | $(obj)/sha1hash > $@ -deps_libc.so = crt0.o __shared_init.o $(LIBOBJS) $(ARCHOBJS) \ - $(syscall-objs) $(socketcall-objs) -quiet_cmd_libc.so = LD $@ - cmd_libc.so = $(USERLD) $(USERLDFLAGS) $(USERSHAREDFLAGS) -o $@ $^ - -$(obj)/libc.so: $(deps_libc.so:%=$(obj)/%) $(USERLIBGCC) - $(call if_changed,libc.so) +# Additional cleanup upon make clean +clean-files += *.so *.hash -quiet_cmd_klibc.so = GEN $@ - cmd_klibc.so = cp $< $@;$(USERSTRIP) $(USERSTRIPFLAGS) $@; \ - rm -f $(obj)/klibc-??????????????????????.so; \ - ln -f $@ $(obj)/klibc-`cat $(obj)/libc.so.hash`.so -$(obj)/klibc.so: $(obj)/libc.so $(obj)/libc.so.hash - $(call if_changed,klibc.so) -targets += $(obj)/klibc.so -# -quiet_cmd_libc.so.hash = HASH $@ - cmd_libc.so.hash = $(USERNM) $< | egrep '^[0-9a-fA-F]+ [ADRTW] ' | \ - sort | $(obj)/sha1hash > $@ -$(obj)/libc.so.hash: $(obj)/libc.so $(obj)/sha1hash - $(call if_changed,libc.so.hash) +ifdef notdef -targets += $(obj)/libc.so.hash +SOLIB = libc.so +SOHASH = klibc.so -ifdef notdef +CRT0 = crt0.o +LIB = libc.a TESTS = $(patsubst %.c,%,$(wildcard tests/*.c)) \ $(patsubst %.c,%.shared,$(wildcard tests/*.c)) @@ -140,6 +138,3 @@ endif -clean-files := syscalls/*.[cS] syscalls.mk \ - socketcalls/*.[cS] socketcalls.mk \ - *.so *.hash ===== usr/nfsmount/Makefile 1.2 vs edited ====--- 1.2/usr/nfsmount/Makefile Mon May 26 07:19:57 2003 +++ edited/usr/nfsmount/Makefile Sat Oct 4 14:26:20 2003 @@ -1,18 +1,12 @@ -user-progs := $(obj)/nfsmount -build-targets := $(obj)/nfsmount $(obj)/nfsmount.a -objs := main.o mount.o portmap.o sunrpc.o -LIBS := $(USERLIBC) $(USERLIBGCC) +user-progs := nfsmount +user-libs := nfsmount.a -OBJS := $(objs:%=$(obj)/%) +#Objects build in local directory +objs := mount.o portmap.o sunrpc.o -quiet_cmd_nfsmount = USERLD $@ - cmd_nfsmount = $(USERLD) $(USERLDFLAGS) -o $@ $^ +targets := $(objs) +objs := $(addprefix $(obj)/,$(objs)) -$(obj)/nfsmount: $(USERCRT0) $(OBJS) $(LIBS) - $(call if_changed,nfsmount) - -quiet_cmd_nfsmount.a = USERAR $@ - cmd_nfsmount.a = $(USERAR) cru $@ $^ - -$(obj)/nfsmount.a: $(OBJS) - $(call if_changed,nfsmount.a) +# Must list explicit dependencies +$(obj)/nfsmount: $(objs) +$(obj)/nfsmount.a: $(objs)