build: Generalize yasm/nasm-related variable names
[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 %.cu   $(SRC_PATH)
15 vpath %.ptx  $(SRC_PATH)
16 vpath %/fate_config.sh.template $(SRC_PATH)
17
18 AVPROGS-$(CONFIG_FFMPEG)   += ffmpeg
19 AVPROGS-$(CONFIG_FFPLAY)   += ffplay
20 AVPROGS-$(CONFIG_FFPROBE)  += ffprobe
21 AVPROGS-$(CONFIG_FFSERVER) += ffserver
22
23 AVPROGS    := $(AVPROGS-yes:%=%$(PROGSSUF)$(EXESUF))
24 INSTPROGS   = $(AVPROGS-yes:%=%$(PROGSSUF)$(EXESUF))
25 PROGS      += $(AVPROGS)
26
27 AVBASENAMES  = ffmpeg ffplay ffprobe ffserver
28 ALLAVPROGS   = $(AVBASENAMES:%=%$(PROGSSUF)$(EXESUF))
29 ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF))
30
31 $(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog) += cmdutils.o))
32 $(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog)-$(CONFIG_OPENCL) += cmdutils_opencl.o))
33
34 OBJS-ffmpeg                   += ffmpeg_opt.o ffmpeg_filter.o ffmpeg_hw.o
35 OBJS-ffmpeg-$(CONFIG_VIDEOTOOLBOX) += ffmpeg_videotoolbox.o
36 OBJS-ffmpeg-$(CONFIG_LIBMFX)  += ffmpeg_qsv.o
37 ifndef CONFIG_VIDEOTOOLBOX
38 OBJS-ffmpeg-$(CONFIG_VDA)     += ffmpeg_videotoolbox.o
39 endif
40 OBJS-ffmpeg-$(CONFIG_CUVID)   += ffmpeg_cuvid.o
41 OBJS-ffmpeg-$(HAVE_DXVA2_LIB) += ffmpeg_dxva2.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 = compat/w32pthreads.h
63
64 # first so "all" becomes default target
65 all: all-yes
66
67 include $(SRC_PATH)/tools/Makefile
68 include $(SRC_PATH)/ffbuild/common.mak
69
70 FF_EXTRALIBS := $(FFEXTRALIBS)
71 FF_DEP_LIBS  := $(DEP_LIBS)
72 FF_STATIC_DEP_LIBS := $(STATIC_DEP_LIBS)
73
74 all: $(AVPROGS)
75
76 $(TOOLS): %$(EXESUF): %.o
77         $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS)
78
79 target_dec_%_fuzzer$(EXESUF): target_dec_%_fuzzer.o $(FF_DEP_LIBS)
80         $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS) $(FF_EXTRALIBS) $(LIBFUZZER_PATH)
81
82 tools/cws2fws$(EXESUF): ELIBS = $(ZLIB)
83 tools/sofa2wavs$(EXESUF): ELIBS = $(FF_EXTRALIBS)
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 X86ASM-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 define DOSUBDIR
112 $(foreach V,$(SUBDIR_VARS),$(eval $(call RESET,$(V))))
113 SUBDIR := $(1)/
114 include $(SRC_PATH)/$(1)/Makefile
115 -include $(SRC_PATH)/$(1)/$(ARCH)/Makefile
116 -include $(SRC_PATH)/$(1)/$(INTRINSICS)/Makefile
117 include $(SRC_PATH)/ffbuild/library.mak
118 endef
119
120 $(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D))))
121
122 include $(SRC_PATH)/doc/Makefile
123
124 define DOPROG
125 OBJS-$(1) += $(1).o $(OBJS-$(1)-yes)
126 $(1)$(PROGSSUF)_g$(EXESUF): $$(OBJS-$(1))
127 $$(OBJS-$(1)): CFLAGS  += $(CFLAGS-$(1))
128 $(1)$(PROGSSUF)_g$(EXESUF): LDFLAGS += $(LDFLAGS-$(1))
129 $(1)$(PROGSSUF)_g$(EXESUF): FF_EXTRALIBS += $(EXTRALIBS-$(1))
130 -include $$(OBJS-$(1):.o=.d)
131 endef
132
133 $(foreach P,$(PROGS),$(eval $(call DOPROG,$(P:$(PROGSSUF)$(EXESUF)=))))
134
135 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
136
137 $(PROGS): %$(PROGSSUF)$(EXESUF): %$(PROGSSUF)_g$(EXESUF)
138         $(CP) $< $@
139         $(STRIP) $@
140
141 %$(PROGSSUF)_g$(EXESUF): %.o $(FF_DEP_LIBS)
142         $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(OBJS-$*) $(FF_EXTRALIBS)
143
144 VERSION_SH  = $(SRC_PATH)/ffbuild/version.sh
145 GIT_LOG     = $(SRC_PATH)/.git/logs/HEAD
146
147 .version: $(wildcard $(GIT_LOG)) $(VERSION_SH) ffbuild/config.mak
148 .version: M=@
149
150 libavutil/ffversion.h .version:
151         $(M)$(VERSION_SH) $(SRC_PATH) libavutil/ffversion.h $(EXTRA_VERSION)
152         $(Q)touch .version
153
154 # force version.sh to run whenever version might have changed
155 -include .version
156
157 ifdef AVPROGS
158 install: install-progs install-data
159 endif
160
161 install: install-libs install-headers
162
163 install-libs: install-libs-yes
164
165 install-progs-yes:
166 install-progs-$(CONFIG_SHARED): install-libs
167
168 install-progs: install-progs-yes $(AVPROGS)
169         $(Q)mkdir -p "$(BINDIR)"
170         $(INSTALL) -c -m 755 $(INSTPROGS) "$(BINDIR)"
171
172 install-data: $(DATA_FILES) $(EXAMPLES_FILES)
173         $(Q)mkdir -p "$(DATADIR)/examples"
174         $(INSTALL) -m 644 $(DATA_FILES) "$(DATADIR)"
175         $(INSTALL) -m 644 $(EXAMPLES_FILES) "$(DATADIR)/examples"
176
177 uninstall: uninstall-libs uninstall-headers uninstall-progs uninstall-data
178
179 uninstall-progs:
180         $(RM) $(addprefix "$(BINDIR)/", $(ALLAVPROGS))
181
182 uninstall-data:
183         $(RM) -r "$(DATADIR)"
184
185 clean::
186         $(RM) $(ALLAVPROGS) $(ALLAVPROGS_G)
187         $(RM) $(CLEANSUFFIXES)
188         $(RM) $(CLEANSUFFIXES:%=compat/msvcrt/%)
189         $(RM) $(CLEANSUFFIXES:%=compat/atomics/pthread/%)
190         $(RM) $(CLEANSUFFIXES:%=compat/%)
191         $(RM) -r coverage-html
192         $(RM) -rf coverage.info coverage.info.in lcov
193
194 distclean::
195         $(RM) $(DISTCLEANSUFFIXES)
196         $(RM) .version avversion.h config.asm config.h mapfile  \
197                 ffbuild/.config ffbuild/config.* libavutil/avconfig.h \
198                 version.h libavutil/ffversion.h libavcodec/codec_names.h \
199                 libavcodec/bsf_list.c libavformat/protocol_list.c
200 ifeq ($(SRC_LINK),src)
201         $(RM) src
202 endif
203         $(RM) -rf doc/examples/pc-uninstalled
204
205 config:
206         $(SRC_PATH)/configure $(value FFMPEG_CONFIGURATION)
207
208 check: all alltools examples testprogs fate
209
210 include $(SRC_PATH)/tests/Makefile
211
212 $(sort $(OBJDIRS)):
213         $(Q)mkdir -p $@
214
215 # Dummy rule to stop make trying to rebuild removed or renamed headers
216 %.h:
217         @:
218
219 # Disable suffix rules.  Most of the builtin rules are suffix rules,
220 # so this saves some time on slow systems.
221 .SUFFIXES:
222
223 .PHONY: all all-yes alltools check *clean config install*
224 .PHONY: testprogs uninstall*