ff25cf6356348cbe1f015b0cf8c62c995546ccbd
[ffmpeg.git] / common.mak
1 #
2 # common bits used by all libraries
3 #
4
5 SRC_DIR = $(SRC_PATH)/$(SUBDIR)
6 VPATH = $(SRC_DIR)
7
8 #FIXME: This should be in configure/config.mak
9 ifeq ($(CONFIG_WIN32),yes)
10 LDFLAGS = -Wl,--output-def,$(@:.dll=.def),--out-implib,lib$(SLIBNAME:$(SLIBSUF)=.dll.a)
11 endif
12
13 ifeq ($(TARGET_GPROF),yes)
14 CFLAGS+=-p
15 LDFLAGS+=-p
16 endif
17
18 ifeq ($(TARGET_ARCH_SPARC64),yes)
19 CFLAGS+= -mcpu=ultrasparc -mtune=ultrasparc
20 endif
21
22 SRCS := $(OBJS:.o=.c) $(ASM_OBJS:.o=.S) $(CPPOBJS:.o=.cpp)
23 OBJS := $(OBJS) $(ASM_OBJS) $(CPPOBJS)
24 STATIC_OBJS := $(OBJS) $(STATIC_OBJS)
25 SHARED_OBJS := $(OBJS) $(SHARED_OBJS)
26
27 all: $(EXTRADEPS) $(LIB) $(SLIBNAME)
28
29 $(LIB): $(STATIC_OBJS)
30         rm -f $@
31         $(AR) rc $@ $^ $(EXTRAOBJS)
32         $(RANLIB) $@
33
34 $(SLIBNAME): $(SLIBNAME_WITH_MAJOR)
35         ln -sf $^ $@
36
37 $(SLIBNAME_WITH_MAJOR): $(SHARED_OBJS)
38         $(CC) $(SHFLAGS) $(LDFLAGS) -o $@ $^ $(EXTRALIBS) $(EXTRAOBJS)
39 ifeq ($(CONFIG_WIN32),yes)
40         -lib /machine:i386 /def:$(@:.dll=.def)
41 endif
42
43 %.o: %.c
44         $(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $<
45
46 %.o: %.S
47         $(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $<
48
49 # BeOS: remove -Wall to get rid of all the "multibyte constant" warnings
50 %.o: %.cpp
51         g++ $(subst -Wall,,$(CFLAGS)) -c -o $@ $<
52
53 depend: $(SRCS)
54         $(CC) -MM $(CFLAGS) $^ 1>.depend
55
56 dep:    depend
57
58 clean::
59         rm -f *.o *.d *~ *.a *.lib *.so *.dylib *.dll \
60               *.lib *.def *.dll.a *.exp
61
62 distclean: clean
63         rm -f .depend
64
65 ifeq ($(BUILD_SHARED),yes)
66 INSTLIBTARGETS += install-lib-shared
67 endif
68 ifeq ($(BUILD_STATIC),yes)
69 INSTLIBTARGETS += install-lib-static
70 endif
71
72 install: install-libs install-headers
73
74 install-libs: $(INSTLIBTARGETS)
75
76 install-lib-shared: $(SLIBNAME)
77         install -d "$(libdir)"
78 ifeq ($(CONFIG_WIN32),yes)
79         install $(INSTALLSTRIP) -m 755 $(SLIBNAME) "$(prefix)"
80 else
81         install $(INSTALLSTRIP) -m 755 $(SLIBNAME) \
82                 $(libdir)/$(SLIBNAME_WITH_VERSION)
83         ln -sf $(SLIBNAME_WITH_VERSION) \
84                 $(libdir)/$(SLIBNAME_WITH_MAJOR)
85         ln -sf $(SLIBNAME_WITH_VERSION) \
86                 $(libdir)/$(SLIBNAME)
87 endif
88
89 install-lib-static: $(LIB)
90         install -d "$(libdir)"
91         install -m 644 $(LIB) "$(libdir)"
92
93 install-headers:
94         install -d "$(incdir)"
95         install -d "$(libdir)/pkgconfig"
96         install -m 644 $(addprefix "$(SRC_DIR)"/,$(HEADERS)) "$(incdir)"
97         install -m 644 $(BUILD_ROOT)/lib$(NAME).pc "$(libdir)/pkgconfig"
98
99 uninstall: uninstall-libs uninstall-headers
100
101 uninstall-libs:
102 ifeq ($(CONFIG_WIN32),yes)
103         -rm -f $(prefix)/$(SLIBNAME)
104 else
105         -rm -f $(libdir)/$(SLIBNAME_WITH_MAJOR) \
106               $(libdir)/$(SLIBNAME)            \
107               $(libdir)/$(SLIBNAME_WITH_VERSION)
108 endif
109         -rm -f $(libdir)/$(LIB)
110
111 uninstall-headers:
112         rm -f $(addprefix $(incdir)/,$(HEADERS))
113         rm -f $(libdir)/pkgconfig/lib$(NAME).pc
114
115 #
116 # include dependency files if they exist
117 #
118 ifneq ($(wildcard .depend),)
119 include .depend
120 endif