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