feb57cbea0942c2719955692b184039f1fae15cc
[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 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 avutil postproc swscale
24
25 IFLAGS := -I. -I$(SRC_PATH)
26 CPPFLAGS := $(IFLAGS) $(CPPFLAGS)
27 CFLAGS += $(ECFLAGS)
28 CCFLAGS = $(CFLAGS)
29 YASMFLAGS += $(IFLAGS) -I$(SRC_PATH)/libavutil/x86/ -Pconfig.asm
30 HOSTCFLAGS += $(IFLAGS)
31 LDFLAGS := $(ALLFFLIBS:%=-Llib%) $(LDFLAGS)
32
33 define COMPILE
34 $($(1)DEP)
35 $($(1)) $(CPPFLAGS) $($(1)FLAGS) $($(1)_DEPFLAGS) -c $($(1)_O) $<
36 endef
37
38 COMPILE_C = $(call COMPILE,CC)
39 COMPILE_S = $(call COMPILE,AS)
40
41 %.o: %.c
42 $(COMPILE_C)
43
44 %.o: %.S
45 $(COMPILE_S)
46
47 %.ho: %.h
48 $(CC) $(CPPFLAGS) $(CFLAGS) -Wno-unused -c -o $@ -x c $<
49
50 %.ver: %.v
51 $(Q)sed 's/$$MAJOR/$($(basename $(@F))_VERSION_MAJOR)/' $^ > $@
52
53 %.c %.h: TAG = GEN
54
55 PROGS-$(CONFIG_FFMPEG) += ffmpeg
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/%)
65 TOOLS = qt-faststart trasher
66 TOOLS-$(CONFIG_ZLIB) += cws2fws
67
68 BASENAMES = ffmpeg 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_AVCODEC) += avcodec
76 FFLIBS-$(CONFIG_POSTPROC) += postproc
77 FFLIBS-$(CONFIG_SWSCALE) += swscale
78
79 FFLIBS := avutil
80
81 DATA_FILES := $(wildcard $(SRC_PATH)/ffpresets/*.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 := OBJS FFLIBS CLEANFILES DIRS TESTPROGS EXAMPLES SKIPHEADERS \
104 ALTIVEC-OBJS MMX-OBJS NEON-OBJS X86-OBJS YASM-OBJS-FFT YASM-OBJS \
105 HOSTPROGS BUILT_HEADERS TESTOBJS ARCH_HEADERS ARMV6-OBJS TOOLS
106
107 define RESET
108 $(1) :=
109 $(1)-yes :=
110 endef
111
112 define DOSUBDIR
113 $(foreach V,$(SUBDIR_VARS),$(eval $(call RESET,$(V))))
114 SUBDIR := $(1)/
115 include $(SRC_PATH)/$(1)/Makefile
116 endef
117
118 $(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D))))
119
120 avplay.o: CFLAGS += $(SDL_CFLAGS)
121 avplay$(EXESUF): FF_EXTRALIBS += $(SDL_LIBS)
122 avserver$(EXESUF): LDFLAGS += $(AVSERVERLDFLAGS)
123
124 $(PROGS): %$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS)
125 $(LD) $(LDFLAGS) -o $@ $< cmdutils.o $(FF_EXTRALIBS)
126
127 OBJDIRS += tools
128
129 -include $(wildcard tools/*.d)
130
131 VERSION_SH = $(SRC_PATH)/version.sh
132 GIT_LOG = $(SRC_PATH)/.git/logs/HEAD
133
134 .version: $(wildcard $(GIT_LOG)) $(VERSION_SH) config.mak
135 .version: M=@
136
137 version.h .version:
138 $(M)$(VERSION_SH) $(SRC_PATH) version.h $(EXTRA_VERSION)
139 $(Q)touch .version
140
141 # force version.sh to run whenever version might have changed
142 -include .version
143
144 ifdef PROGS
145 install: install-progs install-data
146 endif
147
148 install: install-libs install-headers
149
150 install-libs: install-libs-yes
151
152 install-progs-yes:
153 install-progs-$(CONFIG_SHARED): install-libs
154
155 install-progs: install-progs-yes $(PROGS)
156 $(Q)mkdir -p "$(BINDIR)"
157 $(INSTALL) -c -m 755 $(PROGS) "$(BINDIR)"
158
159 install-data: $(DATA_FILES)
160 $(Q)mkdir -p "$(DATADIR)"
161 $(INSTALL) -m 644 $(DATA_FILES) "$(DATADIR)"
162
163 uninstall: uninstall-libs uninstall-headers uninstall-progs uninstall-data
164
165 uninstall-progs:
166 $(RM) $(addprefix "$(BINDIR)/", $(ALLPROGS))
167
168 uninstall-data:
169 $(RM) -r "$(DATADIR)"
170
171 clean::
172 $(RM) $(ALLPROGS)
173 $(RM) $(CLEANSUFFIXES)
174 $(RM) $(TOOLS)
175 $(RM) $(CLEANSUFFIXES:%=tools/%)
176
177 distclean::
178 $(RM) $(DISTCLEANSUFFIXES)
179 $(RM) config.* .version version.h libavutil/avconfig.h
180
181 config:
182 $(SRC_PATH)/configure $(value LIBAV_CONFIGURATION)
183
184 include $(SRC_PATH)/doc/Makefile
185 include $(SRC_PATH)/tests/Makefile
186
187 $(sort $(OBJDIRS)):
188 $(Q)mkdir -p $@
189
190 # Dummy rule to stop make trying to rebuild removed or renamed headers
191 %.h:
192 @:
193
194 # Disable suffix rules. Most of the builtin rules are suffix rules,
195 # so this saves some time on slow systems.
196 .SUFFIXES:
197
198 .PHONY: all all-yes alltools *clean config examples install*
199 .PHONY: testprogs uninstall*