• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
12include config.mk
13quiet?=true
14ifeq ($(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
20all: .DEFAULT
21clean:: .DEFAULT
22exampletest: .DEFAULT
23install:: .DEFAULT
24test: .DEFAULT
25test-no-data-check: .DEFAULT
26testdata: .DEFAULT
27utiltest: .DEFAULT
28exampletest-no-data-check utiltest-no-data-check: .DEFAULT
29test_%: .DEFAULT ;
30
31# Note: md5sum is not installed on OS X, but openssl is. Openssl may not be
32# installed on cygwin, so we need to autodetect here.
33md5sum := $(firstword $(wildcard \
34          $(foreach e,md5sum openssl,\
35          $(foreach p,$(subst :, ,$(PATH)),$(p)/$(e)*))\
36          ))
37md5sum := $(if $(filter %openssl,$(md5sum)),$(md5sum) dgst -md5,$(md5sum))
38
39TGT_CC:=$(word 3, $(subst -, ,$(TOOLCHAIN)))
40dist:
41	@for t in $(ALL_TARGETS); do \
42	     $(MAKE) --no-print-directory target=$$t $(MAKECMDGOALS) || exit $$?;\
43        done
44        # Run configure for the user with the current toolchain.
45	@if [ -d "$(DIST_DIR)/src" ]; then \
46            mkdir -p "$(DIST_DIR)/build"; \
47            cd "$(DIST_DIR)/build"; \
48            echo "Rerunning configure $(CONFIGURE_ARGS)"; \
49            ../src/configure $(CONFIGURE_ARGS); \
50            $(if $(filter vs%,$(TGT_CC)),make NO_LAUNCH_DEVENV=1;) \
51        fi
52	@if [ -d "$(DIST_DIR)" ]; then \
53            echo "    [MD5SUM] $(DIST_DIR)"; \
54	    cd $(DIST_DIR) && \
55	    $(md5sum) `find . -name md5sums.txt -prune -o -type f -print` \
56                | sed -e 's/MD5(\(.*\))= \([0-9a-f]\{32\}\)/\2  \1/' \
57                > md5sums.txt;\
58        fi
59endif
60
61# Since we invoke make recursively for multiple targets we need to include the
62# .mk file for the correct target, but only when $(target) is non-empty.
63ifneq ($(target),)
64include $(target)-$(TOOLCHAIN).mk
65endif
66BUILD_ROOT?=.
67VPATH=$(SRC_PATH_BARE)
68CFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT) -I$(SRC_PATH)
69CXXFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT) -I$(SRC_PATH)
70ASFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT)/ -I$(SRC_PATH)/
71DIST_DIR?=dist
72HOSTCC?=gcc
73TGT_ISA:=$(word 1, $(subst -, ,$(TOOLCHAIN)))
74TGT_OS:=$(word 2, $(subst -, ,$(TOOLCHAIN)))
75TGT_CC:=$(word 3, $(subst -, ,$(TOOLCHAIN)))
76quiet:=$(if $(or $(verbose), $(V)),, yes)
77qexec=$(if $(quiet),@)
78
79# Cancel built-in implicit rules
80%: %.o
81%.asm:
82%.a:
83%: %.cc
84
85#
86# Common rules"
87#
88.PHONY: all
89all:
90
91.PHONY: clean
92clean::
93	rm -f $(OBJS-yes) $(OBJS-yes:.o=.d) $(OBJS-yes:.asm.S.o=.asm.S)
94	rm -f $(CLEAN-OBJS)
95
96.PHONY: clean
97distclean: clean
98	if [ -z "$(target)" ]; then \
99      rm -f Makefile; \
100      rm -f config.log config.mk; \
101      rm -f vpx_config.[hc] vpx_config.asm; \
102      rm -f arm_neon.h; \
103    else \
104      rm -f $(target)-$(TOOLCHAIN).mk; \
105    fi
106
107.PHONY: dist
108dist:
109.PHONY: exampletest
110exampletest:
111.PHONY: install
112install::
113.PHONY: test
114test:
115.PHONY: testdata
116testdata:
117.PHONY: utiltest
118utiltest:
119.PHONY: test-no-data-check exampletest-no-data-check utiltest-no-data-check
120test-no-data-check:
121exampletest-no-data-check utiltest-no-data-check:
122
123# Force to realign stack always on OS/2
124ifeq ($(TOOLCHAIN), x86-os2-gcc)
125CFLAGS += -mstackrealign
126endif
127
128# x86[_64]
129$(BUILD_PFX)%_mmx.c.d: CFLAGS += -mmmx
130$(BUILD_PFX)%_mmx.c.o: CFLAGS += -mmmx
131$(BUILD_PFX)%_sse2.c.d: CFLAGS += -msse2
132$(BUILD_PFX)%_sse2.c.o: CFLAGS += -msse2
133$(BUILD_PFX)%_sse3.c.d: CFLAGS += -msse3
134$(BUILD_PFX)%_sse3.c.o: CFLAGS += -msse3
135$(BUILD_PFX)%_ssse3.c.d: CFLAGS += -mssse3
136$(BUILD_PFX)%_ssse3.c.o: CFLAGS += -mssse3
137$(BUILD_PFX)%_sse4.c.d: CFLAGS += -msse4.1
138$(BUILD_PFX)%_sse4.c.o: CFLAGS += -msse4.1
139$(BUILD_PFX)%_avx.c.d: CFLAGS += -mavx
140$(BUILD_PFX)%_avx.c.o: CFLAGS += -mavx
141$(BUILD_PFX)%_avx2.c.d: CFLAGS += -mavx2
142$(BUILD_PFX)%_avx2.c.o: CFLAGS += -mavx2
143$(BUILD_PFX)%_avx512.c.d: CFLAGS += -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl
144$(BUILD_PFX)%_avx512.c.o: CFLAGS += -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl
145
146# AARCH64
147$(BUILD_PFX)%_neon_dotprod.c.d: CFLAGS += -march=armv8.2-a+dotprod
148$(BUILD_PFX)%_neon_dotprod.c.o: CFLAGS += -march=armv8.2-a+dotprod
149$(BUILD_PFX)%_neon_i8mm.c.d: CFLAGS += -march=armv8.2-a+dotprod+i8mm
150$(BUILD_PFX)%_neon_i8mm.c.o: CFLAGS += -march=armv8.2-a+dotprod+i8mm
151$(BUILD_PFX)%_sve.c.d: CFLAGS += -march=armv8.2-a+dotprod+i8mm+sve
152$(BUILD_PFX)%_sve.c.o: CFLAGS += -march=armv8.2-a+dotprod+i8mm+sve
153
154# POWER
155$(BUILD_PFX)%_vsx.c.d: CFLAGS += -maltivec -mvsx
156$(BUILD_PFX)%_vsx.c.o: CFLAGS += -maltivec -mvsx
157
158# MIPS
159$(BUILD_PFX)%_msa.c.d: CFLAGS += -mmsa
160$(BUILD_PFX)%_msa.c.o: CFLAGS += -mmsa
161
162# LOONGARCH
163$(BUILD_PFX)%_lsx.c.d:  CFLAGS += -mlsx
164$(BUILD_PFX)%_lsx.c.o:  CFLAGS += -mlsx
165$(BUILD_PFX)%_lasx.c.d: CFLAGS += -mlasx
166$(BUILD_PFX)%_lasx.c.o: CFLAGS += -mlasx
167
168$(BUILD_PFX)%.c.d: %.c
169	$(if $(quiet),@echo "    [DEP] $@")
170	$(qexec)mkdir -p $(dir $@)
171	$(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -M $< | $(fmt_deps) > $@
172
173$(BUILD_PFX)%.c.o: %.c
174	$(if $(quiet),@echo "    [CC] $@")
175	$(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
176	$(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -c -o $@ $<
177
178$(BUILD_PFX)%.cc.d: %.cc
179	$(if $(quiet),@echo "    [DEP] $@")
180	$(qexec)mkdir -p $(dir $@)
181	$(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -M $< | $(fmt_deps) > $@
182
183$(BUILD_PFX)%.cc.o: %.cc
184	$(if $(quiet),@echo "    [CXX] $@")
185	$(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
186	$(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $<
187
188$(BUILD_PFX)%.cpp.d: %.cpp
189	$(if $(quiet),@echo "    [DEP] $@")
190	$(qexec)mkdir -p $(dir $@)
191	$(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -M $< | $(fmt_deps) > $@
192
193$(BUILD_PFX)%.cpp.o: %.cpp
194	$(if $(quiet),@echo "    [CXX] $@")
195	$(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
196	$(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $<
197
198$(BUILD_PFX)%.asm.d: %.asm
199	$(if $(quiet),@echo "    [DEP] $@")
200	$(qexec)mkdir -p $(dir $@)
201	$(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \
202            --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@
203
204$(BUILD_PFX)%.asm.o: %.asm
205	$(if $(quiet),@echo "    [AS] $@")
206	$(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
207	$(qexec)$(AS) $(ASFLAGS) -o $@ $<
208
209$(BUILD_PFX)%.S.d: %.S
210	$(if $(quiet),@echo "    [DEP] $@")
211	$(qexec)mkdir -p $(dir $@)
212	$(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \
213            --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@
214
215$(BUILD_PFX)%.S.o: %.S
216	$(if $(quiet),@echo "    [AS] $@")
217	$(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
218	$(qexec)$(AS) $(ASFLAGS) -o $@ $<
219
220.PRECIOUS: %.c.S
221%.c.S: CFLAGS += -DINLINE_ASM
222$(BUILD_PFX)%.c.S: %.c
223	$(if $(quiet),@echo "    [GEN] $@")
224	$(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
225	$(qexec)$(CC) -S $(CFLAGS) -o $@ $<
226
227.PRECIOUS: %.asm.S
228$(BUILD_PFX)%.asm.S: %.asm
229	$(if $(quiet),@echo "    [ASM CONVERSION] $@")
230	$(qexec)mkdir -p $(dir $@)
231	$(qexec)$(ASM_CONVERSION) <$< >$@
232
233# If we're in debug mode, pretend we don't have GNU strip, to fall back to
234# the copy implementation
235HAVE_GNU_STRIP := $(if $(CONFIG_DEBUG),,$(HAVE_GNU_STRIP))
236ifeq ($(HAVE_GNU_STRIP),yes)
237# Older binutils strip global symbols not needed for relocation processing
238# when given --strip-unneeded. Using nm and awk to identify globals and
239# keep them caused command line length issues under mingw and segfaults in
240# test_libvpx were observed under OS/2: simply use --strip-debug.
241%.a: %_g.a
242	$(if $(quiet),@echo "    [STRIP] $@ < $<")
243	$(qexec)$(STRIP) --strip-debug \
244          -o $@ $<
245else
246%.a: %_g.a
247	$(if $(quiet),@echo "    [CP] $@ < $<")
248	$(qexec)cp $< $@
249endif
250
251#
252# Utility functions
253#
254pairmap=$(if $(strip $(2)),\
255    $(call $(1),$(word 1,$(2)),$(word 2,$(2)))\
256    $(call pairmap,$(1),$(wordlist 3,$(words $(2)),$(2)))\
257)
258
259enabled=$(filter-out $($(1)-no),$($(1)-yes))
260cond_enabled=$(if $(filter yes,$($(1))), $(call enabled,$(2)))
261
262find_file1=$(word 1,$(wildcard $(subst //,/,$(addsuffix /$(1),$(2)))))
263find_file=$(foreach f,$(1),$(call find_file1,$(strip $(f)),$(strip $(2))) )
264obj_pats=.c=.c.o $(AS_SFX)=$(AS_SFX).o .cc=.cc.o .cpp=.cpp.o
265objs=$(addprefix $(BUILD_PFX),$(foreach p,$(obj_pats),$(filter %.o,$(1:$(p))) ))
266
267install_map_templates=$(eval $(call install_map_template,$(1),$(2)))
268
269not=$(subst yes,no,$(1))
270
271ifeq ($(CONFIG_MSVS),yes)
272lib_file_name=$(1).lib
273else
274lib_file_name=lib$(1).a
275endif
276#
277# Rule Templates
278#
279define linker_template
280$(1): $(filter-out -%,$(2))
281$(1):
282	$(if $(quiet),@echo    "    [LD] $$@")
283	$(qexec)$$(LD) $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs))
284endef
285define linkerxx_template
286$(1): $(filter-out -%,$(2))
287$(1):
288	$(if $(quiet),@echo    "    [LD] $$@")
289	$(qexec)$$(CXX) $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs))
290endef
291# make-3.80 has a bug with expanding large input strings to the eval function,
292# which was triggered in some cases by the following component of
293# linker_template:
294#   $(1): $$(call find_file, $(patsubst -l%,lib%.a,$(filter -l%,$(2))),\
295#                           $$(patsubst -L%,%,$$(filter -L%,$$(LDFLAGS) $(2))))
296# This may be useful to revisit in the future (it tries to locate libraries
297# in a search path and add them as prerequisites
298
299define install_map_template
300$(DIST_DIR)/$(1): $(2)
301	$(if $(quiet),@echo "    [INSTALL] $$@")
302	$(qexec)mkdir -p $$(dir $$@)
303	$(qexec)cp -p $$< $$@
304endef
305
306define archive_template
307# Not using a pattern rule here because we don't want to generate empty
308# archives when they are listed as a dependency in files not responsible
309# for creating them.
310$(1):
311	$(if $(quiet),@echo "    [AR] $$@")
312	$(qexec)$$(AR) $$(ARFLAGS) $$@ $$^
313endef
314
315# Don't use -Wl,-z,defs with Clang's sanitizers.
316#
317# Clang's AddressSanitizer documentation says "When linking shared libraries,
318# the AddressSanitizer run-time is not linked, so -Wl,-z,defs may cause link
319# errors (don't use it with AddressSanitizer)." See
320# https://clang.llvm.org/docs/AddressSanitizer.html#usage.
321NO_UNDEFINED := -Wl,-z,defs
322ifeq ($(findstring clang,$(CC)),clang)
323    ifneq ($(filter -fsanitize=%,$(LDFLAGS)),)
324        NO_UNDEFINED :=
325    endif
326endif
327
328define so_template
329# Not using a pattern rule here because we don't want to generate empty
330# archives when they are listed as a dependency in files not responsible
331# for creating them.
332#
333# This needs further abstraction for dealing with non-GNU linkers.
334$(1):
335	$(if $(quiet),@echo "    [LD] $$@")
336	$(qexec)$$(LD) -shared $$(LDFLAGS) \
337            $(NO_UNDEFINED) \
338            -Wl,-soname,$$(SONAME) \
339            -Wl,--version-script,$$(EXPORTS_FILE) -o $$@ \
340            $$(filter %.o,$$^) $$(extralibs)
341endef
342
343define dl_template
344# Not using a pattern rule here because we don't want to generate empty
345# archives when they are listed as a dependency in files not responsible
346# for creating them.
347$(1):
348	$(if $(quiet),@echo "    [LD] $$@")
349	$(qexec)$$(LD) -dynamiclib $$(LDFLAGS) \
350	    -exported_symbols_list $$(EXPORTS_FILE) \
351        -Wl,-headerpad_max_install_names,-compatibility_version,1.0,-current_version,$$(VERSION_MAJOR) \
352        -o $$@ \
353        $$(filter %.o,$$^) $$(extralibs)
354endef
355
356define dll_template
357# Not using a pattern rule here because we don't want to generate empty
358# archives when they are listed as a dependency in files not responsible
359# for creating them.
360$(1):
361	$(if $(quiet),@echo "    [LD] $$@")
362	$(qexec)$$(LD) -Zdll $$(LDFLAGS) \
363        -o $$@ \
364        $$(filter %.o,$$^) $$(extralibs) $$(EXPORTS_FILE)
365endef
366
367
368#
369# Get current configuration
370#
371ifneq ($(target),)
372include $(SRC_PATH_BARE)/$(target:-$(TOOLCHAIN)=).mk
373endif
374
375skip_deps := $(filter %clean,$(MAKECMDGOALS))
376skip_deps += $(findstring testdata,$(MAKECMDGOALS))
377ifeq ($(strip $(skip_deps)),)
378  ifeq ($(CONFIG_DEPENDENCY_TRACKING),yes)
379    # Older versions of make don't like -include directives with no arguments
380    ifneq ($(filter %.d,$(OBJS-yes:.o=.d)),)
381      -include $(filter %.d,$(OBJS-yes:.o=.d))
382    endif
383  endif
384endif
385
386#
387# Configuration dependent rules
388#
389$(call pairmap,install_map_templates,$(INSTALL_MAPS))
390
391DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,DOCS)
392.docs: $(DOCS)
393	@touch $@
394
395INSTALL-DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,INSTALL-DOCS)
396ifeq ($(MAKECMDGOALS),dist)
397INSTALL-DOCS+=$(call cond_enabled,CONFIG_INSTALL_DOCS,DIST-DOCS)
398endif
399.install-docs: .docs $(addprefix $(DIST_DIR)/,$(INSTALL-DOCS))
400	@touch $@
401
402clean::
403	rm -f .docs .install-docs $(DOCS)
404
405BINS=$(call enabled,BINS)
406.bins: $(BINS)
407	@touch $@
408
409INSTALL-BINS=$(call cond_enabled,CONFIG_INSTALL_BINS,INSTALL-BINS)
410ifeq ($(MAKECMDGOALS),dist)
411INSTALL-BINS+=$(call cond_enabled,CONFIG_INSTALL_BINS,DIST-BINS)
412endif
413.install-bins: .bins $(addprefix $(DIST_DIR)/,$(INSTALL-BINS))
414	@touch $@
415
416clean::
417	rm -f .bins .install-bins $(BINS)
418
419LIBS=$(call enabled,LIBS)
420.libs: $(LIBS)
421	@touch $@
422$(foreach lib,$(filter %_g.a,$(LIBS)),$(eval $(call archive_template,$(lib))))
423$(foreach lib,$(filter %so.$(SO_VERSION_MAJOR).$(SO_VERSION_MINOR).$(SO_VERSION_PATCH),$(LIBS)),$(eval $(call so_template,$(lib))))
424$(foreach lib,$(filter %$(SO_VERSION_MAJOR).dylib,$(LIBS)),$(eval $(call dl_template,$(lib))))
425$(foreach lib,$(filter %$(SO_VERSION_MAJOR).dll,$(LIBS)),$(eval $(call dll_template,$(lib))))
426
427INSTALL-LIBS=$(call cond_enabled,CONFIG_INSTALL_LIBS,INSTALL-LIBS)
428ifeq ($(MAKECMDGOALS),dist)
429INSTALL-LIBS+=$(call cond_enabled,CONFIG_INSTALL_LIBS,DIST-LIBS)
430endif
431.install-libs: .libs $(addprefix $(DIST_DIR)/,$(INSTALL-LIBS))
432	@touch $@
433
434clean::
435	rm -f .libs .install-libs $(LIBS)
436
437ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
438PROJECTS=$(call enabled,PROJECTS)
439.projects: $(PROJECTS)
440	@touch $@
441
442INSTALL-PROJECTS=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,INSTALL-PROJECTS)
443ifeq ($(MAKECMDGOALS),dist)
444INSTALL-PROJECTS+=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,DIST-PROJECTS)
445endif
446.install-projects: .projects $(addprefix $(DIST_DIR)/,$(INSTALL-PROJECTS))
447	@touch $@
448
449clean::
450	rm -f .projects .install-projects $(PROJECTS)
451endif
452
453# If there are any source files to be distributed, then include the build
454# system too.
455ifneq ($(call enabled,DIST-SRCS),)
456    DIST-SRCS-yes            += configure
457    DIST-SRCS-yes            += build/make/configure.sh
458    DIST-SRCS-yes            += build/make/gen_asm_deps.sh
459    DIST-SRCS-yes            += build/make/Makefile
460    DIST-SRCS-$(CONFIG_MSVS)  += build/make/gen_msvs_def.sh
461    DIST-SRCS-$(CONFIG_MSVS)  += build/make/gen_msvs_sln.sh
462    DIST-SRCS-$(CONFIG_MSVS)  += build/make/gen_msvs_vcxproj.sh
463    DIST-SRCS-$(CONFIG_MSVS)  += build/make/msvs_common.sh
464    DIST-SRCS-$(CONFIG_RVCT) += build/make/armlink_adapter.sh
465    DIST-SRCS-$(VPX_ARCH_ARM) += build/make/ads2gas.pl
466    DIST-SRCS-$(VPX_ARCH_ARM) += build/make/ads2gas_apple.pl
467    DIST-SRCS-$(VPX_ARCH_ARM) += build/make/ads2armasm_ms.pl
468    DIST-SRCS-$(VPX_ARCH_ARM) += build/make/thumb.pm
469    DIST-SRCS-yes            += $(target:-$(TOOLCHAIN)=).mk
470endif
471INSTALL-SRCS := $(call cond_enabled,CONFIG_INSTALL_SRCS,INSTALL-SRCS)
472ifeq ($(MAKECMDGOALS),dist)
473INSTALL-SRCS += $(call cond_enabled,CONFIG_INSTALL_SRCS,DIST-SRCS)
474endif
475.install-srcs: $(addprefix $(DIST_DIR)/src/,$(INSTALL-SRCS))
476	@touch $@
477
478clean::
479	rm -f .install-srcs
480
481ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
482    BUILD_TARGETS += .projects
483    INSTALL_TARGETS += .install-projects
484endif
485BUILD_TARGETS += .docs .libs .bins
486INSTALL_TARGETS += .install-docs .install-srcs .install-libs .install-bins
487all: $(BUILD_TARGETS)
488install:: $(INSTALL_TARGETS)
489dist: $(INSTALL_TARGETS)
490test:
491
492.SUFFIXES:  # Delete default suffix rules
493