blob: cb964ce26c4111560ceeef11774c19904fbde8b3 [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
Daniel Dunbar557a6ea2010-01-13 16:13:01 +00008# If SRCROOT is defined, assume we are doing an Apple style build. We should be
9# able to use RC_XBS for this but that is unused during "make installsrc".
Daniel Dunbarb3a69012009-06-26 16:47:03 +000010ifdef SRCROOT
11 include make/AppleBI.mk
12endif
13
14# Make sure we don't build with a missing ProjObjRoot.
15ifeq ($(ProjObjRoot),)
16$(error Refusing to build with empty ProjObjRoot variable)
17endif
18
19##############
20
21###
22# Rules
23
24###
25# Top level targets
26
Daniel Dunbarf5722752010-01-18 06:48:19 +000027# FIXME: Document the available subtargets.
28help:
29@echo "usage: make [{VARIABLE=VALUE}*] target"
30@echo
31@echo "User variables:"
32@echo " VERBOSE=1: Use to show all commands [default=0]"
33@echo
34@echo "Available targets:"
35@echo " clean: clean all configurations"
36@echo " test: run unit tests"
37@echo " all: build all configurations"
38@echo
39
40help-hidden: help
41@echo "Debugging variables:"
Daniel Dunbarfaf01502010-01-18 06:48:33 +000042@echo " DEBUGMAKE=1: enable some Makefile logging [default=]"
43@echo " =2: enable more Makefile logging"
Daniel Dunbarf5722752010-01-18 06:48:19 +000044@echo
45@echo "Debugging targets:"
46@echo " make-print-FOO: print information on the variable 'FOO'"
47@echo
48
Daniel Dunbarb3a69012009-06-26 16:47:03 +000049# Provide default clean target which is extended by other templates.
50.PHONY: clean
51clean::
52
53# Test
54.PHONY: test
55test:
56cd test/Unit && ./test
57
58# Template: Config_template Config
59#
60# This template is used once per Config at the top-level.
61define Config_template
62$(call Set,ActiveConfig,$1)
63$(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveConfig))
64$(call Set,ActiveLibGen,$(ActiveObjPath)/libcompiler_rt.Generic.a)
65$(call Set,ActiveLibOpt,$(ActiveObjPath)/libcompiler_rt.Optimized.a)
66
67# The sublibraries to use for a generic version.
Daniel Dunbar866d2822009-09-03 20:49:22 +000068$(call Set,GenericInputs,$(foreach arch,$(TargetArchs),$(ActiveObjPath)/$(arch)/libcompiler_rt.Generic.a))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000069# The sublibraries to use for an optimized version.
Daniel Dunbar866d2822009-09-03 20:49:22 +000070$(call Set,OptimizedInputs,$(foreach arch,$(TargetArchs),$(ActiveObjPath)/$(arch)/libcompiler_rt.Optimized.a))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000071
Daniel Dunbar866d2822009-09-03 20:49:22 +000072# Provide top-level fat archive targets. We make sure to not try to lipo if only
73# building one target arch.
Daniel Dunbarb3a69012009-06-26 16:47:03 +000074$(ActiveLibGen): $(GenericInputs) $(ActiveObjPath)/.dir
75$(Summary) " UNIVERSAL: $(ActiveConfig): $$@"
76-$(Verb) $(RM) $$@
Daniel Dunbar866d2822009-09-03 20:49:22 +000077$(if $(TargetArch), \
78 $(Verb) $(CP) $(GenericInputs) $$@, \
79 $(Verb) $(Lipo) -create -output $$@ $(GenericInputs))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000080$(ActiveLibOpt): $(OptimizedInputs) $(ActiveObjPath)/.dir
81$(Summary) " UNIVERSAL: $(ActiveConfig): $$@"
82-$(Verb) $(RM) $$@
Daniel Dunbar866d2822009-09-03 20:49:22 +000083$(if $(TargetArch), \
84 $(Verb) $(CP) $(GenericInputs) $$@, \
85 $(Verb) $(Lipo) -create -output $$@ $(OptimizedInputs))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000086.PRECIOUS: $(ActiveObjPath)/.dir
87
Daniel Dunbarfd17b8a2009-09-10 23:13:59 +000088# Add to default "alias" target.
89$(ActiveConfig):: $(ActiveLibGen) $(ActiveLibOpt)
90
Daniel Dunbarb3a69012009-06-26 16:47:03 +000091# Add to target lists.
92all:: $(ActiveConfig) $(ActiveLibGen) $(ActiveLibOpt)
93
94# Remove entire config directory on clean.
95clean:: $(ActiveObjPath)/.remove
96endef
97
98# Template: CNA_template Config Arch
Daniel Dunbar557a6ea2010-01-13 16:13:01 +000099#
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000100# This template is used once per Config/Arch at the top-level.
101define CNA_template
102$(call Set,ActiveConfig,$1)
103$(call Set,ActiveArch,$2)
104$(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveConfig)/$(ActiveArch))
105$(call Set,ActiveLibGen,$(ActiveObjPath)/libcompiler_rt.Generic.a)
106$(call Set,ActiveLibOpt,$(ActiveObjPath)/libcompiler_rt.Optimized.a)
107
Daniel Dunbar557a6ea2010-01-13 16:13:01 +0000108# Initialize inputs lists. This are extended by the CNA_subdir template. The one
109# tricky bit is that we need to use these quoted, because they are not complete
110# until the entire makefile has been processed.
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000111$(call Set,GenericInputs.$(ActiveConfig).$(ActiveArch),)
112$(call Set,OptimizedInputs.$(ActiveConfig).$(ActiveArch),)
113# Final.Inputs is created once we have loaded all the subdirectories
114# and know what the correct inputs are.
115
116# Provide top-level archive targets.
117$(ActiveLibGen): $(ActiveObjPath)/.dir
118$(Summary) " ARCHIVE: $(ActiveConfig)/$(ActiveArch): $$@"
119-$(Verb) $(RM) $$@
120$(Verb) $(Archive) $$@ $$(Generic.Inputs.$(ActiveConfig).$(ActiveArch))
121$(Verb) $(Ranlib) $$@
122# FIXME: The dependency on ActiveLibGen is a hack, this picks up the
123# dependencies on the generic inputs.
124$(ActiveLibOpt): $(ActiveLibGen) $(ActiveObjPath)/.dir
125$(Summary) " ARCHIVE: $(ActiveConfig)/$(ActiveArch): $$@"
126-$(Verb) $(RM) $$@
127$(Verb) $(Archive) $$@ $$(Final.Inputs.$(ActiveConfig).$(ActiveArch))
128$(Verb) $(Ranlib) $$@
129.PRECIOUS: $(ActiveObjPath)/.dir
130
131# Provide some default "alias" targets.
132$(ActiveConfig):: $(ActiveLibGen) $(ActiveLibOpt)
133$(ActiveArch):: $(ActiveLibGen) $(ActiveLibOpt)
134$(ActiveConfig)-$(ActiveArch):: $(ActiveLibGen) $(ActiveLibOpt)
135endef
136
137$(foreach config,$(Configs), \
138 $(foreach arch,$(Archs), \
139 $(eval $(call CNA_template,$(config),$(arch)))))
140
141$(foreach config,$(Configs), \
142 $(eval $(call Config_template,$(config))))
143
144###
145# How to build things.
146
Daniel Dunbar557a6ea2010-01-13 16:13:01 +0000147# Define rules for building on each configuration & architecture. This is not
148# exactly obvious, but variables inside the template are being expanded during
149# the make processing, so automatic variables must be quoted and normal
150# assignment cannot be used.
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000151
152# Template: CNA_template Config Arch Dir
153# Uses: GetArgs, Dependencies, ObjNames
154#
155# This template is used once per Config/Arch/Dir.
156define CNA_subdir_template
157$(call Set,ActiveConfig,$1)
158$(call Set,ActiveArch,$2)
159$(call Set,ActiveDir,$3)
160$(call Set,ActiveSrcPath,$(ProjSrcRoot)/$(ActiveDir))
161$(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveDir)/$(ActiveConfig)/$(ActiveArch))
162
163$(call Set,ActiveFlags,$(call GetArgs,$(ActiveConfig),$(ActiveArch)))
164$(call Set,ActiveObjects,$(ObjNames:%=$(ActiveObjPath)/%))
165
Daniel Dunbar557a6ea2010-01-13 16:13:01 +0000166# Add to the input list for the appropriate library and update the dependency.
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000167$(call Append,$(Target).Inputs.$(ActiveConfig).$(ActiveArch),$(ActiveObjects))
168$(ProjObjRoot)/$(ActiveConfig)/$(ActiveArch)/libcompiler_rt.$(Target).a: $(ActiveObjects)
169
170$(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.s $(Dependencies) $(ActiveObjPath)/.dir
171$(Summary) " ASSEMBLE: $(ActiveConfig)/$(ActiveArch): $$<"
172$(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$<
173.PRECIOUS: $(ActiveObjPath)/.dir
174
Daniel Dunbardc114bf2009-09-10 23:27:45 +0000175$(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.S $(Dependencies) $(ActiveObjPath)/.dir
176$(Summary) " ASSEMBLE: $(ActiveConfig)/$(ActiveArch): $$<"
177$(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$<
178.PRECIOUS: $(ActiveObjPath)/.dir
179
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000180$(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.c $(Dependencies) $(ActiveObjPath)/.dir
181$(Summary) " COMPILE: $(ActiveConfig)/$(ActiveArch): $$<"
182$(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$<
183.PRECIOUS: $(ActiveObjPath)/.dir
184
185# Remove entire config directory on clean.
186clean:: $(ProjObjRoot)/$(ActiveDir)/$(ActiveConfig)/.remove
187endef
188
189###
190# Directory handling magic.
191
192# Create directories as needed, and timestamp their creation.
193%/.dir:
194$(Summary) " MKDIR: $*"
195$(Verb) $(MKDIR) $* > /dev/null
196$(Verb) $(DATE) > $@
197
198# Remove directories
199%/.remove:
200$(Verb) $(RM) -r $*
201
202###
203# Include child makefile fragments
204
Daniel Dunbarfaf01502010-01-18 06:48:33 +0000205Dir := .
206include make/subdir.mk
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000207
208###
209# Determine the actual inputs for an optimized library.
210
211# Template: Final_CNA_template Config Arch
212# Uses: GetArgs, Dependencies, ObjNames
213#
214# This template is used once per Config/Arch.
215define Final_CNA_template
216$(call Set,ActiveConfig,$1)
217$(call Set,ActiveArch,$2)
218
219$(call Set,Final.Inputs.$(ActiveConfig).$(ActiveArch),\
220 $(shell make/filter-inputs \
221 $(Optimized.Inputs.$(ActiveConfig).$(ActiveArch)) \
222 $(Generic.Inputs.$(ActiveConfig).$(ActiveArch))))
223endef
224
225$(foreach config,$(Configs), \
226 $(foreach arch,$(Archs), \
227 $(eval $(call Final_CNA_template,$(config),$(arch)))))
Daniel Dunbarfaf01502010-01-18 06:48:33 +0000228
229ifneq ($(DEBUGMAKE),)
230 $(info MAKE: Done processing Makefile)
231 $(info )
232endif