blob: 4f6a2e087ffeb8ede9645b9f2ac800309d6e9647 [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:
35cd 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.
Daniel Dunbar866d2822009-09-03 20:49:22 +000047$(call Set,GenericInputs,$(foreach arch,$(TargetArchs),$(ActiveObjPath)/$(arch)/libcompiler_rt.Generic.a))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000048# The sublibraries to use for an optimized version.
Daniel Dunbar866d2822009-09-03 20:49:22 +000049$(call Set,OptimizedInputs,$(foreach arch,$(TargetArchs),$(ActiveObjPath)/$(arch)/libcompiler_rt.Optimized.a))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000050
Daniel Dunbar866d2822009-09-03 20:49:22 +000051# Provide top-level fat archive targets. We make sure to not try to lipo if only
52# building one target arch.
Daniel Dunbarb3a69012009-06-26 16:47:03 +000053$(ActiveLibGen): $(GenericInputs) $(ActiveObjPath)/.dir
54$(Summary) " UNIVERSAL: $(ActiveConfig): $$@"
55-$(Verb) $(RM) $$@
Daniel Dunbar866d2822009-09-03 20:49:22 +000056$(if $(TargetArch), \
57 $(Verb) $(CP) $(GenericInputs) $$@, \
58 $(Verb) $(Lipo) -create -output $$@ $(GenericInputs))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000059$(ActiveLibOpt): $(OptimizedInputs) $(ActiveObjPath)/.dir
60$(Summary) " UNIVERSAL: $(ActiveConfig): $$@"
61-$(Verb) $(RM) $$@
Daniel Dunbar866d2822009-09-03 20:49:22 +000062$(if $(TargetArch), \
63 $(Verb) $(CP) $(GenericInputs) $$@, \
64 $(Verb) $(Lipo) -create -output $$@ $(OptimizedInputs))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000065.PRECIOUS: $(ActiveObjPath)/.dir
66
67# Add to target lists.
68all:: $(ActiveConfig) $(ActiveLibGen) $(ActiveLibOpt)
69
70# Remove entire config directory on clean.
71clean:: $(ActiveObjPath)/.remove
72endef
73
74# Template: CNA_template Config Arch
75#
76# This template is used once per Config/Arch at the top-level.
77define CNA_template
78$(call Set,ActiveConfig,$1)
79$(call Set,ActiveArch,$2)
80$(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveConfig)/$(ActiveArch))
81$(call Set,ActiveLibGen,$(ActiveObjPath)/libcompiler_rt.Generic.a)
82$(call Set,ActiveLibOpt,$(ActiveObjPath)/libcompiler_rt.Optimized.a)
83
84# Initialize inputs lists. This are extended by the CNA_subdir
85# template. The one tricky bit is that we need to use these quoted,
86# because they are not complete until the entire makefile has been
87# processed.
88$(call Set,GenericInputs.$(ActiveConfig).$(ActiveArch),)
89$(call Set,OptimizedInputs.$(ActiveConfig).$(ActiveArch),)
90# Final.Inputs is created once we have loaded all the subdirectories
91# and know what the correct inputs are.
92
93# Provide top-level archive targets.
94$(ActiveLibGen): $(ActiveObjPath)/.dir
95$(Summary) " ARCHIVE: $(ActiveConfig)/$(ActiveArch): $$@"
96-$(Verb) $(RM) $$@
97$(Verb) $(Archive) $$@ $$(Generic.Inputs.$(ActiveConfig).$(ActiveArch))
98$(Verb) $(Ranlib) $$@
99# FIXME: The dependency on ActiveLibGen is a hack, this picks up the
100# dependencies on the generic inputs.
101$(ActiveLibOpt): $(ActiveLibGen) $(ActiveObjPath)/.dir
102$(Summary) " ARCHIVE: $(ActiveConfig)/$(ActiveArch): $$@"
103-$(Verb) $(RM) $$@
104$(Verb) $(Archive) $$@ $$(Final.Inputs.$(ActiveConfig).$(ActiveArch))
105$(Verb) $(Ranlib) $$@
106.PRECIOUS: $(ActiveObjPath)/.dir
107
108# Provide some default "alias" targets.
109$(ActiveConfig):: $(ActiveLibGen) $(ActiveLibOpt)
110$(ActiveArch):: $(ActiveLibGen) $(ActiveLibOpt)
111$(ActiveConfig)-$(ActiveArch):: $(ActiveLibGen) $(ActiveLibOpt)
112endef
113
114$(foreach config,$(Configs), \
115 $(foreach arch,$(Archs), \
116 $(eval $(call CNA_template,$(config),$(arch)))))
117
118$(foreach config,$(Configs), \
119 $(eval $(call Config_template,$(config))))
120
121###
122# How to build things.
123
124# Define rules for building on each configuration & architecture. This
125# is not exactly obvious, but variables inside the template are being
126# expanded during the make processing, so automatic variables must be
127# quoted and normal assignment cannot be used.
128
129# Template: CNA_template Config Arch Dir
130# Uses: GetArgs, Dependencies, ObjNames
131#
132# This template is used once per Config/Arch/Dir.
133define CNA_subdir_template
134$(call Set,ActiveConfig,$1)
135$(call Set,ActiveArch,$2)
136$(call Set,ActiveDir,$3)
137$(call Set,ActiveSrcPath,$(ProjSrcRoot)/$(ActiveDir))
138$(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveDir)/$(ActiveConfig)/$(ActiveArch))
139
140$(call Set,ActiveFlags,$(call GetArgs,$(ActiveConfig),$(ActiveArch)))
141$(call Set,ActiveObjects,$(ObjNames:%=$(ActiveObjPath)/%))
142
143# Add to the input list for the appropriate library and update the
144# dependency.
145$(call Append,$(Target).Inputs.$(ActiveConfig).$(ActiveArch),$(ActiveObjects))
146$(ProjObjRoot)/$(ActiveConfig)/$(ActiveArch)/libcompiler_rt.$(Target).a: $(ActiveObjects)
147
148$(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.s $(Dependencies) $(ActiveObjPath)/.dir
149$(Summary) " ASSEMBLE: $(ActiveConfig)/$(ActiveArch): $$<"
150$(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$<
151.PRECIOUS: $(ActiveObjPath)/.dir
152
153$(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.c $(Dependencies) $(ActiveObjPath)/.dir
154$(Summary) " COMPILE: $(ActiveConfig)/$(ActiveArch): $$<"
155$(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$<
156.PRECIOUS: $(ActiveObjPath)/.dir
157
158# Remove entire config directory on clean.
159clean:: $(ProjObjRoot)/$(ActiveDir)/$(ActiveConfig)/.remove
160endef
161
162###
163# Directory handling magic.
164
165# Create directories as needed, and timestamp their creation.
166%/.dir:
167$(Summary) " MKDIR: $*"
168$(Verb) $(MKDIR) $* > /dev/null
169$(Verb) $(DATE) > $@
170
171# Remove directories
172%/.remove:
173$(Verb) $(RM) -r $*
174
175###
176# Include child makefile fragments
177
178$(foreach subdir,$(SubDirs),$(eval include $(subdir)/Makefile.mk))
179
180###
181# Determine the actual inputs for an optimized library.
182
183# Template: Final_CNA_template Config Arch
184# Uses: GetArgs, Dependencies, ObjNames
185#
186# This template is used once per Config/Arch.
187define Final_CNA_template
188$(call Set,ActiveConfig,$1)
189$(call Set,ActiveArch,$2)
190
191$(call Set,Final.Inputs.$(ActiveConfig).$(ActiveArch),\
192 $(shell make/filter-inputs \
193 $(Optimized.Inputs.$(ActiveConfig).$(ActiveArch)) \
194 $(Generic.Inputs.$(ActiveConfig).$(ActiveArch))))
195endef
196
197$(foreach config,$(Configs), \
198 $(foreach arch,$(Archs), \
199 $(eval $(call Final_CNA_template,$(config),$(arch)))))