consolidate CFLAGS, LDFLAGS, EXTRALIBS assignment
[ffmpeg.git] / common.mak
1 #
2 # common bits used by all libraries
3 #
4
5 LIBSRC = $(SRC_PATH_BARE)/lib$(NAME)
6
7 vpath %.c $(LIBSRC)
8 vpath %.h $(LIBSRC)
9 vpath %.S $(LIBSRC)
10
11 SRC_DIR = "$(LIBSRC)"
12
13 ALLFFLIBS = avcodec avdevice avfilter avformat avutil postproc swscale
14
15 CFLAGS   += $(CFLAGS-yes)
16 OBJS     += $(OBJS-yes)
17 ASM_OBJS += $(ASM_OBJS-yes)
18 CPP_OBJS += $(CPP_OBJS-yes)
19 FFLIBS   += $(FFLIBS-yes)
20
21 CFLAGS += -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
22           -D_ISOC9X_SOURCE -I$(BUILD_ROOT) -I$(SRC_PATH) \
23           $(addprefix -I$(SRC_PATH)/lib,$(ALLFFLIBS)) $(OPTFLAGS)
24
25 EXTRALIBS := $(addprefix -l,$(addsuffix $(BUILDSUF),$(FFLIBS))) $(EXTRALIBS)
26 LDFLAGS   := $(addprefix -L$(BUILD_ROOT)/lib,$(FFLIBS)) $(LDFLAGS)
27
28 SRCS := $(OBJS:.o=.c) $(ASM_OBJS:.o=.S) $(CPPOBJS:.o=.cpp)
29 OBJS := $(OBJS) $(ASM_OBJS) $(CPPOBJS)
30
31 all: $(LIBNAME) $(SLIBNAME)
32
33 $(LIBNAME): $(OBJS)
34         rm -f $@
35         $(AR) rc $@ $^ $(EXTRAOBJS)
36         $(RANLIB) $@
37
38 $(SLIBNAME): $(SLIBNAME_WITH_MAJOR)
39         $(LN_S) $^ $@
40
41 $(SLIBNAME_WITH_MAJOR): $(OBJS)
42         $(SLIB_CREATE_DEF_CMD)
43         $(CC) $(SHFLAGS) $(LDFLAGS) -o $@ $^ $(EXTRALIBS) $(EXTRAOBJS)
44         $(SLIB_EXTRA_CMD)
45
46 %.o: %.c
47         $(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $<
48
49 %.o: %.S
50         $(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $<
51
52 %: %.o $(LIBNAME)
53         $(CC) $(LDFLAGS) -o $@ $^ $(EXTRALIBS)
54
55 %.ho: %.h
56         $(CC) $(CFLAGS) $(LIBOBJFLAGS) -Wno-unused -c -o $@ -x c $<
57
58 ALLHEADERS = $(subst $(LIBSRC)/,,$(wildcard $(LIBSRC)/*.h))
59 checkheaders: $(filter-out %_template.ho,$(ALLHEADERS:.h=.ho))
60
61 depend dep: $(SRCS)
62         $(CC) -MM $(CFLAGS) $^ 1>.depend
63
64 clean::
65         rm -f *.o *~ *.a *.lib *.so *.so.* *.dylib *.dll \
66               *.def *.dll.a *.exp *.ho *.map $(TESTS)
67
68 distclean: clean
69         rm -f .depend
70
71 INSTALL_TARGETS-$(BUILD_SHARED) += install-lib-shared
72 INSTALL_TARGETS-$(BUILD_STATIC) += install-lib-static
73
74 install: install-libs install-headers
75
76 install-libs: $(INSTALL_TARGETS-yes)
77
78 install-lib-shared: $(SLIBNAME)
79         install -d "$(SHLIBDIR)"
80         install -m 755 $(SLIBNAME) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
81         $(STRIP) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
82         cd "$(SHLIBDIR)" && \
83                 $(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME_WITH_MAJOR)
84         cd "$(SHLIBDIR)" && \
85                 $(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME)
86         $(SLIB_INSTALL_EXTRA_CMD)
87
88 install-lib-static: $(LIBNAME)
89         install -d "$(LIBDIR)"
90         install -m 644 $(LIBNAME) "$(LIBDIR)"
91         $(LIB_INSTALL_EXTRA_CMD)
92
93 INCINSTDIR = $(INCDIR)/lib$(NAME)
94
95 install-headers:
96         install -d "$(INCINSTDIR)"
97         install -d "$(LIBDIR)/pkgconfig"
98         install -m 644 $(addprefix $(SRC_DIR)/,$(HEADERS)) "$(INCINSTDIR)"
99         install -m 644 $(BUILD_ROOT)/lib$(NAME).pc "$(LIBDIR)/pkgconfig"
100
101 uninstall: uninstall-libs uninstall-headers
102
103 uninstall-libs:
104         -rm -f "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR)" \
105                "$(SHLIBDIR)/$(SLIBNAME)"            \
106                "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
107         -$(SLIB_UNINSTALL_EXTRA_CMD)
108         -rm -f "$(LIBDIR)/$(LIBNAME)"
109
110 uninstall-headers::
111         rm -f $(addprefix "$(INCINSTDIR)/",$(HEADERS))
112         rm -f "$(LIBDIR)/pkgconfig/lib$(NAME).pc"
113
114 tests: $(TESTS)
115
116 %-test$(EXESUF): %.c $(LIBNAME)
117         $(CC) $(CFLAGS) $(LDFLAGS) -DTEST -o $@ $^ $(EXTRALIBS)
118
119 .PHONY: all depend dep clean distclean install* uninstall* tests
120
121 -include .depend