Handle EXTRALIBS and LDFLAGS for libswscale and libavfilter in a simpler way.
[ffmpeg.git] / Makefile
1 #
2 # Main ffmpeg Makefile
3 # (c) 2000-2004 Fabrice Bellard
4 #
5 include config.mak
6
7 SRC_DIR = $(SRC_PATH_BARE)
8
9 vpath %.c    $(SRC_PATH_BARE)
10 vpath %.h    $(SRC_PATH_BARE)
11 vpath %.texi $(SRC_PATH_BARE)
12
13 PROGS-$(CONFIG_FFMPEG)   += ffmpeg
14 PROGS-$(CONFIG_FFPLAY)   += ffplay
15 PROGS-$(CONFIG_FFSERVER) += ffserver
16
17 PROGS       = $(addsuffix   $(EXESUF), $(PROGS-yes))
18 PROGS_G     = $(addsuffix _g$(EXESUF), $(PROGS-yes))
19 PROGS_SRCS  = $(addsuffix .c,          $(PROGS-yes)) cmdutils.c
20 MANPAGES    = $(addprefix doc/, $(addsuffix .1, $(PROGS-yes)))
21
22 BASENAMES   = ffmpeg ffplay ffserver
23 ALLPROGS    = $(addsuffix   $(EXESUF), $(BASENAMES))
24 ALLPROGS_G  = $(addsuffix _g$(EXESUF), $(BASENAMES))
25 ALLMANPAGES = $(addsuffix .1, $(BASENAMES))
26
27 ifeq ($(BUILD_SHARED),yes)
28 DEP_LIBS=libavcodec/$(SLIBPREF)avcodec$(SLIBSUF) libavformat/$(SLIBPREF)avformat$(SLIBSUF) libavdevice/$(SLIBPREF)avdevice$(SLIBSUF)
29 else
30 DEP_LIBS=libavcodec/$(LIBPREF)avcodec$(LIBSUF) libavformat/$(LIBPREF)avformat$(LIBSUF) libavdevice/$(LIBPREF)avdevice$(LIBSUF)
31 endif
32
33 ALL_TARGETS-$(CONFIG_VHOOK) += videohook
34 ALL_TARGETS-$(BUILD_DOC)    += documentation
35
36 INSTALL_TARGETS-$(CONFIG_VHOOK) += install-vhook
37 ifneq ($(PROGS),)
38 INSTALL_TARGETS-yes             += install-progs
39 INSTALL_TARGETS-$(BUILD_DOC)    += install-man
40 endif
41
42 main: lib $(PROGS_G) $(PROGS) $(ALL_TARGETS-yes)
43
44 %$(EXESUF): %_g$(EXESUF)
45         cp -p $< $@
46         $(STRIP) $@
47
48 vhook/%.o: vhook/%.c
49         $(CC) $(VHOOKCFLAGS) -c -o $@ $<
50
51 .depend: version.h $(PROGS_SRCS)
52
53 include common.mak
54
55 VHOOKCFLAGS += $(filter-out -mdynamic-no-pic,$(CFLAGS))
56
57 BASEHOOKS = fish null watermark
58 ALLHOOKS = $(BASEHOOKS) drawtext imlib2 ppm
59 ALLHOOKS_SRCS = $(addprefix vhook/, $(addsuffix .c, $(ALLHOOKS)))
60
61 HOOKS-$(HAVE_FORK)      += ppm
62 HOOKS-$(HAVE_IMLIB2)    += imlib2
63 HOOKS-$(HAVE_FREETYPE2) += drawtext
64
65 HOOKS = $(addprefix vhook/, $(addsuffix $(SLIBSUF), $(BASEHOOKS) $(HOOKS-yes)))
66
67 VHOOKCFLAGS-$(HAVE_IMLIB2) += `imlib2-config --cflags`
68 LIBS_imlib2$(SLIBSUF)       = `imlib2-config --libs`
69
70 VHOOKCFLAGS-$(HAVE_FREETYPE2) += `freetype-config --cflags`
71 LIBS_drawtext$(SLIBSUF)        = `freetype-config --libs`
72
73 VHOOKCFLAGS += $(VHOOKCFLAGS-yes)
74
75 LDFLAGS-$(CONFIG_SWSCALE) += -L$(BUILD_ROOT)/libswscale
76 LDFLAGS-$(CONFIG_AVFILTER) += -L$(BUILD_ROOT)/libavfilter
77 LDFLAGS := $(LDFLAGS-yes) -L$(BUILD_ROOT)/libavdevice -L$(BUILD_ROOT)/libavformat -L$(BUILD_ROOT)/libavcodec -L$(BUILD_ROOT)/libavutil -g $(LDFLAGS)
78
79 EXTRALIBS-$(CONFIG_AVFILTER) += -lavfilter$(BUILDSUF)
80 EXTRALIBS-$(CONFIG_SWSCALE) += -lswscale$(BUILDSUF)
81 EXTRALIBS := $(EXTRALIBS-yes) -lavdevice$(BUILDSUF) -lavformat$(BUILDSUF) -lavcodec$(BUILDSUF) -lavutil$(BUILDSUF) $(EXTRALIBS)
82
83 MAKE-yes = $(MAKE)
84 MAKE-    = : $(MAKE)
85
86 lib:
87         $(MAKE)                    -C libavutil   all
88         $(MAKE)                    -C libavcodec  all
89         $(MAKE)                    -C libavformat all
90         $(MAKE)                    -C libavdevice all
91         $(MAKE-$(CONFIG_POSTPROC)) -C libpostproc all
92         $(MAKE-$(CONFIG_SWSCALE))  -C libswscale  all
93         $(MAKE-$(CONFIG_AVFILTER)) -C libavfilter all
94
95 ffplay_g$(EXESUF): EXTRALIBS += $(SDL_LIBS)
96 ffserver_g$(EXESUF): LDFLAGS += $(FFSERVERLDFLAGS)
97
98 %_g$(EXESUF): %.o cmdutils.o .libs
99         $(CC) $(LDFLAGS) -o $@ $< cmdutils.o $(EXTRALIBS)
100
101 SVN_ENTRIES = $(SRC_PATH_BARE)/.svn/entries
102 ifeq ($(wildcard $(SVN_ENTRIES)),$(SVN_ENTRIES))
103 version.h: $(SVN_ENTRIES)
104 endif
105
106 version.h:
107         $(SRC_PATH)/version.sh $(SRC_PATH)
108
109 output_example$(EXESUF): output_example.o .libs
110         $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(EXTRALIBS)
111
112 tools/%$(EXESUF): tools/%.c
113         $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(EXTRALIBS)
114
115 ffplay.o .depend: CFLAGS += $(SDL_CFLAGS)
116
117 ffmpeg.o ffplay.o ffserver.o: version.h
118
119 # vhooks compile fine without libav*, but need them nonetheless.
120 videohook: .libs $(HOOKS)
121
122 vhook/%$(SLIBSUF): vhook/%.o
123         $(CC) $(LDFLAGS) -o $@ $(VHOOKSHFLAGS) $< $(VHOOKLIBS) $(LIBS_$(@F))
124
125 documentation: $(addprefix doc/, ffmpeg-doc.html faq.html ffserver-doc.html \
126                                  ffplay-doc.html general.html hooks.html \
127                                  $(ALLMANPAGES))
128
129 doc/%.html: doc/%.texi
130         texi2html -monolithic -number $<
131         mv $(@F) $@
132
133 doc/%.pod: doc/%-doc.texi
134         doc/texi2pod.pl $< $@
135
136 doc/%.1: doc/%.pod
137         pod2man --section=1 --center=" " --release=" " $< > $@
138
139 install: $(INSTALL_TARGETS-yes)
140
141 INSTALL_PROGS_TARGETS-$(BUILD_SHARED) = install-libs
142
143 install-progs: $(PROGS) $(INSTALL_PROGS_TARGETS-yes)
144         install -d "$(BINDIR)"
145         install -c -m 755 $(PROGS) "$(BINDIR)"
146
147 install-man:
148         install -d "$(MANDIR)/man1"
149         install -m 644 $(MANPAGES) "$(MANDIR)/man1"
150
151 install-vhook: videohook
152         install -d "$(SHLIBDIR)/vhook"
153         install -m 755 $(HOOKS) "$(SHLIBDIR)/vhook"
154
155 install-libs:
156         $(MAKE)                    -C libavutil   install-libs
157         $(MAKE)                    -C libavcodec  install-libs
158         $(MAKE)                    -C libavformat install-libs
159         $(MAKE)                    -C libavdevice install-libs
160         $(MAKE-$(CONFIG_POSTPROC)) -C libpostproc install-libs
161         $(MAKE-$(CONFIG_SWSCALE))  -C libswscale  install-libs
162         $(MAKE-$(CONFIG_AVFILTER)) -C libavfilter install-libs
163
164 install-headers::
165         $(MAKE)                    -C libavutil   install-headers
166         $(MAKE)                    -C libavcodec  install-headers
167         $(MAKE)                    -C libavformat install-headers
168         $(MAKE)                    -C libavdevice install-headers
169         $(MAKE-$(CONFIG_POSTPROC)) -C libpostproc install-headers
170         $(MAKE)                    -C libswscale  install-headers
171         $(MAKE-$(CONFIG_AVFILTER)) -C libavfilter install-headers
172
173 uninstall: uninstall-progs uninstall-man uninstall-vhook
174
175 uninstall-progs:
176         rm -f $(addprefix "$(BINDIR)/", $(ALLPROGS))
177
178 uninstall-man:
179         rm -f $(addprefix "$(MANDIR)/man1/",$(ALLMANPAGES))
180
181 uninstall-vhook:
182         rm -f $(addprefix "$(SHLIBDIR)/",$(ALLHOOKS_SRCS:.c=$(SLIBSUF)))
183         -rmdir "$(SHLIBDIR)/vhook/"
184
185 uninstall-libs::
186         $(MAKE) -C libavutil   uninstall-libs
187         $(MAKE) -C libavcodec  uninstall-libs
188         $(MAKE) -C libavformat uninstall-libs
189         $(MAKE) -C libavdevice uninstall-libs
190         $(MAKE) -C libpostproc uninstall-libs
191         $(MAKE) -C libswscale  uninstall-libs
192         $(MAKE) -C libavfilter uninstall-libs
193
194 uninstall-headers::
195         $(MAKE) -C libavutil   uninstall-headers
196         $(MAKE) -C libavcodec  uninstall-headers
197         $(MAKE) -C libavformat uninstall-headers
198         $(MAKE) -C libavdevice uninstall-headers
199         $(MAKE) -C libpostproc uninstall-headers
200         $(MAKE) -C libswscale  uninstall-headers
201         $(MAKE) -C libavfilter uninstall-headers
202         -rmdir "$(INCDIR)"
203
204 depend dep: .vhookdep
205         $(MAKE)                    -C libavutil   depend
206         $(MAKE)                    -C libavcodec  depend
207         $(MAKE)                    -C libavformat depend
208         $(MAKE)                    -C libavdevice depend
209         $(MAKE-$(CONFIG_POSTPROC)) -C libpostproc depend
210         $(MAKE-$(CONFIG_SWSCALE))  -C libswscale  depend
211         $(MAKE-$(CONFIG_AVFILTER)) -C libavfilter depend
212
213 .vhookdep: $(ALLHOOKS_SRCS) version.h
214         $(VHOOK_DEPEND_CMD) > $@
215
216 $(DEP_LIBS): lib
217
218 .libs: $(DEP_LIBS)
219         touch $@
220
221 clean::
222         $(MAKE) -C libavutil   clean
223         $(MAKE) -C libavcodec  clean
224         $(MAKE) -C libavformat clean
225         $(MAKE) -C libavdevice clean
226         $(MAKE) -C libpostproc clean
227         $(MAKE) -C libswscale  clean
228         $(MAKE) -C libavfilter clean
229         rm -f .libs gmon.out TAGS $(ALLPROGS) $(ALLPROGS_G) \
230            output_example$(EXESUF)
231         rm -f doc/*.html doc/*.pod doc/*.1
232         rm -rf tests/vsynth1 tests/vsynth2 tests/data tests/asynth1.sw tests/*~
233         rm -f $(addprefix tests/,$(addsuffix $(EXESUF),audiogen videogen rotozoom seek_test tiny_psnr))
234         rm -f $(addprefix tools/,$(addsuffix $(EXESUF),cws2fws pktdumper qt-faststart trasher))
235         rm -f vhook/*.o vhook/*~ vhook/*.so vhook/*.dylib vhook/*.dll
236
237 distclean::
238         $(MAKE) -C libavutil   distclean
239         $(MAKE) -C libavcodec  distclean
240         $(MAKE) -C libavformat distclean
241         $(MAKE) -C libavdevice distclean
242         $(MAKE) -C libpostproc distclean
243         $(MAKE) -C libswscale  distclean
244         $(MAKE) -C libavfilter distclean
245         rm -f .vhookdep version.h config.* *.pc
246
247 # regression tests
248
249 fulltest test: codectest libavtest seektest
250
251 FFMPEG_REFFILE   = $(SRC_PATH)/tests/ffmpeg.regression.ref
252 FFSERVER_REFFILE = $(SRC_PATH)/tests/ffserver.regression.ref
253 LIBAV_REFFILE    = $(SRC_PATH)/tests/libav.regression.ref
254 ROTOZOOM_REFFILE = $(SRC_PATH)/tests/rotozoom.regression.ref
255 SEEK_REFFILE     = $(SRC_PATH)/tests/seek.regression.ref
256
257 CODEC_TESTS = $(addprefix regtest-,             \
258         mpeg                                    \
259         mpeg2                                   \
260         mpeg2thread                             \
261         msmpeg4v2                               \
262         msmpeg4                                 \
263         wmv1                                    \
264         wmv2                                    \
265         h261                                    \
266         h263                                    \
267         h263p                                   \
268         mpeg4                                   \
269         huffyuv                                 \
270         rc                                      \
271         mpeg4adv                                \
272         mpeg4thread                             \
273         error                                   \
274         mpeg4nr                                 \
275         mpeg1b                                  \
276         mjpeg                                   \
277         ljpeg                                   \
278         jpegls                                  \
279         rv10                                    \
280         rv20                                    \
281         asv1                                    \
282         asv2                                    \
283         flv                                     \
284         ffv1                                    \
285         snow                                    \
286         snowll                                  \
287         dv                                      \
288         dv50                                    \
289         svq1                                    \
290         flashsv                                 \
291         mp2                                     \
292         ac3                                     \
293         g726                                    \
294         adpcm_ima_wav                           \
295         adpcm_ima_qt                            \
296         adpcm_ms                                \
297         adpcm_yam                               \
298         adpcm_swf                               \
299         flac                                    \
300         wma                                     \
301     )
302
303 LAVF_TESTS = $(addprefix regtest-,              \
304         avi                                     \
305         asf                                     \
306         rm                                      \
307         mpg                                     \
308         ts                                      \
309         swf                                     \
310         ffm                                     \
311         flv_fmt                                 \
312         mov                                     \
313         dv_fmt                                  \
314         gxf                                     \
315         nut                                     \
316         mkv                                     \
317         pbmpipe                                 \
318         pgmpipe                                 \
319         ppmpipe                                 \
320         gif                                     \
321         yuv4mpeg                                \
322         pgm                                     \
323         ppm                                     \
324         bmp                                     \
325         tga                                     \
326         tiff                                    \
327         sgi                                     \
328         jpg                                     \
329         wav                                     \
330         alaw                                    \
331         mulaw                                   \
332         au                                      \
333         mmf                                     \
334         aiff                                    \
335         voc                                     \
336         ogg                                     \
337         pixfmt                                  \
338     )
339
340 REGFILES = $(addprefix tests/data/,$(addsuffix .$(1),$(2:regtest-%=%)))
341
342 CODEC_ROTOZOOM = $(call REGFILES,rotozoom.regression,$(CODEC_TESTS))
343 CODEC_VSYNTH   = $(call REGFILES,vsynth.regression,$(CODEC_TESTS))
344
345 LAVF_REGFILES = $(call REGFILES,lavf.regression,$(LAVF_TESTS))
346
347 LAVF_REG     = tests/data/lavf.regression
348 ROTOZOOM_REG = tests/data/rotozoom.regression
349 VSYNTH_REG   = tests/data/vsynth.regression
350
351 codectest: $(VSYNTH_REG) $(ROTOZOOM_REG)
352         diff -u -w $(FFMPEG_REFFILE)   $(VSYNTH_REG)
353         diff -u -w $(ROTOZOOM_REFFILE) $(ROTOZOOM_REG)
354
355 libavtest: $(LAVF_REG)
356         diff -u -w $(LIBAV_REFFILE) $(LAVF_REG)
357
358 $(VSYNTH_REG) $(ROTOZOOM_REG) $(LAVF_REG):
359         cat $^ > $@
360
361 $(LAVF_REG):     $(LAVF_REGFILES)
362 $(ROTOZOOM_REG): $(CODEC_ROTOZOOM)
363 $(VSYNTH_REG):   $(CODEC_VSYNTH)
364
365 $(CODEC_VSYNTH) $(CODEC_ROTOZOOM): $(CODEC_TESTS)
366
367 $(LAVF_REGFILES): $(LAVF_TESTS)
368
369 $(CODEC_TESTS) $(LAVF_TESTS): regtest-ref
370
371 regtest-ref: ffmpeg$(EXESUF) tests/vsynth1/00.pgm tests/vsynth2/00.pgm tests/asynth1.sw
372
373 $(CODEC_TESTS) regtest-ref: tests/tiny_psnr$(EXESUF)
374         $(SRC_PATH)/tests/regression.sh $@ vsynth   tests/vsynth1 a
375         $(SRC_PATH)/tests/regression.sh $@ rotozoom tests/vsynth2 a
376
377 $(LAVF_TESTS):
378         $(SRC_PATH)/tests/regression.sh $@ lavf tests/vsynth1 b
379
380 seektest: codectest libavtest tests/seek_test$(EXESUF)
381         $(SRC_PATH)/tests/seek_test.sh $(SEEK_REFFILE)
382
383 test-server: ffserver$(EXESUF) tests/vsynth1/00.pgm tests/asynth1.sw
384         @echo
385         @echo "Unfortunately ffserver is broken and therefore its regression"
386         @echo "test fails randomly. Treat the results accordingly."
387         @echo
388         $(SRC_PATH)/tests/server-regression.sh $(FFSERVER_REFFILE) $(SRC_PATH)/tests/test.conf
389
390 ifeq ($(CONFIG_SWSCALE),yes)
391 test-server codectest $(CODEC_TESTS) libavtest: swscale_error
392 swscale_error:
393         @echo
394         @echo "This regression test is incompatible with --enable-swscale."
395         @echo
396         @exit 1
397 endif
398
399 tests/vsynth1/00.pgm: tests/videogen$(EXESUF)
400         mkdir -p tests/vsynth1
401         $(BUILD_ROOT)/$< 'tests/vsynth1/'
402
403 tests/vsynth2/00.pgm: tests/rotozoom$(EXESUF)
404         mkdir -p tests/vsynth2
405         $(BUILD_ROOT)/$< 'tests/vsynth2/' $(SRC_PATH)/tests/lena.pnm
406
407 tests/asynth1.sw: tests/audiogen$(EXESUF)
408         $(BUILD_ROOT)/$< $@
409
410 %$(EXESUF): %.c
411         $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $<
412
413 tests/seek_test$(EXESUF): tests/seek_test.c .libs
414         $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $< $(EXTRALIBS)
415
416
417 .PHONY: lib videohook documentation TAGS
418 .PHONY: codectest libavtest seektest test-server fulltest test
419 .PHONY: $(CODEC_TESTS) $(LAVF_TESTS) regtest-ref swscale-error
420
421 -include .vhookdep