Merge commit '06edef3d5e072ef3c4face9ce946d2d9c36cc477'
[ffmpeg.git] / Makefile
1 MAIN_MAKEFILE=1
2 include config.mak
3
4 vpath %.c    $(SRC_PATH)
5 vpath %.cpp  $(SRC_PATH)
6 vpath %.h    $(SRC_PATH)
7 vpath %.inc  $(SRC_PATH)
8 vpath %.m    $(SRC_PATH)
9 vpath %.S    $(SRC_PATH)
10 vpath %.asm  $(SRC_PATH)
11 vpath %.rc   $(SRC_PATH)
12 vpath %.v    $(SRC_PATH)
13 vpath %.texi $(SRC_PATH)
14 vpath %/fate_config.sh.template $(SRC_PATH)
15
16 AVPROGS-$(CONFIG_FFMPEG)   += ffmpeg
17 AVPROGS-$(CONFIG_FFPLAY)   += ffplay
18 AVPROGS-$(CONFIG_FFPROBE)  += ffprobe
19 AVPROGS-$(CONFIG_FFSERVER) += ffserver
20
21 AVPROGS    := $(AVPROGS-yes:%=%$(PROGSSUF)$(EXESUF))
22 INSTPROGS   = $(AVPROGS-yes:%=%$(PROGSSUF)$(EXESUF))
23 PROGS      += $(AVPROGS)
24
25 AVBASENAMES  = ffmpeg ffplay ffprobe ffserver
26 ALLAVPROGS   = $(AVBASENAMES:%=%$(PROGSSUF)$(EXESUF))
27 ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF))
28
29 $(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog) += cmdutils.o))
30 $(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog)-$(CONFIG_OPENCL) += cmdutils_opencl.o))
31
32 OBJS-ffmpeg                   += ffmpeg_opt.o ffmpeg_filter.o
33 OBJS-ffmpeg-$(CONFIG_VIDEOTOOLBOX) += ffmpeg_videotoolbox.o
34 OBJS-ffmpeg-$(CONFIG_LIBMFX)  += ffmpeg_qsv.o
35 OBJS-ffmpeg-$(CONFIG_VAAPI)   += ffmpeg_vaapi.o
36 ifndef CONFIG_VIDEOTOOLBOX
37 OBJS-ffmpeg-$(CONFIG_VDA)     += ffmpeg_videotoolbox.o
38 endif
39 OBJS-ffmpeg-$(HAVE_DXVA2_LIB) += ffmpeg_dxva2.o
40 OBJS-ffmpeg-$(HAVE_VDPAU_X11) += ffmpeg_vdpau.o
41 OBJS-ffserver                 += ffserver_config.o
42
43 TESTTOOLS   = audiogen videogen rotozoom tiny_psnr tiny_ssim base64 audiomatch
44 HOSTPROGS  := $(TESTTOOLS:%=tests/%) doc/print_options
45 TOOLS       = qt-faststart trasher uncoded_frame
46 TOOLS-$(CONFIG_ZLIB) += cws2fws
47
48 # $(FFLIBS-yes) needs to be in linking order
49 FFLIBS-$(CONFIG_AVDEVICE)   += avdevice
50 FFLIBS-$(CONFIG_AVFILTER)   += avfilter
51 FFLIBS-$(CONFIG_AVFORMAT)   += avformat
52 FFLIBS-$(CONFIG_AVCODEC)    += avcodec
53 FFLIBS-$(CONFIG_AVRESAMPLE) += avresample
54 FFLIBS-$(CONFIG_POSTPROC)   += postproc
55 FFLIBS-$(CONFIG_SWRESAMPLE) += swresample
56 FFLIBS-$(CONFIG_SWSCALE)    += swscale
57
58 FFLIBS := avutil
59
60 DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.ffpreset) $(SRC_PATH)/doc/ffprobe.xsd
61 EXAMPLES_FILES := $(wildcard $(SRC_PATH)/doc/examples/*.c) $(SRC_PATH)/doc/examples/Makefile $(SRC_PATH)/doc/examples/README
62
63 SKIPHEADERS = cmdutils_common_opts.h                                    \
64               compat/w32pthreads.h
65
66 include $(SRC_PATH)/common.mak
67
68 FF_EXTRALIBS := $(FFEXTRALIBS)
69 FF_DEP_LIBS  := $(DEP_LIBS)
70 FF_STATIC_DEP_LIBS := $(STATIC_DEP_LIBS)
71
72 all: $(AVPROGS)
73
74 $(TOOLS): %$(EXESUF): %.o $(EXEOBJS)
75         $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS)
76
77 tools/cws2fws$(EXESUF): ELIBS = $(ZLIB)
78 tools/uncoded_frame$(EXESUF): $(FF_DEP_LIBS)
79 tools/uncoded_frame$(EXESUF): ELIBS = $(FF_EXTRALIBS)
80
81 config.h: .config
82 .config: $(wildcard $(FFLIBS:%=$(SRC_PATH)/lib%/all*.c))
83         @-tput bold 2>/dev/null
84         @-printf '\nWARNING: $(?F) newer than config.h, rerun configure\n\n'
85         @-tput sgr0 2>/dev/null
86
87 SUBDIR_VARS := CLEANFILES EXAMPLES FFLIBS HOSTPROGS TESTPROGS TOOLS      \
88                HEADERS ARCH_HEADERS BUILT_HEADERS SKIPHEADERS            \
89                ARMV5TE-OBJS ARMV6-OBJS ARMV8-OBJS VFP-OBJS NEON-OBJS     \
90                ALTIVEC-OBJS MMX-OBJS YASM-OBJS                           \
91                MIPSFPU-OBJS MIPSDSPR2-OBJS MIPSDSP-OBJS MSA-OBJS         \
92                MMI-OBJS OBJS SLIBOBJS HOSTOBJS TESTOBJS
93
94 define RESET
95 $(1) :=
96 $(1)-yes :=
97 endef
98
99 define DOSUBDIR
100 $(foreach V,$(SUBDIR_VARS),$(eval $(call RESET,$(V))))
101 SUBDIR := $(1)/
102 include $(SRC_PATH)/$(1)/Makefile
103 -include $(SRC_PATH)/$(1)/$(ARCH)/Makefile
104 -include $(SRC_PATH)/$(1)/$(INTRINSICS)/Makefile
105 include $(SRC_PATH)/library.mak
106 endef
107
108 $(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D))))
109
110 include $(SRC_PATH)/doc/Makefile
111
112 define DOPROG
113 OBJS-$(1) += $(1).o $(EXEOBJS) $(OBJS-$(1)-yes)
114 $(1)$(PROGSSUF)_g$(EXESUF): $$(OBJS-$(1))
115 $$(OBJS-$(1)): CFLAGS  += $(CFLAGS-$(1))
116 $(1)$(PROGSSUF)_g$(EXESUF): LDFLAGS += $(LDFLAGS-$(1))
117 $(1)$(PROGSSUF)_g$(EXESUF): FF_EXTRALIBS += $(LIBS-$(1))
118 -include $$(OBJS-$(1):.o=.d)
119 endef
120
121 $(foreach P,$(PROGS),$(eval $(call DOPROG,$(P:$(PROGSSUF)$(EXESUF)=))))
122
123 ffprobe.o cmdutils.o libavcodec/utils.o libavformat/utils.o libavdevice/avdevice.o libavfilter/avfilter.o libavutil/utils.o libpostproc/postprocess.o libswresample/swresample.o libswscale/utils.o : libavutil/ffversion.h
124
125 $(PROGS): %$(PROGSSUF)$(EXESUF): %$(PROGSSUF)_g$(EXESUF)
126         $(CP) $< $@
127         $(STRIP) $@
128
129 %$(PROGSSUF)_g$(EXESUF): %.o $(FF_DEP_LIBS)
130         $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(OBJS-$*) $(FF_EXTRALIBS)
131
132 OBJDIRS += tools
133
134 -include $(wildcard tools/*.d)
135
136 VERSION_SH  = $(SRC_PATH)/version.sh
137 GIT_LOG     = $(SRC_PATH)/.git/logs/HEAD
138
139 .version: $(wildcard $(GIT_LOG)) $(VERSION_SH) config.mak
140 .version: M=@
141
142 libavutil/ffversion.h .version:
143         $(M)$(VERSION_SH) $(SRC_PATH) libavutil/ffversion.h $(EXTRA_VERSION)
144         $(Q)touch .version
145
146 # force version.sh to run whenever version might have changed
147 -include .version
148
149 ifdef AVPROGS
150 install: install-progs install-data
151 endif
152
153 install: install-libs install-headers
154
155 install-libs: install-libs-yes
156
157 install-progs-yes:
158 install-progs-$(CONFIG_SHARED): install-libs
159
160 install-progs: install-progs-yes $(AVPROGS)
161         $(Q)mkdir -p "$(BINDIR)"
162         $(INSTALL) -c -m 755 $(INSTPROGS) "$(BINDIR)"
163
164 install-data: $(DATA_FILES) $(EXAMPLES_FILES)
165         $(Q)mkdir -p "$(DATADIR)/examples"
166         $(INSTALL) -m 644 $(DATA_FILES) "$(DATADIR)"
167         $(INSTALL) -m 644 $(EXAMPLES_FILES) "$(DATADIR)/examples"
168
169 uninstall: uninstall-libs uninstall-headers uninstall-progs uninstall-data
170
171 uninstall-progs:
172         $(RM) $(addprefix "$(BINDIR)/", $(ALLAVPROGS))
173
174 uninstall-data:
175         $(RM) -r "$(DATADIR)"
176
177 clean::
178         $(RM) $(ALLAVPROGS) $(ALLAVPROGS_G)
179         $(RM) $(CLEANSUFFIXES)
180         $(RM) $(CLEANSUFFIXES:%=tools/%)
181         $(RM) -r coverage-html
182         $(RM) -rf coverage.info coverage.info.in lcov
183
184 distclean::
185         $(RM) $(DISTCLEANSUFFIXES)
186         $(RM) config.* .config libavutil/avconfig.h .version avversion.h version.h libavutil/ffversion.h libavcodec/codec_names.h libavcodec/bsf_list.c libavformat/protocol_list.c
187 ifeq ($(SRC_LINK),src)
188         $(RM) src
189 endif
190         $(RM) -rf doc/examples/pc-uninstalled
191
192 config:
193         $(SRC_PATH)/configure $(value FFMPEG_CONFIGURATION)
194
195 check: all alltools examples testprogs fate
196
197 include $(SRC_PATH)/tests/Makefile
198
199 $(sort $(OBJDIRS)):
200         $(Q)mkdir -p $@
201
202 # Dummy rule to stop make trying to rebuild removed or renamed headers
203 %.h:
204         @:
205
206 # Disable suffix rules.  Most of the builtin rules are suffix rules,
207 # so this saves some time on slow systems.
208 .SUFFIXES:
209
210 .PHONY: all all-yes alltools check *clean config install*
211 .PHONY: testprogs uninstall*