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