Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 1 | SubDirs := lib |
| 2 | |
| 3 | # Set default rule before anything else. |
| 4 | all:: |
| 5 | |
| 6 | include make/config.mk |
| 7 | include make/util.mk |
Daniel Dunbar | 557a6ea | 2010-01-13 16:13:01 +0000 | [diff] [blame] | 8 | # 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 Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 10 | ifdef SRCROOT |
| 11 | include make/AppleBI.mk |
| 12 | endif |
| 13 | |
| 14 | # Make sure we don't build with a missing ProjObjRoot. |
| 15 | ifeq ($(ProjObjRoot),) |
| 16 | $(error Refusing to build with empty ProjObjRoot variable) |
| 17 | endif |
| 18 | |
| 19 | ############## |
| 20 | |
| 21 | ### |
| 22 | # Rules |
| 23 | |
| 24 | ### |
| 25 | # Top level targets |
| 26 | |
Daniel Dunbar | f572275 | 2010-01-18 06:48:19 +0000 | [diff] [blame] | 27 | # FIXME: Document the available subtargets. |
| 28 | help: |
| 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 Dunbar | 9edf5cd | 2010-01-18 06:48:40 +0000 | [diff] [blame^] | 40 | help-devel: help |
| 41 | @echo "Development targets:" |
| 42 | @echo " info-functions: list available compiler-rt functions" |
| 43 | @echo |
| 44 | |
| 45 | help-hidden: help-devel |
Daniel Dunbar | f572275 | 2010-01-18 06:48:19 +0000 | [diff] [blame] | 46 | @echo "Debugging variables:" |
Daniel Dunbar | faf0150 | 2010-01-18 06:48:33 +0000 | [diff] [blame] | 47 | @echo " DEBUGMAKE=1: enable some Makefile logging [default=]" |
| 48 | @echo " =2: enable more Makefile logging" |
Daniel Dunbar | f572275 | 2010-01-18 06:48:19 +0000 | [diff] [blame] | 49 | @echo |
| 50 | @echo "Debugging targets:" |
| 51 | @echo " make-print-FOO: print information on the variable 'FOO'" |
| 52 | @echo |
| 53 | |
Daniel Dunbar | 9edf5cd | 2010-01-18 06:48:40 +0000 | [diff] [blame^] | 54 | info-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 Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 62 | # Provide default clean target which is extended by other templates. |
| 63 | .PHONY: clean |
| 64 | clean:: |
| 65 | |
| 66 | # Test |
| 67 | .PHONY: test |
| 68 | test: |
| 69 | cd test/Unit && ./test |
| 70 | |
| 71 | # Template: Config_template Config |
| 72 | # |
| 73 | # This template is used once per Config at the top-level. |
| 74 | define 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 Dunbar | 866d282 | 2009-09-03 20:49:22 +0000 | [diff] [blame] | 81 | $(call Set,GenericInputs,$(foreach arch,$(TargetArchs),$(ActiveObjPath)/$(arch)/libcompiler_rt.Generic.a)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 82 | # The sublibraries to use for an optimized version. |
Daniel Dunbar | 866d282 | 2009-09-03 20:49:22 +0000 | [diff] [blame] | 83 | $(call Set,OptimizedInputs,$(foreach arch,$(TargetArchs),$(ActiveObjPath)/$(arch)/libcompiler_rt.Optimized.a)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 84 | |
Daniel Dunbar | 866d282 | 2009-09-03 20:49:22 +0000 | [diff] [blame] | 85 | # Provide top-level fat archive targets. We make sure to not try to lipo if only |
| 86 | # building one target arch. |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 87 | $(ActiveLibGen): $(GenericInputs) $(ActiveObjPath)/.dir |
| 88 | $(Summary) " UNIVERSAL: $(ActiveConfig): $$@" |
| 89 | -$(Verb) $(RM) $$@ |
Daniel Dunbar | 866d282 | 2009-09-03 20:49:22 +0000 | [diff] [blame] | 90 | $(if $(TargetArch), \ |
| 91 | $(Verb) $(CP) $(GenericInputs) $$@, \ |
| 92 | $(Verb) $(Lipo) -create -output $$@ $(GenericInputs)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 93 | $(ActiveLibOpt): $(OptimizedInputs) $(ActiveObjPath)/.dir |
| 94 | $(Summary) " UNIVERSAL: $(ActiveConfig): $$@" |
| 95 | -$(Verb) $(RM) $$@ |
Daniel Dunbar | 866d282 | 2009-09-03 20:49:22 +0000 | [diff] [blame] | 96 | $(if $(TargetArch), \ |
| 97 | $(Verb) $(CP) $(GenericInputs) $$@, \ |
| 98 | $(Verb) $(Lipo) -create -output $$@ $(OptimizedInputs)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 99 | .PRECIOUS: $(ActiveObjPath)/.dir |
| 100 | |
Daniel Dunbar | fd17b8a | 2009-09-10 23:13:59 +0000 | [diff] [blame] | 101 | # Add to default "alias" target. |
| 102 | $(ActiveConfig):: $(ActiveLibGen) $(ActiveLibOpt) |
| 103 | |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 104 | # Add to target lists. |
| 105 | all:: $(ActiveConfig) $(ActiveLibGen) $(ActiveLibOpt) |
| 106 | |
| 107 | # Remove entire config directory on clean. |
| 108 | clean:: $(ActiveObjPath)/.remove |
| 109 | endef |
| 110 | |
| 111 | # Template: CNA_template Config Arch |
Daniel Dunbar | 557a6ea | 2010-01-13 16:13:01 +0000 | [diff] [blame] | 112 | # |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 113 | # This template is used once per Config/Arch at the top-level. |
| 114 | define 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 Dunbar | 557a6ea | 2010-01-13 16:13:01 +0000 | [diff] [blame] | 121 | # 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 Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 124 | $(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) |
| 148 | endef |
| 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 Dunbar | 557a6ea | 2010-01-13 16:13:01 +0000 | [diff] [blame] | 160 | # 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 Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 164 | |
| 165 | # Template: CNA_template Config Arch Dir |
| 166 | # Uses: GetArgs, Dependencies, ObjNames |
| 167 | # |
| 168 | # This template is used once per Config/Arch/Dir. |
| 169 | define 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 Dunbar | 557a6ea | 2010-01-13 16:13:01 +0000 | [diff] [blame] | 179 | # Add to the input list for the appropriate library and update the dependency. |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 180 | $(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 Dunbar | dc114bf | 2009-09-10 23:27:45 +0000 | [diff] [blame] | 188 | $(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.S $(Dependencies) $(ActiveObjPath)/.dir |
| 189 | $(Summary) " ASSEMBLE: $(ActiveConfig)/$(ActiveArch): $$<" |
| 190 | $(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$< |
| 191 | .PRECIOUS: $(ActiveObjPath)/.dir |
| 192 | |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 193 | $(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. |
| 199 | clean:: $(ProjObjRoot)/$(ActiveDir)/$(ActiveConfig)/.remove |
| 200 | endef |
| 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 Dunbar | faf0150 | 2010-01-18 06:48:33 +0000 | [diff] [blame] | 218 | Dir := . |
| 219 | include make/subdir.mk |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 220 | |
| 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. |
| 228 | define 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)))) |
| 236 | endef |
| 237 | |
| 238 | $(foreach config,$(Configs), \ |
| 239 | $(foreach arch,$(Archs), \ |
| 240 | $(eval $(call Final_CNA_template,$(config),$(arch))))) |
Daniel Dunbar | faf0150 | 2010-01-18 06:48:33 +0000 | [diff] [blame] | 241 | |
| 242 | ifneq ($(DEBUGMAKE),) |
| 243 | $(info MAKE: Done processing Makefile) |
| 244 | $(info ) |
| 245 | endif |
Daniel Dunbar | 9edf5cd | 2010-01-18 06:48:40 +0000 | [diff] [blame^] | 246 | |
| 247 | ### |
| 248 | # Function Information |
| 249 | # |
| 250 | # FIXME: Factor out. |
| 251 | |
| 252 | AvailableObjects := $(sort $(foreach key,$(SubDirKeys),\ |
| 253 | $($(key).ObjNames))) |
| 254 | AvailableFunctions := $(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 | |