From 9d8564e56bcd8707d48a331a7f8f4e5eba0c70e5 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Thu, 8 Dec 2011 16:02:03 +0800 Subject: [PATCH] Usermode - More work on new build system --- Usermode/Applications/CLIShell_src/rules.mk | 18 ++++++++ Usermode/Applications/rules.mk | 18 ++++++++ Usermode/Libraries/crt0.o_src/rules.mk | 23 +++++++++++ Usermode/Libraries/ld-acess.so_src/rules.mk | 3 +- .../Libraries/libimage_sif.so_src/rules.mk | 17 ++++++++ Usermode/Libraries/libnet.so_src/rules.mk | 18 ++++++++ .../Libraries/libreadline.so_src/rules.mk | 17 ++++++++ Usermode/Libraries/liburi.so_src/rules.mk | 17 ++++++++ Usermode/body.mk | 2 + Usermode/rules.mk | 41 +++++++++++-------- 10 files changed, 156 insertions(+), 18 deletions(-) create mode 100644 Usermode/Applications/CLIShell_src/rules.mk create mode 100644 Usermode/Applications/rules.mk create mode 100644 Usermode/Libraries/crt0.o_src/rules.mk create mode 100644 Usermode/Libraries/libimage_sif.so_src/rules.mk create mode 100644 Usermode/Libraries/libnet.so_src/rules.mk create mode 100644 Usermode/Libraries/libreadline.so_src/rules.mk create mode 100644 Usermode/Libraries/liburi.so_src/rules.mk diff --git a/Usermode/Applications/CLIShell_src/rules.mk b/Usermode/Applications/CLIShell_src/rules.mk new file mode 100644 index 00000000..472cdcb4 --- /dev/null +++ b/Usermode/Applications/CLIShell_src/rules.mk @@ -0,0 +1,18 @@ +# CLIShell + +include $(BASE)header.mk + +# Variables +SRCS := main.c lib.c +BIN := $(OUTPUTDIR)Bin/CLIShell + +CFLAGS-$(DIR) := $(CFLAGS-$(PDIR)) -g +CPPFLAGS-$(DIR) := $(CPPFLAGS-$(PDIR)) -I$(DIR)/include +LDFLAGS-$(DIR) := $(LDFLAGS-$(PDIR)) -lreadline + +include $(BASE)body.mk + +$(BIN): $(OBJ) + +include $(BASE)footer.mk + diff --git a/Usermode/Applications/rules.mk b/Usermode/Applications/rules.mk new file mode 100644 index 00000000..af5a99e0 --- /dev/null +++ b/Usermode/Applications/rules.mk @@ -0,0 +1,18 @@ +include $(BASE)header.mk + +# Rules +ASFLAGS-$(DIR) := -felf -D ARCHDIR=$(ARCHDIR) -D __ASSEMBLER__=1 +CPPFLAGS-$(DIR) := -I$(ACESSDIR)/Usermode/include/ -DARCHDIR=$(ARCHDIR) -DARCHDIR_is_$(ARCHDIR)=1 +CFLAGS-$(DIR) := -g -Wall -fno-stack-protector -O3 +LDFLAGS-$(DIR) := -T $(OUTPUTDIR)Libs/acess.ld -rpath-link $(OUTPUTDIR)Libs -L $(OUTPUTDIR)Libs -I /Acess/Libs/ld-acess.so -lld-acess -lc $(OUTPUTDIR)Libs/crtbegin.o $(OUTPUTDIR)Libs/crtend.o + +SUB_DIRS = $(wildcard $(DIR)*/rules.mk) + +.PHONY: all-$(DIR) clean-$(DIR) +all-$(DIR): $(addprefix all-,$(dir $(SUB_DIRS))) +clean-$(DIR): $(addprefix clean-,$(dir $(SUB_DIRS))) + +include $(SUB_DIRS) + +include $(BASE)footer.mk + diff --git a/Usermode/Libraries/crt0.o_src/rules.mk b/Usermode/Libraries/crt0.o_src/rules.mk new file mode 100644 index 00000000..728bb566 --- /dev/null +++ b/Usermode/Libraries/crt0.o_src/rules.mk @@ -0,0 +1,23 @@ +# crt0 and friends + +include $(BASE)header.mk + +# Variables +SRCS := crt0.c crtbegin.c crtend.c +# signals.c +BIN := $(OUTPUTDIR)Libs/crt0.o $(OUTPUTDIR)Libs/crtbegin.o $(OUTPUTDIR)Libs/crtend.o + +CFLAGS-$(DIR) := $(CFLAGS-$(PDIR)) -g +CPPFLAGS-$(DIR) := $(CPPFLAGS-$(PDIR)) +LDFLAGS-$(DIR) := $(LDFLAGS-$(PDIR)) + +include $(BASE)body.mk + +$(filter %crt0.o,$(BIN)): $(filter %crt0.c.o,$(OBJ)) + cp $< $@ +$(filter %crtbegin.o,$(BIN)): $(filter %crtbegin.c.o,$(OBJ)) + cp $< $@ +$(filter %crtend.o,$(BIN)): $(filter %crtend.c.o,$(OBJ)) + cp $< $@ + +include $(BASE)footer.mk diff --git a/Usermode/Libraries/ld-acess.so_src/rules.mk b/Usermode/Libraries/ld-acess.so_src/rules.mk index 2c864418..773d8c1b 100644 --- a/Usermode/Libraries/ld-acess.so_src/rules.mk +++ b/Usermode/Libraries/ld-acess.so_src/rules.mk @@ -16,6 +16,7 @@ OBJ := $(call fcn_src2obj,$(SRCS)) ALL_OBJ := $(ALL_OBJ) $(OBJ) OBJ-$(DIR) := $(OBJ) $(XOBJ) BIN-$(DIR) := $(BIN) $(XBIN) +$(foreach f,$(OBJ) $(XOBJ) $(BIN) $(XBIN),$(eval _DIR-$f := $(DIR))) # Rules .PHONY: all-$(DIR) clean-$(DIR) @@ -29,7 +30,7 @@ clean-$(DIR): clean-%: $(BIN): $(OBJ) # Stub library -$(XBIN): $(call fcn_mkobj,_stublib.c.o) +$(XBIN): $(call fcn_mkobj,_stublib.c.o) $(BIN) @echo [LD] -shared -o libld-acess.so @$(LD) -shared -o $@ $< diff --git a/Usermode/Libraries/libimage_sif.so_src/rules.mk b/Usermode/Libraries/libimage_sif.so_src/rules.mk new file mode 100644 index 00000000..17ba273f --- /dev/null +++ b/Usermode/Libraries/libimage_sif.so_src/rules.mk @@ -0,0 +1,17 @@ +# libimage_sif +include $(BASE)header.mk + +# Variables +SRCS := main.c +BIN := $(OUTPUTDIR)Libs/libimage_sif.so + +CFLAGS-$(DIR) := $(CFLAGS-$(PDIR)) +CPPFLAGS-$(DIR) := $(CPPFLAGS-$(PDIR)) +LDFLAGS-$(DIR) := $(LDFLAGS-$(PDIR)) -lc + +include $(BASE)body.mk + +$(BIN): $(OBJ) $(OUTPUTDIR)Libs/libc.so + +include $(BASE)footer.mk + diff --git a/Usermode/Libraries/libnet.so_src/rules.mk b/Usermode/Libraries/libnet.so_src/rules.mk new file mode 100644 index 00000000..e5afa621 --- /dev/null +++ b/Usermode/Libraries/libnet.so_src/rules.mk @@ -0,0 +1,18 @@ +# libnet +include $(BASE)header.mk + +# Variables +SRCS := main.c address.c +BIN := $(OUTPUTDIR)Libs/libnet.so + +CFLAGS-$(DIR) := $(CFLAGS-$(PDIR)) +CPPFLAGS-$(DIR) := $(CPPFLAGS-$(PDIR)) +LDFLAGS-$(DIR) := $(LDFLAGS-$(PDIR)) -lc + +include $(BASE)body.mk + +$(BIN): $(OBJ) $(OUTPUTDIR)Libs/libc.so + +include $(BASE)footer.mk + + diff --git a/Usermode/Libraries/libreadline.so_src/rules.mk b/Usermode/Libraries/libreadline.so_src/rules.mk new file mode 100644 index 00000000..f5d83cbe --- /dev/null +++ b/Usermode/Libraries/libreadline.so_src/rules.mk @@ -0,0 +1,17 @@ +# libreadline +include $(BASE)header.mk + +# Variables +SRCS := main.c +BIN := $(OUTPUTDIR)Libs/libreadline.so + +CFLAGS-$(DIR) := $(CFLAGS-$(PDIR)) +CPPFLAGS-$(DIR) := $(CPPFLAGS-$(PDIR)) +LDFLAGS-$(DIR) := $(LDFLAGS-$(PDIR)) -lc + +include $(BASE)body.mk + +$(BIN): $(OBJ) $(OUTPUTDIR)Libs/libc.so + +include $(BASE)footer.mk + diff --git a/Usermode/Libraries/liburi.so_src/rules.mk b/Usermode/Libraries/liburi.so_src/rules.mk new file mode 100644 index 00000000..0d3fa828 --- /dev/null +++ b/Usermode/Libraries/liburi.so_src/rules.mk @@ -0,0 +1,17 @@ +# liburi +include $(BASE)header.mk + +# Variables +SRCS := main.c +BIN := $(OUTPUTDIR)Libs/liburi.so + +CFLAGS-$(DIR) := $(CFLAGS-$(PDIR)) +CPPFLAGS-$(DIR) := $(CPPFLAGS-$(PDIR)) +LDFLAGS-$(DIR) := $(LDFLAGS-$(PDIR)) -lc + +include $(BASE)body.mk + +$(BIN): $(OBJ) $(OUTPUTDIR)Libs/libc.so + +include $(BASE)footer.mk + diff --git a/Usermode/body.mk b/Usermode/body.mk index 83a7b813..d4c74149 100644 --- a/Usermode/body.mk +++ b/Usermode/body.mk @@ -4,6 +4,8 @@ ALL_OBJ := $(ALL_OBJ) $(OBJ) OBJ-$(DIR) := $(OBJ) BIN-$(DIR) := $(BIN) +$(foreach f,$(OBJ) $(BIN),$(eval _DIR-$f := $(DIR))) + # Rules .PHONY: all-$(DIR) clean-$(DIR) all-$(DIR): $(BIN) diff --git a/Usermode/rules.mk b/Usermode/rules.mk index b31b60da..2d576df9 100644 --- a/Usermode/rules.mk +++ b/Usermode/rules.mk @@ -30,7 +30,7 @@ else DEFAULT_RULES := $(abspath $(pwd)/$(_REL_POS)) endif -include $(_REL_POS)../Makefile.cfg +include $(BASE)Makefile.cfg .PHONY: all clean @@ -44,13 +44,16 @@ include $(SUB_DIRS) # === Rules === fcn_obj2src = $(subst $(OBJECT_DIR)/,$(SOURCE_DIR)/,$(patsubst %$(OBJECT_SUFFIX).o,%,$1)) +# ACESS SPECIFIC +fcn_getlibs = $(patsubst -l%,$(OUTPUTDIR)/Libs/lib%.so,$(filter -l%,$(LDFLAGS-$(_DIR-$1)))) -ifeq (x,) -$(foreach file,$(filter %.cpp$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(eval $f: $(call fcn_obj2src,$f))) -$(foreach file,$(filter %.cc$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(eval $f: $(call fcn_obj2src,$f))) -$(foreach file,$(filter %.c$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(eval $f: $(call fcn_obj2src,$f))) -$(foreach file,$(filter %.S$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(eval $f: $(call fcn_obj2src,$f)))) -$(foreach file,$(filter %.asm$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(eval $f: $(call fcn_obj2src,$f))) +fcn_mkrule = $(eval $f: $(call fcn_getlibs,$f) $(call fcn_obj2src,$f)) +ifeq (,) +$(foreach file,$(filter %.cpp$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f)) +$(foreach file,$(filter %.cc$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f)) +$(foreach file,$(filter %.c$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f)) +$(foreach file,$(filter %.S$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f)) +$(foreach file,$(filter %.asm$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f)) else .PHONY: $(BASE)obj_rules.mk $(BASE)obj_rules.mk: @@ -65,28 +68,28 @@ endif # --- Object Files --- # C++ (.cpp) %.cpp$(OBJECT_SUFFIX).o: - $(eval _dir=$(dir $(subst $(OBJECT_DIR)/,,$*))) + $(eval _dir=$(_DIR-$@)) $(eval <=$(call fcn_obj2src,$@)) @echo [CXX] -o $< @mkdir -p $(dir $@) @$(CCPP) $(CXXFLAGS) $(CPPFLAGS) $(CXXFLAGS-$(_dir)) $(CPPFLAGS-$(_dir))-c $(_src) -o $@ # C++ (.cc) %.cc$(OBJECT_SUFFIX).o: - $(eval _dir=$(dir $(subst $(OBJECT_DIR)/,,$*))) + $(eval _dir=$(_DIR-$@)) $(eval _src=$(call fcn_obj2src,$@)) @echo [CXX] -o $< @mkdir -p $(dir $@) @$(CCPP) $(CXXFLAGS) $(CXXFLAGS-$(_dir)) $(CPPFLAGS-$(_dir)) -c $(_src) -o $@ # C (.c) %.c$(OBJECT_SUFFIX).o: - $(eval _dir=$(dir $(subst $(OBJECT_DIR)/,,$*))) + $(eval _dir=$(_DIR-$@)) $(eval _src=$(call fcn_obj2src,$@)) @echo [CC] -o $@ @mkdir -p $(dir $@) @$(CC) $(CFLAGS) $(CPPFLAGS) $(CFLAGS-$(_dir)) $(CPPFLAGS-$(_dir)) -c $(_src) -o $@ # Assembly (.S) %.S$(OBJECT_SUFFIX).o: - $(eval _dir=$(dir $(subst $(OBJECT_DIR)/,,$*))) + $(eval _dir=$(_DIR-$@)) $(eval _src=$(call fcn_obj2src,$@)) @echo [AS] -o $@ @mkdir -p $(dir $@) @@ -94,7 +97,7 @@ endif @$(AS) $(ASFLAGS) $(ASFLAGS-$(_dir)) -o $@.dep $(_src) -M # Assembly (.asm) %.asm$(OBJECT_SUFFIX).o: - $(eval _dir=$(dir $(subst $(OBJECT_DIR)/,,$*))) + $(eval _dir=$(_DIR-$@)) $(eval _src=$(call fcn_obj2src,$@)) @echo [AS] -o $@ @mkdir -p $(dir $@) @@ -104,19 +107,23 @@ endif # --- Binaries --- # Static Library (.a) %.a: - $(eval _dir=$(subst $(OBJECT_DIR),,$(dir $<))) + $(eval _dir=$(_DIR-$@)) @echo [AR] ru $@ @$(RM) $@ @$(AR) ru $@ $(OBJ-$(_dir)) # Dynamic Library (.so) %.so: - $(eval _dir=$(subst $(OBJECT_DIR),,$(dir $<))) + $(eval _dir=$(_DIR-$@)) @echo [LD] -shared -o $@ @$(LD) $(LDFLAGS) -shared -soname $(basename $@) -o $@ $(filter %.o,$^) $(LDFLAGS-$(_dir)) # Executable (.bin) %.bin: - $(eval _dir=$(subst $(OBJECT_DIR),,$(dir $<))) + $(eval _dir=$(_DIR-$@)) @echo [LD] -o $@ - @$(ld) $(LDFLAGS) -o $@ $(OBJ-$(_dir)) $(LDFLAGS-$(_dir)) - @$(CP) $@ $(@:%.bin=%) + @$(LD) $(LDFLAGS) -o $@ $(OBJ-$(_dir)) $(LDFLAGS-$(_dir)) + @$(CP) $@ $(@:%.bin=%) +$(OUTPUTDIR)%: + $(eval _dir=$(_DIR-$@)) + @echo [LD] -o $@ + @$(LD) $(LDFLAGS) -o $@ $(OBJ-$(_dir)) $(LDFLAGS-$(_dir)) -- 2.20.1