blob: 16ee1a4601f44e3c9acb3ad5b4ac8b9c613c2faf [file] [log] [blame]
Daniel Dunbarb3a69012009-06-26 16:47:03 +00001SubDirs := lib
2
3# Set default rule before anything else.
4all::
5
6include make/config.mk
7include make/util.mk
8# If SRCROOT is defined, assume we are doing an Apple style build. We
9# should be able to use RC_XBS for this but that is unused during
10# "make installsrc".
11ifdef SRCROOT
12 include make/AppleBI.mk
13endif
14
15# Make sure we don't build with a missing ProjObjRoot.
16ifeq ($(ProjObjRoot),)
17$(error Refusing to build with empty ProjObjRoot variable)
18endif
19
20##############
21
22###
23# Rules
24
25###
26# Top level targets
27
28# Provide default clean target which is extended by other templates.
29.PHONY: clean
30clean::
31
32# Test
33.PHONY: test
34test:
35 cd test/Unit && ./test
36
37# Template: Config_template Config
38#
39# This template is used once per Config at the top-level.
40define Config_template
41$(call Set,ActiveConfig,$1)
42$(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveConfig))
43$(call Set,ActiveLibGen,$(ActiveObjPath)/libcompiler_rt.Generic.a)
44$(call Set,ActiveLibOpt,$(ActiveObjPath)/libcompiler_rt.Optimized.a)
45
46# The sublibraries to use for a generic version.
47$(call Set,GenericInputs,$(foreach arch,$(Archs),$(ActiveObjPath)/$(arch)/libcompiler_rt.Generic.a))
48# The sublibraries to use for an optimized version.
49$(call Set,OptimizedInputs,$(foreach arch,$(Archs),$(ActiveObjPath)/$(arch)/libcompiler_rt.Optimized.a))
50
51# Provide top-level fat archive targets.
52$(ActiveLibGen): $(GenericInputs) $(ActiveObjPath)/.dir
53 $(Summary) " UNIVERSAL: $(ActiveConfig): $$@"
54 -$(Verb) $(RM) $$@
55 $(Verb) $(Lipo) -create -output $$@ $(GenericInputs)
56$(ActiveLibOpt): $(OptimizedInputs) $(ActiveObjPath)/.dir
57 $(Summary) " UNIVERSAL: $(ActiveConfig): $$@"
58 -$(Verb) $(RM) $$@
59 $(Verb) $(Lipo) -create -output $$@ $(OptimizedInputs)
60.PRECIOUS: $(ActiveObjPath)/.dir
61
62# Add to target lists.
63all:: $(ActiveConfig) $(ActiveLibGen) $(ActiveLibOpt)
64
65# Remove entire config directory on clean.
66clean:: $(ActiveObjPath)/.remove
67endef
68
69# Template: CNA_template Config Arch
70#
71# This template is used once per Config/Arch at the top-level.
72define CNA_template
73$(call Set,ActiveConfig,$1)
74$(call Set,ActiveArch,$2)
75$(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveConfig)/$(ActiveArch))
76$(call Set,ActiveLibGen,$(ActiveObjPath)/libcompiler_rt.Generic.a)
77$(call Set,ActiveLibOpt,$(ActiveObjPath)/libcompiler_rt.Optimized.a)
78
79# Initialize inputs lists. This are extended by the CNA_subdir
80# template. The one tricky bit is that we need to use these quoted,
81# because they are not complete until the entire makefile has been
82# processed.
83$(call Set,GenericInputs.$(ActiveConfig).$(ActiveArch),)
84$(call Set,OptimizedInputs.$(ActiveConfig).$(ActiveArch),)
85# Final.Inputs is created once we have loaded all the subdirectories
86# and know what the correct inputs are.
87
88# Provide top-level archive targets.
89$(ActiveLibGen): $(ActiveObjPath)/.dir
90 $(Summary) " ARCHIVE: $(ActiveConfig)/$(ActiveArch): $$@"
91 -$(Verb) $(RM) $$@
92 $(Verb) $(Archive) $$@ $$(Generic.Inputs.$(ActiveConfig).$(ActiveArch))
93 $(Verb) $(Ranlib) $$@
94# FIXME: The dependency on ActiveLibGen is a hack, this picks up the
95# dependencies on the generic inputs.
96$(ActiveLibOpt): $(ActiveLibGen) $(ActiveObjPath)/.dir
97 $(Summary) " ARCHIVE: $(ActiveConfig)/$(ActiveArch): $$@"
98 -$(Verb) $(RM) $$@
99 $(Verb) $(Archive) $$@ $$(Final.Inputs.$(ActiveConfig).$(ActiveArch))
100 $(Verb) $(Ranlib) $$@
101.PRECIOUS: $(ActiveObjPath)/.dir
102
103# Provide some default "alias" targets.
104$(ActiveConfig):: $(ActiveLibGen) $(ActiveLibOpt)
105$(ActiveArch):: $(ActiveLibGen) $(ActiveLibOpt)
106$(ActiveConfig)-$(ActiveArch):: $(ActiveLibGen) $(ActiveLibOpt)
107endef
108
109$(foreach config,$(Configs), \
110 $(foreach arch,$(Archs), \
111 $(eval $(call CNA_template,$(config),$(arch)))))
112
113$(foreach config,$(Configs), \
114 $(eval $(call Config_template,$(config))))
115
116###
117# How to build things.
118
119# Define rules for building on each configuration & architecture. This
120# is not exactly obvious, but variables inside the template are being
121# expanded during the make processing, so automatic variables must be
122# quoted and normal assignment cannot be used.
123
124# Template: CNA_template Config Arch Dir
125# Uses: GetArgs, Dependencies, ObjNames
126#
127# This template is used once per Config/Arch/Dir.
128define CNA_subdir_template
129$(call Set,ActiveConfig,$1)
130$(call Set,ActiveArch,$2)
131$(call Set,ActiveDir,$3)
132$(call Set,ActiveSrcPath,$(ProjSrcRoot)/$(ActiveDir))
133$(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveDir)/$(ActiveConfig)/$(ActiveArch))
134
135$(call Set,ActiveFlags,$(call GetArgs,$(ActiveConfig),$(ActiveArch)))
136$(call Set,ActiveObjects,$(ObjNames:%=$(ActiveObjPath)/%))
137
138# Add to the input list for the appropriate library and update the
139# dependency.
140$(call Append,$(Target).Inputs.$(ActiveConfig).$(ActiveArch),$(ActiveObjects))
141$(ProjObjRoot)/$(ActiveConfig)/$(ActiveArch)/libcompiler_rt.$(Target).a: $(ActiveObjects)
142
143$(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.s $(Dependencies) $(ActiveObjPath)/.dir
144 $(Summary) " ASSEMBLE: $(ActiveConfig)/$(ActiveArch): $$<"
145 $(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$<
146.PRECIOUS: $(ActiveObjPath)/.dir
147
148$(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.c $(Dependencies) $(ActiveObjPath)/.dir
149 $(Summary) " COMPILE: $(ActiveConfig)/$(ActiveArch): $$<"
150 $(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$<
151.PRECIOUS: $(ActiveObjPath)/.dir
152
153# Remove entire config directory on clean.
154clean:: $(ProjObjRoot)/$(ActiveDir)/$(ActiveConfig)/.remove
155endef
156
157###
158# Directory handling magic.
159
160# Create directories as needed, and timestamp their creation.
161%/.dir:
162 $(Summary) " MKDIR: $*"
163 $(Verb) $(MKDIR) $* > /dev/null
164 $(Verb) $(DATE) > $@
165
166# Remove directories
167%/.remove:
168 $(Verb) $(RM) -r $*
169
170###
171# Include child makefile fragments
172
173$(foreach subdir,$(SubDirs),$(eval include $(subdir)/Makefile.mk))
174
175###
176# Determine the actual inputs for an optimized library.
177
178# Template: Final_CNA_template Config Arch
179# Uses: GetArgs, Dependencies, ObjNames
180#
181# This template is used once per Config/Arch.
182define Final_CNA_template
183$(call Set,ActiveConfig,$1)
184$(call Set,ActiveArch,$2)
185
186$(call Set,Final.Inputs.$(ActiveConfig).$(ActiveArch),\
187 $(shell make/filter-inputs \
188 $(Optimized.Inputs.$(ActiveConfig).$(ActiveArch)) \
189 $(Generic.Inputs.$(ActiveConfig).$(ActiveArch))))
190endef
191
192$(foreach config,$(Configs), \
193 $(foreach arch,$(Archs), \
194 $(eval $(call Final_CNA_template,$(config),$(arch)))))