Home | History | Annotate | Download | only in make
      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 $(verbose),,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 $(BUILD_PFX)%.c.d: %.c
    107 	$(if $(quiet),@echo "    [DEP] $@")
    108 	$(qexec)mkdir -p $(dir $@)
    109 	$(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -M $< | $(fmt_deps) > $@
    110 
    111 $(BUILD_PFX)%.c.o: %.c
    112 	$(if $(quiet),@echo "    [CC] $@")
    113 	$(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -c -o $@ $<
    114 
    115 $(BUILD_PFX)%.cc.d: %.cc
    116 	$(if $(quiet),@echo "    [DEP] $@")
    117 	$(qexec)mkdir -p $(dir $@)
    118 	$(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -M $< | $(fmt_deps) > $@
    119 
    120 $(BUILD_PFX)%.cc.o: %.cc
    121 	$(if $(quiet),@echo "    [CXX] $@")
    122 	$(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $<
    123 
    124 $(BUILD_PFX)%.asm.d: %.asm
    125 	$(if $(quiet),@echo "    [DEP] $@")
    126 	$(qexec)mkdir -p $(dir $@)
    127 	$(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \
    128             --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@
    129 
    130 $(BUILD_PFX)%.asm.o: %.asm
    131 	$(if $(quiet),@echo "    [AS] $@")
    132 	$(qexec)$(AS) $(ASFLAGS) -o $@ $<
    133 
    134 $(BUILD_PFX)%.s.d: %.s
    135 	$(if $(quiet),@echo "    [DEP] $@")
    136 	$(qexec)mkdir -p $(dir $@)
    137 	$(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \
    138             --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@
    139 
    140 $(BUILD_PFX)%.s.o: %.s
    141 	$(if $(quiet),@echo "    [AS] $@")
    142 	$(qexec)$(AS) $(ASFLAGS) -o $@ $<
    143 
    144 .PRECIOUS: %.c.S
    145 %.c.S: CFLAGS += -DINLINE_ASM
    146 $(BUILD_PFX)%.c.S: %.c
    147 	$(if $(quiet),@echo "    [GEN] $@")
    148 	$(qexec)$(CC) -S $(CFLAGS) -o $@ $<
    149 
    150 .PRECIOUS: %.asm.s
    151 $(BUILD_PFX)%.asm.s: %.asm
    152 	$(if $(quiet),@echo "    [ASM CONVERSION] $@")
    153 	$(qexec)mkdir -p $(dir $@)
    154 	$(qexec)$(ASM_CONVERSION) <$< >$@
    155 
    156 # If we're in debug mode, pretend we don't have GNU strip, to fall back to
    157 # the copy implementation
    158 HAVE_GNU_STRIP := $(if $(CONFIG_DEBUG),,$(HAVE_GNU_STRIP))
    159 ifeq ($(HAVE_GNU_STRIP),yes)
    160 # Older binutils strip global sybols not needed for relocation processing
    161 # when given --strip-unneeded. Use nm and awk to identify globals and
    162 # keep them.
    163 %.a: %_g.a
    164 	$(if $(quiet),@echo "    [STRIP] $@ < $<")
    165 	$(qexec)$(STRIP) --strip-unneeded \
    166          `$(NM) $< | grep ' [A-TV-Z] ' | awk '{print "-K"$$3'}`\
    167           -o $@ $<
    168 else
    169 %.a: %_g.a
    170 	$(if $(quiet),@echo "    [CP] $@ < $<")
    171 	$(qexec)cp $< $@
    172 endif
    173 
    174 #
    175 # Rule to extract assembly constants from C sources
    176 #
    177 obj_int_extract: build/make/obj_int_extract.c
    178 	$(if $(quiet),@echo "    [HOSTCC] $@")
    179 	$(qexec)$(HOSTCC) -I. -I$(SRC_PATH_BARE) -o $@ $<
    180 CLEAN-OBJS += obj_int_extract
    181 
    182 #
    183 # Utility functions
    184 #
    185 pairmap=$(if $(strip $(2)),\
    186     $(call $(1),$(word 1,$(2)),$(word 2,$(2)))\
    187     $(call pairmap,$(1),$(wordlist 3,$(words $(2)),$(2)))\
    188 )
    189 
    190 enabled=$(filter-out $($(1)-no),$($(1)-yes))
    191 cond_enabled=$(if $(filter yes,$($(1))), $(call enabled,$(2)))
    192 
    193 find_file1=$(word 1,$(wildcard $(subst //,/,$(addsuffix /$(1),$(2)))))
    194 find_file=$(foreach f,$(1),$(call find_file1,$(strip $(f)),$(strip $(2))) )
    195 obj_pats=.c=.c.o $(AS_SFX)=$(AS_SFX).o .cc=.cc.o
    196 objs=$(addprefix $(BUILD_PFX),$(foreach p,$(obj_pats),$(filter %.o,$(1:$(p))) ))
    197 
    198 install_map_templates=$(eval $(call install_map_template,$(1),$(2)))
    199 
    200 not=$(subst yes,no,$(1))
    201 
    202 ifeq ($(CONFIG_MSVS),yes)
    203 lib_file_name=$(1).lib
    204 else
    205 lib_file_name=lib$(1).a
    206 endif
    207 #
    208 # Rule Templates
    209 #
    210 define linker_template
    211 $(1): $(filter-out -%,$(2))
    212 $(1):
    213 	$(if $(quiet),@echo    "    [LD] $$@")
    214 	$(qexec)$$(LD) $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs))
    215 endef
    216 define linkerxx_template
    217 $(1): $(filter-out -%,$(2))
    218 $(1):
    219 	$(if $(quiet),@echo    "    [LD] $$@")
    220 	$(qexec)$$(CXX) $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs))
    221 endef
    222 # make-3.80 has a bug with expanding large input strings to the eval function,
    223 # which was triggered in some cases by the following component of
    224 # linker_template:
    225 #   $(1): $$(call find_file, $(patsubst -l%,lib%.a,$(filter -l%,$(2))),\
    226 #                           $$(patsubst -L%,%,$$(filter -L%,$$(LDFLAGS) $(2))))
    227 # This may be useful to revisit in the future (it tries to locate libraries
    228 # in a search path and add them as prerequisites
    229 
    230 define install_map_template
    231 $(DIST_DIR)/$(1): $(2)
    232 	$(if $(quiet),@echo "    [INSTALL] $$@")
    233 	$(qexec)mkdir -p $$(dir $$@)
    234 	$(qexec)cp -p $$< $$@
    235 endef
    236 
    237 define archive_template
    238 # Not using a pattern rule here because we don't want to generate empty
    239 # archives when they are listed as a dependency in files not responsible
    240 # for creating them.
    241 $(1):
    242 	$(if $(quiet),@echo "    [AR] $$@")
    243 	$(qexec)$$(AR) $$(ARFLAGS) $$@ $$?
    244 endef
    245 
    246 define so_template
    247 # Not using a pattern rule here because we don't want to generate empty
    248 # archives when they are listed as a dependency in files not responsible
    249 # for creating them.
    250 #
    251 # This needs further abstraction for dealing with non-GNU linkers.
    252 $(1):
    253 	$(if $(quiet),@echo "    [LD] $$@")
    254 	$(qexec)$$(LD) -shared $$(LDFLAGS) \
    255             -Wl,--no-undefined -Wl,-soname,$$(SONAME) \
    256             -Wl,--version-script,$$(SO_VERSION_SCRIPT) -o $$@ \
    257             $$(filter %.o,$$?) $$(extralibs)
    258 endef
    259 
    260 define lipo_lib_template
    261 $(1): $(addsuffix /$(1),$(FAT_ARCHS))
    262 	$(if $(quiet),@echo "    [LIPO] $$@")
    263 	$(qexec)libtool -static -o $$@ $$?
    264 endef
    265 
    266 define lipo_bin_template
    267 $(1): $(addsuffix /$(1),$(FAT_ARCHS))
    268 	$(if $(quiet),@echo "    [LIPO] $$@")
    269 	$(qexec)lipo -output $$@ -create $$?
    270 endef
    271 
    272 
    273 #
    274 # Get current configuration
    275 #
    276 ifneq ($(target),)
    277 include $(SRC_PATH_BARE)/$(target:-$(TOOLCHAIN)=).mk
    278 endif
    279 ifeq ($(filter clean,$(MAKECMDGOALS)),)
    280   # Older versions of make don't like -include directives with no arguments
    281   ifneq ($(filter %.d,$(OBJS-yes:.o=.d)),)
    282     -include $(filter %.d,$(OBJS-yes:.o=.d))
    283   endif
    284 endif
    285 
    286 #
    287 # Configuration dependent rules
    288 #
    289 $(call pairmap,install_map_templates,$(INSTALL_MAPS))
    290 
    291 DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,DOCS)
    292 .docs: $(DOCS)
    293 	@touch $@
    294 
    295 INSTALL-DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,INSTALL-DOCS)
    296 ifeq ($(MAKECMDGOALS),dist)
    297 INSTALL-DOCS+=$(call cond_enabled,CONFIG_INSTALL_DOCS,DIST-DOCS)
    298 endif
    299 .install-docs: .docs $(addprefix $(DIST_DIR)/,$(INSTALL-DOCS))
    300 	@touch $@
    301 
    302 clean::
    303 	rm -f .docs .install-docs $(DOCS)
    304 
    305 BINS=$(call enabled,BINS)
    306 .bins: $(BINS)
    307 	@touch $@
    308 
    309 INSTALL-BINS=$(call cond_enabled,CONFIG_INSTALL_BINS,INSTALL-BINS)
    310 ifeq ($(MAKECMDGOALS),dist)
    311 INSTALL-BINS+=$(call cond_enabled,CONFIG_INSTALL_BINS,DIST-BINS)
    312 endif
    313 .install-bins: .bins $(addprefix $(DIST_DIR)/,$(INSTALL-BINS))
    314 	@touch $@
    315 
    316 clean::
    317 	rm -f .bins .install-bins $(BINS)
    318 
    319 LIBS=$(call enabled,LIBS)
    320 .libs: $(LIBS)
    321 	@touch $@
    322 $(foreach lib,$(filter %_g.a,$(LIBS)),$(eval $(call archive_template,$(lib))))
    323 $(foreach lib,$(filter %so.$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH),$(LIBS)),$(eval $(call so_template,$(lib))))
    324 
    325 INSTALL-LIBS=$(call cond_enabled,CONFIG_INSTALL_LIBS,INSTALL-LIBS)
    326 ifeq ($(MAKECMDGOALS),dist)
    327 INSTALL-LIBS+=$(call cond_enabled,CONFIG_INSTALL_LIBS,DIST-LIBS)
    328 endif
    329 .install-libs: .libs $(addprefix $(DIST_DIR)/,$(INSTALL-LIBS))
    330 	@touch $@
    331 
    332 clean::
    333 	rm -f .libs .install-libs $(LIBS)
    334 
    335 ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
    336 PROJECTS=$(call enabled,PROJECTS)
    337 .projects: $(PROJECTS)
    338 	@touch $@
    339 
    340 INSTALL-PROJECTS=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,INSTALL-PROJECTS)
    341 ifeq ($(MAKECMDGOALS),dist)
    342 INSTALL-PROJECTS+=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,DIST-PROJECTS)
    343 endif
    344 .install-projects: .projects $(addprefix $(DIST_DIR)/,$(INSTALL-PROJECTS))
    345 	@touch $@
    346 
    347 clean::
    348 	rm -f .projects .install-projects $(PROJECTS)
    349 endif
    350 
    351 # If there are any source files to be distributed, then include the build
    352 # system too.
    353 ifneq ($(call enabled,DIST-SRCS),)
    354     DIST-SRCS-yes            += configure
    355     DIST-SRCS-yes            += build/make/configure.sh
    356     DIST-SRCS-yes            += build/make/gen_asm_deps.sh
    357     DIST-SRCS-yes            += build/make/Makefile
    358     DIST-SRCS-$(CONFIG_MSVS)  += build/make/gen_msvs_def.sh
    359     DIST-SRCS-$(CONFIG_MSVS)  += build/make/gen_msvs_proj.sh
    360     DIST-SRCS-$(CONFIG_MSVS)  += build/make/gen_msvs_sln.sh
    361     DIST-SRCS-$(CONFIG_MSVS)  += build/x86-msvs/yasm.rules
    362     DIST-SRCS-$(CONFIG_MSVS)  += build/x86-msvs/obj_int_extract.bat
    363     DIST-SRCS-$(CONFIG_RVCT) += build/make/armlink_adapter.sh
    364     # Include obj_int_extract if we use offsets from asm_*_offsets
    365     DIST-SRCS-$(ARCH_ARM)$(ARCH_X86)$(ARCH_X86_64)    += build/make/obj_int_extract.c
    366     DIST-SRCS-$(ARCH_ARM)    += build/make/ads2gas.pl
    367     DIST-SRCS-yes            += $(target:-$(TOOLCHAIN)=).mk
    368 endif
    369 INSTALL-SRCS := $(call cond_enabled,CONFIG_INSTALL_SRCS,INSTALL-SRCS)
    370 ifeq ($(MAKECMDGOALS),dist)
    371 INSTALL-SRCS += $(call cond_enabled,CONFIG_INSTALL_SRCS,DIST-SRCS)
    372 endif
    373 .install-srcs: $(addprefix $(DIST_DIR)/src/,$(INSTALL-SRCS))
    374 	@touch $@
    375 
    376 clean::
    377 	rm -f .install-srcs
    378 
    379 ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
    380     BUILD_TARGETS += .projects
    381     INSTALL_TARGETS += .install-projects
    382 endif
    383 BUILD_TARGETS += .docs .libs .bins
    384 INSTALL_TARGETS += .install-docs .install-srcs .install-libs .install-bins
    385 all: $(BUILD_TARGETS)
    386 install:: $(INSTALL_TARGETS)
    387 dist: $(INSTALL_TARGETS)
    388 test::
    389