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