build: Add proper infrastructure for adding and checking host CPPFLAGS
[libav.git] / Makefile
CommitLineData
bde51e6a
JR
1include config.mak
2
f038cf3c
MR
3vpath %.c $(SRC_PATH)
4vpath %.h $(SRC_PATH)
5vpath %.S $(SRC_PATH)
6vpath %.asm $(SRC_PATH)
7vpath %.v $(SRC_PATH)
8vpath %.texi $(SRC_PATH)
bde51e6a 9
bb524924
MR
10ifndef V
11Q = @
12ECHO = printf "$(1)\t%s\n" $(2)
095792f2 13BRIEF = CC HOSTCC HOSTLD AS YASM AR LD
5864eb42 14SILENT = DEPCC DEPHOSTCC DEPAS DEPYASM RANLIB RM
bb524924
MR
15MSG = $@
16M = @$(call ECHO,$(TAG),$@);
17$(foreach VAR,$(BRIEF), \
18 $(eval override $(VAR) = @$$(call ECHO,$(VAR),$$(MSG)); $($(VAR))))
19$(foreach VAR,$(SILENT),$(eval override $(VAR) = @$($(VAR))))
f038cf3c 20$(eval INSTALL = @$(call ECHO,INSTALL,$$(^:$(SRC_PATH)/%=%)); $(INSTALL))
bb524924
MR
21endif
22
c8af852b 23ALLFFLIBS = avcodec avdevice avfilter avformat avresample avutil swscale
371584c4 24
bb524924
MR
25IFLAGS := -I. -I$(SRC_PATH)
26CPPFLAGS := $(IFLAGS) $(CPPFLAGS)
27CFLAGS += $(ECFLAGS)
a758c5e2
MR
28CCFLAGS = $(CPPFLAGS) $(CFLAGS)
29ASFLAGS := $(CPPFLAGS) $(ASFLAGS)
04581c8c 30YASMFLAGS += $(IFLAGS:%=%/) -Pconfig.asm
4cc4b33f 31HOSTCCFLAGS = $(IFLAGS) $(HOSTCPPFLAGS) $(HOSTCFLAGS)
8db73c61 32LDFLAGS := $(ALLFFLIBS:%=$(LD_PATH)lib%) $(LDFLAGS)
bb524924 33
bc877faf 34define COMPILE
a758c5e2 35 $(call $(1)DEP,$(1))
23565c26 36 $($(1)) $($(1)FLAGS) $($(1)_DEPFLAGS) $($(1)_C) $($(1)_O) $<
bc877faf
MR
37endef
38
39COMPILE_C = $(call COMPILE,CC)
40COMPILE_S = $(call COMPILE,AS)
41
bb524924 42%.o: %.c
bc877faf 43 $(COMPILE_C)
bb524924
MR
44
45%.o: %.S
bc877faf 46 $(COMPILE_S)
bb524924 47
c2626492
MR
48%.i: %.c
49 $(CC) $(CCFLAGS) $(CC_E) $<
50
dfd9159f
MR
51%.h.c:
52 $(Q)echo '#include "$*.h"' >$@
bb524924
MR
53
54%.ver: %.v
55 $(Q)sed 's/$$MAJOR/$($(basename $(@F))_VERSION_MAJOR)/' $^ > $@
56
57%.c %.h: TAG = GEN
58
6291d7e4 59PROGS-$(CONFIG_AVCONV) += avconv
266463da 60PROGS-$(CONFIG_AVPLAY) += avplay
9e12f0bf 61PROGS-$(CONFIG_AVPROBE) += avprobe
4d58e4cb 62PROGS-$(CONFIG_AVSERVER) += avserver
bde51e6a 63
583fcb52 64PROGS := $(PROGS-yes:%=%$(EXESUF))
80521c19 65OBJS = cmdutils.o $(EXEOBJS)
fe2147e9 66OBJS-avconv = avconv_opt.o avconv_filter.o
3d157bf3 67TESTTOOLS = audiogen videogen rotozoom tiny_psnr base64
0d0b81f9 68HOSTPROGS := $(TESTTOOLS:%=tests/%) doc/print_options
28e1c979
MR
69TOOLS = qt-faststart trasher
70TOOLS-$(CONFIG_ZLIB) += cws2fws
bde51e6a 71
0fec2cb1 72BASENAMES = avconv avplay avprobe avserver
583fcb52 73ALLPROGS = $(BASENAMES:%=%$(EXESUF))
583fcb52 74ALLMANPAGES = $(BASENAMES:%=%.1)
bde51e6a 75
5a0f7131 76FFLIBS-$(CONFIG_AVDEVICE) += avdevice
bde51e6a 77FFLIBS-$(CONFIG_AVFILTER) += avfilter
5a0f7131 78FFLIBS-$(CONFIG_AVFORMAT) += avformat
c8af852b 79FFLIBS-$(CONFIG_AVRESAMPLE) += avresample
97d5fa38 80FFLIBS-$(CONFIG_AVCODEC) += avcodec
5a0f7131 81FFLIBS-$(CONFIG_SWSCALE) += swscale
bde51e6a 82
5a0f7131 83FFLIBS := avutil
bde51e6a 84
8096fdf0 85DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.avpreset)
a1a84f69 86
9b55e2e7
MR
87SKIPHEADERS = cmdutils_common_opts.h
88
57b4a3dd 89include $(SRC_PATH)/common.mak
bde51e6a 90
bde51e6a
JR
91FF_EXTRALIBS := $(FFEXTRALIBS)
92FF_DEP_LIBS := $(DEP_LIBS)
93
1fef92fd 94all: $(PROGS)
bde51e6a 95
80521c19
MR
96$(TOOLS): %$(EXESUF): %.o $(EXEOBJS)
97 $(LD) $(LDFLAGS) $(LD_O) $^ $(ELIBS)
28e1c979 98
7baa115a 99tools/cws2fws$(EXESUF): ELIBS = $(ZLIB)
28e1c979 100
86601915 101config.h: .config
f038cf3c 102.config: $(wildcard $(FFLIBS:%=$(SRC_PATH)/lib%/all*.c))
9d0b3042
MR
103 @-tput bold 2>/dev/null
104 @-printf '\nWARNING: $(?F) newer than config.h, rerun configure\n\n'
105 @-tput sgr0 2>/dev/null
86601915 106
e7e19b15 107SUBDIR_VARS := CLEANFILES EXAMPLES FFLIBS HOSTPROGS TESTPROGS TOOLS \
121604b0 108 HEADERS ARCH_HEADERS BUILT_HEADERS SKIPHEADERS \
b3267559 109 ARMV5TE-OBJS ARMV6-OBJS VFP-OBJS NEON-OBJS \
ca411fc1 110 ALTIVEC-OBJS VIS-OBJS \
5864eb42 111 MMX-OBJS YASM-OBJS \
24d3796d 112 OBJS HOSTOBJS TESTOBJS
bde51e6a
JR
113
114define RESET
115$(1) :=
116$(1)-yes :=
117endef
118
119define DOSUBDIR
120$(foreach V,$(SUBDIR_VARS),$(eval $(call RESET,$(V))))
121SUBDIR := $(1)/
57b4a3dd 122include $(SRC_PATH)/$(1)/Makefile
07a873a2 123-include $(SRC_PATH)/$(1)/$(ARCH)/Makefile
144904e9 124include $(SRC_PATH)/library.mak
bde51e6a
JR
125endef
126
127$(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D))))
128
baac24e6 129define DOPROG
80521c19 130OBJS-$(1) += $(1).o cmdutils.o $(EXEOBJS)
07b3790d 131$(1)$(EXESUF): $$(OBJS-$(1))
baac24e6
MR
132$$(OBJS-$(1)): CFLAGS += $(CFLAGS-$(1))
133$(1)$(EXESUF): LDFLAGS += $(LDFLAGS-$(1))
134$(1)$(EXESUF): FF_EXTRALIBS += $(LIBS-$(1))
135-include $$(OBJS-$(1):.o=.d)
136endef
137
138$(foreach P,$(PROGS-yes),$(eval $(call DOPROG,$(P))))
bde51e6a 139
07b3790d
MR
140$(PROGS): %$(EXESUF): %.o $(FF_DEP_LIBS)
141 $(LD) $(LDFLAGS) $(LD_O) $(OBJS-$*) $(FF_EXTRALIBS)
bde51e6a 142
5e27ec28
MR
143OBJDIRS += tools
144
08df7f86 145-include $(wildcard tools/*.d)
bde51e6a 146
f038cf3c
MR
147VERSION_SH = $(SRC_PATH)/version.sh
148GIT_LOG = $(SRC_PATH)/.git/logs/HEAD
6a53fffd 149
faa6f1c3 150.version: $(wildcard $(GIT_LOG)) $(VERSION_SH) config.mak
6a53fffd
MR
151.version: M=@
152
153version.h .version:
0853a2b4 154 $(M)$(VERSION_SH) $(SRC_PATH) version.h $(EXTRA_VERSION)
6a53fffd
MR
155 $(Q)touch .version
156
157# force version.sh to run whenever version might have changed
158-include .version
36798f1b 159
623ffe8c
MR
160ifdef PROGS
161install: install-progs install-data
162endif
163
164install: install-libs install-headers
d7a72d25
MR
165
166install-libs: install-libs-yes
bde51e6a 167
151c5841 168install-progs-yes:
623ffe8c
MR
169install-progs-$(CONFIG_SHARED): install-libs
170
171install-progs: install-progs-yes $(PROGS)
63611f31 172 $(Q)mkdir -p "$(BINDIR)"
fd676deb 173 $(INSTALL) -c -m 755 $(PROGS) "$(BINDIR)"
bde51e6a 174
a1a84f69 175install-data: $(DATA_FILES)
63611f31 176 $(Q)mkdir -p "$(DATADIR)"
fd676deb 177 $(INSTALL) -m 644 $(DATA_FILES) "$(DATADIR)"
a1a84f69 178
f87b03b5 179uninstall: uninstall-libs uninstall-headers uninstall-progs uninstall-data
d3cb93b3
RP
180
181uninstall-progs:
50e10cbd 182 $(RM) $(addprefix "$(BINDIR)/", $(ALLPROGS))
d3cb93b3
RP
183
184uninstall-data:
50e10cbd 185 $(RM) -r "$(DATADIR)"
d3cb93b3 186
698a183e 187clean::
e0be794a 188 $(RM) $(ALLPROGS)
50e10cbd 189 $(RM) $(CLEANSUFFIXES)
40321376 190 $(RM) $(CLEANSUFFIXES:%=tools/%)
bde51e6a
JR
191
192distclean::
50e10cbd 193 $(RM) $(DISTCLEANSUFFIXES)
59748689 194 $(RM) config.* .version version.h libavutil/avconfig.h
bde51e6a 195
9d0b3042 196config:
29ba0911 197 $(SRC_PATH)/configure $(value LIBAV_CONFIGURATION)
0c3b2d65 198
4982e1dd
DB
199check: all alltools checkheaders examples testprogs fate
200
57b4a3dd
MR
201include $(SRC_PATH)/doc/Makefile
202include $(SRC_PATH)/tests/Makefile
d29d9ccc 203
5e27ec28
MR
204$(sort $(OBJDIRS)):
205 $(Q)mkdir -p $@
206
8d853efe
MR
207# Dummy rule to stop make trying to rebuild removed or renamed headers
208%.h:
209 @:
210
211# Disable suffix rules. Most of the builtin rules are suffix rules,
212# so this saves some time on slow systems.
213.SUFFIXES:
214
4982e1dd 215.PHONY: all all-yes alltools check *clean config examples install*
698a183e 216.PHONY: testprogs uninstall*