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