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 |
| 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". |
| 11 | ifdef SRCROOT |
| 12 | include make/AppleBI.mk |
| 13 | endif |
| 14 | |
| 15 | # Make sure we don't build with a missing ProjObjRoot. |
| 16 | ifeq ($(ProjObjRoot),) |
| 17 | $(error Refusing to build with empty ProjObjRoot variable) |
| 18 | endif |
| 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 |
| 30 | clean:: |
| 31 | |
| 32 | # Test |
| 33 | .PHONY: test |
| 34 | test: |
| 35 | cd test/Unit && ./test |
| 36 | |
| 37 | # Template: Config_template Config |
| 38 | # |
| 39 | # This template is used once per Config at the top-level. |
| 40 | define 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 Dunbar | 866d282 | 2009-09-03 20:49:22 +0000 | [diff] [blame] | 47 | $(call Set,GenericInputs,$(foreach arch,$(TargetArchs),$(ActiveObjPath)/$(arch)/libcompiler_rt.Generic.a)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 48 | # The sublibraries to use for an optimized version. |
Daniel Dunbar | 866d282 | 2009-09-03 20:49:22 +0000 | [diff] [blame] | 49 | $(call Set,OptimizedInputs,$(foreach arch,$(TargetArchs),$(ActiveObjPath)/$(arch)/libcompiler_rt.Optimized.a)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 50 | |
Daniel Dunbar | 866d282 | 2009-09-03 20:49:22 +0000 | [diff] [blame] | 51 | # Provide top-level fat archive targets. We make sure to not try to lipo if only |
| 52 | # building one target arch. |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 53 | $(ActiveLibGen): $(GenericInputs) $(ActiveObjPath)/.dir |
| 54 | $(Summary) " UNIVERSAL: $(ActiveConfig): $$@" |
| 55 | -$(Verb) $(RM) $$@ |
Daniel Dunbar | 866d282 | 2009-09-03 20:49:22 +0000 | [diff] [blame] | 56 | $(if $(TargetArch), \ |
| 57 | $(Verb) $(CP) $(GenericInputs) $$@, \ |
| 58 | $(Verb) $(Lipo) -create -output $$@ $(GenericInputs)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 59 | $(ActiveLibOpt): $(OptimizedInputs) $(ActiveObjPath)/.dir |
| 60 | $(Summary) " UNIVERSAL: $(ActiveConfig): $$@" |
| 61 | -$(Verb) $(RM) $$@ |
Daniel Dunbar | 866d282 | 2009-09-03 20:49:22 +0000 | [diff] [blame] | 62 | $(if $(TargetArch), \ |
| 63 | $(Verb) $(CP) $(GenericInputs) $$@, \ |
| 64 | $(Verb) $(Lipo) -create -output $$@ $(OptimizedInputs)) |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 65 | .PRECIOUS: $(ActiveObjPath)/.dir |
| 66 | |
Daniel Dunbar | fd17b8a | 2009-09-10 23:13:59 +0000 | [diff] [blame] | 67 | # Add to default "alias" target. |
| 68 | $(ActiveConfig):: $(ActiveLibGen) $(ActiveLibOpt) |
| 69 | |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 70 | # Add to target lists. |
| 71 | all:: $(ActiveConfig) $(ActiveLibGen) $(ActiveLibOpt) |
| 72 | |
| 73 | # Remove entire config directory on clean. |
| 74 | clean:: $(ActiveObjPath)/.remove |
| 75 | endef |
| 76 | |
| 77 | # Template: CNA_template Config Arch |
| 78 | # |
| 79 | # This template is used once per Config/Arch at the top-level. |
| 80 | define 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) |
| 115 | endef |
| 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. |
| 136 | define 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 Dunbar | dc114bf | 2009-09-10 23:27:45 +0000 | [diff] [blame] | 156 | $(ActiveObjPath)/%.o: $(ActiveSrcPath)/%.S $(Dependencies) $(ActiveObjPath)/.dir |
| 157 | $(Summary) " ASSEMBLE: $(ActiveConfig)/$(ActiveArch): $$<" |
| 158 | $(Verb) $(CC) -c -o $$@ $(ActiveFlags) $$< |
| 159 | .PRECIOUS: $(ActiveObjPath)/.dir |
| 160 | |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 161 | $(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. |
| 167 | clean:: $(ProjObjRoot)/$(ActiveDir)/$(ActiveConfig)/.remove |
| 168 | endef |
| 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. |
| 195 | define 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)))) |
| 203 | endef |
| 204 | |
| 205 | $(foreach config,$(Configs), \ |
| 206 | $(foreach arch,$(Archs), \ |
| 207 | $(eval $(call Final_CNA_template,$(config),$(arch))))) |