Merge commit '92db5083077a8b0f8e1050507671b456fd155125'
[ffmpeg.git] / Makefile
1 MAIN_MAKEFILE=1
2 include ffbuild/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-$(CONFIG_CUVID)   += ffmpeg_cuvid.o
40 OBJS-ffmpeg-$(HAVE_DXVA2_LIB) += ffmpeg_dxva2.o
41 OBJS-ffmpeg-$(HAVE_VDPAU_X11) += ffmpeg_vdpau.o
42 OBJS-ffserver                 += ffserver_config.o
43
44 TESTTOOLS   = audiogen videogen rotozoom tiny_psnr tiny_ssim base64 audiomatch
45 HOSTPROGS  := $(TESTTOOLS:%=tests/%) doc/print_options
46
47 # $(FFLIBS-yes) needs to be in linking order
48 FFLIBS-$(CONFIG_AVDEVICE)   += avdevice
49 FFLIBS-$(CONFIG_AVFILTER)   += avfilter
50 FFLIBS-$(CONFIG_AVFORMAT)   += avformat
51 FFLIBS-$(CONFIG_AVCODEC)    += avcodec
52 FFLIBS-$(CONFIG_AVRESAMPLE) += avresample
53 FFLIBS-$(CONFIG_POSTPROC)   += postproc
54 FFLIBS-$(CONFIG_SWRESAMPLE) += swresample
55 FFLIBS-$(CONFIG_SWSCALE)    += swscale
56
57 FFLIBS := avutil
58
59 DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.ffpreset) $(SRC_PATH)/doc/ffprobe.xsd
60 EXAMPLES_FILES := $(wildcard $(SRC_PATH)/doc/examples/*.c) $(SRC_PATH)/doc/examples/Makefile $(SRC_PATH)/doc/examples/README
61
62 SKIPHEADERS = cmdutils_common_opts.h                                    \
63               compat/w32pthreads.h
64
65 # first so "all" becomes default target
66 all: all-yes
67
68 include $(SRC_PATH)/tools/Makefile
69 include $(SRC_PATH)/ffbuild/common.mak
70
71 FF_EXTRALIBS := $(FFEXTRALIBS)
72 FF_DEP_LIBS  := $(DEP_LIBS)
73 FF_STATIC_DEP_LIBS := $(STATIC_DEP_LIBS)
74
75 all: $(AVPROGS)
76
77 $(TOOLS): %$(EXESUF): %.o
78         $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS)
79
80 target_dec_%_fuzzer$(EXESUF): target_dec_%_fuzzer.o $(FF_DEP_LIBS)
81         $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS) $(FF_EXTRALIBS) $(LIBFUZZER_PATH)
82
83 tools/cws2fws$(EXESUF): ELIBS = $(ZLIB)
84 tools/uncoded_frame$(EXESUF): $(FF_DEP_LIBS)
85 tools/uncoded_frame$(EXESUF): ELIBS = $(FF_EXTRALIBS)
86 tools/target_dec_%_fuzzer$(EXESUF): $(FF_DEP_LIBS)
87
88 CONFIGURABLE_COMPONENTS =                                           \
89     $(wildcard $(FFLIBS:%=$(SRC_PATH)/lib%/all*.c))                 \
90     $(SRC_PATH)/libavcodec/bitstream_filters.c                      \
91     $(SRC_PATH)/libavformat/protocols.c                             \
92
93 config.h: ffbuild/.config
94 ffbuild/.config: $(CONFIGURABLE_COMPONENTS)
95         @-tput bold 2>/dev/null
96         @-printf '\nWARNING: $(?) newer than config.h, rerun configure\n\n'
97         @-tput sgr0 2>/dev/null
98
99 SUBDIR_VARS := CLEANFILES EXAMPLES FFLIBS HOSTPROGS TESTPROGS TOOLS      \
100                HEADERS ARCH_HEADERS BUILT_HEADERS SKIPHEADERS            \
101                ARMV5TE-OBJS ARMV6-OBJS ARMV8-OBJS VFP-OBJS NEON-OBJS     \
102                ALTIVEC-OBJS VSX-OBJS MMX-OBJS YASM-OBJS                  \
103                MIPSFPU-OBJS MIPSDSPR2-OBJS MIPSDSP-OBJS MSA-OBJS         \
104                MMI-OBJS OBJS SLIBOBJS HOSTOBJS TESTOBJS
105
106 define RESET
107 $(1) :=
108 $(1)-yes :=
109 endef
110
111 ifdef CONFIG_RAISE_MAJOR
112 RAISE_MAJOR = 100
113 else
114 RAISE_MAJOR = 0
115 endif
116
117 define DOSUBDIR
118 $(foreach V,$(SUBDIR_VARS),$(eval $(call RESET,$(V))))
119 SUBDIR := $(1)/
120 include $(SRC_PATH)/$(1)/Makefile
121 -include $(SRC_PATH)/$(1)/$(ARCH)/Makefile
122 -include $(SRC_PATH)/$(1)/$(INTRINSICS)/Makefile
123 include $(SRC_PATH)/ffbuild/library.mak
124 endef
125
126 $(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D))))
127
128 include $(SRC_PATH)/doc/Makefile
129
130 define DOPROG
131 OBJS-$(1) += $(1).o $(OBJS-$(1)-yes)
132 $(1)$(PROGSSUF)_g$(EXESUF): $$(OBJS-$(1))
133 $$(OBJS-$(1)): CFLAGS  += $(CFLAGS-$(1))
134 $(1)$(PROGSSUF)_g$(EXESUF): LDFLAGS += $(LDFLAGS-$(1))
135 $(1)$(PROGSSUF)_g$(EXESUF): FF_EXTRALIBS += $(EXTRALIBS-$(1))
136 -include $$(OBJS-$(1):.o=.d)
137 endef
138
139 $(foreach P,$(PROGS),$(eval $(call DOPROG,$(P:$(PROGSSUF)$(EXESUF)=))))
140
141 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
142
143 $(PROGS): %$(PROGSSUF)$(EXESUF): %$(PROGSSUF)_g$(EXESUF)
144         $(CP) $< $@
145         $(STRIP) $@
146
147 %$(PROGSSUF)_g$(EXESUF): %.o $(FF_DEP_LIBS)
148         $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(OBJS-$*) $(FF_EXTRALIBS)
149
150 VERSION_SH  = $(SRC_PATH)/ffbuild/version.sh
151 GIT_LOG     = $(SRC_PATH)/.git/logs/HEAD
152
153 .version: $(wildcard $(GIT_LOG)) $(VERSION_SH) ffbuild/config.mak
154 .version: M=@
155
156 libavutil/ffversion.h .version:
157         $(M)$(VERSION_SH) $(SRC_PATH) libavutil/ffversion.h $(EXTRA_VERSION)
158         $(Q)touch .version
159
160 # force version.sh to run whenever version might have changed
161 -include .version
162
163 ifdef AVPROGS
164 install: install-progs install-data
165 endif
166
167 install: install-libs install-headers
168
169 install-libs: install-libs-yes
170
171 install-progs-yes:
172 install-progs-$(CONFIG_SHARED): install-libs
173
174 install-progs: install-progs-yes $(AVPROGS)
175         $(Q)mkdir -p "$(BINDIR)"
176         $(INSTALL) -c -m 755 $(INSTPROGS) "$(BINDIR)"
177
178 install-data: $(DATA_FILES) $(EXAMPLES_FILES)
179         $(Q)mkdir -p "$(DATADIR)/examples"
180         $(INSTALL) -m 644 $(DATA_FILES) "$(DATADIR)"
181         $(INSTALL) -m 644 $(EXAMPLES_FILES) "$(DATADIR)/examples"
182
183 uninstall: uninstall-libs uninstall-headers uninstall-progs uninstall-data
184
185 uninstall-progs:
186         $(RM) $(addprefix "$(BINDIR)/", $(ALLAVPROGS))
187
188 uninstall-data:
189         $(RM) -r "$(DATADIR)"
190
191 clean::
192         $(RM) $(ALLAVPROGS) $(ALLAVPROGS_G)
193         $(RM) $(CLEANSUFFIXES)
194         $(RM) $(CLEANSUFFIXES:%=compat/msvcrt/%)
195         $(RM) $(CLEANSUFFIXES:%=compat/atomics/pthread/%)
196         $(RM) $(CLEANSUFFIXES:%=compat/%)
197         $(RM) -r coverage-html
198         $(RM) -rf coverage.info coverage.info.in lcov
199
200 distclean::
201         $(RM) $(DISTCLEANSUFFIXES)
202         $(RM) .version avversion.h config.asm config.h mapfile  \
203                 ffbuild/.config ffbuild/config.* libavutil/avconfig.h \
204                 version.h libavutil/ffversion.h libavcodec/codec_names.h \
205                 libavcodec/bsf_list.c libavformat/protocol_list.c
206 ifeq ($(SRC_LINK),src)
207         $(RM) src
208 endif
209         $(RM) -rf doc/examples/pc-uninstalled
210
211 config:
212         $(SRC_PATH)/configure $(value FFMPEG_CONFIGURATION)
213
214 check: all alltools examples testprogs fate
215
216 include $(SRC_PATH)/tests/Makefile
217
218 $(sort $(OBJDIRS)):
219         $(Q)mkdir -p $@
220
221 # Dummy rule to stop make trying to rebuild removed or renamed headers
222 %.h:
223         @:
224
225 # Disable suffix rules.  Most of the builtin rules are suffix rules,
226 # so this saves some time on slow systems.
227 .SUFFIXES:
228
229 .PHONY: all all-yes alltools check *clean config install*
230 .PHONY: testprogs uninstall*