ChangeSet 1.914.157.3, 2003/02/15 23:09:41-06:00, kai@tp1.ruhr-uni-bochum.de kbuild/klibc: Integrate klibc into the build. Basically, add a scripts/Makefile.user, which does similar things to scripts/Makefile.build, but compiles userspace for the target instead. It's tested for a static klibc on i386, building the shared lib works, too, but is not further integrated. This patch also adds gregkh's hello test program, which works as well. diff -Nru a/Makefile b/Makefile --- a/Makefile Wed Feb 19 11:42:31 2003 +++ b/Makefile Wed Feb 19 11:42:31 2003 @@ -180,13 +180,46 @@ export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION KERNELRELEASE ARCH \ CONFIG_SHELL TOPDIR HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \ CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE \ - HOSTCXX HOSTCXXFLAGS LDFLAGS_BLOB LDFLAGS_MODULE + HOSTCXX HOSTCXXFLAGS LDFLAGS_BLOB LDFLAGS_MODULE \ export CPPFLAGS NOSTDINC_FLAGS OBJCOPYFLAGS LDFLAGS export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE -export MODVERDIR := .tmp_versions +KLIBSRC = usr/lib +USERWARNFLAGS = -W -Wall -Wpointer-arith -Wwrite-strings \ + -Wstrict-prototypes -Winline + +USERCROSS = $(CROSS_COMPILE) + +USERLD = $(USERCROSS)ld +USERCC = $(USERCROSS)gcc +USERAR = $(USERCROSS)ar +USERSTRIP = $(USERCROSS)strip +USERNM = $(USERCROSS)nm + +USERCPPFLAGS = -I$(KLIBSRC)/arch/$(ARCH)/include \ + -I$(KLIBSRC)/include/bits$(BITSIZE) \ + -I$(KLIBSRC)/include \ + -Iinclude \ + -D__KLIBC__ -DBITSIZE=$(BITSIZE) +USERCFLAGS = $(USERCPPFLAGS) $(ARCHREQFLAGS) $(OPTFLAGS) \ + $(USERWARNFLAGS) +USERAFLAGS = -D__ASSEMBLY__ $(USERCPPFLAGS) +USERSTRIPFLAGS = --strip-all -R .comment -R .note + +USERLIBGCC = $(shell $(USERCC) --print-libgcc) +USERSHAREDFLAGS = $(SHAREDFLAGS) +USERCRT0 = $(KLIBSRC)/crt0.o +USERLIBC = $(KLIBSRC)/libc.a + +include $(KLIBSRC)/arch/$(ARCH)/MCONFIG + +export USERLD USERCC USERAR USERSTRIP USERNM \ + USERCFLAGS USERAFLAGS USERLIBGCC USERSHAREDFLAGS USERSTRIPFLAGS \ + USERCRT0 USERLIBC + +export MODVERDIR := .tmp_versions # The temporary file to save gcc -MD generated dependencies must not # contain a comma @@ -457,7 +490,7 @@ # Split autoconf.h into include/linux/config/* include/config/MARKER: scripts/split-include include/linux/autoconf.h - @echo ' SPLIT include/linux/autoconf.h -> include/config/*' + @echo ' SPLIT include/linux/autoconf.h -> include/config/*' @scripts/split-include include/linux/autoconf.h include/config @touch $@ diff -Nru a/scripts/Makefile.build b/scripts/Makefile.build --- a/scripts/Makefile.build Wed Feb 19 11:42:31 2003 +++ b/scripts/Makefile.build Wed Feb 19 11:42:31 2003 @@ -248,7 +248,7 @@ $(filter $(addprefix $(obj)/, \ $($(subst $(obj)/,,$(@:.o=-objs))) \ $($(subst $(obj)/,,$(@:.o=-y)))), $^) - + quiet_cmd_link_multi-y = LD $@ cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) @@ -295,6 +295,8 @@ # Note: Shared libraries consisting of C++ files are not supported # +ifdef host-progs + # Create executable from a single .c file # host-csingle -> Executable quiet_cmd_host-csingle = HOSTCC $@ @@ -352,6 +354,8 @@ targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\ $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) + +endif # Descending # --------------------------------------------------------------------------- diff -Nru a/scripts/Makefile.clean b/scripts/Makefile.clean --- a/scripts/Makefile.clean Wed Feb 19 11:42:31 2003 +++ b/scripts/Makefile.clean Wed Feb 19 11:42:31 2003 @@ -31,11 +31,13 @@ EXTRA_TARGETS := $(addprefix $(obj)/,$(EXTRA_TARGETS)) clean-files := $(addprefix $(obj)/,$(clean-files)) host-progs := $(addprefix $(obj)/,$(host-progs)) +user-progs := $(addprefix $(obj)/,$(user-progs)) subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn)) # ========================================================================== -__clean-files := $(wildcard $(EXTRA_TARGETS) $(host-progs) $(clean-files)) +__clean-files := $(wildcard $(EXTRA_TARGETS) $(host-progs) \ + $(user-progs) $(clean-files)) quiet_cmd_clean = CLEAN $(obj) cmd_clean = rm -f $(__clean-files); $(clean-rule) @@ -66,3 +68,10 @@ # Usage: # $(Q)$(MAKE) $(clean)=dir clean := -f scripts/Makefile.clean obj + +# Add FORCE to the prequisites of a target to force it to be always rebuilt. +# --------------------------------------------------------------------------- + +.PHONY: FORCE + +FORCE: diff -Nru a/scripts/Makefile.lib b/scripts/Makefile.lib --- a/scripts/Makefile.lib Wed Feb 19 11:42:31 2003 +++ b/scripts/Makefile.lib Wed Feb 19 11:42:31 2003 @@ -243,4 +243,5 @@ # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= # Usage: # $(Q)$(MAKE) $(build)=dir -build := -f scripts/Makefile.build obj +build := -f scripts/Makefile.build obj +user := -rR -f scripts/Makefile.user obj diff -Nru a/scripts/Makefile.user b/scripts/Makefile.user --- /dev/null Wed Dec 31 16:00:00 1969 +++ b/scripts/Makefile.user Wed Feb 19 11:42:31 2003 @@ -0,0 +1,209 @@ +# ========================================================================== +# Building +# ========================================================================== + +src := $(obj) + +.PHONY: __build +__build: + +include .config + +include $(obj)/Makefile + +objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o))) + +build-multi := $(foreach o,$(build-targets),$(if $(deps_$(o)),$(o))) +build-y := $(foreach o,$(build-multi),$(deps_$(o))) + +include scripts/Makefile.lib + +build-multi := $(addprefix $(obj)/,$(build-multi)) +build-y := $(call objectify,$(build-y)) +real-objs-y += $(build-y) + +__build: $(subdir-ym) $(build-targets) + @: + +# Compile C sources (.c) +# --------------------------------------------------------------------------- + +usercflags = -Wp,-MD,$(depfile) $(USERCFLAGS) $(NOSTDINC_FLAGS) + +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) +# --------------------------------------------------------------------------- + +useraflags = -Wp,-MD,$(depfile) $(USERAFLAGS) $(NOSTDINC_FLAGS) + +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) $(build-targets) + +# User defined commands... +# ========================================================================== + +$(build-multi) : %: $(build-y) FORCE + $(call if_changed,$(subst $(obj)/,,$@)) + +# Compile userspace programs for the target +# =========================================================================== + +ifdef user-progs + +user-progs := $(addprefix $(obj)/,$(user-progs)) +user-single := $(user-progs) + +quiet_cmd_user-ld-single = USERLD $@ + cmd_user-ld-single = $(USERLD) $(USERLDFLAGS) -o $@ \ + $(USERCRT0) $< $(USERLIBC) $(USERLIBGCC); \ + $(USERSTRIP) $(USERSTRIPFLAGS) $@ + +$(user-single): %: %.o FORCE + $(call if_changed,user-ld-single) + +targets += $(user-single) $(user-single:=.o) + +endif + +# Compile programs on the host +# =========================================================================== +# host-progs := bin2hex +# Will compile bin2hex.c and create an executable named bin2hex +# +# host-progs := lxdialog +# lxdialog-objs := checklist.o lxdialog.o +# Will compile lxdialog.c and checklist.c, and then link the executable +# lxdialog, based on checklist.o and lxdialog.o +# +# host-progs := qconf +# qconf-cxxobjs := qconf.o +# qconf-objs := menu.o +# Will compile qconf as a C++ program, and menu as a C program. +# They are linked as C++ code to the executable qconf + +# host-progs := conf +# conf-objs := conf.o libkconfig.so +# libkconfig-objs := expr.o type.o +# Will create a shared library named libkconfig.so that consist of +# expr.o and type.o (they are both compiled as C code and the object file +# are made as position independent code). +# conf.c is compiled as a c program, and conf.o is linked together with +# libkconfig.so as the executable conf. +# Note: Shared libraries consisting of C++ files are not supported +# + +ifdef host-progs + +# Create executable from a single .c file +# host-csingle -> Executable +quiet_cmd_host-csingle = HOSTCC $@ + cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(HOST_LOADLIBES) -o $@ $< +$(host-csingle): %: %.c FORCE + $(call if_changed_dep,host-csingle) + +# Link an executable based on list of .o files, all plain c +# host-cmulti -> executable +quiet_cmd_host-cmulti = HOSTLD $@ + cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \ + $(addprefix $(obj)/,$($(@F)-objs)) \ + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) +$(host-cmulti): %: $(host-cobjs) $(host-cshlib) FORCE + $(call if_changed,host-cmulti) + +# Create .o file from a single .c file +# host-cobjs -> .o +quiet_cmd_host-cobjs = HOSTCC $@ + cmd_host-cobjs = $(HOSTCC) $(hostc_flags) -c -o $@ $< +$(host-cobjs): %.o: %.c FORCE + $(call if_changed_dep,host-cobjs) + +# Link an executable based on list of .o files, a mixture of .c and .cc +# host-cxxmulti -> executable +quiet_cmd_host-cxxmulti = HOSTLD $@ + cmd_host-cxxmulti = $(HOSTCXX) $(HOSTLDFLAGS) -o $@ \ + $(foreach o,objs cxxobjs,\ + $(addprefix $(obj)/,$($(@F)-$(o)))) \ + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) +$(host-cxxmulti): %: $(host-cobjs) $(host-cxxobjs) $(host-cshlib) FORCE + $(call if_changed,host-cxxmulti) + +# Create .o file from a single .cc (C++) file +quiet_cmd_host-cxxobjs = HOSTCXX $@ + cmd_host-cxxobjs = $(HOSTCXX) $(hostcxx_flags) -c -o $@ $< +$(host-cxxobjs): %.o: %.cc FORCE + $(call if_changed_dep,host-cxxobjs) + +# Compile .c file, create position independent .o file +# host-cshobjs -> .o +quiet_cmd_host-cshobjs = HOSTCC -fPIC $@ + cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $< +$(host-cshobjs): %.o: %.c FORCE + $(call if_changed_dep,host-cshobjs) + +# Link a shared library, based on position independent .o files +# *.o -> .so shared library (host-cshlib) +quiet_cmd_host-cshlib = HOSTLLD -shared $@ + cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \ + $(addprefix $(obj)/,$($(@F:.so=-objs))) \ + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) +$(host-cshlib): %: $(host-cshobjs) FORCE + $(call if_changed,host-cshlib) + +targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\ + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) + +endif + +# Descending +# --------------------------------------------------------------------------- + +.PHONY: $(subdir-ym) +$(subdir-ym): + $(Q)$(MAKE) $(user)=$@ + +# Add FORCE to the prequisites of a target to force it to be always rebuilt. +# --------------------------------------------------------------------------- + +.PHONY: FORCE + +FORCE: + +# 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 diff -Nru a/usr/Makefile b/usr/Makefile --- a/usr/Makefile Wed Feb 19 11:42:31 2003 +++ b/usr/Makefile Wed Feb 19 11:42:31 2003 @@ -1,16 +1,38 @@ obj-y := initramfs_data.o -host-progs := gen_init_cpio +host-progs := gen_init_cpio clean-files := initramfs_data.cpio.gz +clean-rule = $(Q)$(MAKE) $(clean)=$(obj)/lib + +# LDFLAGS_initramfs_data.o := $(LDFLAGS_BLOB) -r -T $(obj)/initramfs_data.o: $(src)/initramfs_data.scr $(obj)/initramfs_data.cpio.gz FORCE $(call if_changed,ld) -$(obj)/initramfs_data.cpio.gz: $(obj)/gen_init_cpio - ./$< | gzip -9c > $@ +quiet_cmd_cpio = CPIO $@ + cmd_cpio = ./$< | gzip -9c > $@ + +# + +initramfs-y := $(obj)/root/hello + +$(obj)/initramfs_data.cpio.gz: $(obj)/gen_init_cpio $(initramfs-y) FORCE + $(call if_changed,cpio) + +targets += $(obj)/initramfs_data.cpio.gz + +# + +$(initramfs-y): $(obj)/root ; + +$(obj)/root: $(obj)/lib + +.PHONY: $(obj)/lib $(obj)/root +$(obj)/lib $(obj)/root: + $(Q)$(MAKE) $(user)=$@ diff -Nru a/usr/lib/MCONFIG b/usr/lib/MCONFIG --- a/usr/lib/MCONFIG Wed Feb 19 11:42:31 2003 +++ b/usr/lib/MCONFIG Wed Feb 19 11:42:31 2003 @@ -3,31 +3,29 @@ # Makefile configuration, without explicit rules # -SRCROOT = .. -include ../MCONFIG - -WARNFLAGS = -W -Wall -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Winline -CFLAGS = -Wp,-MD,$(dir $*).$(notdir $*).d $(OPTFLAGS) $(REQFLAGS) $(WARNFLAGS) +# +# Makefile configuration, without explicit rules +# + +STRIP = $(CROSS)strip --strip-all -R .comment -R .note + +# +# 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 + +# +# Include arch-specific rule fragments +# +include $(KLIBSRC)/arch/$(ARCH)/MCONFIG SOFLAGS = -fPIC +ifdef notdef .SUFFIXES: .c .o .a .so .lo .i .S .s .ls .ss .lss -.c.o: - $(CC) $(CFLAGS) -c -o $@ $< - -.c.i: - $(CC) $(CFLAGS) -E -o $@ $< - -.c.s: - $(CC) $(CFLAGS) -S -o $@ $< - -.S.o: - $(CC) $(CFLAGS) -D__ASSEMBLY__ -c -o $@ $< - -.S.s: - $(CC) $(CFLAGS) -D__ASSEMBLY__ -E -o $@ $< - .S.lo: $(CC) $(CFLAGS) $(SOFLAGS) -D__ASSEMBLY__ -c -o $@ $< @@ -45,5 +43,6 @@ .c.ls: $(CC) $(CFLAGS) $(SOFLAGS) -S -o $@ $< +endif diff -Nru a/usr/lib/Makefile b/usr/lib/Makefile --- a/usr/lib/Makefile Wed Feb 19 11:42:31 2003 +++ b/usr/lib/Makefile Wed Feb 19 11:42:31 2003 @@ -1,14 +1,4 @@ -# -# Makefile -# -# Main makefile -# -# Include configuration rules -include MCONFIG - -TESTS = $(patsubst %.c,%,$(wildcard tests/*.c)) \ - $(patsubst %.c,%.shared,$(wildcard tests/*.c)) LIBOBJS = vsnprintf.o snprintf.o vsprintf.o sprintf.o \ vsscanf.o sscanf.o ctypes.o \ strntoumax.o strntoimax.o \ @@ -45,10 +35,81 @@ CRT0 = crt0.o LIB = libc.a -all: tests $(CRT0) $(LIB) $(SOLIB) klibc.so - # Add any architecture-specific rules -include arch/$(ARCH)/Makefile.inc +include $(src)/arch/$(ARCH)/Makefile.inc + +# Generate the the files in syscalls/, socketcall/ and +# save the names into $(syscall-objs)/$(socketcall-objs) +-include $(obj)/syscalls.mk $(obj)/socketcalls.mk + +quiet_cmd_objs.mk = GEN $@ + cmd_objs.mk = $(PERL) $(word 2,$^) $(ARCH) $(obj) < $< > $@ + +$(obj)/syscalls.mk: $(src)/SYSCALLS $(src)/syscalls.pl FORCE + $(call if_changed,objs.mk) + +$(obj)/socketcalls.mk: $(src)/SOCKETCALLS $(src)/socketcalls.pl FORCE + $(call if_changed,objs.mk) + +targets += $(obj)/syscalls.mk $(obj)/socketcalls.mk + +# That's what we're supposed to build + +build-targets := crt0.o libc.a libc.so klibc.so + +host-progs := sha1hash + +# crt0.o + +quiet_cmd_cp = CP $@ + cmd_cp = cp $< $@ + +$(obj)/crt0.o: $(obj)/arch/$(ARCH)/crt0.o FORCE + $(call if_changed,cp) + +targets += $(obj)/crt0.o $(obj)/arch/$(ARCH)/crt0.o + +# static lib + + deps_libc.a = __static_init.o $(LIBOBJS) $(ARCHOBJS) \ + $(syscall-objs) $(socketcall-objs) +quiet_cmd_libc.a = USERAR $@ + cmd_libc.a = rm -f $@; $(USERAR) rcs $@ $(call objectify,$(deps_libc.a)) + +# shared lib + + deps_libc.so = crt0.o __shared_init.o $(LIBOBJS) $(ARCHOBJS) \ + $(syscall-objs) $(socketcall-objs) $(USERLIBGCC) +quiet_cmd_libc.so = LD $@ + cmd_libc.so = $(USERLD) $(USERLDFLAGS) $(USERSHAREDFLAGS) \ + -o $@ $(call objectify,$(deps_libc.so)) +# + +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) + +targets += $(obj)/libc.so.hash + +ifdef notdef + +TESTS = $(patsubst %.c,%,$(wildcard tests/*.c)) \ + $(patsubst %.c,%.shared,$(wildcard tests/*.c)) tests: $(TESTS) @@ -60,75 +121,21 @@ cp $@ $@.stripped $(STRIP) $@.stripped -tests/%.shared : tests/%.o interp.o $(SOLIB) - $(LD) $(LDFLAGS) -o $@ -e main interp.o tests/$*.o -R $(SOLIB) $(LIBGCC) +tests/%.shared : tests/%.o interp.o libc.so + $(LD) $(LDFLAGS) -o $@ -e main interp.o tests/$*.o -R libc.so $(LIBGCC) cp $@ $@.stripped $(STRIP) $@.stripped -$(LIB): __static_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/static.obj socketcalls/static.obj - rm -f $(LIB) - $(AR) cq $(LIB) __static_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/*.o socketcalls/*.o - $(RANLIB) $(LIB) - -$(SOLIB): $(CRT0) __shared_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/static.obj socketcalls/static.obj - $(LD) $(LDFLAGS) $(SHAREDFLAGS) -o $@ \ - $(CRT0) __shared_init.o $(LIBOBJS) $(ARCHOBJS) \ - syscalls/*.o socketcalls/*.o \ - $(LIBGCC) - -sha1hash: sha1hash.c - $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ $< - -$(SOLIB).hash: $(SOLIB) sha1hash - $(NM) $(SOLIB) | \ - egrep '^[0-9a-fA-F]+ [ADRTW] ' | sort | ./sha1hash > $@ - -$(SOHASH): $(SOLIB) $(SOLIB).hash - cp -f $(SOLIB) $@ - $(STRIP) $@ - rm -f klibc-??????????????????????.so - ln -f $@ klibc-`cat $(SOLIB).hash`.so - -interp.o: interp.S $(SOLIB).hash +interp.o: interp.S libc.so.hash $(CC) $(CFLAGS) -D__ASSEMBLY__ -DLIBDIR=\"$(SHLIBDIR)\" \ - -DSOHASH=\"`cat $(SOLIB).hash`\" \ + -DSOHASH=\"`cat libc.so.hash`\" \ -c -o $@ $< -crt0.o: arch/$(ARCH)/crt0.o - cp arch/$(ARCH)/crt0.o . - -syscalls.dir: SYSCALLS syscalls.pl syscommon.h - rm -rf syscalls - mkdir syscalls - $(PERL) syscalls.pl $(ARCH) < SYSCALLS - touch $@ - -socketcalls.dir: SOCKETCALLS socketcalls.pl socketcommon.h - rm -rf socketcalls - mkdir socketcalls - $(PERL) socketcalls.pl $(ARCH) < SOCKETCALLS - touch $@ - -%/static.obj: %.dir - $(MAKE) objects-$(basename $(notdir $@)) DIR=$* - -STATIC = $(addsuffix .o,$(basename $(wildcard $(DIR)/*.[cS]))) - -objects-static: $(STATIC) - touch $(DIR)/static.obj - -clean: archclean - find . -type f -a \( -name \*.[isoa] -o -name \*.l[iso] \) -print0 | xargs -0rt rm -f - rm -f *.a *.so *.hash *.syms *.stripped +clean: rm -f $(TESTS) tests/*.stripped - rm -rf syscalls syscalls.dir - rm -rf socketcalls socketcalls.dir - rm -f sha1hash - -spotless: clean - find . \( -name \*~ -o -name '.*.d' \) -not -type d -print0 | \ - xargs -0rt rm -f -ifneq ($(wildcard $(DIR)/.*.d),) -include $(wildcard $(DIR)/.*.d) endif + +clean-files := syscalls/*.[cS] syscalls.mk \ + socketcalls/*.[cS] socketcalls.mk \ + *.so *.hash diff -Nru a/usr/lib/socketcalls/socketcommon.h b/usr/lib/socketcalls/socketcommon.h --- /dev/null Wed Dec 31 16:00:00 1969 +++ b/usr/lib/socketcalls/socketcommon.h Wed Feb 19 11:42:31 2003 @@ -0,0 +1,25 @@ +/* + * socketcommon.h + * + * Common header file for socketcall stubs + */ + +#define __IN_SYS_COMMON +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Some architectures have socketcall(), some have real syscalls, + * and some have both, but the syscall version is always preferred. + * Look for __NR_ to probe for the existence of a syscall. + */ + +#ifdef __NR_socketcall +static inline _syscall2(int,socketcall,int,call,unsigned long *,args); +#endif diff -Nru a/usr/lib/socketcalls.pl b/usr/lib/socketcalls.pl --- a/usr/lib/socketcalls.pl Wed Feb 19 11:42:31 2003 +++ b/usr/lib/socketcalls.pl Wed Feb 19 11:42:31 2003 @@ -1,5 +1,8 @@ #!/usr/bin/perl -($arch) = @ARGV; +$arch = $ARGV[0]; +$obj = $ARGV[1]; + +print STDOUT "socketcall-objs := "; while ( defined($line = ) ) { chomp $line; @@ -19,8 +22,10 @@ } $nargs = $i; + print STDOUT " \\\n\tsocketcalls/${name}.o"; + if ( $arch eq 'i386' ) { - open(OUT, "> socketcalls/${name}.S") + open(OUT, "> ${obj}/socketcalls/${name}.S") or die "$0: Cannot open socketcalls/${name}.S\n"; print OUT "#include \n"; @@ -34,7 +39,7 @@ print OUT "\tjmp __socketcall_common\n"; print OUT "\t.size ${name},.-${name}\n"; } else { - open(OUT, "> socketcalls/${name}.c") + open(OUT, "> ${obj}/${name}.c") or die "$0: Cannot open socketcalls/${name}.c\n"; print OUT "#include \"socketcommon.h\"\n\n"; diff -Nru a/usr/lib/socketcommon.h b/usr/lib/socketcommon.h --- a/usr/lib/socketcommon.h Wed Feb 19 11:42:31 2003 +++ /dev/null Wed Dec 31 16:00:00 1969 @@ -1,25 +0,0 @@ -/* - * socketcommon.h - * - * Common header file for socketcall stubs - */ - -#define __IN_SYS_COMMON -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * Some architectures have socketcall(), some have real syscalls, - * and some have both, but the syscall version is always preferred. - * Look for __NR_ to probe for the existence of a syscall. - */ - -#ifdef __NR_socketcall -static inline _syscall2(int,socketcall,int,call,unsigned long *,args); -#endif diff -Nru a/usr/lib/syscalls/syscommon.h b/usr/lib/syscalls/syscommon.h --- /dev/null Wed Dec 31 16:00:00 1969 +++ b/usr/lib/syscalls/syscommon.h Wed Feb 19 11:42:31 2003 @@ -0,0 +1,29 @@ +/* + * syscommon.h + * + * Common header file for system call stubs + */ + +#define __IN_SYS_COMMON +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff -Nru a/usr/lib/syscalls.pl b/usr/lib/syscalls.pl --- a/usr/lib/syscalls.pl Wed Feb 19 11:42:31 2003 +++ b/usr/lib/syscalls.pl Wed Feb 19 11:42:31 2003 @@ -1,5 +1,8 @@ #!/usr/bin/perl -($arch) = @ARGV; +$arch = $ARGV[0]; +$obj = $ARGV[1]; + +print STDOUT "syscall-objs := "; while ( defined($line = ) ) { chomp $line; @@ -44,9 +47,11 @@ @args = split(/\s*\,\s*/, $argv); - open(OUT, "> syscalls/${fname}.c") - or die "$0: Cannot open syscalls/${fname}.c\n"; + open(OUT, "> ${obj}/syscalls/${fname}.c") + or die "$0: Cannot open ${obj}/${fname}.c\n"; + print STDOUT " \\\n\tsyscalls/${fname}.o"; + if ( $fname eq "rt_sigaction") { print OUT "#ifdef __x86_64__\n\n"; print OUT "struct sigaction;\n\n"; @@ -70,3 +75,4 @@ close(OUT); } } +print STDOUT "\n"; diff -Nru a/usr/lib/syscommon.h b/usr/lib/syscommon.h --- a/usr/lib/syscommon.h Wed Feb 19 11:42:31 2003 +++ /dev/null Wed Dec 31 16:00:00 1969 @@ -1,29 +0,0 @@ -/* - * syscommon.h - * - * Common header file for system call stubs - */ - -#define __IN_SYS_COMMON -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff -Nru a/usr/root/Makefile b/usr/root/Makefile --- /dev/null Wed Dec 31 16:00:00 1969 +++ b/usr/root/Makefile Wed Feb 19 11:42:31 2003 @@ -0,0 +1,3 @@ + +user-progs := hello +build-targets := hello \ No newline at end of file Binary files a/usr/root/hello and b/usr/root/hello differ diff -Nru a/usr/root/hello.c b/usr/root/hello.c --- /dev/null Wed Dec 31 16:00:00 1969 +++ b/usr/root/hello.c Wed Feb 19 11:42:31 2003 @@ -0,0 +1,8 @@ +#include + +const char hello[] = "Hi Ma!\n"; +int main (void) +{ + fputs("Hi Ma!\n", stdout); + return 0; +}