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