7b1e55015bff299bf7ae2ad08d7739bf124f66e1
[libav.git] / Makefile
1 include config.mak
2
3 vpath %.c $(SRC_PATH)
4 vpath %.m $(SRC_PATH)
5 vpath %.h $(SRC_PATH)
6 vpath %.S $(SRC_PATH)
7 vpath %.asm $(SRC_PATH)
8 vpath %.v $(SRC_PATH)
9 vpath %.texi $(SRC_PATH)
10
11 ifndef V
12 Q = @
13 ECHO = printf "$(1)\t%s\n" $(2)
14 BRIEF = CC HOSTCC HOSTLD AS YASM AR LD
15 SILENT = DEPCC DEPHOSTCC DEPAS DEPYASM RANLIB RM STRIP
16 MSG = $@
17 M = @$(call ECHO,$(TAG),$@);
18 $(foreach VAR,$(BRIEF), \
19 $(eval override $(VAR) = @$$(call ECHO,$(VAR),$$(MSG)); $($(VAR))))
20 $(foreach VAR,$(SILENT),$(eval override $(VAR) = @$($(VAR))))
21 $(eval INSTALL = @$(call ECHO,INSTALL,$$(^:$(SRC_PATH)/%=%)); $(INSTALL))
22 endif
23
24 ALLFFLIBS = avcodec avdevice avfilter avformat avresample avutil swscale
25
26 IFLAGS := -I. -I$(SRC_PATH)
27 CPPFLAGS := $(IFLAGS) $(CPPFLAGS)
28 CFLAGS += $(ECFLAGS)
29 CCFLAGS = $(CPPFLAGS) $(CFLAGS)
30 OBJCFLAGS += $(EOBJCFLAGS)
31 OBJCCFLAGS = $(CPPFLAGS) $(CFLAGS) $(OBJCFLAGS)
32 ASFLAGS := $(CPPFLAGS) $(ASFLAGS)
33 YASMFLAGS += $(IFLAGS:%=%/) -Pconfig.asm
34 HOSTCCFLAGS = $(IFLAGS) $(HOSTCPPFLAGS) $(HOSTCFLAGS)
35 LDFLAGS := $(ALLFFLIBS:%=$(LD_PATH)lib%) $(LDFLAGS)
36
37 define COMPILE
38 $(call $(1)DEP,$(1))
39 $($(1)) $($(1)FLAGS) $($(1)_DEPFLAGS) $($(1)_C) $($(1)_O) $<
40 endef
41
42 COMPILE_C = $(call COMPILE,CC)
43 COMPILE_S = $(call COMPILE,AS)
44 COMPILE_M = $(call COMPILE,OBJCC)
45 COMPILE_HOSTC = $(call COMPILE,HOSTCC)
46
47 %.o: %.c
48 $(COMPILE_C)
49
50 %.o: %.S
51 $(COMPILE_S)
52
53 %.o: %.m
54 $(COMPILE_M)
55
56 %_host.o: %.c
57 $(COMPILE_HOSTC)
58
59 %.i: %.c
60 $(CC) $(CCFLAGS) $(CC_E) $<
61
62 %.h.c:
63 $(Q)echo '#include "$*.h"' >$@
64
65 %.ver: %.v
66 $(Q)sed 's/$$MAJOR/$($(basename $(@F))_VERSION_MAJOR)/' $^ | sed -e 's/:/:\
67 /' -e 's/; /;\
68 /g' > $@
69
70 %.c %.h: TAG = GEN
71
72 AVPROGS-$(CONFIG_AVCONV) += avconv
73 AVPROGS-$(CONFIG_AVPLAY) += avplay
74 AVPROGS-$(CONFIG_AVPROBE) += avprobe
75
76 AVPROGS := $(AVPROGS-yes:%=%$(EXESUF))
77 PROGS += $(AVPROGS)
78
79 AVBASENAMES = avconv avplay avprobe
80 ALLAVPROGS = $(AVBASENAMES:%=%$(EXESUF))
81
82 $(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog) += cmdutils.o))
83
84 OBJS-avconv += avconv_opt.o avconv_filter.o
85 OBJS-avconv-$(HAVE_VDPAU_X11) += avconv_vdpau.o
86 OBJS-avconv-$(HAVE_DXVA2_LIB) += avconv_dxva2.o
87 OBJS-avconv-$(CONFIG_VDA) += avconv_vda.o
88 OBJS-avconv-$(CONFIG_LIBMFX) += avconv_qsv.o
89
90 TESTTOOLS = audiogen videogen rotozoom tiny_psnr base64
91 HOSTPROGS := $(TESTTOOLS:%=tests/%) doc/print_options
92 TOOLS = qt-faststart trasher
93 TOOLS-$(CONFIG_ZLIB) += cws2fws
94
95 # $(FFLIBS-yes) needs to be in linking order
96 FFLIBS-$(CONFIG_AVDEVICE) += avdevice
97 FFLIBS-$(CONFIG_AVFILTER) += avfilter
98 FFLIBS-$(CONFIG_AVFORMAT) += avformat
99 FFLIBS-$(CONFIG_AVCODEC) += avcodec
100 FFLIBS-$(CONFIG_AVRESAMPLE) += avresample
101 FFLIBS-$(CONFIG_SWSCALE) += swscale
102
103 FFLIBS := avutil
104
105 DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.avpreset)
106
107 SKIPHEADERS = cmdutils_common_opts.h compat/w32pthreads.h
108
109 include $(SRC_PATH)/common.mak
110
111 FF_EXTRALIBS := $(FFEXTRALIBS)
112 FF_DEP_LIBS := $(DEP_LIBS)
113 FF_STATIC_DEP_LIBS := $(STATIC_DEP_LIBS)
114
115 all: $(AVPROGS)
116
117 $(TOOLS): %$(EXESUF): %.o $(EXEOBJS)
118 $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS)
119
120 tools/cws2fws$(EXESUF): ELIBS = $(ZLIB)
121
122 config.h: .config
123 .config: $(wildcard $(FFLIBS:%=$(SRC_PATH)/lib%/all*.c))
124 @-tput bold 2>/dev/null
125 @-printf '\nWARNING: $(?F) newer than config.h, rerun configure\n\n'
126 @-tput sgr0 2>/dev/null
127
128 SUBDIR_VARS := CLEANFILES EXAMPLES FFLIBS HOSTPROGS TESTPROGS TOOLS \
129 HEADERS ARCH_HEADERS BUILT_HEADERS SKIPHEADERS \
130 ARMV5TE-OBJS ARMV6-OBJS ARMV8-OBJS VFP-OBJS NEON-OBJS \
131 ALTIVEC-OBJS MMX-OBJS YASM-OBJS \
132 OBJS HOSTOBJS TESTOBJS
133
134 define RESET
135 $(1) :=
136 $(1)-yes :=
137 endef
138
139 define DOSUBDIR
140 $(foreach V,$(SUBDIR_VARS),$(eval $(call RESET,$(V))))
141 SUBDIR := $(1)/
142 include $(SRC_PATH)/$(1)/Makefile
143 -include $(SRC_PATH)/$(1)/$(ARCH)/Makefile
144 -include $(SRC_PATH)/$(1)/$(INTRINSICS)/Makefile
145 include $(SRC_PATH)/library.mak
146 endef
147
148 $(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D))))
149
150 include $(SRC_PATH)/doc/Makefile
151
152 define DOPROG
153 OBJS-$(1) += $(1).o $(EXEOBJS) $(OBJS-$(1)-yes)
154 $(1)$(EXESUF): $$(OBJS-$(1))
155 $$(OBJS-$(1)): CFLAGS += $(CFLAGS-$(1))
156 $(1)$(EXESUF): LDFLAGS += $(LDFLAGS-$(1))
157 $(1)$(EXESUF): FF_EXTRALIBS += $(LIBS-$(1))
158 -include $$(OBJS-$(1):.o=.d)
159 endef
160
161 $(foreach P,$(PROGS),$(eval $(call DOPROG,$(P:$(EXESUF)=))))
162
163 $(PROGS): %$(EXESUF): %.o $(FF_DEP_LIBS)
164 $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(OBJS-$*) $(FF_EXTRALIBS)
165
166 OBJDIRS += tools
167
168 -include $(wildcard tools/*.d)
169
170 VERSION_SH = $(SRC_PATH)/version.sh
171 GIT_LOG = $(SRC_PATH)/.git/logs/HEAD
172
173 .version: $(wildcard $(GIT_LOG)) $(VERSION_SH) config.mak
174 .version: M=@
175
176 avversion.h .version:
177 $(M)$(VERSION_SH) $(SRC_PATH) avversion.h $(EXTRA_VERSION)
178 $(Q)touch .version
179
180 # force version.sh to run whenever version might have changed
181 -include .version
182
183 ifdef AVPROGS
184 install: install-progs install-data
185 endif
186
187 install: install-libs install-headers
188
189 install-libs: install-libs-yes
190
191 install-progs-yes:
192 install-progs-$(CONFIG_SHARED): install-libs
193
194 install-progs: install-progs-yes $(AVPROGS)
195 $(Q)mkdir -p "$(BINDIR)"
196 $(INSTALL) -c -m 755 $(AVPROGS) "$(BINDIR)"
197
198 install-data: $(DATA_FILES)
199 $(Q)mkdir -p "$(DATADIR)"
200 $(INSTALL) -m 644 $(DATA_FILES) "$(DATADIR)"
201
202 uninstall: uninstall-libs uninstall-headers uninstall-progs uninstall-data
203
204 uninstall-progs:
205 $(RM) $(addprefix "$(BINDIR)/", $(ALLAVPROGS))
206
207 uninstall-data:
208 $(RM) -r "$(DATADIR)"
209
210 clean::
211 $(RM) $(ALLAVPROGS)
212 $(RM) $(CLEANSUFFIXES)
213 $(RM) $(CLEANSUFFIXES:%=tools/%)
214 $(RM) -rf coverage.info lcov
215
216 distclean::
217 $(RM) $(DISTCLEANSUFFIXES)
218 $(RM) config.* .config libavutil/avconfig.h .version avversion.h
219
220 config:
221 $(SRC_PATH)/configure $(value LIBAV_CONFIGURATION)
222
223 check: all alltools checkheaders examples testprogs fate
224
225 include $(SRC_PATH)/tests/Makefile
226
227 $(sort $(OBJDIRS)):
228 $(Q)mkdir -p $@
229
230 # Dummy rule to stop make trying to rebuild removed or renamed headers
231 %.h:
232 @:
233
234 # Disable suffix rules. Most of the builtin rules are suffix rules,
235 # so this saves some time on slow systems.
236 .SUFFIXES:
237
238 .PHONY: all all-yes alltools check *clean config examples install*
239 .PHONY: testprogs uninstall*