3716e9ee84087ca0b44ca670346b6563f6f8df2b
[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 AS YASM AR LD HOSTCC
14 SILENT = DEPCC DEPAS DEPHOSTCC YASMDEP RM RANLIB
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) -I$(SRC_PATH)/libavutil/x86/ -Pconfig.asm
31 HOSTCCFLAGS = $(IFLAGS) $(HOSTCFLAGS)
32 LDFLAGS := $(ALLFFLIBS:%=-Llib%) $(LDFLAGS)
33
34 define COMPILE
35 $(call $(1)DEP,$(1))
36 $($(1)) $($(1)FLAGS) $($(1)_DEPFLAGS) -c $($(1)_O) $<
37 endef
38
39 COMPILE_C = $(call COMPILE,CC)
40 COMPILE_S = $(call COMPILE,AS)
41
42 %.o: %.c
43 $(COMPILE_C)
44
45 %.o: %.S
46 $(COMPILE_S)
47
48 %.ho: %.h
49 $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ -x c $<
50
51 %.ver: %.v
52 $(Q)sed 's/$$MAJOR/$($(basename $(@F))_VERSION_MAJOR)/' $^ > $@
53
54 %.c %.h: TAG = GEN
55
56 PROGS-$(CONFIG_AVCONV) += avconv
57 PROGS-$(CONFIG_AVPLAY) += avplay
58 PROGS-$(CONFIG_AVPROBE) += avprobe
59 PROGS-$(CONFIG_AVSERVER) += avserver
60
61 PROGS := $(PROGS-yes:%=%$(EXESUF))
62 OBJS = $(PROGS-yes:%=%.o) cmdutils.o
63 TESTTOOLS = audiogen videogen rotozoom tiny_psnr base64
64 HOSTPROGS := $(TESTTOOLS:%=tests/%) doc/print_options
65 TOOLS = qt-faststart trasher
66 TOOLS-$(CONFIG_ZLIB) += cws2fws
67
68 BASENAMES = avconv avplay avprobe avserver
69 ALLPROGS = $(BASENAMES:%=%$(EXESUF))
70 ALLMANPAGES = $(BASENAMES:%=%.1)
71
72 FFLIBS-$(CONFIG_AVDEVICE) += avdevice
73 FFLIBS-$(CONFIG_AVFILTER) += avfilter
74 FFLIBS-$(CONFIG_AVFORMAT) += avformat
75 FFLIBS-$(CONFIG_AVRESAMPLE) += avresample
76 FFLIBS-$(CONFIG_AVCODEC) += avcodec
77 FFLIBS-$(CONFIG_SWSCALE) += swscale
78
79 FFLIBS := avutil
80
81 DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.avpreset)
82
83 SKIPHEADERS = cmdutils_common_opts.h
84
85 include $(SRC_PATH)/common.mak
86
87 FF_EXTRALIBS := $(FFEXTRALIBS)
88 FF_DEP_LIBS := $(DEP_LIBS)
89
90 all: $(PROGS)
91
92 $(TOOLS): %$(EXESUF): %.o
93 $(LD) $(LDFLAGS) -o $@ $< $(ELIBS)
94
95 tools/cws2fws$(EXESUF): ELIBS = -lz
96
97 config.h: .config
98 .config: $(wildcard $(FFLIBS:%=$(SRC_PATH)/lib%/all*.c))
99 @-tput bold 2>/dev/null
100 @-printf '\nWARNING: $(?F) newer than config.h, rerun configure\n\n'
101 @-tput sgr0 2>/dev/null
102
103 SUBDIR_VARS := CLEANFILES EXAMPLES FFLIBS HOSTPROGS TESTPROGS TOOLS \
104 ARCH_HEADERS BUILT_HEADERS SKIPHEADERS \
105 ALTIVEC-OBJS ARMV5TE-OBJS ARMV6-OBJS ARMVFP-OBJS MMI-OBJS \
106 MMX-OBJS NEON-OBJS VIS-OBJS YASM-OBJS \
107 OBJS TESTOBJS
108
109 define RESET
110 $(1) :=
111 $(1)-yes :=
112 endef
113
114 define DOSUBDIR
115 $(foreach V,$(SUBDIR_VARS),$(eval $(call RESET,$(V))))
116 SUBDIR := $(1)/
117 include $(SRC_PATH)/$(1)/Makefile
118 -include $(SRC_PATH)/$(1)/$(ARCH)/Makefile
119 include $(SRC_PATH)/library.mak
120 endef
121
122 $(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D))))
123
124 avplay.o: CFLAGS += $(SDL_CFLAGS)
125 avplay$(EXESUF): FF_EXTRALIBS += $(SDL_LIBS)
126 avserver$(EXESUF): LDFLAGS += $(AVSERVERLDFLAGS)
127
128 $(PROGS): %$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS)
129 $(LD) $(LDFLAGS) -o $@ $< cmdutils.o $(FF_EXTRALIBS)
130
131 OBJDIRS += tools
132
133 -include $(wildcard tools/*.d)
134
135 VERSION_SH = $(SRC_PATH)/version.sh
136 GIT_LOG = $(SRC_PATH)/.git/logs/HEAD
137
138 .version: $(wildcard $(GIT_LOG)) $(VERSION_SH) config.mak
139 .version: M=@
140
141 version.h .version:
142 $(M)$(VERSION_SH) $(SRC_PATH) version.h $(EXTRA_VERSION)
143 $(Q)touch .version
144
145 # force version.sh to run whenever version might have changed
146 -include .version
147
148 ifdef PROGS
149 install: install-progs install-data
150 endif
151
152 install: install-libs install-headers
153
154 install-libs: install-libs-yes
155
156 install-progs-yes:
157 install-progs-$(CONFIG_SHARED): install-libs
158
159 install-progs: install-progs-yes $(PROGS)
160 $(Q)mkdir -p "$(BINDIR)"
161 $(INSTALL) -c -m 755 $(PROGS) "$(BINDIR)"
162
163 install-data: $(DATA_FILES)
164 $(Q)mkdir -p "$(DATADIR)"
165 $(INSTALL) -m 644 $(DATA_FILES) "$(DATADIR)"
166
167 uninstall: uninstall-libs uninstall-headers uninstall-progs uninstall-data
168
169 uninstall-progs:
170 $(RM) $(addprefix "$(BINDIR)/", $(ALLPROGS))
171
172 uninstall-data:
173 $(RM) -r "$(DATADIR)"
174
175 clean::
176 $(RM) $(ALLPROGS)
177 $(RM) $(CLEANSUFFIXES)
178 $(RM) $(TOOLS)
179 $(RM) $(CLEANSUFFIXES:%=tools/%)
180
181 distclean::
182 $(RM) $(DISTCLEANSUFFIXES)
183 $(RM) config.* .version version.h libavutil/avconfig.h
184
185 config:
186 $(SRC_PATH)/configure $(value LIBAV_CONFIGURATION)
187
188 check: all alltools checkheaders examples testprogs fate
189
190 include $(SRC_PATH)/doc/Makefile
191 include $(SRC_PATH)/tests/Makefile
192
193 $(sort $(OBJDIRS)):
194 $(Q)mkdir -p $@
195
196 # Dummy rule to stop make trying to rebuild removed or renamed headers
197 %.h:
198 @:
199
200 # Disable suffix rules. Most of the builtin rules are suffix rules,
201 # so this saves some time on slow systems.
202 .SUFFIXES:
203
204 .PHONY: all all-yes alltools check *clean config examples install*
205 .PHONY: testprogs uninstall*