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