build: Store library version numbers in .version files
[libav.git] / Makefile
CommitLineData
11a9320d 1include avbuild/config.mak
bde51e6a 2
f038cf3c 3vpath %.c $(SRC_PATH)
9f57f134 4vpath %.m $(SRC_PATH)
f038cf3c
MR
5vpath %.h $(SRC_PATH)
6vpath %.S $(SRC_PATH)
7vpath %.asm $(SRC_PATH)
8vpath %.v $(SRC_PATH)
9vpath %.texi $(SRC_PATH)
bde51e6a 10
bb524924
MR
11ifndef V
12Q = @
13ECHO = printf "$(1)\t%s\n" $(2)
095792f2 14BRIEF = CC HOSTCC HOSTLD AS YASM AR LD
c7f25d4c 15SILENT = DEPCC DEPHOSTCC DEPAS DEPYASM RANLIB RM STRIP
bb524924
MR
16MSG = $@
17M = @$(call ECHO,$(TAG),$@);
18$(foreach VAR,$(BRIEF), \
19 $(eval override $(VAR) = @$$(call ECHO,$(VAR),$$(MSG)); $($(VAR))))
20$(foreach VAR,$(SILENT),$(eval override $(VAR) = @$($(VAR))))
f038cf3c 21$(eval INSTALL = @$(call ECHO,INSTALL,$$(^:$(SRC_PATH)/%=%)); $(INSTALL))
bb524924
MR
22endif
23
c8af852b 24ALLFFLIBS = avcodec avdevice avfilter avformat avresample avutil swscale
371584c4 25
bb524924
MR
26IFLAGS := -I. -I$(SRC_PATH)
27CPPFLAGS := $(IFLAGS) $(CPPFLAGS)
28CFLAGS += $(ECFLAGS)
a758c5e2 29CCFLAGS = $(CPPFLAGS) $(CFLAGS)
9f57f134
LB
30OBJCFLAGS += $(EOBJCFLAGS)
31OBJCCFLAGS = $(CPPFLAGS) $(CFLAGS) $(OBJCFLAGS)
a758c5e2 32ASFLAGS := $(CPPFLAGS) $(ASFLAGS)
04581c8c 33YASMFLAGS += $(IFLAGS:%=%/) -Pconfig.asm
4cc4b33f 34HOSTCCFLAGS = $(IFLAGS) $(HOSTCPPFLAGS) $(HOSTCFLAGS)
8db73c61 35LDFLAGS := $(ALLFFLIBS:%=$(LD_PATH)lib%) $(LDFLAGS)
bb524924 36
bc877faf 37define COMPILE
a758c5e2 38 $(call $(1)DEP,$(1))
23565c26 39 $($(1)) $($(1)FLAGS) $($(1)_DEPFLAGS) $($(1)_C) $($(1)_O) $<
bc877faf
MR
40endef
41
42COMPILE_C = $(call COMPILE,CC)
43COMPILE_S = $(call COMPILE,AS)
9f57f134 44COMPILE_M = $(call COMPILE,OBJCC)
ad477710 45COMPILE_HOSTC = $(call COMPILE,HOSTCC)
bc877faf 46
bb524924 47%.o: %.c
bc877faf 48 $(COMPILE_C)
bb524924
MR
49
50%.o: %.S
bc877faf 51 $(COMPILE_S)
bb524924 52
9f57f134
LB
53%.o: %.m
54 $(COMPILE_M)
55
5a9fcc7d
DB
56%_host.o: %.c
57 $(COMPILE_HOSTC)
58
93d5b022
DB
59%.o: %.asm
60 $(DEPYASM) $(YASMFLAGS) -I $(<D)/ -M -o $@ $< > $(@:.o=.d)
61 $(YASM) $(YASMFLAGS) -I $(<D)/ -o $@ $<
62 -$(STRIP) $(STRIPFLAGS) $@
63
c2626492
MR
64%.i: %.c
65 $(CC) $(CCFLAGS) $(CC_E) $<
66
dfd9159f
MR
67%.h.c:
68 $(Q)echo '#include "$*.h"' >$@
bb524924 69
edb43487 70%.c %.h %.ver %.version: TAG = GEN
bb524924 71
14abeaa4
DB
72AVPROGS-$(CONFIG_AVCONV) += avconv
73AVPROGS-$(CONFIG_AVPLAY) += avplay
74AVPROGS-$(CONFIG_AVPROBE) += avprobe
bde51e6a 75
14abeaa4
DB
76AVPROGS := $(AVPROGS-yes:%=%$(EXESUF))
77PROGS += $(AVPROGS)
7671dd7c 78
894682a9 79AVBASENAMES = avconv avplay avprobe
14abeaa4
DB
80ALLAVPROGS = $(AVBASENAMES:%=%$(EXESUF))
81
dc80e2f7 82$(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog) += cmdutils.o))
14abeaa4
DB
83
84OBJS-avconv += avconv_opt.o avconv_filter.o
fb472e1a 85OBJS-avconv-$(CONFIG_LIBMFX) += avconv_qsv.o
5d273d3e 86OBJS-avconv-$(CONFIG_VAAPI) += avconv_vaapi.o
01621202
DB
87OBJS-avconv-$(CONFIG_VDA) += avconv_vda.o
88OBJS-avconv-$(HAVE_DXVA2_LIB) += avconv_dxva2.o
89OBJS-avconv-$(HAVE_VDPAU_X11) += avconv_vdpau.o
7671dd7c 90
3d157bf3 91TESTTOOLS = audiogen videogen rotozoom tiny_psnr base64
0d0b81f9 92HOSTPROGS := $(TESTTOOLS:%=tests/%) doc/print_options
bde51e6a 93
5e2ba41d
JG
94# $(FFLIBS-yes) needs to be in linking order
95FFLIBS-$(CONFIG_AVDEVICE) += avdevice
96FFLIBS-$(CONFIG_AVFILTER) += avfilter
97FFLIBS-$(CONFIG_AVFORMAT) += avformat
98FFLIBS-$(CONFIG_AVCODEC) += avcodec
c8af852b 99FFLIBS-$(CONFIG_AVRESAMPLE) += avresample
5e2ba41d 100FFLIBS-$(CONFIG_SWSCALE) += swscale
bde51e6a 101
5a0f7131 102FFLIBS := avutil
bde51e6a 103
8096fdf0 104DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.avpreset)
a1a84f69 105
01621202
DB
106SKIPHEADERS = cmdutils_common_opts.h \
107 compat/w32pthreads.h
9b55e2e7 108
c833c203
DB
109# first so "all" becomes default target
110all: all-yes
111
3e105d08 112include $(SRC_PATH)/tools/Makefile
11a9320d 113include $(SRC_PATH)/avbuild/common.mak
bde51e6a 114
bde51e6a
JR
115FF_EXTRALIBS := $(FFEXTRALIBS)
116FF_DEP_LIBS := $(DEP_LIBS)
3ae0e721 117FF_STATIC_DEP_LIBS := $(STATIC_DEP_LIBS)
bde51e6a 118
14abeaa4 119all: $(AVPROGS)
bde51e6a 120
3794062a 121$(TOOLS): %$(EXESUF): %.o
5d45fe7d 122 $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(EXTRALIBS) $(ELIBS)
28e1c979 123
7baa115a 124tools/cws2fws$(EXESUF): ELIBS = $(ZLIB)
28e1c979 125
7c9e2b29
AK
126CONFIGURABLE_COMPONENTS = \
127 $(wildcard $(FFLIBS:%=$(SRC_PATH)/lib%/all*.c)) \
4104cc56 128 $(wildcard $(FFLIBS:%=$(SRC_PATH)/lib%/version.h)) \
7c9e2b29
AK
129 $(SRC_PATH)/libavcodec/bitstream_filters.c \
130 $(SRC_PATH)/libavformat/protocols.c \
131
11a9320d
DB
132config.h: avbuild/.config
133avbuild/.config: $(CONFIGURABLE_COMPONENTS)
9d0b3042 134 @-tput bold 2>/dev/null
4104cc56 135 @-printf '\nWARNING: $(?) newer than config.h, rerun configure\n\n'
9d0b3042 136 @-tput sgr0 2>/dev/null
86601915 137
e7e19b15 138SUBDIR_VARS := CLEANFILES EXAMPLES FFLIBS HOSTPROGS TESTPROGS TOOLS \
121604b0 139 HEADERS ARCH_HEADERS BUILT_HEADERS SKIPHEADERS \
8675bcb0 140 ARMV5TE-OBJS ARMV6-OBJS ARMV8-OBJS VFP-OBJS NEON-OBJS \
d3257162 141 ALTIVEC-OBJS VSX-OBJS MMX-OBJS YASM-OBJS \
24d3796d 142 OBJS HOSTOBJS TESTOBJS
bde51e6a
JR
143
144define RESET
145$(1) :=
146$(1)-yes :=
147endef
148
149define DOSUBDIR
150$(foreach V,$(SUBDIR_VARS),$(eval $(call RESET,$(V))))
151SUBDIR := $(1)/
57b4a3dd 152include $(SRC_PATH)/$(1)/Makefile
07a873a2 153-include $(SRC_PATH)/$(1)/$(ARCH)/Makefile
d45ebd48 154-include $(SRC_PATH)/$(1)/$(INTRINSICS)/Makefile
11a9320d 155include $(SRC_PATH)/avbuild/library.mak
bde51e6a
JR
156endef
157
158$(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D))))
159
ab81f24a
DB
160include $(SRC_PATH)/doc/Makefile
161
baac24e6 162define DOPROG
3794062a 163OBJS-$(1) += $(1).o $(OBJS-$(1)-yes)
07b3790d 164$(1)$(EXESUF): $$(OBJS-$(1))
baac24e6
MR
165$$(OBJS-$(1)): CFLAGS += $(CFLAGS-$(1))
166$(1)$(EXESUF): LDFLAGS += $(LDFLAGS-$(1))
be2d555c 167$(1)$(EXESUF): FF_EXTRALIBS += $(EXTRALIBS-$(1))
baac24e6
MR
168-include $$(OBJS-$(1):.o=.d)
169endef
170
dc80e2f7 171$(foreach P,$(PROGS),$(eval $(call DOPROG,$(P:$(EXESUF)=))))
bde51e6a 172
07b3790d 173$(PROGS): %$(EXESUF): %.o $(FF_DEP_LIBS)
bb0babd7 174 $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(OBJS-$*) $(FF_EXTRALIBS)
bde51e6a 175
11a9320d 176VERSION_SH = $(SRC_PATH)/avbuild/version.sh
f038cf3c 177GIT_LOG = $(SRC_PATH)/.git/logs/HEAD
6a53fffd 178
11a9320d 179.version: $(wildcard $(GIT_LOG)) $(VERSION_SH) avbuild/config.mak
6a53fffd
MR
180.version: M=@
181
14cab426 182cmdutils.o libavutil/utils.o: avversion.h
1316df7a 183avversion.h .version:
184 $(M)$(VERSION_SH) $(SRC_PATH) avversion.h $(EXTRA_VERSION)
6a53fffd
MR
185 $(Q)touch .version
186
187# force version.sh to run whenever version might have changed
188-include .version
36798f1b 189
14abeaa4 190ifdef AVPROGS
623ffe8c
MR
191install: install-progs install-data
192endif
193
194install: install-libs install-headers
d7a72d25
MR
195
196install-libs: install-libs-yes
bde51e6a 197
151c5841 198install-progs-yes:
623ffe8c
MR
199install-progs-$(CONFIG_SHARED): install-libs
200
14abeaa4 201install-progs: install-progs-yes $(AVPROGS)
63611f31 202 $(Q)mkdir -p "$(BINDIR)"
14abeaa4 203 $(INSTALL) -c -m 755 $(AVPROGS) "$(BINDIR)"
bde51e6a 204
a1a84f69 205install-data: $(DATA_FILES)
63611f31 206 $(Q)mkdir -p "$(DATADIR)"
fd676deb 207 $(INSTALL) -m 644 $(DATA_FILES) "$(DATADIR)"
a1a84f69 208
f87b03b5 209uninstall: uninstall-libs uninstall-headers uninstall-progs uninstall-data
d3cb93b3
RP
210
211uninstall-progs:
14abeaa4 212 $(RM) $(addprefix "$(BINDIR)/", $(ALLAVPROGS))
d3cb93b3
RP
213
214uninstall-data:
50e10cbd 215 $(RM) -r "$(DATADIR)"
d3cb93b3 216
698a183e 217clean::
14abeaa4 218 $(RM) $(ALLAVPROGS)
50e10cbd 219 $(RM) $(CLEANSUFFIXES)
a862c7d3 220 $(RM) -rf coverage.info lcov
bde51e6a
JR
221
222distclean::
50e10cbd 223 $(RM) $(DISTCLEANSUFFIXES)
11a9320d
DB
224 $(RM) .version avversion.h config.asm config.h mapfile \
225 avbuild/.config avbuild/config.* libavutil/avconfig.h \
226 libavcodec/bsf_list.c libavformat/protocol_list.c
bde51e6a 227
9d0b3042 228config:
29ba0911 229 $(SRC_PATH)/configure $(value LIBAV_CONFIGURATION)
0c3b2d65 230
4982e1dd
DB
231check: all alltools checkheaders examples testprogs fate
232
57b4a3dd 233include $(SRC_PATH)/tests/Makefile
d29d9ccc 234
5e27ec28
MR
235$(sort $(OBJDIRS)):
236 $(Q)mkdir -p $@
237
8d853efe
MR
238# Dummy rule to stop make trying to rebuild removed or renamed headers
239%.h:
240 @:
241
242# Disable suffix rules. Most of the builtin rules are suffix rules,
243# so this saves some time on slow systems.
244.SUFFIXES:
245
4982e1dd 246.PHONY: all all-yes alltools check *clean config examples install*
698a183e 247.PHONY: testprogs uninstall*