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