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