common.mak 3.07 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
ALLFFLIBS = avcodec avdevice avfilter avformat avutil postproc swscale

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

21 22
CFLAGS += -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
          -D_ISOC9X_SOURCE -I$(BUILD_ROOT) -I$(SRC_PATH) \
23 24 25 26
          $(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
27

28
SRCS := $(OBJS:.o=.c) $(ASM_OBJS:.o=.S) $(CPPOBJS:.o=.cpp)
29 30
OBJS := $(OBJS) $(ASM_OBJS) $(CPPOBJS)

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

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

38
$(SLIBNAME): $(SLIBNAME_WITH_MAJOR)
39
	$(LN_S) $^ $@
40

41
$(SLIBNAME_WITH_MAJOR): $(OBJS)
42
	$(SLIB_CREATE_DEF_CMD)
43
	$(CC) $(SHFLAGS) $(LDFLAGS) -o $@ $^ $(EXTRALIBS) $(EXTRAOBJS)
44
	$(SLIB_EXTRA_CMD)
45 46 47 48 49 50 51

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

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

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

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

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

61
depend dep: $(SRCS)
62 63 64
	$(CC) -MM $(CFLAGS) $^ 1>.depend

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

distclean: clean
	rm -f .depend

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

install: install-libs install-headers

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

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

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

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

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

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

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

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

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

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

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

121
-include .depend