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

5
SRC_DIR = $(SRC_PATH_BARE)/lib$(NAME)
6

7 8 9
LIBVERSION = $(lib$(NAME)_VERSION)
LIBMAJOR   = $(lib$(NAME)_VERSION_MAJOR)

10 11 12
vpath %.c $(SRC_DIR)
vpath %.h $(SRC_DIR)
vpath %.S $(SRC_DIR)
13

14 15
ALLFFLIBS = avcodec avdevice avfilter avformat avutil postproc swscale

16 17 18
CFLAGS   += $(CFLAGS-yes)
OBJS     += $(OBJS-yes)
ASM_OBJS += $(ASM_OBJS-yes)
19
CPP_OBJS += $(CPP_OBJS-yes)
20
FFLIBS   += $(FFLIBS-yes)
21

22 23
CFLAGS += -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
          -D_ISOC9X_SOURCE -I$(BUILD_ROOT) -I$(SRC_PATH) \
24 25 26 27
          $(addprefix -I$(SRC_PATH)/lib,$(ALLFFLIBS)) $(OPTFLAGS)

EXTRALIBS := $(addprefix -l,$(addsuffix $(BUILDSUF),$(FFLIBS))) $(EXTRALIBS)
LDFLAGS   := $(addprefix -L$(BUILD_ROOT)/lib,$(FFLIBS)) $(LDFLAGS)
Diego Biurrun's avatar
Diego Biurrun committed
28

29 30
SRCS := $(OBJS:.o=.c) $(ASM_OBJS:.o=.S) $(CPP_OBJS:.o=.cpp)
OBJS := $(OBJS) $(ASM_OBJS) $(CPP_OBJS)
31

32
all: $(LIBNAME) $(SLIBNAME)
33

34
$(LIBNAME)$(DISABLE): $(OBJS)
35 36 37 38
	rm -f $@
	$(AR) rc $@ $^ $(EXTRAOBJS)
	$(RANLIB) $@

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 48 49 50 51 52

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

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

53
%: %.o $(LIBNAME)
Diego Biurrun's avatar
Diego Biurrun committed
54 55
	$(CC) $(LDFLAGS) -o $@ $^ $(EXTRALIBS)

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

59
ALLHEADERS = $(subst $(SRC_DIR)/,,$(wildcard $(SRC_DIR)/*.h))
Måns Rullgård's avatar
Måns Rullgård committed
60 61
checkheaders: $(filter-out %_template.ho,$(ALLHEADERS:.h=.ho))

62 63 64
depend dep: .depend

.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 73
	rm -f .depend

74 75
INSTALL_LIB_TARGETS-$(BUILD_SHARED) += install-lib-shared
INSTALL_LIB_TARGETS-$(BUILD_STATIC) += install-lib-static
76 77 78

install: install-libs install-headers

79
install-libs$(DISABLE): $(INSTALL_LIB_TARGETS-yes)
80 81

install-lib-shared: $(SLIBNAME)
82 83 84 85
	install -d "$(SHLIBDIR)"
	install -m 755 $(SLIBNAME) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
	$(STRIP) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
	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 97
INCINSTDIR = $(INCDIR)/lib$(NAME)

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

Diego Biurrun's avatar
Diego Biurrun committed
104 105
uninstall: uninstall-libs uninstall-headers

106
uninstall-libs::
107 108 109
	-rm -f "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR)" \
	       "$(SHLIBDIR)/$(SLIBNAME)"            \
	       "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
110
	-$(SLIB_UNINSTALL_EXTRA_CMD)
111
	-rm -f "$(LIBDIR)/$(LIBNAME)"
Diego Biurrun's avatar
Diego Biurrun committed
112

113
uninstall-headers::
114
	rm -f $(addprefix "$(INCINSTDIR)/",$(HEADERS))
115
	rm -f "$(LIBDIR)/pkgconfig/lib$(NAME).pc"
Diego Biurrun's avatar
Diego Biurrun committed
116

117 118 119 120 121 122
tests: $(TESTS)

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

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

124
-include .depend