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 | |
| 40 | help-hidden: help |
| 41 | @echo "Debugging variables:" |
Daniel Dunbar | faf0150 | 2010-01-18 06:48:33 +0000 | [diff] [blame^] | 42 | @echo " DEBUGMAKE=1: enable some Makefile logging [default=]" |
| 43 | @echo " =2: enable more Makefile logging" |
Daniel Dunbar | f572275 | 2010-01-18 06:48:19 +0000 | [diff] [blame] | 44 | @echo |
| 45 | @echo "Debugging targets:" |
| 46 | @echo " make-print-FOO: print information on the variable 'FOO'" |
| 47 | @echo |
| 48 | |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 49 | # Provide default clean target which is extended by other templates. |
| 50 | .PHONY: clean |
| 51 | clean:: |
| 52 | |
| 53 | # Test |
| 54 | .PHONY: test |
| 55 | test: |
| 56 | cd test/Unit && ./test |
| 57 | |
| 58 | # Template: Config_template Config |
| 59 | # |
| 60 | # This template is used once per Config at the top-level. |
| 61 | define Config_template |
| 62 | $(call Set,ActiveConfig,$1) |
| 63 | $(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveConfig)) |
| 64 | $(call Set,ActiveLibGen,$(ActiveObjPath)/libcompiler_rt.Generic.a) |
| 65 | $(call Set,ActiveLibOpt,$(ActiveObjPath)/libcompiler_rt.Optimized.a) |
| 66 | |
| 67 | # The sublibraries to use for a generic version. |
Daniel Dunbar | 866d282 | 2009-09-03 20:49:22 +0000 | [diff] [blame] | 68 | $(call Set,GenericInputs,$(foreach arch,$(TargetArchs),$(ActiveObjPath)/$(arch)/libcompiler_rt.Generic.a)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 69 | # The sublibraries to use for an optimized version. |
Daniel Dunbar | 866d282 | 2009-09-03 20:49:22 +0000 | [diff] [blame] | 70 | $(call Set,OptimizedInputs,$(foreach arch,$(TargetArchs),$(ActiveObjPath)/$(arch)/libcompiler_rt.Optimized.a)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 71 | |
Daniel Dunbar | 866d282 | 2009-09-03 20:49:22 +0000 | [diff] [blame] | 72 | # Provide top-level fat archive targets. We make sure to not try to lipo if only |
| 73 | # building one target arch. |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 74 | $(ActiveLibGen): $(GenericInputs) $(ActiveObjPath)/.dir |
| 75 | $(Summary) " UNIVERSAL: $(ActiveConfig): $$@" |
| 76 | -$(Verb) $(RM) $$@ |
Daniel Dunbar | 866d282 | 2009-09-03 20:49:22 +0000 | [diff] [blame] | 77 | $(if $(TargetArch), \ |
| 78 | $(Verb) $(CP) $(GenericInputs) $$@, \ |
| 79 | $(Verb) $(Lipo) -create -output $$@ $(GenericInputs)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 80 | $(ActiveLibOpt): $(OptimizedInputs) $(ActiveObjPath)/.dir |
| 81 | $(Summary) " UNIVERSAL: $(ActiveConfig): $$@" |
| 82 | -$(Verb) $(RM) $$@ |
Daniel Dunbar | 866d282 | 2009-09-03 20:49:22 +0000 | [diff] [blame] | 83 | $(if $(TargetArch), \ |
| 84 | $(Verb) $(CP) $(GenericInputs) $$@, \ |
| 85 | $(Verb) $(Lipo) -create -output $$@ $(OptimizedInputs)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 86 | .PRECIOUS: $(ActiveObjPath)/.dir |
| 87 | |
Daniel Dunbar | fd17b8a | 2009-09-10 23:13:59 +0000 | [diff] [blame] | 88 | # Add to default "alias" target. |
| 89 | $(ActiveConfig):: $(ActiveLibGen) $(ActiveLibOpt) |
| 90 | |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 91 | # Add to target lists. |
| 92 | all:: $(ActiveConfig) $(ActiveLibGen) $(ActiveLibOpt) |
| 93 | |
| 94 | # Remove entire config directory on clean. |
| 95 | clean:: $(ActiveObjPath)/.remove |
| 96 | endef |
| 97 | |
| 98 | # Template: CNA_template Config Arch |
Daniel Dunbar | 557a6ea | 2010-01-13 16:13:01 +0000 | [diff] [blame] | 99 | # |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 100 | # This template is used once per Config/Arch at the top-level. |
| 101 | define CNA_template |
| 102 | $(call Set,ActiveConfig,$1) |
| 103 | $(call Set,ActiveArch,$2) |
| 104 | $(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveConfig)/$(ActiveArch)) |
| 105 | $(call Set,ActiveLibGen,$(ActiveObjPath)/libcompiler_rt.Generic.a) |
| 106 | $(call Set,ActiveLibOpt,$(ActiveObjPath)/libcompiler_rt.Optimized.a) |
| 107 | |
Daniel Dunbar | 557a6ea | 2010-01-13 16:13:01 +0000 | [diff] [blame] | 108 | # Initialize inputs lists. This are extended by the CNA_subdir template. The one |
| 109 | # tricky bit is that we need to use these quoted, because they are not complete |
| 110 | # until the entire makefile has been processed. |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 111 | $(call Set,GenericInputs.$(ActiveConfig).$(ActiveArch),) |
| 112 | $(call Set,OptimizedInputs.$(ActiveConfig).$(ActiveArch),) |
| 113 | # Final.Inputs is created once we have loaded all the subdirectories |
| 114 | # and know what the correct inputs are. |
| 115 | |
| 116 | # Provide top-level archive targets. |
| 117 | $(ActiveLibGen): $(ActiveObjPath)/.dir |
| 118 | $(Summary) " ARCHIVE: $(ActiveConfig)/$(ActiveArch): $$@" |
| 119 | -$(Verb) $(RM) $$@ |
| 120 | $(Verb) $(Archive) $$@ $$(Generic.Inputs.$(ActiveConfig).$(ActiveArch)) |
| 121 | $(Verb) $(Ranlib) $$@ |
| 122 | # FIXME: The dependency on ActiveLibGen is a hack, this picks up the |
| 123 | # dependencies on the generic inputs. |
| 124 | $(ActiveLibOpt): $(ActiveLibGen) $(ActiveObjPath)/.dir |
| 125 | $(Summary) " ARCHIVE: $(ActiveConfig)/$(ActiveArch): $$@" |
| 126 | -$(Verb) $(RM) $$@ |
| 127 | $(Verb) $(Archive) $$@ $$(Final.Inputs.$(ActiveConfig).$(ActiveArch)) |
| 128 | $(Verb) $(Ranlib) $$@ |
| 129 | .PRECIOUS: $(ActiveObjPath)/.dir |
| 130 | |
| 131 | # Provide some default "alias" targets. |
| 132 | $(ActiveConfig):: $(ActiveLibGen) $(ActiveLibOpt) |
| 133 | $(ActiveArch):: $(ActiveLibGen) $(ActiveLibOpt) |
| 134 | $(ActiveConfig)-$(ActiveArch):: $(ActiveLibGen) $(ActiveLibOpt) |
| 135 | endef |
| 136 | |
| 137 | $(foreach config,$(Configs), \ |
| 138 | $(foreach arch,$(Archs), \ |
| 139 | $(eval $(call CNA_template,$(config),$(arch))))) |
| 140 | |
| 141 | $(foreach config,$(Configs), \ |
| 142 | $(eval $(call Config_template,$(config)))) |
| 143 | |
| 144 | ### |
| 145 | # How to build things. |
| 146 | |
Daniel Dunbar | 557a6ea | 2010-01-13 16:13:01 +0000 | [diff] [blame] | 147 | # Define rules for building on each configuration & architecture. This is not |
| 148 | # exactly obvious, but variables inside the template are being expanded during |
| 149 | # the make processing, so automatic variables must be quoted and normal |
| 150 | # assignment cannot be used. |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 151 | |
| 152 | # Template: CNA_template Config Arch Dir |
| 153 | # Uses: GetArgs, Dependencies, ObjNames |
| 154 | # |
| 155 | # This template is used once per Config/Arch/Dir. |
| 156 | define CNA_subdir_template |
| 157 | $(call Set,ActiveConfig,$1) |
| 158 | $(call Set,ActiveArch,$2) |
| 159 | $(call Set,ActiveDir,$3) |
| 160 | $(call Set,ActiveSrcPath,$(ProjSrcRoot)/$(ActiveDir)) |
| 161 | $(call Set,ActiveObjPath,$(ProjObjRoot)/$(ActiveDir)/$(ActiveConfig)/$(ActiveArch)) |
| 162 | |
| 163 | $(call Set,ActiveFlags,$(call GetArgs,$(ActiveConfig),$(ActiveArch))) |
| 164 | $(call Set,ActiveObjects,$(ObjNames:%=$(ActiveObjPath)/%)) |
| 165 | |
Daniel Dunbar | 557a6ea | 2010-01-13 16:13:01 +0000 | [diff] [blame] | 166 | # 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] | 167 | $(call Append,$(Target).Inputs.$(ActiveConfig).$(ActiveArch),$(ActiveObjects)) |
| 168 | $(ProjObjRoot)/$(ActiveConfig)/$(ActiveArch)/libcompiler_rt.$(Target).a: $(ActiveObjects) |
| 169 | |
| 170 | $(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.s $(Dependencies) $(ActiveObjPath)/.dir |
| 171 | $(Summary) " ASSEMBLE: $(ActiveConfig)/$(ActiveArch): $$<" |
| 172 | $(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$< |
| 173 | .PRECIOUS: $(ActiveObjPath)/.dir |
| 174 | |
Daniel Dunbar | dc114bf | 2009-09-10 23:27:45 +0000 | [diff] [blame] | 175 | $(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.S $(Dependencies) $(ActiveObjPath)/.dir |
| 176 | $(Summary) " ASSEMBLE: $(ActiveConfig)/$(ActiveArch): $$<" |
| 177 | $(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$< |
| 178 | .PRECIOUS: $(ActiveObjPath)/.dir |
| 179 | |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 180 | $(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.c $(Dependencies) $(ActiveObjPath)/.dir |
| 181 | $(Summary) " COMPILE: $(ActiveConfig)/$(ActiveArch): $$<" |
| 182 | $(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$< |
| 183 | .PRECIOUS: $(ActiveObjPath)/.dir |
| 184 | |
| 185 | # Remove entire config directory on clean. |
| 186 | clean:: $(ProjObjRoot)/$(ActiveDir)/$(ActiveConfig)/.remove |
| 187 | endef |
| 188 | |
| 189 | ### |
| 190 | # Directory handling magic. |
| 191 | |
| 192 | # Create directories as needed, and timestamp their creation. |
| 193 | %/.dir: |
| 194 | $(Summary) " MKDIR: $*" |
| 195 | $(Verb) $(MKDIR) $* > /dev/null |
| 196 | $(Verb) $(DATE) > $@ |
| 197 | |
| 198 | # Remove directories |
| 199 | %/.remove: |
| 200 | $(Verb) $(RM) -r $* |
| 201 | |
| 202 | ### |
| 203 | # Include child makefile fragments |
| 204 | |
Daniel Dunbar | faf0150 | 2010-01-18 06:48:33 +0000 | [diff] [blame^] | 205 | Dir := . |
| 206 | include make/subdir.mk |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 207 | |
| 208 | ### |
| 209 | # Determine the actual inputs for an optimized library. |
| 210 | |
| 211 | # Template: Final_CNA_template Config Arch |
| 212 | # Uses: GetArgs, Dependencies, ObjNames |
| 213 | # |
| 214 | # This template is used once per Config/Arch. |
| 215 | define Final_CNA_template |
| 216 | $(call Set,ActiveConfig,$1) |
| 217 | $(call Set,ActiveArch,$2) |
| 218 | |
| 219 | $(call Set,Final.Inputs.$(ActiveConfig).$(ActiveArch),\ |
| 220 | $(shell make/filter-inputs \ |
| 221 | $(Optimized.Inputs.$(ActiveConfig).$(ActiveArch)) \ |
| 222 | $(Generic.Inputs.$(ActiveConfig).$(ActiveArch)))) |
| 223 | endef |
| 224 | |
| 225 | $(foreach config,$(Configs), \ |
| 226 | $(foreach arch,$(Archs), \ |
| 227 | $(eval $(call Final_CNA_template,$(config),$(arch))))) |
Daniel Dunbar | faf0150 | 2010-01-18 06:48:33 +0000 | [diff] [blame^] | 228 | |
| 229 | ifneq ($(DEBUGMAKE),) |
| 230 | $(info MAKE: Done processing Makefile) |
| 231 | $(info ) |
| 232 | endif |