blob: 82efba1a6ed476b728ce99f6490a0de5f4fa2ce8 [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
27# Provide default clean target which is extended by other templates.
28.PHONY: clean
29clean::
30
31# Test
32.PHONY: test
33test:
34cd test/Unit && ./test
35
36# Template: Config_template Config
37#
38# This template is used once per Config at the top-level.
39define Config_template
40$(call Set,ActiveConfig,$1)
41$(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveConfig))
42$(call Set,ActiveLibGen,$(ActiveObjPath)/libcompiler_rt.Generic.a)
43$(call Set,ActiveLibOpt,$(ActiveObjPath)/libcompiler_rt.Optimized.a)
44
45# The sublibraries to use for a generic version.
Daniel Dunbar866d2822009-09-03 20:49:22 +000046$(call Set,GenericInputs,$(foreach arch,$(TargetArchs),$(ActiveObjPath)/$(arch)/libcompiler_rt.Generic.a))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000047# The sublibraries to use for an optimized version.
Daniel Dunbar866d2822009-09-03 20:49:22 +000048$(call Set,OptimizedInputs,$(foreach arch,$(TargetArchs),$(ActiveObjPath)/$(arch)/libcompiler_rt.Optimized.a))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000049
Daniel Dunbar866d2822009-09-03 20:49:22 +000050# Provide top-level fat archive targets. We make sure to not try to lipo if only
51# building one target arch.
Daniel Dunbarb3a69012009-06-26 16:47:03 +000052$(ActiveLibGen): $(GenericInputs) $(ActiveObjPath)/.dir
53$(Summary) " UNIVERSAL: $(ActiveConfig): $$@"
54-$(Verb) $(RM) $$@
Daniel Dunbar866d2822009-09-03 20:49:22 +000055$(if $(TargetArch), \
56 $(Verb) $(CP) $(GenericInputs) $$@, \
57 $(Verb) $(Lipo) -create -output $$@ $(GenericInputs))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000058$(ActiveLibOpt): $(OptimizedInputs) $(ActiveObjPath)/.dir
59$(Summary) " UNIVERSAL: $(ActiveConfig): $$@"
60-$(Verb) $(RM) $$@
Daniel Dunbar866d2822009-09-03 20:49:22 +000061$(if $(TargetArch), \
62 $(Verb) $(CP) $(GenericInputs) $$@, \
63 $(Verb) $(Lipo) -create -output $$@ $(OptimizedInputs))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000064.PRECIOUS: $(ActiveObjPath)/.dir
65
Daniel Dunbarfd17b8a2009-09-10 23:13:59 +000066# Add to default "alias" target.
67$(ActiveConfig):: $(ActiveLibGen) $(ActiveLibOpt)
68
Daniel Dunbarb3a69012009-06-26 16:47:03 +000069# Add to target lists.
70all:: $(ActiveConfig) $(ActiveLibGen) $(ActiveLibOpt)
71
72# Remove entire config directory on clean.
73clean:: $(ActiveObjPath)/.remove
74endef
75
76# Template: CNA_template Config Arch
Daniel Dunbar557a6ea2010-01-13 16:13:01 +000077#
Daniel Dunbarb3a69012009-06-26 16:47:03 +000078# This template is used once per Config/Arch at the top-level.
79define CNA_template
80$(call Set,ActiveConfig,$1)
81$(call Set,ActiveArch,$2)
82$(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveConfig)/$(ActiveArch))
83$(call Set,ActiveLibGen,$(ActiveObjPath)/libcompiler_rt.Generic.a)
84$(call Set,ActiveLibOpt,$(ActiveObjPath)/libcompiler_rt.Optimized.a)
85
Daniel Dunbar557a6ea2010-01-13 16:13:01 +000086# Initialize inputs lists. This are extended by the CNA_subdir template. The one
87# tricky bit is that we need to use these quoted, because they are not complete
88# until the entire makefile has been processed.
Daniel Dunbarb3a69012009-06-26 16:47:03 +000089$(call Set,GenericInputs.$(ActiveConfig).$(ActiveArch),)
90$(call Set,OptimizedInputs.$(ActiveConfig).$(ActiveArch),)
91# Final.Inputs is created once we have loaded all the subdirectories
92# and know what the correct inputs are.
93
94# Provide top-level archive targets.
95$(ActiveLibGen): $(ActiveObjPath)/.dir
96$(Summary) " ARCHIVE: $(ActiveConfig)/$(ActiveArch): $$@"
97-$(Verb) $(RM) $$@
98$(Verb) $(Archive) $$@ $$(Generic.Inputs.$(ActiveConfig).$(ActiveArch))
99$(Verb) $(Ranlib) $$@
100# FIXME: The dependency on ActiveLibGen is a hack, this picks up the
101# dependencies on the generic inputs.
102$(ActiveLibOpt): $(ActiveLibGen) $(ActiveObjPath)/.dir
103$(Summary) " ARCHIVE: $(ActiveConfig)/$(ActiveArch): $$@"
104-$(Verb) $(RM) $$@
105$(Verb) $(Archive) $$@ $$(Final.Inputs.$(ActiveConfig).$(ActiveArch))
106$(Verb) $(Ranlib) $$@
107.PRECIOUS: $(ActiveObjPath)/.dir
108
109# Provide some default "alias" targets.
110$(ActiveConfig):: $(ActiveLibGen) $(ActiveLibOpt)
111$(ActiveArch):: $(ActiveLibGen) $(ActiveLibOpt)
112$(ActiveConfig)-$(ActiveArch):: $(ActiveLibGen) $(ActiveLibOpt)
113endef
114
115$(foreach config,$(Configs), \
116 $(foreach arch,$(Archs), \
117 $(eval $(call CNA_template,$(config),$(arch)))))
118
119$(foreach config,$(Configs), \
120 $(eval $(call Config_template,$(config))))
121
122###
123# How to build things.
124
Daniel Dunbar557a6ea2010-01-13 16:13:01 +0000125# Define rules for building on each configuration & architecture. This is not
126# exactly obvious, but variables inside the template are being expanded during
127# the make processing, so automatic variables must be quoted and normal
128# assignment cannot be used.
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000129
130# Template: CNA_template Config Arch Dir
131# Uses: GetArgs, Dependencies, ObjNames
132#
133# This template is used once per Config/Arch/Dir.
134define CNA_subdir_template
135$(call Set,ActiveConfig,$1)
136$(call Set,ActiveArch,$2)
137$(call Set,ActiveDir,$3)
138$(call Set,ActiveSrcPath,$(ProjSrcRoot)/$(ActiveDir))
139$(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveDir)/$(ActiveConfig)/$(ActiveArch))
140
141$(call Set,ActiveFlags,$(call GetArgs,$(ActiveConfig),$(ActiveArch)))
142$(call Set,ActiveObjects,$(ObjNames:%=$(ActiveObjPath)/%))
143
Daniel Dunbar557a6ea2010-01-13 16:13:01 +0000144# Add to the input list for the appropriate library and update the dependency.
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000145$(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
Daniel Dunbardc114bf2009-09-10 23:27:45 +0000153$(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.S $(Dependencies) $(ActiveObjPath)/.dir
154$(Summary) " ASSEMBLE: $(ActiveConfig)/$(ActiveArch): $$<"
155$(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$<
156.PRECIOUS: $(ActiveObjPath)/.dir
157
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000158$(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.c $(Dependencies) $(ActiveObjPath)/.dir
159$(Summary) " COMPILE: $(ActiveConfig)/$(ActiveArch): $$<"
160$(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$<
161.PRECIOUS: $(ActiveObjPath)/.dir
162
163# Remove entire config directory on clean.
164clean:: $(ProjObjRoot)/$(ActiveDir)/$(ActiveConfig)/.remove
165endef
166
167###
168# Directory handling magic.
169
170# Create directories as needed, and timestamp their creation.
171%/.dir:
172$(Summary) " MKDIR: $*"
173$(Verb) $(MKDIR) $* > /dev/null
174$(Verb) $(DATE) > $@
175
176# Remove directories
177%/.remove:
178$(Verb) $(RM) -r $*
179
180###
181# Include child makefile fragments
182
183$(foreach subdir,$(SubDirs),$(eval include $(subdir)/Makefile.mk))
184
185###
186# Determine the actual inputs for an optimized library.
187
188# Template: Final_CNA_template Config Arch
189# Uses: GetArgs, Dependencies, ObjNames
190#
191# This template is used once per Config/Arch.
192define Final_CNA_template
193$(call Set,ActiveConfig,$1)
194$(call Set,ActiveArch,$2)
195
196$(call Set,Final.Inputs.$(ActiveConfig).$(ActiveArch),\
197 $(shell make/filter-inputs \
198 $(Optimized.Inputs.$(ActiveConfig).$(ActiveArch)) \
199 $(Generic.Inputs.$(ActiveConfig).$(ActiveArch))))
200endef
201
202$(foreach config,$(Configs), \
203 $(foreach arch,$(Archs), \
204 $(eval $(call Final_CNA_template,$(config),$(arch)))))