blob: 1f47dd4a8f491a9c8eeb3519a137ce9be24e7dd6 [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
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000040help-devel: help
41@echo "Development targets:"
42@echo " info-functions: list available compiler-rt functions"
43@echo
44
45help-hidden: help-devel
Daniel Dunbarf5722752010-01-18 06:48:19 +000046@echo "Debugging variables:"
Daniel Dunbarfaf01502010-01-18 06:48:33 +000047@echo " DEBUGMAKE=1: enable some Makefile logging [default=]"
48@echo " =2: enable more Makefile logging"
Daniel Dunbarf5722752010-01-18 06:48:19 +000049@echo
50@echo "Debugging targets:"
51@echo " make-print-FOO: print information on the variable 'FOO'"
52@echo
53
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000054info-functions:
55@echo "compiler-rt Available Functions"
56@echo
57@echo "All Functions: $(AvailableFunctions)"
58@$(foreach fn,$(AvailableFunctions),\
59 printf " %-20s - available in (%s)\n" $(fn)\
60 "$(foreach key,$(AvailableIn.$(fn)),$($(key).Dir))";)
61
Daniel Dunbarb3a69012009-06-26 16:47:03 +000062# Provide default clean target which is extended by other templates.
63.PHONY: clean
64clean::
65
66# Test
67.PHONY: test
68test:
69cd test/Unit && ./test
70
71# Template: Config_template Config
72#
73# This template is used once per Config at the top-level.
74define Config_template
75$(call Set,ActiveConfig,$1)
76$(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveConfig))
77$(call Set,ActiveLibGen,$(ActiveObjPath)/libcompiler_rt.Generic.a)
78$(call Set,ActiveLibOpt,$(ActiveObjPath)/libcompiler_rt.Optimized.a)
79
80# The sublibraries to use for a generic version.
Daniel Dunbar866d2822009-09-03 20:49:22 +000081$(call Set,GenericInputs,$(foreach arch,$(TargetArchs),$(ActiveObjPath)/$(arch)/libcompiler_rt.Generic.a))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000082# The sublibraries to use for an optimized version.
Daniel Dunbar866d2822009-09-03 20:49:22 +000083$(call Set,OptimizedInputs,$(foreach arch,$(TargetArchs),$(ActiveObjPath)/$(arch)/libcompiler_rt.Optimized.a))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000084
Daniel Dunbar866d2822009-09-03 20:49:22 +000085# Provide top-level fat archive targets. We make sure to not try to lipo if only
86# building one target arch.
Daniel Dunbarb3a69012009-06-26 16:47:03 +000087$(ActiveLibGen): $(GenericInputs) $(ActiveObjPath)/.dir
88$(Summary) " UNIVERSAL: $(ActiveConfig): $$@"
89-$(Verb) $(RM) $$@
Daniel Dunbar866d2822009-09-03 20:49:22 +000090$(if $(TargetArch), \
91 $(Verb) $(CP) $(GenericInputs) $$@, \
92 $(Verb) $(Lipo) -create -output $$@ $(GenericInputs))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000093$(ActiveLibOpt): $(OptimizedInputs) $(ActiveObjPath)/.dir
94$(Summary) " UNIVERSAL: $(ActiveConfig): $$@"
95-$(Verb) $(RM) $$@
Daniel Dunbar866d2822009-09-03 20:49:22 +000096$(if $(TargetArch), \
97 $(Verb) $(CP) $(GenericInputs) $$@, \
98 $(Verb) $(Lipo) -create -output $$@ $(OptimizedInputs))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000099.PRECIOUS: $(ActiveObjPath)/.dir
100
Daniel Dunbarfd17b8a2009-09-10 23:13:59 +0000101# Add to default "alias" target.
102$(ActiveConfig):: $(ActiveLibGen) $(ActiveLibOpt)
103
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000104# Add to target lists.
105all:: $(ActiveConfig) $(ActiveLibGen) $(ActiveLibOpt)
106
107# Remove entire config directory on clean.
108clean:: $(ActiveObjPath)/.remove
109endef
110
111# Template: CNA_template Config Arch
Daniel Dunbar557a6ea2010-01-13 16:13:01 +0000112#
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000113# This template is used once per Config/Arch at the top-level.
114define CNA_template
115$(call Set,ActiveConfig,$1)
116$(call Set,ActiveArch,$2)
117$(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveConfig)/$(ActiveArch))
118$(call Set,ActiveLibGen,$(ActiveObjPath)/libcompiler_rt.Generic.a)
119$(call Set,ActiveLibOpt,$(ActiveObjPath)/libcompiler_rt.Optimized.a)
120
Daniel Dunbar557a6ea2010-01-13 16:13:01 +0000121# Initialize inputs lists. This are extended by the CNA_subdir template. The one
122# tricky bit is that we need to use these quoted, because they are not complete
123# until the entire makefile has been processed.
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000124$(call Set,GenericInputs.$(ActiveConfig).$(ActiveArch),)
125$(call Set,OptimizedInputs.$(ActiveConfig).$(ActiveArch),)
126# Final.Inputs is created once we have loaded all the subdirectories
127# and know what the correct inputs are.
128
129# Provide top-level archive targets.
130$(ActiveLibGen): $(ActiveObjPath)/.dir
131$(Summary) " ARCHIVE: $(ActiveConfig)/$(ActiveArch): $$@"
132-$(Verb) $(RM) $$@
133$(Verb) $(Archive) $$@ $$(Generic.Inputs.$(ActiveConfig).$(ActiveArch))
134$(Verb) $(Ranlib) $$@
135# FIXME: The dependency on ActiveLibGen is a hack, this picks up the
136# dependencies on the generic inputs.
137$(ActiveLibOpt): $(ActiveLibGen) $(ActiveObjPath)/.dir
138$(Summary) " ARCHIVE: $(ActiveConfig)/$(ActiveArch): $$@"
139-$(Verb) $(RM) $$@
140$(Verb) $(Archive) $$@ $$(Final.Inputs.$(ActiveConfig).$(ActiveArch))
141$(Verb) $(Ranlib) $$@
142.PRECIOUS: $(ActiveObjPath)/.dir
143
144# Provide some default "alias" targets.
145$(ActiveConfig):: $(ActiveLibGen) $(ActiveLibOpt)
146$(ActiveArch):: $(ActiveLibGen) $(ActiveLibOpt)
147$(ActiveConfig)-$(ActiveArch):: $(ActiveLibGen) $(ActiveLibOpt)
148endef
149
150$(foreach config,$(Configs), \
151 $(foreach arch,$(Archs), \
152 $(eval $(call CNA_template,$(config),$(arch)))))
153
154$(foreach config,$(Configs), \
155 $(eval $(call Config_template,$(config))))
156
157###
158# How to build things.
159
Daniel Dunbar557a6ea2010-01-13 16:13:01 +0000160# Define rules for building on each configuration & architecture. This is not
161# exactly obvious, but variables inside the template are being expanded during
162# the make processing, so automatic variables must be quoted and normal
163# assignment cannot be used.
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000164
165# Template: CNA_template Config Arch Dir
166# Uses: GetArgs, Dependencies, ObjNames
167#
168# This template is used once per Config/Arch/Dir.
169define CNA_subdir_template
170$(call Set,ActiveConfig,$1)
171$(call Set,ActiveArch,$2)
172$(call Set,ActiveDir,$3)
173$(call Set,ActiveSrcPath,$(ProjSrcRoot)/$(ActiveDir))
174$(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveDir)/$(ActiveConfig)/$(ActiveArch))
175
176$(call Set,ActiveFlags,$(call GetArgs,$(ActiveConfig),$(ActiveArch)))
177$(call Set,ActiveObjects,$(ObjNames:%=$(ActiveObjPath)/%))
178
Daniel Dunbar557a6ea2010-01-13 16:13:01 +0000179# Add to the input list for the appropriate library and update the dependency.
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000180$(call Append,$(Target).Inputs.$(ActiveConfig).$(ActiveArch),$(ActiveObjects))
181$(ProjObjRoot)/$(ActiveConfig)/$(ActiveArch)/libcompiler_rt.$(Target).a: $(ActiveObjects)
182
183$(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.s $(Dependencies) $(ActiveObjPath)/.dir
184$(Summary) " ASSEMBLE: $(ActiveConfig)/$(ActiveArch): $$<"
185$(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$<
186.PRECIOUS: $(ActiveObjPath)/.dir
187
Daniel Dunbardc114bf2009-09-10 23:27:45 +0000188$(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.S $(Dependencies) $(ActiveObjPath)/.dir
189$(Summary) " ASSEMBLE: $(ActiveConfig)/$(ActiveArch): $$<"
190$(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$<
191.PRECIOUS: $(ActiveObjPath)/.dir
192
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000193$(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.c $(Dependencies) $(ActiveObjPath)/.dir
194$(Summary) " COMPILE: $(ActiveConfig)/$(ActiveArch): $$<"
195$(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$<
196.PRECIOUS: $(ActiveObjPath)/.dir
197
198# Remove entire config directory on clean.
199clean:: $(ProjObjRoot)/$(ActiveDir)/$(ActiveConfig)/.remove
200endef
201
202###
203# Directory handling magic.
204
205# Create directories as needed, and timestamp their creation.
206%/.dir:
207$(Summary) " MKDIR: $*"
208$(Verb) $(MKDIR) $* > /dev/null
209$(Verb) $(DATE) > $@
210
211# Remove directories
212%/.remove:
213$(Verb) $(RM) -r $*
214
215###
216# Include child makefile fragments
217
Daniel Dunbarfaf01502010-01-18 06:48:33 +0000218Dir := .
219include make/subdir.mk
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000220
221###
222# Determine the actual inputs for an optimized library.
223
224# Template: Final_CNA_template Config Arch
225# Uses: GetArgs, Dependencies, ObjNames
226#
227# This template is used once per Config/Arch.
228define Final_CNA_template
229$(call Set,ActiveConfig,$1)
230$(call Set,ActiveArch,$2)
231
232$(call Set,Final.Inputs.$(ActiveConfig).$(ActiveArch),\
233 $(shell make/filter-inputs \
234 $(Optimized.Inputs.$(ActiveConfig).$(ActiveArch)) \
235 $(Generic.Inputs.$(ActiveConfig).$(ActiveArch))))
236endef
237
238$(foreach config,$(Configs), \
239 $(foreach arch,$(Archs), \
240 $(eval $(call Final_CNA_template,$(config),$(arch)))))
Daniel Dunbarfaf01502010-01-18 06:48:33 +0000241
242ifneq ($(DEBUGMAKE),)
243 $(info MAKE: Done processing Makefile)
244 $(info )
245endif
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +0000246
247###
248# Function Information
249#
250# FIXME: Factor out.
251
252AvailableObjects := $(sort $(foreach key,$(SubDirKeys),\
253$($(key).ObjNames)))
254AvailableFunctions := $(AvailableObjects:%.o=%)
255
256# Compute lists of where each function is available.
257$(foreach key,$(SubDirKeys),\
258 $(foreach fn,$(subst .o,,$($(key).ObjNames)),\
259 $(call Append,AvailableIn.$(fn),$(key))))
260