From: John Hodge Date: Thu, 8 Dec 2011 13:47:47 +0000 (+0800) Subject: Fixing new build system X-Git-Tag: rel0.14~28 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=10a01542f62120b5117cc9638c78380edc771690;p=tpg%2Facess2.git Fixing new build system --- diff --git a/Usermode/Applications/rules.mk b/Usermode/Applications/rules.mk index af5a99e0..d4b67786 100644 --- a/Usermode/Applications/rules.mk +++ b/Usermode/Applications/rules.mk @@ -7,6 +7,7 @@ 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) +EXTRA_DEP-$(DIR) += $(OUTPUTDIR)Libs/crtbegin.o $(OUTPUTDIR)Libs/crt0.o $(OUTPUTDIR)Libs/crtend.o .PHONY: all-$(DIR) clean-$(DIR) all-$(DIR): $(addprefix all-,$(dir $(SUB_DIRS))) diff --git a/Usermode/Libraries/ld-acess.so_src/rules.mk b/Usermode/Libraries/ld-acess.so_src/rules.mk index 773d8c1b..b3b560ae 100644 --- a/Usermode/Libraries/ld-acess.so_src/rules.mk +++ b/Usermode/Libraries/ld-acess.so_src/rules.mk @@ -1,38 +1,18 @@ -# Acess2 - ld-acess +# ld-acess include $(BASE)header.mk # Variables SRCS := main.c lib.c loadlib.c export.c elf.c pe.c SRCS += arch/$(ARCHDIR).$(ASSUFFIX) BIN := $(OUTPUTDIR)Libs/ld-acess.so -XOBJ := $(call fcn_mkobj,_stublib.o) -XBIN := $(OUTPUTDIR)Libs/libld-acess.so CFLAGS-$(DIR) := -Wall -fno-builtin -fno-leading-underscore -fno-stack-protector -fPIC -g CPPFLAGS-$(DIR) := $(CPPFLAGS-$(PDIR)) LDFLAGS-$(DIR) := -g -T $(DIR)/arch/$(ARCHDIR).ld -Map $(call fcn_mkobj,map.txt) --export-dynamic -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))) +include $(BASE)body.mk -# Rules -.PHONY: all-$(DIR) clean-$(DIR) - -all-$(DIR): $(BIN-$(DIR)) -clean-$(DIR): clean-%: - $(eval BIN=$(BIN-$*/)) - $(eval OBJ=$(OBJ-$*/)) - $(RM) $(BIN) $(OBJ) - -$(BIN): $(OBJ) - -# Stub library -$(XBIN): $(call fcn_mkobj,_stublib.c.o) $(BIN) - @echo [LD] -shared -o libld-acess.so - @$(LD) -shared -o $@ $< +$(call fcn_addbin, $(OUTPUTDIR)Libs/libld-acess.so, $(call fcn_mkobj,_stublib.c.o)) # Handle preprocessed files $(DIR)/%: $(DIR)/%.h diff --git a/Usermode/Libraries/libc.so_src/rules.mk b/Usermode/Libraries/libc.so_src/rules.mk index 5bc4289a..f689f341 100644 --- a/Usermode/Libraries/libc.so_src/rules.mk +++ b/Usermode/Libraries/libc.so_src/rules.mk @@ -10,10 +10,8 @@ BIN := $(OUTPUTDIR)Libs/libc.so CFLAGS-$(DIR) := $(CFLAGS-$(PDIR)) -g CPPFLAGS-$(DIR) := $(CPPFLAGS-$(PDIR)) -LDFLAGS-$(DIR) := $(LDFLAGS-$(PDIR)) +LDFLAGS-$(DIR) := $(LDFLAGS-$(PDIR)) -lgcc include $(BASE)body.mk -$(BIN): $(OBJ) $(OUTPUTDIR)Libs/libgcc.so - include $(BASE)footer.mk diff --git a/Usermode/Libraries/rules.mk b/Usermode/Libraries/rules.mk index e7e93029..4786df96 100644 --- a/Usermode/Libraries/rules.mk +++ b/Usermode/Libraries/rules.mk @@ -1,3 +1,5 @@ +# Library - Common Rules + include $(BASE)header.mk # Rules diff --git a/Usermode/body.mk b/Usermode/body.mk index d4c74149..0d77d203 100644 --- a/Usermode/body.mk +++ b/Usermode/body.mk @@ -1,10 +1,7 @@ OBJ := $(call fcn_src2obj,$(SRCS)) -ALL_OBJ := $(ALL_OBJ) $(OBJ) -OBJ-$(DIR) := $(OBJ) -BIN-$(DIR) := $(BIN) -$(foreach f,$(OBJ) $(BIN),$(eval _DIR-$f := $(DIR))) +$(call fcn_addbin,$(BIN),$(OBJ)) # Rules .PHONY: all-$(DIR) clean-$(DIR) @@ -12,5 +9,5 @@ all-$(DIR): $(BIN) clean-$(DIR): clean-%: $(eval BIN=$(BIN-$*/)) $(eval OBJ=$(OBJ-$*/)) - $(RM) $(BIN) $(OBJ) + $(RM) $(BIN) $(OBJ) $(OBJ:%=%.dep) diff --git a/Usermode/header.mk b/Usermode/header.mk index 6f3c1a73..b0e1802c 100644 --- a/Usermode/header.mk +++ b/Usermode/header.mk @@ -3,3 +3,4 @@ x := $(x).x DIR_$(x) := $(DIR) DIR := $(dir $(lastword $(filter-out %/header.mk,$(MAKEFILE_LIST)))) PDIR := $(DIR_$(x)) +EXTRA_DEP-$(DIR) := $(EXTRA_DEP-$(PDIR)) diff --git a/Usermode/rules.mk b/Usermode/rules.mk index 2d576df9..067b2227 100644 --- a/Usermode/rules.mk +++ b/Usermode/rules.mk @@ -4,7 +4,7 @@ # Config Options SOURCE_DIR = -OBJECT_DIR = obj-$(ARCH) +OBJECT_DIR = obj-$(ARCH)/ OBJECT_SUFFIX = # Functions used later @@ -14,8 +14,11 @@ fcn_src2obj_int = \ $(patsubst %,%$(OBJECT_SUFFIX).o,$(filter %.cc,$1)) \ $(patsubst %,%$(OBJECT_SUFFIX).o,$(filter %.S,$1)) \ $(patsubst %,%$(OBJECT_SUFFIX).o,$(filter %.asm,$1)) -fcn_mkobj = $(addprefix $(DIR)$(OBJECT_DIR)/,$(patsubst $(SOURCE_DIR)%,%,$1)) +fcn_mkobj = $(addprefix $(DIR)$(OBJECT_DIR),$(patsubst $(SOURCE_DIR)%,%,$1)) fcn_src2obj = $(call fcn_mkobj, $(call fcn_src2obj_int,$1)) +fcn_obj2src = $(subst $(OBJECT_DIR),$(SOURCE_DIR),$(patsubst %$(OBJECT_SUFFIX).o,%,$1)) + +fcn_addbin = $(eval ALL_OBJ:=$(ALL_OBJ) $2) $(eval ALL_BIN:=$(ALL_BIN) $1) $(foreach f,$2 $1,$(eval _DIR-$f := $(DIR))) $(eval $1: $2) $(eval OBJ-$(DIR):=$(OBJ-$(DIR)) $2) $(eval BIN-$(DIR):=$(BIN-$(DIR)) $1) # Start of Voodoo code SUB_DIRS = $(wildcard */rules.mk) @@ -34,7 +37,7 @@ include $(BASE)Makefile.cfg .PHONY: all clean -all: $(BASE)obj_rules.mk $(addprefix all-,$(DEFAULT_RULES)) +all: $(addprefix all-,$(DEFAULT_RULES)) clean: $(addprefix clean-,$(DEFAULT_RULES)) # Sub-directory rules @@ -43,27 +46,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)))) - -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: - @echo "$(foreach f,$(filter %.cpp$(OBJECT_SUFFIX).o,$(ALL_OBJ)),$f: $(call fcn_obj2src,$f)\n)" > $@ - @echo "$(foreach f,$(filter %.cc$(OBJECT_SUFFIX).o,$(ALL_OBJ)),$f: $(call fcn_obj2src,$f)\n)" >> $@ - @echo "$(foreach f,$(filter %.c$(OBJECT_SUFFIX).o,$(ALL_OBJ)),$f: $(call fcn_obj2src,$f)\n)" >> $@ - @echo "$(foreach f,$(filter %.S$(OBJECT_SUFFIX).o,$(ALL_OBJ)),$f: $(call fcn_obj2src,$f)\n)" >> $@ - @echo "$(foreach f,$(filter %.asm$(OBJECT_SUFFIX).o,$(ALL_OBJ)),$f: $(call fcn_obj2src,$f)\n)" >> $@ -include $(BASE)obj_rules.mk -endif +fcn_getlibs = $(patsubst -l%,$(OUTPUTDIR)Libs/lib%.so,$(filter -l%,$(LDFLAGS-$(_DIR-$1)))) + +fcn_mkrule = $(eval $1: $(call fcn_obj2src,$1)) +$(foreach f,$(filter %.cpp$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f)) +$(foreach f,$(filter %.cc$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f)) +$(foreach f,$(filter %.c$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f)) +$(foreach f,$(filter %.S$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f)) +$(foreach f,$(filter %.asm$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f)) +$(foreach f,$(ALL_BIN), $(eval $f: $(EXTRA_DEP-$(_DIR-$f)) $(call fcn_getlibs,$f))) # --- Object Files --- # C++ (.cpp) @@ -102,7 +94,7 @@ endif @echo [AS] -o $@ @mkdir -p $(dir $@) @$(AS) $(ASFLAGS) $(ASFLAGS-$(_dir)) -o $@ $(_src) - @$(AS) $(ASFLAGS) $(ASFLAGS-$(_dir)) -o $@ $(_src) -MD $@.dep + @$(AS) $(ASFLAGS) $(ASFLAGS-$(_dir)) -o $@ $(_src) -MT $@ -MD $@.dep # --- Binaries --- # Static Library (.a) @@ -126,4 +118,8 @@ $(OUTPUTDIR)%: $(eval _dir=$(_DIR-$@)) @echo [LD] -o $@ @$(LD) $(LDFLAGS) -o $@ $(OBJ-$(_dir)) $(LDFLAGS-$(_dir)) - + +-include $(ALL_OBJ:%=%.dep) + +%.asm: %.asm.o +