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