enable version.h to be created from subdirs
[libav.git] / common.mak
CommitLineData
8b2121e3
MR
1#
2# common bits used by all libraries
3#
4
71c61f62 5all: # make "all" default target
0e32c8c6 6
8e255b8b 7ifndef SUBDIR
c415857d
MR
8vpath %.c $(SRC_DIR)
9vpath %.h $(SRC_DIR)
10vpath %.S $(SRC_DIR)
8b2121e3 11
9e6165b5
MR
12ifeq ($(SRC_DIR),$(SRC_PATH_BARE))
13BUILD_ROOT_REL = .
14else
15BUILD_ROOT_REL = ..
16endif
17
5671fc14
MR
18ALLFFLIBS = avcodec avdevice avfilter avformat avutil postproc swscale
19
9e6165b5
MR
20CFLAGS := -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
21 -D_ISOC9X_SOURCE -I$(BUILD_ROOT_REL) -I$(SRC_PATH) $(OPTFLAGS)
8b2121e3
MR
22
23%.o: %.c
24 $(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $<
25
26%.o: %.S
27 $(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $<
28
e4d86a57
MR
29%.ho: %.h
30 $(CC) $(CFLAGS) $(LIBOBJFLAGS) -Wno-unused -c -o $@ -x c $<
31
caec74dd
MR
32%.d: %.c
33 $(DEPEND_CMD) > $@
34
35%.d: %.S
36 $(DEPEND_CMD) > $@
37
38%.d: %.cpp
39 $(DEPEND_CMD) > $@
40
bf237413
MR
41%$(EXESUF): %.c
42
9e6165b5
MR
43SVN_ENTRIES = $(SRC_PATH_BARE)/.svn/entries
44ifeq ($(wildcard $(SVN_ENTRIES)),$(SVN_ENTRIES))
45$(BUILD_ROOT_REL)/version.h: $(SVN_ENTRIES)
46endif
47
48$(BUILD_ROOT_REL)/version.h:
49 $(SRC_PATH)/version.sh $(SRC_PATH) $@
50
71c61f62 51install: install-libs install-headers
7716f7ff 52
71c61f62 53uninstall: uninstall-libs uninstall-headers
8b2121e3 54
71c61f62
MR
55.PHONY: all depend dep clean distclean install* uninstall* tests
56endif
8b2121e3 57
71c61f62
MR
58CFLAGS += $(CFLAGS-yes)
59OBJS += $(OBJS-yes)
60ASM_OBJS += $(ASM_OBJS-yes)
61CPP_OBJS += $(CPP_OBJS-yes)
62FFLIBS := $(FFLIBS-yes) $(FFLIBS)
dbe6c6ff 63TESTS += $(TESTS-yes)
8b2121e3 64
71c61f62
MR
65FFEXTRALIBS := $(addprefix -l,$(addsuffix $(BUILDSUF),$(FFLIBS))) $(EXTRALIBS)
66FFLDFLAGS := $(addprefix -L$(BUILD_ROOT)/lib,$(FFLIBS)) $(LDFLAGS)
8b2121e3 67
71c61f62
MR
68SRCS := $(OBJS:.o=.c) $(ASM_OBJS:.o=.S) $(CPP_OBJS:.o=.cpp)
69OBJS := $(OBJS) $(ASM_OBJS) $(CPP_OBJS)
8b2121e3 70
71c61f62
MR
71SRCS := $(addprefix $(SUBDIR),$(SRCS))
72OBJS := $(addprefix $(SUBDIR),$(OBJS))
73TESTS := $(addprefix $(SUBDIR),$(TESTS))
8b2121e3 74
76ca42a8
MR
75DEP_LIBS:=$(foreach NAME,$(FFLIBS),lib$(NAME)/$($(BUILD_SHARED:yes=S)LIBNAME))
76
71c61f62
MR
77ALLHEADERS := $(subst $(SRC_DIR)/,$(SUBDIR),$(wildcard $(SRC_DIR)/*.h))
78checkheaders: $(filter-out %_template.ho,$(ALLHEADERS:.h=.ho))
8b2121e3 79
caec74dd
MR
80DEPS := $(OBJS:.o=.d)
81depend dep: $(DEPS)
8b2121e3 82
0147b92e 83CLEANSUFFIXES = *.o *~ *.ho
d4210e2a 84LIBSUFFIXES = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a *.exp *.map
25cd5cb3 85DISTCLEANSUFFIXES = *.d *.pc
76a448ed 86
71c61f62 87define RULES
b153c68b
MR
88$(SUBDIR)%$(EXESUF): $(SUBDIR)%.o
89 $(CC) $(FFLDFLAGS) -o $$@ $$^ $(SUBDIR)$(LIBNAME) $(FFEXTRALIBS)
8b2121e3 90
b153c68b
MR
91$(SUBDIR)%-test.o: $(SUBDIR)%.c
92 $(CC) $(CFLAGS) -DTEST -c -o $$@ $$^
93
94$(SUBDIR)%-test.o: $(SUBDIR)%-test.c
95 $(CC) $(CFLAGS) -DTEST -c -o $$@ $$^
f9edb717 96
71c61f62 97clean::
adc39350
DB
98 rm -f $(TESTS) $(addprefix $(SUBDIR),$(CLEANFILES) $(CLEANSUFFIXES) $(LIBSUFFIXES)) \
99 $(addprefix $(SUBDIR), $(foreach suffix,$(CLEANSUFFIXES),$(addsuffix /$(suffix),$(DIRS))))
f9edb717 100
71c61f62 101distclean:: clean
95d2afec
DB
102 rm -f $(addprefix $(SUBDIR),$(DISTCLEANSUFFIXES)) \
103 $(addprefix $(SUBDIR), $(foreach suffix,$(DISTCLEANSUFFIXES),$(addsuffix /$(suffix),$(DIRS))))
71c61f62 104endef
bca9e0bc 105
71c61f62 106$(eval $(RULES))
bca9e0bc 107
71c61f62 108tests: $(TESTS)
3263626f 109
caec74dd 110-include $(DEPS)