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