Makefile 13 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
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
6
##  that can be found in the LICENSE file in the root of the source
##  tree. An additional intellectual property rights grant can be found
7
8
##  in the file PATENTS.  All contributing project authors may
##  be found in the AUTHORS file in the root of the source tree.
John Koleszar's avatar
John Koleszar committed
9
10
11
12
13
14
15
16
17
18
19
20
21
##


include config.mk
quiet?=true
ifeq ($(target),)
# If a target wasn't specified, invoke for all enabled targets.
.DEFAULT:
	@for t in $(ALL_TARGETS); do \
	     $(MAKE) --no-print-directory target=$$t $(MAKECMDGOALS) || exit $$?;\
        done
all: .DEFAULT
clean:: .DEFAULT
22
install:: .DEFAULT
23
test:: .DEFAULT
John Koleszar's avatar
John Koleszar committed
24
testdata:: .DEFAULT
John Koleszar's avatar
John Koleszar committed
25
26
27
28
29
30
31
32
33
34
35


# Note: md5sum is not installed on OS X, but openssl is. Openssl may not be
# installed on cygwin, so we need to autodetect here.
md5sum := $(firstword $(wildcard \
          $(foreach e,md5sum openssl,\
          $(foreach p,$(subst :, ,$(PATH)),$(p)/$(e)*))\
          ))
md5sum := $(if $(filter %openssl,$(md5sum)),$(md5sum) dgst -md5,$(md5sum))

TGT_CC:=$(word 3, $(subst -, ,$(TOOLCHAIN)))
36
dist:
John Koleszar's avatar
John Koleszar committed
37
38
39
40
41
42
43
	@for t in $(ALL_TARGETS); do \
	     $(MAKE) --no-print-directory target=$$t $(MAKECMDGOALS) || exit $$?;\
        done
        # Run configure for the user with the current toolchain.
	@if [ -d "$(DIST_DIR)/src" ]; then \
            mkdir -p "$(DIST_DIR)/build"; \
            cd "$(DIST_DIR)/build"; \
44
45
            echo "Rerunning configure $(CONFIGURE_ARGS)"; \
            ../src/configure $(CONFIGURE_ARGS); \
John Koleszar's avatar
John Koleszar committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
            $(if $(filter vs%,$(TGT_CC)),make NO_LAUNCH_DEVENV=1;) \
        fi
	@if [ -d "$(DIST_DIR)" ]; then \
            echo "    [MD5SUM] $(DIST_DIR)"; \
	    cd $(DIST_DIR) && \
	    $(md5sum) `find . -name md5sums.txt -prune -o -type f -print` \
                | sed -e 's/MD5(\(.*\))= \([0-9a-f]\{32\}\)/\2  \1/' \
                > md5sums.txt;\
        fi


endif

ifneq ($(target),)
# Normally, we want to build the filename from the target and the toolchain.
# This disambiguates from the $(target).mk file that exists in the source tree.
# However, the toolchain is part of the target in universal builds, so we
# don't want to include TOOLCHAIN in that case. FAT_ARCHS is used to test
# if we're in the universal case.
include $(target)$(if $(FAT_ARCHS),,-$(TOOLCHAIN)).mk
endif
BUILD_ROOT?=.
VPATH=$(SRC_PATH_BARE)
CFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT) -I$(SRC_PATH)
John Koleszar's avatar
John Koleszar committed
70
CXXFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT) -I$(SRC_PATH)
71
ASFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT)/ -I$(SRC_PATH)/
John Koleszar's avatar
John Koleszar committed
72
73
74
75
76
77
78
79
80
81
82
83
DIST_DIR?=dist
HOSTCC?=gcc
TGT_ISA:=$(word 1, $(subst -, ,$(TOOLCHAIN)))
TGT_OS:=$(word 2, $(subst -, ,$(TOOLCHAIN)))
TGT_CC:=$(word 3, $(subst -, ,$(TOOLCHAIN)))
quiet:=$(if $(verbose),,yes)
qexec=$(if $(quiet),@)

# Cancel built-in implicit rules
%: %.o
%.asm:
%.a:
84
%: %.cc
John Koleszar's avatar
John Koleszar committed
85
86
87
88

#
# Common rules"
#
89
90
.PHONY: all
all:
John Koleszar's avatar
John Koleszar committed
91
92
93
94
95
96

.PHONY: clean
clean::
	rm -f $(OBJS-yes) $(OBJS-yes:.o=.d) $(OBJS-yes:.asm.s.o=.asm.s)
	rm -f $(CLEAN-OBJS)

97
98
.PHONY: dist
dist:
John Koleszar's avatar
John Koleszar committed
99
.PHONY: install
100
install::
101
102
.PHONY: test
test::
John Koleszar's avatar
John Koleszar committed
103
104
.PHONY: testdata
testdata::
John Koleszar's avatar
John Koleszar committed
105

106
107
xform_obj_prefix:=.objs/$(TOOLCHAIN)/
xform_obj_path=$(if $(1),$(addprefix $(xform_obj_prefix),$(subst /,_,$(1))),$(xform_obj_prefix))
108
xform_obj_path_o_d=$(call xform_obj_path,$(1)).o $(call xform_obj_path,$(1)).d
109
110
111
112
113
114
define obj_rules_template
$(BUILD_PFX)$(call xform_obj_path,$(1))%.c.d: $(1)%.c
	$(if $(quiet),@echo "    [DEP] $$@")
	$(qexec)mkdir -p $$(dir $$@)
	$(qexec)$(CC) $$(INTERNAL_CFLAGS) $$(CFLAGS) -M $$< | $(fmt_deps) > $$@

115
$(BUILD_PFX)$(call xform_obj_path,$(1))%.c.o: $(1)%.c $(BUILD_PFX)$(call xform_obj_path,$(1))%.c.d
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
	$(if $(quiet),@echo "    [CC] $$@")
	$(qexec)$(CC) $$(INTERNAL_CFLAGS) $$(CFLAGS) -c -o $$@ $$<

$(BUILD_PFX)$(call xform_obj_path,$(1))%.cc.d: $(1)%.cc
	$(if $(quiet),@echo "    [DEP] $$@")
	$(qexec)mkdir -p $$(dir $$@)
	$(qexec)$(CXX) $$(INTERNAL_CFLAGS) $$(CXXFLAGS) -M $$< | $(fmt_deps) > $$@

$(BUILD_PFX)$(call xform_obj_path,$(1))%.cc.o: $(1)%.cc
	$(if $(quiet),@echo "    [CXX] $$@")
	$(qexec)$(CXX) $$(INTERNAL_CFLAGS) $$(CXXFLAGS) -c -o $$@ $$<

$(BUILD_PFX)$(call xform_obj_path,$(1))%.asm.d: $(1)%.asm
	$(if $(quiet),@echo "    [DEP] $$@")
	$(qexec)mkdir -p $$(dir $$@)
John Koleszar's avatar
John Koleszar committed
131
	$(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \
132
            --build-pfx=$(BUILD_PFX) --depfile=$$@ $$(ASFLAGS) $$< > $$@
John Koleszar's avatar
John Koleszar committed
133

134
135
136
$(BUILD_PFX)$(call xform_obj_path,$(1))%.asm.o: $(1)%.asm
	$(if $(quiet),@echo "    [AS] $$@")
	$(qexec)$(AS) $$(ASFLAGS) -o $$@ $$<
John Koleszar's avatar
John Koleszar committed
137

138
139
140
$(BUILD_PFX)$(call xform_obj_path,$(1))%.s.d: $(1)%.s
	$(if $(quiet),@echo "    [DEP] $$@")
	$(qexec)mkdir -p $$(dir $$@)
John Koleszar's avatar
John Koleszar committed
141
	$(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \
142
            --build-pfx=$(BUILD_PFX) --depfile=$$@ $$(ASFLAGS) $$< > $$@
John Koleszar's avatar
John Koleszar committed
143

144
145
146
$(BUILD_PFX)$(call xform_obj_path,$(1))%.s.o: $(1)%.s
	$(if $(quiet),@echo "    [AS] $$@")
	$(qexec)$(AS) $$(ASFLAGS) -o $$@ $$<
John Koleszar's avatar
John Koleszar committed
147

Johann's avatar
Johann committed
148
149
.PRECIOUS: %.c.S
%.c.S: CFLAGS += -DINLINE_ASM
150
151
152
$(BUILD_PFX)$(call xform_obj_path,$(1))%.c.S: $(1)%.c
	$(if $(quiet),@echo "    [GEN] $$@")
	$(qexec)$(CC) -S $$(CFLAGS) -o $$@ $$<
Johann's avatar
Johann committed
153

John Koleszar's avatar
John Koleszar committed
154
.PRECIOUS: %.asm.s
155
156
157
158
159
$(BUILD_PFX)$(call xform_obj_path,$(1))%.asm.s: $(1)%.asm
	$(if $(quiet),@echo "    [ASM CONVERSION] $$@")
	$(qexec)mkdir -p $$(dir $$@)
	$(qexec)$(ASM_CONVERSION) <$$< >$$@
endef
John Koleszar's avatar
John Koleszar committed
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182

# If we're in debug mode, pretend we don't have GNU strip, to fall back to
# the copy implementation
HAVE_GNU_STRIP := $(if $(CONFIG_DEBUG),,$(HAVE_GNU_STRIP))
ifeq ($(HAVE_GNU_STRIP),yes)
# Older binutils strip global sybols not needed for relocation processing
# when given --strip-unneeded. Use nm and awk to identify globals and
# keep them.
%.a: %_g.a
	$(if $(quiet),@echo "    [STRIP] $@ < $<")
	$(qexec)$(STRIP) --strip-unneeded \
         `$(NM) $< | grep ' [A-TV-Z] ' | awk '{print "-K"$$3'}`\
          -o $@ $<
else
%.a: %_g.a
	$(if $(quiet),@echo "    [CP] $@ < $<")
	$(qexec)cp $< $@
endif

#
# Rule to extract assembly constants from C sources
#
obj_int_extract: build/make/obj_int_extract.c
183
	$(if $(quiet),@echo "    [HOSTCC] $@")
Johann's avatar
Johann committed
184
	$(qexec)$(HOSTCC) -I. -I$(SRC_PATH_BARE) -o $@ $<
John Koleszar's avatar
John Koleszar committed
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
CLEAN-OBJS += obj_int_extract

#
# Utility functions
#
pairmap=$(if $(strip $(2)),\
    $(call $(1),$(word 1,$(2)),$(word 2,$(2)))\
    $(call pairmap,$(1),$(wordlist 3,$(words $(2)),$(2)))\
)

enabled=$(filter-out $($(1)-no),$($(1)-yes))
cond_enabled=$(if $(filter yes,$($(1))), $(call enabled,$(2)))

find_file1=$(word 1,$(wildcard $(subst //,/,$(addsuffix /$(1),$(2)))))
find_file=$(foreach f,$(1),$(call find_file1,$(strip $(f)),$(strip $(2))) )
200
obj_pats=.c=.c.o $(AS_SFX)=$(AS_SFX).o .cc=.cc.o
201
objs=$(addprefix $(BUILD_PFX),$(call xform_obj_path,$(foreach p,$(obj_pats),$(filter %.o,$(1:$(p))) )))
John Koleszar's avatar
John Koleszar committed
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218

install_map_templates=$(eval $(call install_map_template,$(1),$(2)))

not=$(subst yes,no,$(1))

ifeq ($(CONFIG_MSVS),yes)
lib_file_name=$(1).lib
else
lib_file_name=lib$(1).a
endif
#
# Rule Templates
#
define linker_template
$(1): $(filter-out -%,$(2))
$(1):
	$(if $(quiet),@echo    "    [LD] $$@")
219
	$(qexec)$$(LD) $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs))
John Koleszar's avatar
John Koleszar committed
220
endef
221
222
223
224
define linkerxx_template
$(1): $(filter-out -%,$(2))
$(1):
	$(if $(quiet),@echo    "    [LD] $$@")
John Koleszar's avatar
John Koleszar committed
225
	$(qexec)$$(CXX) $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs))
226
endef
John Koleszar's avatar
John Koleszar committed
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# make-3.80 has a bug with expanding large input strings to the eval function,
# which was triggered in some cases by the following component of
# linker_template:
#   $(1): $$(call find_file, $(patsubst -l%,lib%.a,$(filter -l%,$(2))),\
#                           $$(patsubst -L%,%,$$(filter -L%,$$(LDFLAGS) $(2))))
# This may be useful to revisit in the future (it tries to locate libraries
# in a search path and add them as prerequisites

define install_map_template
$(DIST_DIR)/$(1): $(2)
	$(if $(quiet),@echo "    [INSTALL] $$@")
	$(qexec)mkdir -p $$(dir $$@)
	$(qexec)cp -p $$< $$@
endef

define archive_template
# Not using a pattern rule here because we don't want to generate empty
# archives when they are listed as a dependency in files not responsible
# for creating them.
$(1):
	$(if $(quiet),@echo "    [AR] $$@")
	$(qexec)$$(AR) $$(ARFLAGS) $$@ $$?
endef

John Koleszar's avatar
John Koleszar committed
251
252
253
254
255
256
257
258
259
define so_template
# Not using a pattern rule here because we don't want to generate empty
# archives when they are listed as a dependency in files not responsible
# for creating them.
#
# This needs further abstraction for dealing with non-GNU linkers.
$(1):
	$(if $(quiet),@echo "    [LD] $$@")
	$(qexec)$$(LD) -shared $$(LDFLAGS) \
260
            -Wl,--no-undefined -Wl,-soname,$$(SONAME) \
jimbankoski's avatar
jimbankoski committed
261
            -Wl,--version-script,$$(EXPORTS_FILE) -o $$@ \
John Koleszar's avatar
John Koleszar committed
262
            $$(filter %.o,$$^) $$(extralibs)
John Koleszar's avatar
John Koleszar committed
263
264
endef

jimbankoski's avatar
jimbankoski committed
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
define dl_template
# Not using a pattern rule here because we don't want to generate empty
# archives when they are listed as a dependency in files not responsible
# for creating them.
$(1):
	$(if $(quiet),@echo "    [LD] $$@")
	$(qexec)$$(LD) -dynamiclib $$(LDFLAGS) \
	    -exported_symbols_list $$(EXPORTS_FILE) \
        -Wl,-headerpad_max_install_names,-compatibility_version,1.0,-current_version,$$(VERSION_MAJOR) \
        -o $$@ \
        $$(filter %.o,$$^) $$(extralibs)
endef



John Koleszar's avatar
John Koleszar committed
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
define lipo_lib_template
$(1): $(addsuffix /$(1),$(FAT_ARCHS))
	$(if $(quiet),@echo "    [LIPO] $$@")
	$(qexec)libtool -static -o $$@ $$?
endef

define lipo_bin_template
$(1): $(addsuffix /$(1),$(FAT_ARCHS))
	$(if $(quiet),@echo "    [LIPO] $$@")
	$(qexec)lipo -output $$@ -create $$?
endef


#
# Get current configuration
#
ifneq ($(target),)
include $(SRC_PATH_BARE)/$(target:-$(TOOLCHAIN)=).mk
endif
ifeq ($(filter clean,$(MAKECMDGOALS)),)
  # Older versions of make don't like -include directives with no arguments
  ifneq ($(filter %.d,$(OBJS-yes:.o=.d)),)
    -include $(filter %.d,$(OBJS-yes:.o=.d))
  endif
endif

#
307
# Configuration dependent rules
John Koleszar's avatar
John Koleszar committed
308
#
309
310
311
312
SRC_DIRS:=$(patsubst %/,%,$(sort $(dir $(SRCS))))
$(foreach d,$(SRC_DIRS), $(eval $(call obj_rules_template,$(d)/)))
$(eval $(call obj_rules_template)) # for ./

John Koleszar's avatar
John Koleszar committed
313
314
315
316
317
318
319
$(call pairmap,install_map_templates,$(INSTALL_MAPS))

DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,DOCS)
.docs: $(DOCS)
	@touch $@

INSTALL-DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,INSTALL-DOCS)
320
321
322
ifeq ($(MAKECMDGOALS),dist)
INSTALL-DOCS+=$(call cond_enabled,CONFIG_INSTALL_DOCS,DIST-DOCS)
endif
John Koleszar's avatar
John Koleszar committed
323
324
325
326
327
328
329
330
331
332
333
.install-docs: .docs $(addprefix $(DIST_DIR)/,$(INSTALL-DOCS))
	@touch $@

clean::
	rm -f .docs .install-docs $(DOCS)

BINS=$(call enabled,BINS)
.bins: $(BINS)
	@touch $@

INSTALL-BINS=$(call cond_enabled,CONFIG_INSTALL_BINS,INSTALL-BINS)
334
335
336
ifeq ($(MAKECMDGOALS),dist)
INSTALL-BINS+=$(call cond_enabled,CONFIG_INSTALL_BINS,DIST-BINS)
endif
John Koleszar's avatar
John Koleszar committed
337
338
339
340
341
342
343
344
345
346
.install-bins: .bins $(addprefix $(DIST_DIR)/,$(INSTALL-BINS))
	@touch $@

clean::
	rm -f .bins .install-bins $(BINS)

LIBS=$(call enabled,LIBS)
.libs: $(LIBS)
	@touch $@
$(foreach lib,$(filter %_g.a,$(LIBS)),$(eval $(call archive_template,$(lib))))
347
$(foreach lib,$(filter %so.$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH),$(LIBS)),$(eval $(call so_template,$(lib))))
jimbankoski's avatar
jimbankoski committed
348
$(foreach lib,$(filter %$(VERSION_MAJOR).dylib,$(LIBS)),$(eval $(call dl_template,$(lib))))
John Koleszar's avatar
John Koleszar committed
349
350

INSTALL-LIBS=$(call cond_enabled,CONFIG_INSTALL_LIBS,INSTALL-LIBS)
351
352
353
ifeq ($(MAKECMDGOALS),dist)
INSTALL-LIBS+=$(call cond_enabled,CONFIG_INSTALL_LIBS,DIST-LIBS)
endif
John Koleszar's avatar
John Koleszar committed
354
355
356
357
358
359
360
361
362
363
364
365
.install-libs: .libs $(addprefix $(DIST_DIR)/,$(INSTALL-LIBS))
	@touch $@

clean::
	rm -f .libs .install-libs $(LIBS)

ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
PROJECTS=$(call enabled,PROJECTS)
.projects: $(PROJECTS)
	@touch $@

INSTALL-PROJECTS=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,INSTALL-PROJECTS)
366
367
368
ifeq ($(MAKECMDGOALS),dist)
INSTALL-PROJECTS+=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,DIST-PROJECTS)
endif
John Koleszar's avatar
John Koleszar committed
369
370
371
372
373
374
375
.install-projects: .projects $(addprefix $(DIST_DIR)/,$(INSTALL-PROJECTS))
	@touch $@

clean::
	rm -f .projects .install-projects $(PROJECTS)
endif

376
# If there are any source files to be distributed, then include the build
John Koleszar's avatar
John Koleszar committed
377
# system too.
378
379
380
381
382
383
384
385
ifneq ($(call enabled,DIST-SRCS),)
    DIST-SRCS-yes            += configure
    DIST-SRCS-yes            += build/make/configure.sh
    DIST-SRCS-yes            += build/make/gen_asm_deps.sh
    DIST-SRCS-yes            += build/make/Makefile
    DIST-SRCS-$(CONFIG_MSVS)  += build/make/gen_msvs_def.sh
    DIST-SRCS-$(CONFIG_MSVS)  += build/make/gen_msvs_proj.sh
    DIST-SRCS-$(CONFIG_MSVS)  += build/make/gen_msvs_sln.sh
386
    DIST-SRCS-$(CONFIG_MSVS)  += build/x86-msvs/yasm.rules
387
    DIST-SRCS-$(CONFIG_MSVS)  += build/x86-msvs/obj_int_extract.bat
388
    DIST-SRCS-$(CONFIG_RVCT) += build/make/armlink_adapter.sh
389
390
    # Include obj_int_extract if we use offsets from asm_*_offsets
    DIST-SRCS-$(ARCH_ARM)$(ARCH_X86)$(ARCH_X86_64)    += build/make/obj_int_extract.c
391
392
    DIST-SRCS-$(ARCH_ARM)    += build/make/ads2gas.pl
    DIST-SRCS-yes            += $(target:-$(TOOLCHAIN)=).mk
John Koleszar's avatar
John Koleszar committed
393
394
endif
INSTALL-SRCS := $(call cond_enabled,CONFIG_INSTALL_SRCS,INSTALL-SRCS)
395
396
397
ifeq ($(MAKECMDGOALS),dist)
INSTALL-SRCS += $(call cond_enabled,CONFIG_INSTALL_SRCS,DIST-SRCS)
endif
John Koleszar's avatar
John Koleszar committed
398
399
400
401
402
403
404
405
406
407
408
409
.install-srcs: $(addprefix $(DIST_DIR)/src/,$(INSTALL-SRCS))
	@touch $@

clean::
	rm -f .install-srcs

ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
    BUILD_TARGETS += .projects
    INSTALL_TARGETS += .install-projects
endif
BUILD_TARGETS += .docs .libs .bins
INSTALL_TARGETS += .install-docs .install-srcs .install-libs .install-bins
410
all: $(BUILD_TARGETS)
411
412
install:: $(INSTALL_TARGETS)
dist: $(INSTALL_TARGETS)
413
test::