build: simplify some conditional targets
[ffmpeg.git] / Makefile
1 include config.mak
2
3 SRC_DIR = $(SRC_PATH_BARE)
4
5 vpath %.texi $(SRC_PATH_BARE)
6
7 PROGS-$(CONFIG_FFMPEG)   += ffmpeg
8 PROGS-$(CONFIG_FFPLAY)   += ffplay
9 PROGS-$(CONFIG_FFPROBE)  += ffprobe
10 PROGS-$(CONFIG_FFSERVER) += ffserver
11
12 PROGS      := $(PROGS-yes:%=%$(EXESUF))
13 OBJS        = $(PROGS-yes:%=%.o) cmdutils.o
14 MANPAGES    = $(PROGS-yes:%=doc/%.1)
15 PODPAGES    = $(PROGS-yes:%=doc/%.pod)
16 HTMLPAGES   = $(PROGS-yes:%=doc/%.html)
17 TOOLS       = $(addprefix tools/, $(addsuffix $(EXESUF), cws2fws graph2dot lavfi-showfiltfmts pktdumper probetest qt-faststart trasher))
18 TESTTOOLS   = audiogen videogen rotozoom tiny_psnr base64
19 HOSTPROGS  := $(TESTTOOLS:%=tests/%)
20
21 BASENAMES   = ffmpeg ffplay ffprobe ffserver
22 ALLPROGS    = $(BASENAMES:%=%$(EXESUF))
23 ALLMANPAGES = $(BASENAMES:%=%.1)
24
25 FFLIBS-$(CONFIG_AVDEVICE) += avdevice
26 FFLIBS-$(CONFIG_AVFILTER) += avfilter
27 FFLIBS-$(CONFIG_AVFORMAT) += avformat
28 FFLIBS-$(CONFIG_AVCODEC)  += avcodec
29 FFLIBS-$(CONFIG_POSTPROC) += postproc
30 FFLIBS-$(CONFIG_SWSCALE)  += swscale
31
32 FFLIBS := avutil
33
34 DATA_FILES := $(wildcard $(SRC_DIR)/ffpresets/*.ffpreset)
35
36 SKIPHEADERS = cmdutils_common_opts.h
37
38 include common.mak
39
40 FF_LDFLAGS   := $(FFLDFLAGS)
41 FF_EXTRALIBS := $(FFEXTRALIBS)
42 FF_DEP_LIBS  := $(DEP_LIBS)
43
44 all-$(CONFIG_DOC): documentation
45
46 all: $(FF_DEP_LIBS) $(PROGS)
47
48 config.h: .config
49 .config: $(wildcard $(FFLIBS:%=$(SRC_DIR)/lib%/all*.c))
50         @-tput bold 2>/dev/null
51         @-printf '\nWARNING: $(?F) newer than config.h, rerun configure\n\n'
52         @-tput sgr0 2>/dev/null
53
54 SUBDIR_VARS := OBJS FFLIBS CLEANFILES DIRS TESTPROGS EXAMPLES SKIPHEADERS \
55                ALTIVEC-OBJS MMX-OBJS NEON-OBJS X86-OBJS YASM-OBJS-FFT YASM-OBJS \
56                HOSTPROGS BUILT_HEADERS TESTOBJS ARCH_HEADERS ARMV6-OBJS
57
58 define RESET
59 $(1) :=
60 $(1)-yes :=
61 endef
62
63 define DOSUBDIR
64 $(foreach V,$(SUBDIR_VARS),$(eval $(call RESET,$(V))))
65 SUBDIR := $(1)/
66 include $(1)/Makefile
67 endef
68
69 $(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D))))
70
71 ffplay.o: CFLAGS += $(SDL_CFLAGS)
72 ffplay$(EXESUF): FF_EXTRALIBS += $(SDL_LIBS)
73 ffserver$(EXESUF): FF_LDFLAGS += $(FFSERVERLDFLAGS)
74
75 $(PROGS): %$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS)
76         $(LD) $(FF_LDFLAGS) -o $@ $< cmdutils.o $(FF_EXTRALIBS)
77
78 alltools: $(TOOLS)
79
80 tools/%$(EXESUF): tools/%.o
81         $(LD) $(FF_LDFLAGS) -o $@ $< $(FF_EXTRALIBS)
82
83 tools/%.o: tools/%.c
84         $(CC) $(CPPFLAGS) $(CFLAGS) -c $(CC_O) $<
85
86 -include $(wildcard tools/*.d)
87 -include $(wildcard tests/*.d)
88
89 VERSION_SH  = $(SRC_PATH_BARE)/version.sh
90 GIT_LOG     = $(SRC_PATH_BARE)/.git/logs/HEAD
91
92 .version: $(wildcard $(GIT_LOG)) $(VERSION_SH) config.mak
93 .version: M=@
94
95 version.h .version:
96         $(M)$(VERSION_SH) $(SRC_PATH) version.h $(EXTRA_VERSION)
97         $(Q)touch .version
98
99 # force version.sh to run whenever version might have changed
100 -include .version
101
102 DOCS = $(addprefix doc/, developer.html faq.html general.html libavfilter.html) $(HTMLPAGES) $(MANPAGES) $(PODPAGES)
103
104 documentation: $(DOCS)
105
106 -include $(wildcard $(DOCS:%=%.d))
107
108 TEXIDEP = awk '/^@include/ { printf "$@: $(@D)/%s\n", $$2 }' <$< >$(@:%=%.d)
109
110 doc/%.html: TAG = HTML
111 doc/%.html: doc/%.texi $(SRC_PATH_BARE)/doc/t2h.init
112         $(Q)$(TEXIDEP)
113         $(M)texi2html -monolithic --init-file $(SRC_PATH_BARE)/doc/t2h.init --output $@ $<
114
115 doc/%.pod: TAG = POD
116 doc/%.pod: doc/%.texi
117         $(Q)$(TEXIDEP)
118         $(M)doc/texi2pod.pl $< $@
119
120 doc/%.1: TAG = MAN
121 doc/%.1: doc/%.pod
122         $(M)pod2man --section=1 --center=" " --release=" " $< > $@
123
124 ifdef PROGS
125 install: install-progs install-data
126 endif
127
128 install: install-libs install-headers
129
130 install-libs: install-libs-yes
131
132 install-progs-$(CONFIG_DOC): install-man
133 install-progs-$(CONFIG_SHARED): install-libs
134
135 install-progs: install-progs-yes $(PROGS)
136         $(Q)mkdir -p "$(BINDIR)"
137         $(INSTALL) -c -m 755 $(PROGS) "$(BINDIR)"
138
139 install-data: $(DATA_FILES)
140         $(Q)mkdir -p "$(DATADIR)"
141         $(INSTALL) -m 644 $(DATA_FILES) "$(DATADIR)"
142
143 install-man: $(MANPAGES)
144         $(Q)mkdir -p "$(MANDIR)/man1"
145         $(INSTALL) -m 644 $(MANPAGES) "$(MANDIR)/man1"
146
147 uninstall: uninstall-libs uninstall-headers uninstall-progs uninstall-data uninstall-man
148
149 uninstall-progs:
150         $(RM) $(addprefix "$(BINDIR)/", $(ALLPROGS))
151
152 uninstall-data:
153         $(RM) -r "$(DATADIR)"
154
155 uninstall-man:
156         $(RM) $(addprefix "$(MANDIR)/man1/",$(ALLMANPAGES))
157
158 testclean:
159         $(RM) -r tests/vsynth1 tests/vsynth2 tests/data
160         $(RM) $(addprefix tests/,$(CLEANSUFFIXES))
161         $(RM) tests/seek_test$(EXESUF) tests/seek_test.o
162         $(RM) $(TESTTOOLS:%=tests/%$(HOSTEXESUF))
163
164 clean:: testclean
165         $(RM) $(ALLPROGS)
166         $(RM) $(CLEANSUFFIXES)
167         $(RM) doc/*.html doc/*.pod doc/*.1
168         $(RM) $(TOOLS)
169         $(RM) $(CLEANSUFFIXES:%=tools/%)
170
171 distclean::
172         $(RM) $(DISTCLEANSUFFIXES)
173         $(RM) config.* .version version.h libavutil/avconfig.h
174
175 config:
176         $(SRC_PATH)/configure $(value LIBAV_CONFIGURATION)
177
178 # regression tests
179
180 check: test checkheaders
181
182 fulltest test: codectest lavftest lavfitest seektest
183
184 FFSERVER_REFFILE = $(SRC_PATH)/tests/ffserver.regression.ref
185
186 codectest: fate-codec
187 lavftest:  fate-lavf
188 lavfitest: fate-lavfi
189 seektest:  fate-seek
190
191 AREF = fate-acodec-aref
192 VREF = fate-vsynth1-vref fate-vsynth2-vref
193 REFS = $(AREF) $(VREF)
194
195 $(VREF): ffmpeg$(EXESUF) tests/vsynth1/00.pgm tests/vsynth2/00.pgm
196 $(AREF): ffmpeg$(EXESUF) tests/data/asynth1.sw
197
198 ffservertest: ffserver$(EXESUF) tests/vsynth1/00.pgm tests/data/asynth1.sw
199         @echo
200         @echo "Unfortunately ffserver is broken and therefore its regression"
201         @echo "test fails randomly. Treat the results accordingly."
202         @echo
203         $(SRC_PATH)/tests/ffserver-regression.sh $(FFSERVER_REFFILE) $(SRC_PATH)/tests/ffserver.conf
204
205 tests/vsynth1/00.pgm: tests/videogen$(HOSTEXESUF)
206         @mkdir -p tests/vsynth1
207         $(M)./$< 'tests/vsynth1/'
208
209 tests/vsynth2/00.pgm: tests/rotozoom$(HOSTEXESUF)
210         @mkdir -p tests/vsynth2
211         $(M)./$< 'tests/vsynth2/' $(SRC_PATH)/tests/lena.pnm
212
213 tests/data/asynth1.sw: tests/audiogen$(HOSTEXESUF)
214         @mkdir -p tests/data
215         $(M)./$< $@
216
217 tests/data/asynth1.sw tests/vsynth%/00.pgm: TAG = GEN
218
219 tests/seek_test$(EXESUF): tests/seek_test.o $(FF_DEP_LIBS)
220         $(LD) $(FF_LDFLAGS) -o $@ $< $(FF_EXTRALIBS)
221
222 tools/lavfi-showfiltfmts$(EXESUF): tools/lavfi-showfiltfmts.o $(FF_DEP_LIBS)
223         $(LD) $(FF_LDFLAGS) -o $@ $< $(FF_EXTRALIBS)
224
225 include $(SRC_PATH_BARE)/tests/fate.mak
226 include $(SRC_PATH_BARE)/tests/fate2.mak
227
228 include $(SRC_PATH_BARE)/tests/fate/aac.mak
229 include $(SRC_PATH_BARE)/tests/fate/als.mak
230 include $(SRC_PATH_BARE)/tests/fate/fft.mak
231 include $(SRC_PATH_BARE)/tests/fate/h264.mak
232 include $(SRC_PATH_BARE)/tests/fate/mp3.mak
233 include $(SRC_PATH_BARE)/tests/fate/vorbis.mak
234 include $(SRC_PATH_BARE)/tests/fate/vp8.mak
235
236 FATE_ACODEC  = $(ACODEC_TESTS:%=fate-acodec-%)
237 FATE_VSYNTH1 = $(VCODEC_TESTS:%=fate-vsynth1-%)
238 FATE_VSYNTH2 = $(VCODEC_TESTS:%=fate-vsynth2-%)
239 FATE_VCODEC  = $(FATE_VSYNTH1) $(FATE_VSYNTH2)
240 FATE_LAVF    = $(LAVF_TESTS:%=fate-lavf-%)
241 FATE_LAVFI   = $(LAVFI_TESTS:%=fate-lavfi-%)
242 FATE_SEEK    = $(SEEK_TESTS:seek_%=fate-seek-%)
243
244 FATE = $(FATE_ACODEC)                                                   \
245        $(FATE_VCODEC)                                                   \
246        $(FATE_LAVF)                                                     \
247        $(FATE_LAVFI)                                                    \
248        $(FATE_SEEK)                                                     \
249
250 $(filter-out %-aref,$(FATE_ACODEC)): $(AREF)
251 $(filter-out %-vref,$(FATE_VCODEC)): $(VREF)
252 $(FATE_LAVF):   $(REFS)
253 $(FATE_LAVFI):  $(REFS) tools/lavfi-showfiltfmts$(EXESUF)
254 $(FATE_SEEK):   fate-codec fate-lavf tests/seek_test$(EXESUF)
255
256 $(FATE_ACODEC):  CMD = codectest acodec
257 $(FATE_VSYNTH1): CMD = codectest vsynth1
258 $(FATE_VSYNTH2): CMD = codectest vsynth2
259 $(FATE_LAVF):    CMD = lavftest
260 $(FATE_LAVFI):   CMD = lavfitest
261 $(FATE_SEEK):    CMD = seektest
262
263 fate-codec:  fate-acodec fate-vcodec
264 fate-acodec: $(FATE_ACODEC)
265 fate-vcodec: $(FATE_VCODEC)
266 fate-lavf:   $(FATE_LAVF)
267 fate-lavfi:  $(FATE_LAVFI)
268 fate-seek:   $(FATE_SEEK)
269
270 ifdef SAMPLES
271 FATE += $(FATE_TESTS)
272 fate-rsync:
273         rsync -vaLW rsync://fate-suite.libav.org/fate-suite/ $(SAMPLES)
274 else
275 fate-rsync:
276         @echo "use 'make fate-rsync SAMPLES=/path/to/samples' to sync the fate suite"
277 $(FATE_TESTS):
278         @echo "SAMPLES not specified, cannot run FATE"
279 endif
280
281 FATE_UTILS = base64 tiny_psnr
282
283 fate: $(FATE)
284
285 $(FATE): ffmpeg$(EXESUF) $(FATE_UTILS:%=tests/%$(HOSTEXESUF))
286         @echo "TEST    $(@:fate-%=%)"
287         $(Q)$(SRC_PATH)/tests/fate-run.sh $@ "$(SAMPLES)" "$(TARGET_EXEC)" "$(TARGET_PATH)" '$(CMD)' '$(CMP)' '$(REF)' '$(FUZZ)' '$(THREADS)' '$(THREAD_TYPE)'
288
289 fate-list:
290         @printf '%s\n' $(sort $(FATE))
291
292 .PHONY: all alltools *clean check config documentation examples install*
293 .PHONY: *test testprogs uninstall*