blob: ff40ddbec2ccbd5707bf151f67b90b940d27abb2 [file] [log] [blame]
John Koleszar0ea50ce2010-05-18 11:58:33 -04001##
John Koleszarc2140b82010-09-09 08:16:39 -04002## Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar94c52e42010-06-18 12:39:21 -04003##
4## Use of this source code is governed by a BSD-style license
John Koleszar09202d82010-06-04 16:19:40 -04005## 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
John Koleszar94c52e42010-06-18 12:39:21 -04007## in the file PATENTS. All contributing project authors may
8## be found in the AUTHORS file in the root of the source tree.
John Koleszar0ea50ce2010-05-18 11:58:33 -04009##
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
John Koleszaree8bcb12010-05-24 10:16:44 -040022install:: .DEFAULT
John Koleszar0ea50ce2010-05-18 11:58:33 -040023
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.
27md5sum := $(firstword $(wildcard \
28 $(foreach e,md5sum openssl,\
29 $(foreach p,$(subst :, ,$(PATH)),$(p)/$(e)*))\
30 ))
31md5sum := $(if $(filter %openssl,$(md5sum)),$(md5sum) dgst -md5,$(md5sum))
32
33TGT_CC:=$(word 3, $(subst -, ,$(TOOLCHAIN)))
John Koleszaree8bcb12010-05-24 10:16:44 -040034dist:
John Koleszar0ea50ce2010-05-18 11:58:33 -040035 @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"; \
John Koleszar23d68a52010-06-22 09:53:23 -040042 echo "Rerunning configure $(CONFIGURE_ARGS)"; \
43 ../src/configure $(CONFIGURE_ARGS); \
John Koleszar0ea50ce2010-05-18 11:58:33 -040044 $(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
John Koleszar0ea50ce2010-05-18 11:58:33 -040055endif
56
57ifneq ($(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.
63include $(target)$(if $(FAT_ARCHS),,-$(TOOLCHAIN)).mk
64endif
65BUILD_ROOT?=.
66VPATH=$(SRC_PATH_BARE)
67CFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT) -I$(SRC_PATH)
John Koleszar2ad48102010-10-25 10:28:45 -040068ASFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT)/ -I$(SRC_PATH)/
John Koleszar0ea50ce2010-05-18 11:58:33 -040069DIST_DIR?=dist
70HOSTCC?=gcc
71TGT_ISA:=$(word 1, $(subst -, ,$(TOOLCHAIN)))
72TGT_OS:=$(word 2, $(subst -, ,$(TOOLCHAIN)))
73TGT_CC:=$(word 3, $(subst -, ,$(TOOLCHAIN)))
74quiet:=$(if $(verbose),,yes)
75qexec=$(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)
86all-$(target):
87
88.PHONY: clean
89clean::
90 rm -f $(OBJS-yes) $(OBJS-yes:.o=.d) $(OBJS-yes:.asm.s.o=.asm.s)
91 rm -f $(CLEAN-OBJS)
92
John Koleszaree8bcb12010-05-24 10:16:44 -040093.PHONY: dist
94dist:
John Koleszar0ea50ce2010-05-18 11:58:33 -040095.PHONY: install
John Koleszaree8bcb12010-05-24 10:16:44 -040096install::
John Koleszar0ea50ce2010-05-18 11:58:33 -040097
98$(BUILD_PFX)%.c.d: %.c
99 $(if $(quiet),@echo " [DEP] $@")
100 $(qexec)mkdir -p $(dir $@)
Ronald S. Bultjebbf890f2011-05-02 13:56:41 -0400101 $(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -M $< | $(fmt_deps) > $@
John Koleszar0ea50ce2010-05-18 11:58:33 -0400102
103$(BUILD_PFX)%.c.o: %.c
104 $(if $(quiet),@echo " [CC] $@")
Ronald S. Bultjebbf890f2011-05-02 13:56:41 -0400105 $(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -c -o $@ $<
John Koleszar0ea50ce2010-05-18 11:58:33 -0400106
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
Johann79327be2011-06-08 14:43:34 -0400127.PRECIOUS: %.c.S
128%.c.S: CFLAGS += -DINLINE_ASM
129$(BUILD_PFX)%.c.S: %.c
130 $(if $(quiet),@echo " [GEN] $@")
131 $(qexec)$(CC) -S $(CFLAGS) -o $@ $<
132
John Koleszar0ea50ce2010-05-18 11:58:33 -0400133.PRECIOUS: %.asm.s
134$(BUILD_PFX)%.asm.s: %.asm
135 $(if $(quiet),@echo " [ASM CONVERSION] $@")
136 $(qexec)mkdir -p $(dir $@)
137 $(qexec)$(ASM_CONVERSION) <$< >$@
138
139# If we're in debug mode, pretend we don't have GNU strip, to fall back to
140# the copy implementation
141HAVE_GNU_STRIP := $(if $(CONFIG_DEBUG),,$(HAVE_GNU_STRIP))
142ifeq ($(HAVE_GNU_STRIP),yes)
143# Older binutils strip global sybols not needed for relocation processing
144# when given --strip-unneeded. Use nm and awk to identify globals and
145# keep them.
146%.a: %_g.a
147 $(if $(quiet),@echo " [STRIP] $@ < $<")
148 $(qexec)$(STRIP) --strip-unneeded \
149 `$(NM) $< | grep ' [A-TV-Z] ' | awk '{print "-K"$$3'}`\
150 -o $@ $<
151else
152%.a: %_g.a
153 $(if $(quiet),@echo " [CP] $@ < $<")
154 $(qexec)cp $< $@
155endif
156
157#
158# Rule to extract assembly constants from C sources
159#
160obj_int_extract: build/make/obj_int_extract.c
Attila Nagy346b3e72011-03-16 12:56:52 +0200161 $(if $(quiet),@echo " [HOSTCC] $@")
Johannfb037ec2011-03-08 17:41:45 -0500162 $(qexec)$(HOSTCC) -I. -I$(SRC_PATH_BARE) -o $@ $<
John Koleszar0ea50ce2010-05-18 11:58:33 -0400163CLEAN-OBJS += obj_int_extract
164
165#
166# Utility functions
167#
168pairmap=$(if $(strip $(2)),\
169 $(call $(1),$(word 1,$(2)),$(word 2,$(2)))\
170 $(call pairmap,$(1),$(wordlist 3,$(words $(2)),$(2)))\
171)
172
173enabled=$(filter-out $($(1)-no),$($(1)-yes))
174cond_enabled=$(if $(filter yes,$($(1))), $(call enabled,$(2)))
175
176find_file1=$(word 1,$(wildcard $(subst //,/,$(addsuffix /$(1),$(2)))))
177find_file=$(foreach f,$(1),$(call find_file1,$(strip $(f)),$(strip $(2))) )
178obj_pats=.c=.c.o $(AS_SFX)=$(AS_SFX).o
179objs=$(addprefix $(BUILD_PFX),$(foreach p,$(obj_pats),$(filter %.o,$(1:$(p))) ))
180
181install_map_templates=$(eval $(call install_map_template,$(1),$(2)))
182
183not=$(subst yes,no,$(1))
184
185ifeq ($(CONFIG_MSVS),yes)
186lib_file_name=$(1).lib
187else
188lib_file_name=lib$(1).a
189endif
190#
191# Rule Templates
192#
193define linker_template
194$(1): $(filter-out -%,$(2))
195$(1):
196 $(if $(quiet),@echo " [LD] $$@")
Ronald S. Bultjebbf890f2011-05-02 13:56:41 -0400197 $(qexec)$$(LD) $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs))
John Koleszar0ea50ce2010-05-18 11:58:33 -0400198endef
199# make-3.80 has a bug with expanding large input strings to the eval function,
200# which was triggered in some cases by the following component of
201# linker_template:
202# $(1): $$(call find_file, $(patsubst -l%,lib%.a,$(filter -l%,$(2))),\
203# $$(patsubst -L%,%,$$(filter -L%,$$(LDFLAGS) $(2))))
204# This may be useful to revisit in the future (it tries to locate libraries
205# in a search path and add them as prerequisites
206
207define install_map_template
208$(DIST_DIR)/$(1): $(2)
209 $(if $(quiet),@echo " [INSTALL] $$@")
210 $(qexec)mkdir -p $$(dir $$@)
211 $(qexec)cp -p $$< $$@
212endef
213
214define archive_template
215# Not using a pattern rule here because we don't want to generate empty
216# archives when they are listed as a dependency in files not responsible
217# for creating them.
218$(1):
219 $(if $(quiet),@echo " [AR] $$@")
220 $(qexec)$$(AR) $$(ARFLAGS) $$@ $$?
221endef
222
John Koleszar7aa97a32010-06-03 10:29:04 -0400223define so_template
224# Not using a pattern rule here because we don't want to generate empty
225# archives when they are listed as a dependency in files not responsible
226# for creating them.
227#
228# This needs further abstraction for dealing with non-GNU linkers.
229$(1):
230 $(if $(quiet),@echo " [LD] $$@")
231 $(qexec)$$(LD) -shared $$(LDFLAGS) \
Johannabb7c212011-06-08 11:36:04 -0700232 -Wl,--no-undefined -Wl,-soname,$$(SONAME) \
233 -Wl,--version-script,$$(SO_VERSION_SCRIPT) -o $$@ \
Luca Barbato8916fa22010-06-06 18:51:49 +0200234 $$(filter %.o,$$?) $$(extralibs)
John Koleszar7aa97a32010-06-03 10:29:04 -0400235endef
236
John Koleszar0ea50ce2010-05-18 11:58:33 -0400237define lipo_lib_template
238$(1): $(addsuffix /$(1),$(FAT_ARCHS))
239 $(if $(quiet),@echo " [LIPO] $$@")
240 $(qexec)libtool -static -o $$@ $$?
241endef
242
243define lipo_bin_template
244$(1): $(addsuffix /$(1),$(FAT_ARCHS))
245 $(if $(quiet),@echo " [LIPO] $$@")
246 $(qexec)lipo -output $$@ -create $$?
247endef
248
249
250#
251# Get current configuration
252#
253ifneq ($(target),)
254include $(SRC_PATH_BARE)/$(target:-$(TOOLCHAIN)=).mk
255endif
256ifeq ($(filter clean,$(MAKECMDGOALS)),)
257 # Older versions of make don't like -include directives with no arguments
258 ifneq ($(filter %.d,$(OBJS-yes:.o=.d)),)
259 -include $(filter %.d,$(OBJS-yes:.o=.d))
260 endif
261endif
262
263#
Gaute Strokkenes6795e252011-03-15 12:20:54 +0000264# Configuration dependent rules
John Koleszar0ea50ce2010-05-18 11:58:33 -0400265#
266$(call pairmap,install_map_templates,$(INSTALL_MAPS))
267
268DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,DOCS)
269.docs: $(DOCS)
270 @touch $@
271
272INSTALL-DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,INSTALL-DOCS)
John Koleszaree8bcb12010-05-24 10:16:44 -0400273ifeq ($(MAKECMDGOALS),dist)
274INSTALL-DOCS+=$(call cond_enabled,CONFIG_INSTALL_DOCS,DIST-DOCS)
275endif
John Koleszar0ea50ce2010-05-18 11:58:33 -0400276.install-docs: .docs $(addprefix $(DIST_DIR)/,$(INSTALL-DOCS))
277 @touch $@
278
279clean::
280 rm -f .docs .install-docs $(DOCS)
281
282BINS=$(call enabled,BINS)
283.bins: $(BINS)
284 @touch $@
285
286INSTALL-BINS=$(call cond_enabled,CONFIG_INSTALL_BINS,INSTALL-BINS)
John Koleszaree8bcb12010-05-24 10:16:44 -0400287ifeq ($(MAKECMDGOALS),dist)
288INSTALL-BINS+=$(call cond_enabled,CONFIG_INSTALL_BINS,DIST-BINS)
289endif
John Koleszar0ea50ce2010-05-18 11:58:33 -0400290.install-bins: .bins $(addprefix $(DIST_DIR)/,$(INSTALL-BINS))
291 @touch $@
292
293clean::
294 rm -f .bins .install-bins $(BINS)
295
296LIBS=$(call enabled,LIBS)
297.libs: $(LIBS)
298 @touch $@
299$(foreach lib,$(filter %_g.a,$(LIBS)),$(eval $(call archive_template,$(lib))))
Johannabb7c212011-06-08 11:36:04 -0700300$(foreach lib,$(filter %so.$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH),$(LIBS)),$(eval $(call so_template,$(lib))))
John Koleszar0ea50ce2010-05-18 11:58:33 -0400301
302INSTALL-LIBS=$(call cond_enabled,CONFIG_INSTALL_LIBS,INSTALL-LIBS)
John Koleszaree8bcb12010-05-24 10:16:44 -0400303ifeq ($(MAKECMDGOALS),dist)
304INSTALL-LIBS+=$(call cond_enabled,CONFIG_INSTALL_LIBS,DIST-LIBS)
305endif
John Koleszar0ea50ce2010-05-18 11:58:33 -0400306.install-libs: .libs $(addprefix $(DIST_DIR)/,$(INSTALL-LIBS))
307 @touch $@
308
309clean::
310 rm -f .libs .install-libs $(LIBS)
311
312ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
313PROJECTS=$(call enabled,PROJECTS)
314.projects: $(PROJECTS)
315 @touch $@
316
317INSTALL-PROJECTS=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,INSTALL-PROJECTS)
John Koleszaree8bcb12010-05-24 10:16:44 -0400318ifeq ($(MAKECMDGOALS),dist)
319INSTALL-PROJECTS+=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,DIST-PROJECTS)
320endif
John Koleszar0ea50ce2010-05-18 11:58:33 -0400321.install-projects: .projects $(addprefix $(DIST_DIR)/,$(INSTALL-PROJECTS))
322 @touch $@
323
324clean::
325 rm -f .projects .install-projects $(PROJECTS)
326endif
327
John Koleszaree8bcb12010-05-24 10:16:44 -0400328# If there are any source files to be distributed, then include the build
John Koleszar0ea50ce2010-05-18 11:58:33 -0400329# system too.
John Koleszaree8bcb12010-05-24 10:16:44 -0400330ifneq ($(call enabled,DIST-SRCS),)
331 DIST-SRCS-yes += configure
332 DIST-SRCS-yes += build/make/configure.sh
333 DIST-SRCS-yes += build/make/gen_asm_deps.sh
334 DIST-SRCS-yes += build/make/Makefile
335 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_def.sh
336 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_proj.sh
337 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_sln.sh
John Koleszar4d86ef32010-06-22 08:44:48 -0400338 DIST-SRCS-$(CONFIG_MSVS) += build/x86-msvs/yasm.rules
James Berry61046b82011-08-01 16:10:41 -0400339 DIST-SRCS-$(CONFIG_MSVS) += build/x86-msvs/obj_int_extract.bat
John Koleszaree8bcb12010-05-24 10:16:44 -0400340 DIST-SRCS-$(CONFIG_RVCT) += build/make/armlink_adapter.sh
Johann8edaf6e2011-02-10 14:57:43 -0500341 # Include obj_int_extract if we use offsets from asm_*_offsets
342 DIST-SRCS-$(ARCH_ARM)$(ARCH_X86)$(ARCH_X86_64) += build/make/obj_int_extract.c
John Koleszaree8bcb12010-05-24 10:16:44 -0400343 DIST-SRCS-$(ARCH_ARM) += build/make/ads2gas.pl
344 DIST-SRCS-yes += $(target:-$(TOOLCHAIN)=).mk
John Koleszar0ea50ce2010-05-18 11:58:33 -0400345endif
346INSTALL-SRCS := $(call cond_enabled,CONFIG_INSTALL_SRCS,INSTALL-SRCS)
John Koleszaree8bcb12010-05-24 10:16:44 -0400347ifeq ($(MAKECMDGOALS),dist)
348INSTALL-SRCS += $(call cond_enabled,CONFIG_INSTALL_SRCS,DIST-SRCS)
349endif
John Koleszar0ea50ce2010-05-18 11:58:33 -0400350.install-srcs: $(addprefix $(DIST_DIR)/src/,$(INSTALL-SRCS))
351 @touch $@
352
353clean::
354 rm -f .install-srcs
355
356ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
357 BUILD_TARGETS += .projects
358 INSTALL_TARGETS += .install-projects
359endif
360BUILD_TARGETS += .docs .libs .bins
361INSTALL_TARGETS += .install-docs .install-srcs .install-libs .install-bins
362all-$(target): $(BUILD_TARGETS)
John Koleszaree8bcb12010-05-24 10:16:44 -0400363install:: $(INSTALL_TARGETS)
364dist: $(INSTALL_TARGETS)