1 ## 2 ## Copyright (c) 2010 The WebM project authors. All Rights Reserved. 3 ## 4 ## Use of this source code is governed by a BSD-style license 5 ## that can be found in the LICENSE file in the root of the source 6 ## tree. An additional intellectual property rights grant can be found 7 ## in the file PATENTS. All contributing project authors may 8 ## be found in the AUTHORS file in the root of the source tree. 9 ## 10 11 12 include config.mk 13 quiet?=true 14 ifeq ($(target),) 15 # If a target wasn't specified, invoke for all enabled targets. 16 .DEFAULT: 17 @for t in $(ALL_TARGETS); do \ 18 $(MAKE) --no-print-directory target=$$t $(MAKECMDGOALS) || exit $$?;\ 19 done 20 all: .DEFAULT 21 clean:: .DEFAULT 22 install:: .DEFAULT 23 24 25 # Note: md5sum is not installed on OS X, but openssl is. Openssl may not be 26 # installed on cygwin, so we need to autodetect here. 27 md5sum := $(firstword $(wildcard \ 28 $(foreach e,md5sum openssl,\ 29 $(foreach p,$(subst :, ,$(PATH)),$(p)/$(e)*))\ 30 )) 31 md5sum := $(if $(filter %openssl,$(md5sum)),$(md5sum) dgst -md5,$(md5sum)) 32 33 TGT_CC:=$(word 3, $(subst -, ,$(TOOLCHAIN))) 34 dist: 35 @for t in $(ALL_TARGETS); do \ 36 $(MAKE) --no-print-directory target=$$t $(MAKECMDGOALS) || exit $$?;\ 37 done 38 # Run configure for the user with the current toolchain. 39 @if [ -d "$(DIST_DIR)/src" ]; then \ 40 mkdir -p "$(DIST_DIR)/build"; \ 41 cd "$(DIST_DIR)/build"; \ 42 echo "Rerunning configure $(CONFIGURE_ARGS)"; \ 43 ../src/configure $(CONFIGURE_ARGS); \ 44 $(if $(filter vs%,$(TGT_CC)),make NO_LAUNCH_DEVENV=1;) \ 45 fi 46 @if [ -d "$(DIST_DIR)" ]; then \ 47 echo " [MD5SUM] $(DIST_DIR)"; \ 48 cd $(DIST_DIR) && \ 49 $(md5sum) `find . -name md5sums.txt -prune -o -type f -print` \ 50 | sed -e 's/MD5(\(.*\))= \([0-9a-f]\{32\}\)/\2 \1/' \ 51 > md5sums.txt;\ 52 fi 53 54 55 endif 56 57 ifneq ($(target),) 58 # Normally, we want to build the filename from the target and the toolchain. 59 # This disambiguates from the $(target).mk file that exists in the source tree. 60 # However, the toolchain is part of the target in universal builds, so we 61 # don't want to include TOOLCHAIN in that case. FAT_ARCHS is used to test 62 # if we're in the universal case. 63 include $(target)$(if $(FAT_ARCHS),,-$(TOOLCHAIN)).mk 64 endif 65 BUILD_ROOT?=. 66 VPATH=$(SRC_PATH_BARE) 67 CFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT) -I$(SRC_PATH) 68 ASFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT)/ -I$(SRC_PATH)/ 69 DIST_DIR?=dist 70 HOSTCC?=gcc 71 TGT_ISA:=$(word 1, $(subst -, ,$(TOOLCHAIN))) 72 TGT_OS:=$(word 2, $(subst -, ,$(TOOLCHAIN))) 73 TGT_CC:=$(word 3, $(subst -, ,$(TOOLCHAIN))) 74 quiet:=$(if $(verbose),,yes) 75 qexec=$(if $(quiet),@) 76 77 # Cancel built-in implicit rules 78 %: %.o 79 %.asm: 80 %.a: 81 82 # 83 # Common rules" 84 # 85 .PHONY: all-$(target) 86 all-$(target): 87 88 .PHONY: clean 89 clean:: 90 rm -f $(OBJS-yes) $(OBJS-yes:.o=.d) $(OBJS-yes:.asm.s.o=.asm.s) 91 rm -f $(CLEAN-OBJS) 92 93 .PHONY: dist 94 dist: 95 .PHONY: install 96 install:: 97 98 $(BUILD_PFX)%.c.d: %.c 99 $(if $(quiet),@echo " [DEP] $@") 100 $(qexec)mkdir -p $(dir $@) 101 $(qexec)$(CC) $(CFLAGS) -M $< | $(fmt_deps) > $@ 102 103 $(BUILD_PFX)%.c.o: %.c 104 $(if $(quiet),@echo " [CC] $@") 105 $(qexec)$(CC) $(CFLAGS) -c -o $@ $< 106 107 $(BUILD_PFX)%.asm.d: %.asm 108 $(if $(quiet),@echo " [DEP] $@") 109 $(qexec)mkdir -p $(dir $@) 110 $(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \ 111 --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@ 112 113 $(BUILD_PFX)%.asm.o: %.asm 114 $(if $(quiet),@echo " [AS] $@") 115 $(qexec)$(AS) $(ASFLAGS) -o $@ $< 116 117 $(BUILD_PFX)%.s.d: %.s 118 $(if $(quiet),@echo " [DEP] $@") 119 $(qexec)mkdir -p $(dir $@) 120 $(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \ 121 --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@ 122 123 $(BUILD_PFX)%.s.o: %.s 124 $(if $(quiet),@echo " [AS] $@") 125 $(qexec)$(AS) $(ASFLAGS) -o $@ $< 126 127 .PRECIOUS: %.asm.s 128 $(BUILD_PFX)%.asm.s: %.asm 129 $(if $(quiet),@echo " [ASM CONVERSION] $@") 130 $(qexec)mkdir -p $(dir $@) 131 $(qexec)$(ASM_CONVERSION) <$< >$@ 132 133 # If we're in debug mode, pretend we don't have GNU strip, to fall back to 134 # the copy implementation 135 HAVE_GNU_STRIP := $(if $(CONFIG_DEBUG),,$(HAVE_GNU_STRIP)) 136 ifeq ($(HAVE_GNU_STRIP),yes) 137 # Older binutils strip global sybols not needed for relocation processing 138 # when given --strip-unneeded. Use nm and awk to identify globals and 139 # keep them. 140 %.a: %_g.a 141 $(if $(quiet),@echo " [STRIP] $@ < $<") 142 $(qexec)$(STRIP) --strip-unneeded \ 143 `$(NM) $< | grep ' [A-TV-Z] ' | awk '{print "-K"$$3'}`\ 144 -o $@ $< 145 else 146 %.a: %_g.a 147 $(if $(quiet),@echo " [CP] $@ < $<") 148 $(qexec)cp $< $@ 149 endif 150 151 # 152 # Rule to extract assembly constants from C sources 153 # 154 obj_int_extract: build/make/obj_int_extract.c 155 $(if $(quiet),@echo " [HOSTCC] $@") 156 $(qexec)$(HOSTCC) -I. -I$(SRC_PATH_BARE) -o $@ $< 157 CLEAN-OBJS += obj_int_extract 158 159 # 160 # Utility functions 161 # 162 pairmap=$(if $(strip $(2)),\ 163 $(call $(1),$(word 1,$(2)),$(word 2,$(2)))\ 164 $(call pairmap,$(1),$(wordlist 3,$(words $(2)),$(2)))\ 165 ) 166 167 enabled=$(filter-out $($(1)-no),$($(1)-yes)) 168 cond_enabled=$(if $(filter yes,$($(1))), $(call enabled,$(2))) 169 170 find_file1=$(word 1,$(wildcard $(subst //,/,$(addsuffix /$(1),$(2))))) 171 find_file=$(foreach f,$(1),$(call find_file1,$(strip $(f)),$(strip $(2))) ) 172 obj_pats=.c=.c.o $(AS_SFX)=$(AS_SFX).o 173 objs=$(addprefix $(BUILD_PFX),$(foreach p,$(obj_pats),$(filter %.o,$(1:$(p))) )) 174 175 install_map_templates=$(eval $(call install_map_template,$(1),$(2))) 176 177 not=$(subst yes,no,$(1)) 178 179 ifeq ($(CONFIG_MSVS),yes) 180 lib_file_name=$(1).lib 181 else 182 lib_file_name=lib$(1).a 183 endif 184 # 185 # Rule Templates 186 # 187 define linker_template 188 $(1): $(filter-out -%,$(2)) 189 $(1): 190 $(if $(quiet),@echo " [LD] $$@") 191 $(qexec)$$(LD) $$(strip $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs)) 192 endef 193 # make-3.80 has a bug with expanding large input strings to the eval function, 194 # which was triggered in some cases by the following component of 195 # linker_template: 196 # $(1): $$(call find_file, $(patsubst -l%,lib%.a,$(filter -l%,$(2))),\ 197 # $$(patsubst -L%,%,$$(filter -L%,$$(LDFLAGS) $(2)))) 198 # This may be useful to revisit in the future (it tries to locate libraries 199 # in a search path and add them as prerequisites 200 201 define install_map_template 202 $(DIST_DIR)/$(1): $(2) 203 $(if $(quiet),@echo " [INSTALL] $$@") 204 $(qexec)mkdir -p $$(dir $$@) 205 $(qexec)cp -p $$< $$@ 206 endef 207 208 define archive_template 209 # Not using a pattern rule here because we don't want to generate empty 210 # archives when they are listed as a dependency in files not responsible 211 # for creating them. 212 $(1): 213 $(if $(quiet),@echo " [AR] $$@") 214 $(qexec)$$(AR) $$(ARFLAGS) $$@ $$? 215 endef 216 217 define so_template 218 # Not using a pattern rule here because we don't want to generate empty 219 # archives when they are listed as a dependency in files not responsible 220 # for creating them. 221 # 222 # This needs further abstraction for dealing with non-GNU linkers. 223 $(1): 224 $(if $(quiet),@echo " [LD] $$@") 225 $(qexec)$$(LD) -shared $$(LDFLAGS) \ 226 -Wl,--no-undefined -Wl,-soname,$$(SONAME) \ 227 -Wl,--version-script,$$(SO_VERSION_SCRIPT) -o $$@ \ 228 $$(filter %.o,$$?) $$(extralibs) 229 endef 230 231 define lipo_lib_template 232 $(1): $(addsuffix /$(1),$(FAT_ARCHS)) 233 $(if $(quiet),@echo " [LIPO] $$@") 234 $(qexec)libtool -static -o $$@ $$? 235 endef 236 237 define lipo_bin_template 238 $(1): $(addsuffix /$(1),$(FAT_ARCHS)) 239 $(if $(quiet),@echo " [LIPO] $$@") 240 $(qexec)lipo -output $$@ -create $$? 241 endef 242 243 244 # 245 # Get current configuration 246 # 247 ifneq ($(target),) 248 include $(SRC_PATH_BARE)/$(target:-$(TOOLCHAIN)=).mk 249 endif 250 ifeq ($(filter clean,$(MAKECMDGOALS)),) 251 # Older versions of make don't like -include directives with no arguments 252 ifneq ($(filter %.d,$(OBJS-yes:.o=.d)),) 253 -include $(filter %.d,$(OBJS-yes:.o=.d)) 254 endif 255 endif 256 257 # 258 # Configuration dependent rules 259 # 260 $(call pairmap,install_map_templates,$(INSTALL_MAPS)) 261 262 DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,DOCS) 263 .docs: $(DOCS) 264 @touch $@ 265 266 INSTALL-DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,INSTALL-DOCS) 267 ifeq ($(MAKECMDGOALS),dist) 268 INSTALL-DOCS+=$(call cond_enabled,CONFIG_INSTALL_DOCS,DIST-DOCS) 269 endif 270 .install-docs: .docs $(addprefix $(DIST_DIR)/,$(INSTALL-DOCS)) 271 @touch $@ 272 273 clean:: 274 rm -f .docs .install-docs $(DOCS) 275 276 BINS=$(call enabled,BINS) 277 .bins: $(BINS) 278 @touch $@ 279 280 INSTALL-BINS=$(call cond_enabled,CONFIG_INSTALL_BINS,INSTALL-BINS) 281 ifeq ($(MAKECMDGOALS),dist) 282 INSTALL-BINS+=$(call cond_enabled,CONFIG_INSTALL_BINS,DIST-BINS) 283 endif 284 .install-bins: .bins $(addprefix $(DIST_DIR)/,$(INSTALL-BINS)) 285 @touch $@ 286 287 clean:: 288 rm -f .bins .install-bins $(BINS) 289 290 LIBS=$(call enabled,LIBS) 291 .libs: $(LIBS) 292 @touch $@ 293 $(foreach lib,$(filter %_g.a,$(LIBS)),$(eval $(call archive_template,$(lib)))) 294 $(foreach lib,$(filter %so.$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH),$(LIBS)),$(eval $(call so_template,$(lib)))) 295 296 INSTALL-LIBS=$(call cond_enabled,CONFIG_INSTALL_LIBS,INSTALL-LIBS) 297 ifeq ($(MAKECMDGOALS),dist) 298 INSTALL-LIBS+=$(call cond_enabled,CONFIG_INSTALL_LIBS,DIST-LIBS) 299 endif 300 .install-libs: .libs $(addprefix $(DIST_DIR)/,$(INSTALL-LIBS)) 301 @touch $@ 302 303 clean:: 304 rm -f .libs .install-libs $(LIBS) 305 306 ifeq ($(CONFIG_EXTERNAL_BUILD),yes) 307 PROJECTS=$(call enabled,PROJECTS) 308 .projects: $(PROJECTS) 309 @touch $@ 310 311 INSTALL-PROJECTS=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,INSTALL-PROJECTS) 312 ifeq ($(MAKECMDGOALS),dist) 313 INSTALL-PROJECTS+=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,DIST-PROJECTS) 314 endif 315 .install-projects: .projects $(addprefix $(DIST_DIR)/,$(INSTALL-PROJECTS)) 316 @touch $@ 317 318 clean:: 319 rm -f .projects .install-projects $(PROJECTS) 320 endif 321 322 # If there are any source files to be distributed, then include the build 323 # system too. 324 ifneq ($(call enabled,DIST-SRCS),) 325 DIST-SRCS-yes += configure 326 DIST-SRCS-yes += build/make/configure.sh 327 DIST-SRCS-yes += build/make/gen_asm_deps.sh 328 DIST-SRCS-yes += build/make/Makefile 329 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_def.sh 330 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_proj.sh 331 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_sln.sh 332 DIST-SRCS-$(CONFIG_MSVS) += build/x86-msvs/yasm.rules 333 DIST-SRCS-$(CONFIG_RVCT) += build/make/armlink_adapter.sh 334 # Include obj_int_extract if we use offsets from asm_*_offsets 335 DIST-SRCS-$(ARCH_ARM)$(ARCH_X86)$(ARCH_X86_64) += build/make/obj_int_extract.c 336 DIST-SRCS-$(ARCH_ARM) += build/make/ads2gas.pl 337 DIST-SRCS-yes += $(target:-$(TOOLCHAIN)=).mk 338 endif 339 INSTALL-SRCS := $(call cond_enabled,CONFIG_INSTALL_SRCS,INSTALL-SRCS) 340 ifeq ($(MAKECMDGOALS),dist) 341 INSTALL-SRCS += $(call cond_enabled,CONFIG_INSTALL_SRCS,DIST-SRCS) 342 endif 343 .install-srcs: $(addprefix $(DIST_DIR)/src/,$(INSTALL-SRCS)) 344 @touch $@ 345 346 clean:: 347 rm -f .install-srcs 348 349 ifeq ($(CONFIG_EXTERNAL_BUILD),yes) 350 BUILD_TARGETS += .projects 351 INSTALL_TARGETS += .install-projects 352 endif 353 BUILD_TARGETS += .docs .libs .bins 354 INSTALL_TARGETS += .install-docs .install-srcs .install-libs .install-bins 355 all-$(target): $(BUILD_TARGETS) 356 install:: $(INSTALL_TARGETS) 357 dist: $(INSTALL_TARGETS) 358