blob: a96c692b308530dfa33347a705109f2d11516b38 [file] [log] [blame]
Daniel Dunbarb3a69012009-06-26 16:47:03 +00001SubDirs := lib
2
3# Set default rule before anything else.
Daniel Dunbar48464e02010-01-18 06:49:33 +00004all: help
Daniel Dunbarb3a69012009-06-26 16:47:03 +00005
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:"
Daniel Dunbar48464e02010-01-18 06:49:33 +000035 @echo " <platform name>: build the libraries for 'platform'"
36 @echo " clean: clean all configurations"
37 @echo " test: run unit tests"
38 @echo
39 @echo " info-platforms: list available platforms"
40 @echo " help-devel: print additional help for developers"
Daniel Dunbarf5722752010-01-18 06:48:19 +000041 @echo
42
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000043help-devel: help
44 @echo "Development targets:"
Daniel Dunbar48464e02010-01-18 06:49:33 +000045 @echo " <platform name>-<config name>:"
46 @echo " build the libraries for a single platform config"
47 @echo " <platform name>-<config name>-<arch name>:"
48 @echo " build the libraries for a single config and arch"
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000049 @echo " info-functions: list available compiler-rt functions"
Daniel Dunbar48464e02010-01-18 06:49:33 +000050 @echo " help-hidden: print help for Makefile debugging"
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000051 @echo
52
53help-hidden: help-devel
Daniel Dunbarf5722752010-01-18 06:48:19 +000054 @echo "Debugging variables:"
Daniel Dunbarfaf01502010-01-18 06:48:33 +000055 @echo " DEBUGMAKE=1: enable some Makefile logging [default=]"
56 @echo " =2: enable more Makefile logging"
Daniel Dunbarf5722752010-01-18 06:48:19 +000057 @echo
58 @echo "Debugging targets:"
59 @echo " make-print-FOO: print information on the variable 'FOO'"
60 @echo
61
Daniel Dunbar9edf5cd2010-01-18 06:48:40 +000062info-functions:
63 @echo "compiler-rt Available Functions"
64 @echo
65 @echo "All Functions: $(AvailableFunctions)"
66 @$(foreach fn,$(AvailableFunctions),\
67 printf " %-20s - available in (%s)\n" $(fn)\
68 "$(foreach key,$(AvailableIn.$(fn)),$($(key).Dir))";)
69
Daniel Dunbar48464e02010-01-18 06:49:33 +000070info-platforms:
71 @echo "compiler-rt Available Platforms"
72 @echo
73 @echo "Platforms:"
74 @$(foreach key,$(PlatformKeys),\
75 printf " %s - from '%s'\n" $($(key).Name) $($(key).Path);\
76 printf " %s\n" "$($(key).Description)";\
77 printf " Configurations: %s\n\n" "$($(key).Configs)";)
78
Daniel Dunbarb3a69012009-06-26 16:47:03 +000079# Provide default clean target which is extended by other templates.
80.PHONY: clean
81clean::
82
83# Test
84.PHONY: test
85test:
86 cd test/Unit && ./test
87
Daniel Dunbarb3a69012009-06-26 16:47:03 +000088###
89# Directory handling magic.
90
91# Create directories as needed, and timestamp their creation.
92%/.dir:
93 $(Summary) " MKDIR: $*"
94 $(Verb) $(MKDIR) $* > /dev/null
95 $(Verb) $(DATE) > $@
96
97# Remove directories
98%/.remove:
99 $(Verb) $(RM) -r $*
100
101###
102# Include child makefile fragments
103
Daniel Dunbarfaf01502010-01-18 06:48:33 +0000104Dir := .
105include make/subdir.mk
Daniel Dunbar78cfbc52010-01-18 06:48:56 +0000106include make/lib_info.mk
107include make/lib_util.mk
Daniel Dunbar48464e02010-01-18 06:49:33 +0000108include make/lib_platforms.mk
109
110###
111# Define Platform Rules
112
113define PerPlatform_template
114$(call Set,Tmp.Key,$(1))
115$(call Set,Tmp.Name,$($(Tmp.Key).Name))
116$(call Set,Tmp.Configs,$($(Tmp.Key).Configs))
117$(call Set,Tmp.ObjPath,$(ProjObjRoot)/$(Tmp.Name))
118
119# Top-Level Platform Target
Daniel Dunbar8bc01cb2012-09-07 19:57:23 +0000120$(Tmp.Name):: $(Tmp.Configs:%=$(Tmp.Name)-%)
Daniel Dunbar48464e02010-01-18 06:49:33 +0000121.PHONY: $(Tmp.Name)
122
123clean::
124 $(Verb) rm -rf $(Tmp.ObjPath)
125
126# Per-Config Libraries
127$(foreach config,$(Tmp.Configs),\
128 $(call PerPlatformConfig_template,$(config)))
129endef
130
131define PerPlatformConfig_template
132$(call Set,Tmp.Config,$(1))
133$(call Set,Tmp.ObjPath,$(ProjObjRoot)/$(Tmp.Name)/$(Tmp.Config))
Daniel Dunbar8bc01cb2012-09-07 19:57:23 +0000134$(call Set,Tmp.SHARED_LIBRARY,$(strip \
135 $(call GetCNAVar,SHARED_LIBRARY,$(Tmp.Key),$(Tmp.Config),$(Tmp.Arch))))
136
137# Compute the library suffix.
138$(if $(call streq,1,$(Tmp.SHARED_LIBRARY)),
139 $(call Set,Tmp.LibrarySuffix,dylib),
140 $(call Set,Tmp.LibrarySuffix,a))
Daniel Dunbar48464e02010-01-18 06:49:33 +0000141
142# Compute the archs to build, depending on whether this is a universal build or
143# not.
144$(call Set,Tmp.ArchsToBuild,\
145 $(if $(call IsDefined,$(Tmp.Key).UniversalArchs),\
Daniel Dunbar06f38e52010-01-19 00:01:15 +0000146 $(strip \
147 $(or $($(Tmp.Key).UniversalArchs.$(Tmp.Config)),\
148 $($(Tmp.Key).UniversalArchs))),\
Daniel Dunbar48464e02010-01-18 06:49:33 +0000149 $(call VarOrDefault,$(Tmp.Key).Arch.$(Tmp.Config),$($(Tmp.Key).Arch))))
150
151# Copy or lipo to create the per-config library.
Daniel Dunbar8bc01cb2012-09-07 19:57:23 +0000152$(call Set,Tmp.Inputs,$(Tmp.ArchsToBuild:%=$(Tmp.ObjPath)/%/libcompiler_rt.$(Tmp.LibrarySuffix)))
153$(Tmp.ObjPath)/libcompiler_rt.$(Tmp.LibrarySuffix): $(Tmp.Inputs) $(Tmp.ObjPath)/.dir
Daniel Dunbar48464e02010-01-18 06:49:33 +0000154 $(Summary) " FINAL-ARCHIVE: $(Tmp.Name)/$(Tmp.Config): $$@"
155 -$(Verb) $(RM) $$@
156 $(if $(call streq,1,$(words $(Tmp.ArchsToBuild))), \
157 $(Verb) $(CP) $(Tmp.Inputs) $$@, \
158 $(Verb) $(LIPO) -create -output $$@ $(Tmp.Inputs))
159.PRECIOUS: $(Tmp.ObjPath)/.dir
160
161# Per-Config Targets
Daniel Dunbar8bc01cb2012-09-07 19:57:23 +0000162$(Tmp.Name)-$(Tmp.Config):: $(Tmp.ObjPath)/libcompiler_rt.$(Tmp.LibrarySuffix)
Daniel Dunbar48464e02010-01-18 06:49:33 +0000163.PHONY: $(Tmp.Name)-$(Tmp.Config)
164
165# Per-Config-Arch Libraries
166$(foreach arch,$(Tmp.ArchsToBuild),\
167 $(call PerPlatformConfigArch_template,$(arch)))
168endef
169
170define PerPlatformConfigArch_template
171$(call Set,Tmp.Arch,$(1))
172$(call Set,Tmp.ObjPath,$(ProjObjRoot)/$(Tmp.Name)/$(Tmp.Config)/$(Tmp.Arch))
173$(call Set,Tmp.Functions,$(strip \
Daniel Dunbar401f6932011-11-16 01:19:19 +0000174 $(AlwaysRequiredModules) \
Daniel Dunbar48464e02010-01-18 06:49:33 +0000175 $(call GetCNAVar,FUNCTIONS,$(Tmp.Key),$(Tmp.Config),$(Tmp.Arch))))
176$(call Set,Tmp.Optimized,$(strip \
177 $(call GetCNAVar,OPTIMIZED,$(Tmp.Key),$(Tmp.Config),$(Tmp.Arch))))
178$(call Set,Tmp.AR,$(strip \
179 $(call GetCNAVar,AR,$(Tmp.Key),$(Tmp.Config),$(Tmp.Arch))))
180$(call Set,Tmp.ARFLAGS,$(strip \
181 $(call GetCNAVar,ARFLAGS,$(Tmp.Key),$(Tmp.Config),$(Tmp.Arch))))
Daniel Dunbar8bc01cb2012-09-07 19:57:23 +0000182$(call Set,Tmp.CC,$(strip \
183 $(call GetCNAVar,CC,$(Tmp.Key),$(Tmp.Config),$(Tmp.Arch))))
184$(call Set,Tmp.LDFLAGS,$(strip \
185 $(call GetCNAVar,LDFLAGS,$(Tmp.Key),$(Tmp.Config),$(Tmp.Arch))))
Daniel Dunbar48464e02010-01-18 06:49:33 +0000186$(call Set,Tmp.RANLIB,$(strip \
187 $(call GetCNAVar,RANLIB,$(Tmp.Key),$(Tmp.Config),$(Tmp.Arch))))
188$(call Set,Tmp.RANLIBFLAGS,$(strip \
189 $(call GetCNAVar,RANLIBFLAGS,$(Tmp.Key),$(Tmp.Config),$(Tmp.Arch))))
Daniel Dunbar8bc01cb2012-09-07 19:57:23 +0000190$(call Set,Tmp.SHARED_LIBRARY,$(strip \
191 $(call GetCNAVar,SHARED_LIBRARY,$(Tmp.Key),$(Tmp.Config),$(Tmp.Arch))))
192
193# Compute the library suffix.
194$(if $(call streq,1,$(Tmp.SHARED_LIBRARY)),
195 $(call Set,Tmp.LibrarySuffix,dylib),
196 $(call Set,Tmp.LibrarySuffix,a))
Daniel Dunbar48464e02010-01-18 06:49:33 +0000197
198# Compute the object inputs for this library.
199$(call Set,Tmp.Inputs,\
200 $(foreach fn,$(sort $(Tmp.Functions)),\
201 $(call Set,Tmp.FnDir,\
202 $(call SelectFunctionDir,$(Tmp.Config),$(Tmp.Arch),$(fn),$(Tmp.Optimized)))\
203 $(Tmp.ObjPath)/$(Tmp.FnDir)/$(fn).o))
204$(Tmp.ObjPath)/libcompiler_rt.a: $(Tmp.Inputs) $(Tmp.ObjPath)/.dir
205 $(Summary) " ARCHIVE: $(Tmp.Name)/$(Tmp.Config)/$(Tmp.Arch): $$@"
206 -$(Verb) $(RM) $$@
207 $(Verb) $(Tmp.AR) $(Tmp.ARFLAGS) $$@ $(Tmp.Inputs)
208 $(Verb) $(Tmp.RANLIB) $(Tmp.RANLIBFLAGS) $$@
Daniel Dunbar8bc01cb2012-09-07 19:57:23 +0000209$(Tmp.ObjPath)/libcompiler_rt.dylib: $(Tmp.Inputs) $(Tmp.ObjPath)/.dir
210 $(Summary) " DYLIB: $(Tmp.Name)/$(Tmp.Config)/$(Tmp.Arch): $$@"
211 $(Verb) $(Tmp.CC) -arch $(Tmp.Arch) -dynamiclib -o $$@ \
212 $(Tmp.Inputs) $(Tmp.LDFLAGS)
Daniel Dunbar48464e02010-01-18 06:49:33 +0000213.PRECIOUS: $(Tmp.ObjPath)/.dir
214
215# Per-Config-Arch Targets
Daniel Dunbar8bc01cb2012-09-07 19:57:23 +0000216$(Tmp.Name)-$(Tmp.Config)-$(Tmp.Arch):: $(Tmp.ObjPath)/libcompiler_rt.$(Tmp.LibrarySuffix)
Daniel Dunbar48464e02010-01-18 06:49:33 +0000217.PHONY: $(Tmp.Name)-$(Tmp.Config)-$(Tmp.Arch)
218
219# Per-Config-Arch-SubDir Objects
220$(foreach key,$(SubDirKeys),\
221 $(call PerPlatformConfigArchSubDir_template,$(key)))
222endef
223
224define PerPlatformConfigArchSubDir_template
225$(call Set,Tmp.SubDirKey,$(1))
226$(call Set,Tmp.SubDir,$($(Tmp.SubDirKey).Dir))
227$(call Set,Tmp.SrcPath,$(ProjSrcRoot)/$(Tmp.SubDir))
228$(call Set,Tmp.ObjPath,$(ProjObjRoot)/$(Tmp.Name)/$(Tmp.Config)/$(Tmp.Arch)/$(Tmp.SubDirKey))
229$(call Set,Tmp.Dependencies,$($(Tmp.SubDirKey).Dependencies))
230$(call Set,Tmp.CC,$(strip \
231 $(call GetCNAVar,CC,$(Tmp.Key),$(Tmp.Config),$(Tmp.Arch))))
Daniel Dunbard3d22632010-03-31 17:00:48 +0000232$(call Set,Tmp.KERNEL_USE,$(strip \
233 $(call GetCNAVar,KERNEL_USE,$(Tmp.Key),$(Tmp.Config),$(Tmp.Arch))))
234$(call Set,Tmp.VISIBILITY_HIDDEN,$(strip \
235 $(call GetCNAVar,VISIBILITY_HIDDEN,$(Tmp.Key),$(Tmp.Config),$(Tmp.Arch))))
Daniel Dunbar48464e02010-01-18 06:49:33 +0000236$(call Set,Tmp.CFLAGS,$(strip \
Daniel Dunbar6a571fb2010-01-18 22:19:34 +0000237 $(if $(call IsDefined,$(Tmp.Key).UniversalArchs),-arch $(Tmp.Arch),)\
Daniel Dunbard3d22632010-03-31 17:00:48 +0000238 $(if $(call streq,$(Tmp.VISIBILITY_HIDDEN),1),\
Daniel Dunbar6a571fb2010-01-18 22:19:34 +0000239 -fvisibility=hidden -DVISIBILITY_HIDDEN,)\
Daniel Dunbard3d22632010-03-31 17:00:48 +0000240 $(if $(call streq,$(Tmp.KERNEL_USE),1),\
241 -mkernel -DKERNEL_USE,)\
Daniel Dunbar48464e02010-01-18 06:49:33 +0000242 $(call GetCNAVar,CFLAGS,$(Tmp.Key),$(Tmp.Config),$(Tmp.Arch))))
Daniel Dunbar48464e02010-01-18 06:49:33 +0000243
244$(Tmp.ObjPath)/%.o: $(Tmp.SrcPath)/%.s $(Tmp.Dependencies) $(Tmp.ObjPath)/.dir
245 $(Summary) " ASSEMBLE: $(Tmp.Name)/$(Tmp.Config)/$(Tmp.Arch): $$<"
Daniel Dunbar6a571fb2010-01-18 22:19:34 +0000246 $(Verb) $(Tmp.CC) $(Tmp.CFLAGS) -c -o $$@ $$<
Daniel Dunbar48464e02010-01-18 06:49:33 +0000247$(Tmp.ObjPath)/%.o: $(Tmp.SrcPath)/%.S $(Tmp.Dependencies) $(Tmp.ObjPath)/.dir
248 $(Summary) " ASSEMBLE: $(Tmp.Name)/$(Tmp.Config)/$(Tmp.Arch): $$<"
Daniel Dunbar6a571fb2010-01-18 22:19:34 +0000249 $(Verb) $(Tmp.CC) $(Tmp.CFLAGS) -c -o $$@ $$<
Daniel Dunbar48464e02010-01-18 06:49:33 +0000250$(Tmp.ObjPath)/%.o: $(Tmp.SrcPath)/%.c $(Tmp.Dependencies) $(Tmp.ObjPath)/.dir
251 $(Summary) " COMPILE: $(Tmp.Name)/$(Tmp.Config)/$(Tmp.Arch): $$<"
Kostya Serebryany803c1242011-12-13 18:58:47 +0000252 $(Verb) $(Tmp.CC) $(Tmp.CFLAGS) -c $(COMMON_CFLAGS) -o $$@ $$<
Daniel Dunbara6fd8452011-12-01 23:35:49 +0000253$(Tmp.ObjPath)/%.o: $(Tmp.SrcPath)/%.cc $(Tmp.Dependencies) $(Tmp.ObjPath)/.dir
254 $(Summary) " COMPILE: $(Tmp.Name)/$(Tmp.Config)/$(Tmp.Arch): $$<"
Kostya Serebryanye2357152011-12-06 21:11:50 +0000255 $(Verb) $(Tmp.CC) $(Tmp.CFLAGS) -c $(COMMON_CXXFLAGS) -o $$@ $$<
Daniel Dunbar48464e02010-01-18 06:49:33 +0000256.PRECIOUS: $(Tmp.ObjPath)/.dir
257
258endef
259
260# Run templates.
261$(foreach key,$(PlatformKeys),\
262 $(eval $(call PerPlatform_template,$(key))))
263
264###
Daniel Dunbar78cfbc52010-01-18 06:48:56 +0000265
Daniel Dunbarfaf01502010-01-18 06:48:33 +0000266ifneq ($(DEBUGMAKE),)
267 $(info MAKE: Done processing Makefile)
268 $(info )
269endif