build: Simplify postprocessing of linker version script files
[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 %.c %.h %.ver: TAG = GEN
66
67 AVPROGS-$(CONFIG_AVCONV) += avconv
68 AVPROGS-$(CONFIG_AVPLAY) += avplay
69 AVPROGS-$(CONFIG_AVPROBE) += avprobe
70
71 AVPROGS := $(AVPROGS-yes:%=%$(EXESUF))
72 PROGS += $(AVPROGS)
73
74 AVBASENAMES = avconv avplay avprobe
75 ALLAVPROGS = $(AVBASENAMES:%=%$(EXESUF))
76
77 $(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog) += cmdutils.o))
78
79 OBJS-avconv += avconv_opt.o avconv_filter.o
80 OBJS-avconv-$(CONFIG_LIBMFX) += avconv_qsv.o
81 OBJS-avconv-$(CONFIG_VAAPI) += avconv_vaapi.o
82 OBJS-avconv-$(CONFIG_VDA) += avconv_vda.o
83 OBJS-avconv-$(HAVE_DXVA2_LIB) += avconv_dxva2.o
84 OBJS-avconv-$(HAVE_VDPAU_X11) += avconv_vdpau.o
85
86 TESTTOOLS = audiogen videogen rotozoom tiny_psnr base64
87 HOSTPROGS := $(TESTTOOLS:%=tests/%) doc/print_options
88 TOOLS = qt-faststart trasher
89 TOOLS-$(CONFIG_ZLIB) += cws2fws
90
91 # $(FFLIBS-yes) needs to be in linking order
92 FFLIBS-$(CONFIG_AVDEVICE) += avdevice
93 FFLIBS-$(CONFIG_AVFILTER) += avfilter
94 FFLIBS-$(CONFIG_AVFORMAT) += avformat
95 FFLIBS-$(CONFIG_AVCODEC) += avcodec
96 FFLIBS-$(CONFIG_AVRESAMPLE) += avresample
97 FFLIBS-$(CONFIG_SWSCALE) += swscale
98
99 FFLIBS := avutil
100
101 DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.avpreset)
102
103 SKIPHEADERS = cmdutils_common_opts.h \
104 compat/w32pthreads.h
105
106 include $(SRC_PATH)/common.mak
107
108 FF_EXTRALIBS := $(FFEXTRALIBS)
109 FF_DEP_LIBS := $(DEP_LIBS)
110 FF_STATIC_DEP_LIBS := $(STATIC_DEP_LIBS)
111
112 all: $(AVPROGS)
113
114 $(TOOLS): %$(EXESUF): %.o $(EXEOBJS)
115 $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS)
116
117 tools/cws2fws$(EXESUF): ELIBS = $(ZLIB)
118
119 config.h: .config
120 .config: $(wildcard $(FFLIBS:%=$(SRC_PATH)/lib%/all*.c))
121 @-tput bold 2>/dev/null
122 @-printf '\nWARNING: $(?F) newer than config.h, rerun configure\n\n'
123 @-tput sgr0 2>/dev/null
124
125 SUBDIR_VARS := CLEANFILES EXAMPLES FFLIBS HOSTPROGS TESTPROGS TOOLS \
126 HEADERS ARCH_HEADERS BUILT_HEADERS SKIPHEADERS \
127 ARMV5TE-OBJS ARMV6-OBJS ARMV8-OBJS VFP-OBJS NEON-OBJS \
128 ALTIVEC-OBJS MMX-OBJS YASM-OBJS \
129 OBJS HOSTOBJS TESTOBJS
130
131 define RESET
132 $(1) :=
133 $(1)-yes :=
134 endef
135
136 define DOSUBDIR
137 $(foreach V,$(SUBDIR_VARS),$(eval $(call RESET,$(V))))
138 SUBDIR := $(1)/
139 include $(SRC_PATH)/$(1)/Makefile
140 -include $(SRC_PATH)/$(1)/$(ARCH)/Makefile
141 -include $(SRC_PATH)/$(1)/$(INTRINSICS)/Makefile
142 include $(SRC_PATH)/library.mak
143 endef
144
145 $(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D))))
146
147 include $(SRC_PATH)/doc/Makefile
148
149 define DOPROG
150 OBJS-$(1) += $(1).o $(EXEOBJS) $(OBJS-$(1)-yes)
151 $(1)$(EXESUF): $$(OBJS-$(1))
152 $$(OBJS-$(1)): CFLAGS += $(CFLAGS-$(1))
153 $(1)$(EXESUF): LDFLAGS += $(LDFLAGS-$(1))
154 $(1)$(EXESUF): FF_EXTRALIBS += $(LIBS-$(1))
155 -include $$(OBJS-$(1):.o=.d)
156 endef
157
158 $(foreach P,$(PROGS),$(eval $(call DOPROG,$(P:$(EXESUF)=))))
159
160 $(PROGS): %$(EXESUF): %.o $(FF_DEP_LIBS)
161 $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(OBJS-$*) $(FF_EXTRALIBS)
162
163 OBJDIRS += tools
164
165 -include $(wildcard tools/*.d)
166
167 VERSION_SH = $(SRC_PATH)/version.sh
168 GIT_LOG = $(SRC_PATH)/.git/logs/HEAD
169
170 .version: $(wildcard $(GIT_LOG)) $(VERSION_SH) config.mak
171 .version: M=@
172
173 avversion.h .version:
174 $(M)$(VERSION_SH) $(SRC_PATH) avversion.h $(EXTRA_VERSION)
175 $(Q)touch .version
176
177 # force version.sh to run whenever version might have changed
178 -include .version
179
180 ifdef AVPROGS
181 install: install-progs install-data
182 endif
183
184 install: install-libs install-headers
185
186 install-libs: install-libs-yes
187
188 install-progs-yes:
189 install-progs-$(CONFIG_SHARED): install-libs
190
191 install-progs: install-progs-yes $(AVPROGS)
192 $(Q)mkdir -p "$(BINDIR)"
193 $(INSTALL) -c -m 755 $(AVPROGS) "$(BINDIR)"
194
195 install-data: $(DATA_FILES)
196 $(Q)mkdir -p "$(DATADIR)"
197 $(INSTALL) -m 644 $(DATA_FILES) "$(DATADIR)"
198
199 uninstall: uninstall-libs uninstall-headers uninstall-progs uninstall-data
200
201 uninstall-progs:
202 $(RM) $(addprefix "$(BINDIR)/", $(ALLAVPROGS))
203
204 uninstall-data:
205 $(RM) -r "$(DATADIR)"
206
207 clean::
208 $(RM) $(ALLAVPROGS)
209 $(RM) $(CLEANSUFFIXES)
210 $(RM) $(CLEANSUFFIXES:%=tools/%)
211 $(RM) -rf coverage.info lcov
212
213 distclean::
214 $(RM) $(DISTCLEANSUFFIXES)
215 $(RM) config.* .config libavutil/avconfig.h .version avversion.h \
216 mapfile libavcodec/bsf_list.c libavformat/protocol_list.c
217
218 config:
219 $(SRC_PATH)/configure $(value LIBAV_CONFIGURATION)
220
221 check: all alltools checkheaders examples testprogs fate
222
223 include $(SRC_PATH)/tests/Makefile
224
225 $(sort $(OBJDIRS)):
226 $(Q)mkdir -p $@
227
228 # Dummy rule to stop make trying to rebuild removed or renamed headers
229 %.h:
230 @:
231
232 # Disable suffix rules. Most of the builtin rules are suffix rules,
233 # so this saves some time on slow systems.
234 .SUFFIXES:
235
236 .PHONY: all all-yes alltools check *clean config examples install*
237 .PHONY: testprogs uninstall*