2 # Acess2 Global Makefile
7 OBJECT_DIR = obj-$(ARCH)/
10 # Functions used later
12 $(patsubst %,%$(OBJECT_SUFFIX).o,$(filter %.c,$1)) \
13 $(patsubst %,%$(OBJECT_SUFFIX).o,$(filter %.cpp,$1)) \
14 $(patsubst %,%$(OBJECT_SUFFIX).o,$(filter %.cc,$1)) \
15 $(patsubst %,%$(OBJECT_SUFFIX).o,$(filter %.S,$1)) \
16 $(patsubst %,%$(OBJECT_SUFFIX).o,$(filter %.asm,$1))
17 fcn_mkobj = $(addprefix $(DIR)$(OBJECT_DIR),$(patsubst $(SOURCE_DIR)%,%,$1))
18 fcn_src2obj = $(call fcn_mkobj, $(call fcn_src2obj_int,$1))
19 fcn_obj2src = $(subst $(OBJECT_DIR),$(SOURCE_DIR),$(patsubst %$(OBJECT_SUFFIX).o,%,$1))
21 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 BIN-$(DIR):=$(BIN-$(DIR)) $1) $(eval OBJ-$1:=$2)
23 # Start of Voodoo code
24 _REL_POS := $(dir $(lastword $(MAKEFILE_LIST)))
25 BASE = $(abspath $(_REL_POS))/
26 SUB_DIRS = $(wildcard $(BASE)*/rules.mk)
27 #$(warning $(SUB_DIRS))
30 DEFAULT_RULES := $(dir $(SUB_DIRS))
32 # Build part of the tree
33 DEFAULT_RULES := $(abspath $(shell pwd))/
34 # $(warning $(DEFAULT_RULES))
37 include $(BASE)Makefile.cfg
41 all: $(addprefix all-,$(DEFAULT_RULES))
42 clean: $(addprefix clean-,$(DEFAULT_RULES))
49 # Transforms LDFLAGS -l arguments into library binary paths
50 fcn_getlibs = $(foreach f,$(patsubst -l%,lib%.so,$(filter -l%,$(LDFLAGS-$(_DIR-$1)))),$(filter %/$f,$(ALL_BIN)))
53 # - Binds source files to object targets
54 fcn_mkrule = $(eval $1: $(call fcn_obj2src,$1))
55 $(foreach f,$(filter %.cpp$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f))
56 $(foreach f,$(filter %.cc$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f))
57 $(foreach f,$(filter %.c$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f))
58 $(foreach f,$(filter %.S$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f))
59 $(foreach f,$(filter %.asm$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f))
60 # - Bind extra dependencies and libraries to objects
61 $(foreach f,$(ALL_BIN), $(eval $f: $(EXTRA_DEP-$(_DIR-$f)) $(call fcn_getlibs,$f)))
63 # --- Object Files ---
65 %.cpp$(OBJECT_SUFFIX).o:
66 $(eval _dir=$(_DIR-$@))
67 $(eval <=$(call fcn_obj2src,$@))
70 @$(CCPP) $(CXXFLAGS) $(CPPFLAGS) $(CXXFLAGS-$(_dir)) $(CPPFLAGS-$(_dir))-c $(_src) -o $@
72 %.cc$(OBJECT_SUFFIX).o:
73 $(eval _dir=$(_DIR-$@))
74 $(eval _src=$(call fcn_obj2src,$@))
77 @$(CCPP) $(CXXFLAGS) $(CXXFLAGS-$(_dir)) $(CPPFLAGS-$(_dir)) -c $(_src) -o $@
79 %.c$(OBJECT_SUFFIX).o:
80 $(eval _dir=$(_DIR-$@))
81 $(eval _src=$(call fcn_obj2src,$@))
84 @$(CC) $(CFLAGS) $(CPPFLAGS) $(CFLAGS-$(_dir)) $(CPPFLAGS-$(_dir)) -c $(_src) -o $@
86 %.S$(OBJECT_SUFFIX).o:
87 $(eval _dir=$(_DIR-$@))
88 $(eval _src=$(call fcn_obj2src,$@))
91 @$(AS) $(ASFLAGS) $(ASFLAGS-$(_dir)) -o $@ $(_src)
94 %.asm$(OBJECT_SUFFIX).o:
95 $(eval _dir=$(_DIR-$@))
96 $(eval _src=$(call fcn_obj2src,$@))
99 @$(AS) $(ASFLAGS) $(ASFLAGS-$(_dir)) -o $@ $(_src)
103 # Static Library (.a)
105 $(eval _dir=$(_DIR-$@))
109 @$(AR) ru $@ $(OBJ-$@)
110 # Dynamic Library (.so)
112 $(eval _dir=$(_DIR-$@))
113 @echo [LD] -shared -o $@
115 @$(LD) $(LDFLAGS) -shared -soname $(notdir $@) -o $@ $(OBJ-$@) $(LDFLAGS-$(_dir))
118 $(eval _dir=$(_DIR-$@))
121 @$(LD) $(LDFLAGS) -o $@ $(OBJ-$@) $(LDFLAGS-$(_dir))
122 @$(CP) $@ $(@:%.bin=%)
124 $(eval _dir=$(_DIR-$@))
127 @$(LD) $(LDFLAGS) -o $@ $(OBJ-$@) $(LDFLAGS-$(_dir))
129 -include $(ALL_OBJ:%=%.dep)