common.mak 2.81 KB
Newer Older
1 2 3 4
#
# common bits used by all libraries
#

5 6 7 8 9 10 11
LIBSRC = $(SRC_PATH_BARE)/lib$(NAME)

vpath %.c $(LIBSRC)
vpath %.h $(LIBSRC)
vpath %.S $(LIBSRC)

SRC_DIR = "$(LIBSRC)"
12

13 14 15
CFLAGS   += $(CFLAGS-yes)
OBJS     += $(OBJS-yes)
ASM_OBJS += $(ASM_OBJS-yes)
16
CPP_OBJS += $(CPP_OBJS-yes)
17

18 19 20
CFLAGS += -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
          -D_ISOC9X_SOURCE -I$(BUILD_ROOT) -I$(SRC_PATH) \
          -I$(SRC_PATH)/libavutil $(OPTFLAGS)
Diego Biurrun's avatar
Diego Biurrun committed
21

22
SRCS := $(OBJS:.o=.c) $(ASM_OBJS:.o=.S) $(CPPOBJS:.o=.cpp)
23 24
OBJS := $(OBJS) $(ASM_OBJS) $(CPPOBJS)

25
all: $(LIBNAME) $(SLIBNAME)
26

27
$(LIBNAME): $(OBJS)
28 29 30 31
	rm -f $@
	$(AR) rc $@ $^ $(EXTRAOBJS)
	$(RANLIB) $@

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 41 42 43 44 45

%.o: %.c
	$(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $<

%.o: %.S
	$(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $<

46
%: %.o $(LIBNAME)
Diego Biurrun's avatar
Diego Biurrun committed
47 48
	$(CC) $(LDFLAGS) -o $@ $^ $(EXTRALIBS)

Måns Rullgård's avatar
Måns Rullgård committed
49 50 51
%.ho: %.h
	$(CC) $(CFLAGS) $(LIBOBJFLAGS) -Wno-unused -c -o $@ -x c $<

52
ALLHEADERS = $(subst $(LIBSRC)/,,$(wildcard $(LIBSRC)/*.h))
Måns Rullgård's avatar
Måns Rullgård committed
53 54
checkheaders: $(filter-out %_template.ho,$(ALLHEADERS:.h=.ho))

55
depend dep: $(SRCS)
56 57 58
	$(CC) -MM $(CFLAGS) $^ 1>.depend

clean::
59
	rm -f *.o *~ *.a *.lib *.so *.so.* *.dylib *.dll \
60
	      *.def *.dll.a *.exp *.ho *.map $(TESTS)
61 62 63 64

distclean: clean
	rm -f .depend

65 66
INSTALL_TARGETS-$(BUILD_SHARED) += install-lib-shared
INSTALL_TARGETS-$(BUILD_STATIC) += install-lib-static
67 68 69

install: install-libs install-headers

70
install-libs: $(INSTALL_TARGETS-yes)
71 72

install-lib-shared: $(SLIBNAME)
73 74 75 76
	install -d "$(SHLIBDIR)"
	install -m 755 $(SLIBNAME) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
	$(STRIP) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
	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 88
INCINSTDIR = $(INCDIR)/lib$(NAME)

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

Diego Biurrun's avatar
Diego Biurrun committed
95 96 97
uninstall: uninstall-libs uninstall-headers

uninstall-libs:
98 99 100
	-rm -f "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR)" \
	       "$(SHLIBDIR)/$(SLIBNAME)"            \
	       "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
101
	-$(SLIB_UNINSTALL_EXTRA_CMD)
102
	-rm -f "$(LIBDIR)/$(LIBNAME)"
Diego Biurrun's avatar
Diego Biurrun committed
103

104
uninstall-headers::
105
	rm -f $(addprefix "$(INCINSTDIR)/",$(HEADERS))
106
	rm -f "$(LIBDIR)/pkgconfig/lib$(NAME).pc"
Diego Biurrun's avatar
Diego Biurrun committed
107

108 109 110 111 112 113
tests: $(TESTS)

%-test$(EXESUF): %.c $(LIBNAME)
	$(CC) $(CFLAGS) $(LDFLAGS) -DTEST -o $@ $^ $(EXTRALIBS)

.PHONY: all depend dep clean distclean install* uninstall* tests
114

115
-include .depend