build: move basic rules and variables to main Makefile
[libav.git] / Makefile
CommitLineData
bde51e6a
JR
1include config.mak
2
3SRC_DIR = $(SRC_PATH_BARE)
4
d530e579
MR
5vpath %.c $(SRC_DIR)
6vpath %.h $(SRC_DIR)
7vpath %.S $(SRC_DIR)
8vpath %.asm $(SRC_DIR)
9vpath %.v $(SRC_DIR)
bde51e6a
JR
10vpath %.texi $(SRC_PATH_BARE)
11
bb524924
MR
12ifndef V
13Q = @
14ECHO = printf "$(1)\t%s\n" $(2)
15BRIEF = CC AS YASM AR LD HOSTCC
16SILENT = DEPCC YASMDEP RM RANLIB
17MSG = $@
18M = @$(call ECHO,$(TAG),$@);
19$(foreach VAR,$(BRIEF), \
20 $(eval override $(VAR) = @$$(call ECHO,$(VAR),$$(MSG)); $($(VAR))))
21$(foreach VAR,$(SILENT),$(eval override $(VAR) = @$($(VAR))))
22$(eval INSTALL = @$(call ECHO,INSTALL,$$(^:$(SRC_DIR)/%=%)); $(INSTALL))
23endif
24
25IFLAGS := -I. -I$(SRC_PATH)
26CPPFLAGS := $(IFLAGS) $(CPPFLAGS)
27CFLAGS += $(ECFLAGS)
28YASMFLAGS += $(IFLAGS) -Pconfig.asm
29HOSTCFLAGS += $(IFLAGS)
30
31%.o: %.c
32 $(CCDEP)
33 $(CC) $(CPPFLAGS) $(CFLAGS) $(CC_DEPFLAGS) -c $(CC_O) $<
34
35%.o: %.S
36 $(ASDEP)
37 $(AS) $(CPPFLAGS) $(ASFLAGS) $(AS_DEPFLAGS) -c -o $@ $<
38
39%.ho: %.h
40 $(CC) $(CPPFLAGS) $(CFLAGS) -Wno-unused -c -o $@ -x c $<
41
42%.ver: %.v
43 $(Q)sed 's/$$MAJOR/$($(basename $(@F))_VERSION_MAJOR)/' $^ > $@
44
45%.c %.h: TAG = GEN
46
bde51e6a
JR
47PROGS-$(CONFIG_FFMPEG) += ffmpeg
48PROGS-$(CONFIG_FFPLAY) += ffplay
336ce917 49PROGS-$(CONFIG_FFPROBE) += ffprobe
bde51e6a
JR
50PROGS-$(CONFIG_FFSERVER) += ffserver
51
583fcb52 52PROGS := $(PROGS-yes:%=%$(EXESUF))
583fcb52 53OBJS = $(PROGS-yes:%=%.o) cmdutils.o
cd6a5a57 54TOOLS = $(addprefix tools/, $(addsuffix $(EXESUF), cws2fws graph2dot lavfi-showfiltfmts pktdumper probetest qt-faststart trasher))
3d157bf3
MR
55TESTTOOLS = audiogen videogen rotozoom tiny_psnr base64
56HOSTPROGS := $(TESTTOOLS:%=tests/%)
bde51e6a 57
336ce917 58BASENAMES = ffmpeg ffplay ffprobe ffserver
583fcb52 59ALLPROGS = $(BASENAMES:%=%$(EXESUF))
583fcb52 60ALLMANPAGES = $(BASENAMES:%=%.1)
bde51e6a 61
cf53c486
MR
62ALLFFLIBS = avcodec avdevice avfilter avformat avutil postproc swscale
63
5a0f7131 64FFLIBS-$(CONFIG_AVDEVICE) += avdevice
bde51e6a 65FFLIBS-$(CONFIG_AVFILTER) += avfilter
5a0f7131 66FFLIBS-$(CONFIG_AVFORMAT) += avformat
97d5fa38 67FFLIBS-$(CONFIG_AVCODEC) += avcodec
bde51e6a 68FFLIBS-$(CONFIG_POSTPROC) += postproc
5a0f7131 69FFLIBS-$(CONFIG_SWSCALE) += swscale
bde51e6a 70
5a0f7131 71FFLIBS := avutil
bde51e6a 72
a1a84f69
RS
73DATA_FILES := $(wildcard $(SRC_DIR)/ffpresets/*.ffpreset)
74
9b55e2e7
MR
75SKIPHEADERS = cmdutils_common_opts.h
76
bde51e6a
JR
77include common.mak
78
79FF_LDFLAGS := $(FFLDFLAGS)
80FF_EXTRALIBS := $(FFEXTRALIBS)
81FF_DEP_LIBS := $(DEP_LIBS)
82
623ffe8c 83all: $(FF_DEP_LIBS) $(PROGS)
bde51e6a 84
86601915
MR
85config.h: .config
86.config: $(wildcard $(FFLIBS:%=$(SRC_DIR)/lib%/all*.c))
9d0b3042
MR
87 @-tput bold 2>/dev/null
88 @-printf '\nWARNING: $(?F) newer than config.h, rerun configure\n\n'
89 @-tput sgr0 2>/dev/null
86601915 90
95f2c769 91SUBDIR_VARS := OBJS FFLIBS CLEANFILES DIRS TESTPROGS EXAMPLES SKIPHEADERS \
de4070b5 92 ALTIVEC-OBJS MMX-OBJS NEON-OBJS X86-OBJS YASM-OBJS-FFT YASM-OBJS \
a7878c9f 93 HOSTPROGS BUILT_HEADERS TESTOBJS ARCH_HEADERS ARMV6-OBJS
bde51e6a
JR
94
95define RESET
96$(1) :=
97$(1)-yes :=
98endef
99
100define DOSUBDIR
101$(foreach V,$(SUBDIR_VARS),$(eval $(call RESET,$(V))))
102SUBDIR := $(1)/
103include $(1)/Makefile
104endef
105
106$(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D))))
107
d93d7349 108ffplay.o: CFLAGS += $(SDL_CFLAGS)
e0be794a
MR
109ffplay$(EXESUF): FF_EXTRALIBS += $(SDL_LIBS)
110ffserver$(EXESUF): FF_LDFLAGS += $(FFSERVERLDFLAGS)
bde51e6a 111
6d170962 112$(PROGS): %$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS)
684b28e0 113 $(LD) $(FF_LDFLAGS) -o $@ $< cmdutils.o $(FF_EXTRALIBS)
bde51e6a 114
d93d7349
MR
115alltools: $(TOOLS)
116
2dfa3054
MR
117tools/%$(EXESUF): tools/%.o
118 $(LD) $(FF_LDFLAGS) -o $@ $< $(FF_EXTRALIBS)
119
2205da0d 120tools/%.o: tools/%.c
4d1156cb 121 $(CC) $(CPPFLAGS) $(CFLAGS) -c $(CC_O) $<
08df7f86
MR
122
123-include $(wildcard tools/*.d)
bde51e6a 124
6a53fffd 125VERSION_SH = $(SRC_PATH_BARE)/version.sh
f82bf850 126GIT_LOG = $(SRC_PATH_BARE)/.git/logs/HEAD
6a53fffd 127
faa6f1c3 128.version: $(wildcard $(GIT_LOG)) $(VERSION_SH) config.mak
6a53fffd
MR
129.version: M=@
130
131version.h .version:
0853a2b4 132 $(M)$(VERSION_SH) $(SRC_PATH) version.h $(EXTRA_VERSION)
6a53fffd
MR
133 $(Q)touch .version
134
135# force version.sh to run whenever version might have changed
136-include .version
36798f1b 137
623ffe8c
MR
138ifdef PROGS
139install: install-progs install-data
140endif
141
142install: install-libs install-headers
d7a72d25
MR
143
144install-libs: install-libs-yes
bde51e6a 145
151c5841 146install-progs-yes:
623ffe8c
MR
147install-progs-$(CONFIG_SHARED): install-libs
148
149install-progs: install-progs-yes $(PROGS)
63611f31 150 $(Q)mkdir -p "$(BINDIR)"
fd676deb 151 $(INSTALL) -c -m 755 $(PROGS) "$(BINDIR)"
bde51e6a 152
a1a84f69 153install-data: $(DATA_FILES)
63611f31 154 $(Q)mkdir -p "$(DATADIR)"
fd676deb 155 $(INSTALL) -m 644 $(DATA_FILES) "$(DATADIR)"
a1a84f69 156
f87b03b5 157uninstall: uninstall-libs uninstall-headers uninstall-progs uninstall-data
d3cb93b3
RP
158
159uninstall-progs:
50e10cbd 160 $(RM) $(addprefix "$(BINDIR)/", $(ALLPROGS))
d3cb93b3
RP
161
162uninstall-data:
50e10cbd 163 $(RM) -r "$(DATADIR)"
d3cb93b3 164
698a183e 165clean::
e0be794a 166 $(RM) $(ALLPROGS)
50e10cbd 167 $(RM) $(CLEANSUFFIXES)
50e10cbd 168 $(RM) $(TOOLS)
40321376 169 $(RM) $(CLEANSUFFIXES:%=tools/%)
bde51e6a
JR
170
171distclean::
50e10cbd 172 $(RM) $(DISTCLEANSUFFIXES)
59748689 173 $(RM) config.* .version version.h libavutil/avconfig.h
bde51e6a 174
9d0b3042 175config:
29ba0911 176 $(SRC_PATH)/configure $(value LIBAV_CONFIGURATION)
0c3b2d65 177
5bab8536
DB
178check: test checkheaders
179
f87b03b5 180include doc/Makefile
698a183e 181include tests/Makefile
d29d9ccc 182
8d853efe
MR
183# Dummy rule to stop make trying to rebuild removed or renamed headers
184%.h:
185 @:
186
187# Disable suffix rules. Most of the builtin rules are suffix rules,
188# so this saves some time on slow systems.
189.SUFFIXES:
190
f87b03b5 191.PHONY: all alltools *clean check config examples install*
698a183e 192.PHONY: testprogs uninstall*