build: change checkheaders to use regular build rules
[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 DEPYASM 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) $($(1)_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 %.h.c:
49 $(Q)echo '#include "$*.h"' >$@
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 = 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 define DOPROG
125 OBJS-$(1) += $(1).o
126 $(1)$(EXESUF): $(OBJS-$(1))
127 $$(OBJS-$(1)): CFLAGS += $(CFLAGS-$(1))
128 $(1)$(EXESUF): LDFLAGS += $(LDFLAGS-$(1))
129 $(1)$(EXESUF): FF_EXTRALIBS += $(LIBS-$(1))
130 -include $$(OBJS-$(1):.o=.d)
131 endef
132
133 $(foreach P,$(PROGS-yes),$(eval $(call DOPROG,$(P))))
134
135 $(PROGS): %$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS)
136 $(LD) $(LDFLAGS) -o $@ $(OBJS-$*) cmdutils.o $(FF_EXTRALIBS)
137
138 OBJDIRS += tools
139
140 -include $(wildcard tools/*.d)
141
142 VERSION_SH = $(SRC_PATH)/version.sh
143 GIT_LOG = $(SRC_PATH)/.git/logs/HEAD
144
145 .version: $(wildcard $(GIT_LOG)) $(VERSION_SH) config.mak
146 .version: M=@
147
148 version.h .version:
149 $(M)$(VERSION_SH) $(SRC_PATH) version.h $(EXTRA_VERSION)
150 $(Q)touch .version
151
152 # force version.sh to run whenever version might have changed
153 -include .version
154
155 ifdef PROGS
156 install: install-progs install-data
157 endif
158
159 install: install-libs install-headers
160
161 install-libs: install-libs-yes
162
163 install-progs-yes:
164 install-progs-$(CONFIG_SHARED): install-libs
165
166 install-progs: install-progs-yes $(PROGS)
167 $(Q)mkdir -p "$(BINDIR)"
168 $(INSTALL) -c -m 755 $(PROGS) "$(BINDIR)"
169
170 install-data: $(DATA_FILES)
171 $(Q)mkdir -p "$(DATADIR)"
172 $(INSTALL) -m 644 $(DATA_FILES) "$(DATADIR)"
173
174 uninstall: uninstall-libs uninstall-headers uninstall-progs uninstall-data
175
176 uninstall-progs:
177 $(RM) $(addprefix "$(BINDIR)/", $(ALLPROGS))
178
179 uninstall-data:
180 $(RM) -r "$(DATADIR)"
181
182 clean::
183 $(RM) $(ALLPROGS)
184 $(RM) $(CLEANSUFFIXES)
185 $(RM) $(TOOLS)
186 $(RM) $(CLEANSUFFIXES:%=tools/%)
187
188 distclean::
189 $(RM) $(DISTCLEANSUFFIXES)
190 $(RM) config.* .version version.h libavutil/avconfig.h
191
192 config:
193 $(SRC_PATH)/configure $(value LIBAV_CONFIGURATION)
194
195 check: all alltools checkheaders examples testprogs fate
196
197 include $(SRC_PATH)/doc/Makefile
198 include $(SRC_PATH)/tests/Makefile
199
200 $(sort $(OBJDIRS)):
201 $(Q)mkdir -p $@
202
203 # Dummy rule to stop make trying to rebuild removed or renamed headers
204 %.h:
205 @:
206
207 # Disable suffix rules. Most of the builtin rules are suffix rules,
208 # so this saves some time on slow systems.
209 .SUFFIXES:
210
211 .PHONY: all all-yes alltools check *clean config examples install*
212 .PHONY: testprogs uninstall*