common.mak 3.12 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
SRCS := $(OBJS:.o=.c) $(ASM_OBJS:.o=.S) $(CPPOBJS:.o=.cpp)
30 31
OBJS := $(OBJS) $(ASM_OBJS) $(CPPOBJS)

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

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

39
$(SLIBNAME): $(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
depend dep: $(SRCS)
63
	$(DEPEND_CMD) > .depend
64 65

clean::
66
	rm -f *.o *~ *.a *.lib *.so *.so.* *.dylib *.dll \
67
	      *.def *.dll.a *.exp *.ho *.map $(TESTS)
68 69 70 71

distclean: clean
	rm -f .depend

72 73
INSTALL_TARGETS-$(BUILD_SHARED) += install-lib-shared
INSTALL_TARGETS-$(BUILD_STATIC) += install-lib-static
74 75 76

install: install-libs install-headers

77
install-libs: $(INSTALL_TARGETS-yes)
78 79

install-lib-shared: $(SLIBNAME)
80 81 82 83
	install -d "$(SHLIBDIR)"
	install -m 755 $(SLIBNAME) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
	$(STRIP) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
	cd "$(SHLIBDIR)" && \
84
		$(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME_WITH_MAJOR)
85
	cd "$(SHLIBDIR)" && \
86
		$(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME)
87
	$(SLIB_INSTALL_EXTRA_CMD)
88

89
install-lib-static: $(LIBNAME)
90
	install -d "$(LIBDIR)"
91
	install -m 644 $(LIBNAME) "$(LIBDIR)"
92
	$(LIB_INSTALL_EXTRA_CMD)
93

94 95
INCINSTDIR = $(INCDIR)/lib$(NAME)

96
install-headers:
97
	install -d "$(INCINSTDIR)"
98
	install -d "$(LIBDIR)/pkgconfig"
99
	install -m 644 $(addprefix "$(SRC_DIR)"/,$(HEADERS)) "$(INCINSTDIR)"
100
	install -m 644 $(BUILD_ROOT)/lib$(NAME).pc "$(LIBDIR)/pkgconfig"
101

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

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

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

115 116 117 118 119 120
tests: $(TESTS)

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

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

122
-include .depend