Unset DIRS after including subdir.mak so that the variable is not used
[libav.git] / common.mak
... / ...
CommitLineData
1#
2# common bits used by all libraries
3#
4
5all: # make "all" default target
6
7ifndef SUBDIR
8vpath %.c $(SRC_DIR)
9vpath %.h $(SRC_DIR)
10vpath %.S $(SRC_DIR)
11
12ALLFFLIBS = avcodec avdevice avfilter avformat avutil postproc swscale
13
14CFLAGS = -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
15 -D_ISOC9X_SOURCE -I$(BUILD_ROOT) -I$(SRC_PATH) \
16 $(addprefix -I$(SRC_PATH)/lib,$(ALLFFLIBS)) $(OPTFLAGS)
17
18%.o: %.c
19 $(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $<
20
21%.o: %.S
22 $(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $<
23
24%.ho: %.h
25 $(CC) $(CFLAGS) $(LIBOBJFLAGS) -Wno-unused -c -o $@ -x c $<
26
27%.d: %.c
28 $(DEPEND_CMD) > $@
29
30%.d: %.S
31 $(DEPEND_CMD) > $@
32
33%.d: %.cpp
34 $(DEPEND_CMD) > $@
35
36install: install-libs install-headers
37
38uninstall: uninstall-libs uninstall-headers
39
40.PHONY: all depend dep clean distclean install* uninstall* tests
41endif
42
43CFLAGS += $(CFLAGS-yes)
44OBJS += $(OBJS-yes)
45ASM_OBJS += $(ASM_OBJS-yes)
46CPP_OBJS += $(CPP_OBJS-yes)
47FFLIBS := $(FFLIBS-yes) $(FFLIBS)
48TESTS += $(TESTS-yes)
49
50FFEXTRALIBS := $(addprefix -l,$(addsuffix $(BUILDSUF),$(FFLIBS))) $(EXTRALIBS)
51FFLDFLAGS := $(addprefix -L$(BUILD_ROOT)/lib,$(FFLIBS)) $(LDFLAGS)
52
53SRCS := $(OBJS:.o=.c) $(ASM_OBJS:.o=.S) $(CPP_OBJS:.o=.cpp)
54OBJS := $(OBJS) $(ASM_OBJS) $(CPP_OBJS)
55
56SRCS := $(addprefix $(SUBDIR),$(SRCS))
57OBJS := $(addprefix $(SUBDIR),$(OBJS))
58TESTS := $(addprefix $(SUBDIR),$(TESTS))
59
60DEP_LIBS:=$(foreach NAME,$(FFLIBS),lib$(NAME)/$($(BUILD_SHARED:yes=S)LIBNAME))
61
62ALLHEADERS := $(subst $(SRC_DIR)/,$(SUBDIR),$(wildcard $(SRC_DIR)/*.h))
63checkheaders: $(filter-out %_template.ho,$(ALLHEADERS:.h=.ho))
64
65DEPS := $(OBJS:.o=.d)
66depend dep: $(DEPS)
67
68CLEANSUFFIXES = *.o *~ *.ho
69LIBSUFFIXES = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a *.exp *.map
70
71define RULES
72$(SUBDIR)%: $(SUBDIR)%.o $(LIBNAME)
73 $(CC) $(FFLDFLAGS) -o $$@ $$^ $(FFEXTRALIBS)
74
75$(SUBDIR)%-test$(EXESUF): $(SUBDIR)%.c $(LIBNAME)
76 $(CC) $(CFLAGS) $(FFLDFLAGS) -DTEST -o $$@ $$^ $(FFEXTRALIBS)
77
78clean::
79 rm -f $(TESTS) $(addprefix $(SUBDIR),$(CLEANFILES) $(CLEANSUFFIXES) $(LIBSUFFIXES)) \
80 $(addprefix $(SUBDIR), $(foreach suffix,$(CLEANSUFFIXES),$(addsuffix /$(suffix),$(DIRS))))
81
82distclean:: clean
83 rm -f $(DEPS)
84endef
85
86$(eval $(RULES))
87
88tests: $(TESTS)
89
90-include $(DEPS)