22f1e4c37f68ec75b4483680ac6ad138d2898c5f
[ffmpeg.git] / ffbuild / library.mak
1 include $(SRC_PATH)/ffbuild/common.mak
2
3 -include $(SUBDIR)lib$(NAME).version
4
5 LIBVERSION := $(lib$(NAME)_VERSION)
6 LIBMAJOR   := $(lib$(NAME)_VERSION_MAJOR)
7 LIBMINOR   := $(lib$(NAME)_VERSION_MINOR)
8 INCINSTDIR := $(INCDIR)/lib$(NAME)
9
10 INSTHEADERS := $(INSTHEADERS) $(HEADERS:%=$(SUBDIR)%)
11
12 all-$(CONFIG_STATIC): $(SUBDIR)$(LIBNAME)  $(SUBDIR)lib$(FULLNAME).pc
13 all-$(CONFIG_SHARED): $(SUBDIR)$(SLIBNAME) $(SUBDIR)lib$(FULLNAME).pc
14
15 LIBOBJS := $(OBJS) $(SUBDIR)%.h.o $(TESTOBJS)
16 $(LIBOBJS) $(LIBOBJS:.o=.s) $(LIBOBJS:.o=.i):   CPPFLAGS += -DHAVE_AV_CONFIG_H
17 $(TESTOBJS) $(TESTOBJS:.o=.i): CFLAGS += -Umain
18
19 $(SUBDIR)$(LIBNAME): $(OBJS)
20         $(RM) $@
21         $(AR) $(ARFLAGS) $(AR_O) $^
22         $(RANLIB) $@
23
24 install-headers: install-lib$(NAME)-headers install-lib$(NAME)-pkgconfig
25
26 install-libs-$(CONFIG_STATIC): install-lib$(NAME)-static
27 install-libs-$(CONFIG_SHARED): install-lib$(NAME)-shared
28
29 define RULES
30 $(TOOLS):     THISLIB = $(FULLNAME:%=$(LD_LIB))
31 $(TESTPROGS): THISLIB = $(SUBDIR)$(LIBNAME)
32
33 $(TESTPROGS) $(TOOLS): %$(EXESUF): %.o
34         $$(LD) $(LDFLAGS) $(LDEXEFLAGS) $$(LD_O) $$(filter %.o,$$^) $$(THISLIB) $(FFEXTRALIBS) $$(ELIBS)
35
36 $(SUBDIR)lib$(NAME).version: $(SUBDIR)version.h | $(SUBDIR)
37         $$(M) $$(SRC_PATH)/ffbuild/libversion.sh $(NAME) $$< > $$@
38
39 $(SUBDIR)lib$(FULLNAME).pc: $(SUBDIR)version.h | $(SUBDIR)
40         $$(M) $$(SRC_PATH)/ffbuild/pkgconfig_generate.sh $(NAME) "$(DESC)"
41
42 $(SUBDIR)lib$(NAME).ver: $(SUBDIR)lib$(NAME).v $(OBJS)
43         $$(M)sed 's/MAJOR/$(lib$(NAME)_VERSION_MAJOR)/' $$< | $(VERSION_SCRIPT_POSTPROCESS_CMD) > $$@
44
45 $(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR)
46         $(Q)cd ./$(SUBDIR) && $(LN_S) $(SLIBNAME_WITH_MAJOR) $(SLIBNAME)
47
48 $(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SLIBOBJS) $(SUBDIR)lib$(NAME).ver
49         $(SLIB_CREATE_DEF_CMD)
50         $$(LD) $(SHFLAGS) $(LDFLAGS) $(LDLIBFLAGS) $$(LD_O) $$(filter %.o,$$^) $(FFEXTRALIBS)
51         $(SLIB_EXTRA_CMD)
52
53 ifdef SUBDIR
54 $(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(DEP_LIBS)
55 endif
56
57 clean::
58         $(RM) $(addprefix $(SUBDIR),$(CLEANFILES) $(CLEANSUFFIXES) $(LIBSUFFIXES)) \
59             $(CLEANSUFFIXES:%=$(SUBDIR)$(ARCH)/%) $(CLEANSUFFIXES:%=$(SUBDIR)tests/%)
60
61 distclean:: clean
62         $(RM) $(DISTCLEANSUFFIXES:%=$(SUBDIR)%) $(DISTCLEANSUFFIXES:%=$(SUBDIR)$(ARCH)/%) \
63             $(DISTCLEANSUFFIXES:%=$(SUBDIR)tests/%)
64
65 install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)
66         $(Q)mkdir -p "$(SHLIBDIR)"
67         $$(INSTALL) -m 755 $$< "$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"
68         $$(STRIP) "$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"
69         $(Q)$(foreach F,$(SLIB_INSTALL_LINKS),(cd "$(SHLIBDIR)" && $(LN_S) $(SLIB_INSTALL_NAME) $(F));)
70         $(if $(SLIB_INSTALL_EXTRA_SHLIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_SHLIB:%=$(SUBDIR)%) "$(SHLIBDIR)")
71         $(if $(SLIB_INSTALL_EXTRA_LIB),$(Q)mkdir -p "$(LIBDIR)")
72         $(if $(SLIB_INSTALL_EXTRA_LIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_LIB:%=$(SUBDIR)%) "$(LIBDIR)")
73
74 install-lib$(NAME)-static: $(SUBDIR)$(LIBNAME)
75         $(Q)mkdir -p "$(LIBDIR)"
76         $$(INSTALL) -m 644 $$< "$(LIBDIR)"
77         $(LIB_INSTALL_EXTRA_CMD)
78
79 install-lib$(NAME)-headers: $(addprefix $(SUBDIR),$(HEADERS) $(BUILT_HEADERS))
80         $(Q)mkdir -p "$(INCINSTDIR)"
81         $$(INSTALL) -m 644 $$^ "$(INCINSTDIR)"
82
83 install-lib$(NAME)-pkgconfig: $(SUBDIR)lib$(FULLNAME).pc
84         $(Q)mkdir -p "$(PKGCONFIGDIR)"
85         $$(INSTALL) -m 644 $$^ "$(PKGCONFIGDIR)"
86
87 uninstall-libs::
88         -$(RM) "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR)" \
89                "$(SHLIBDIR)/$(SLIBNAME)"            \
90                "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
91         -$(RM)  $(SLIB_INSTALL_EXTRA_SHLIB:%="$(SHLIBDIR)/%")
92         -$(RM)  $(SLIB_INSTALL_EXTRA_LIB:%="$(LIBDIR)/%")
93         -$(RM) "$(LIBDIR)/$(LIBNAME)"
94
95 uninstall-headers::
96         $(RM) $(addprefix "$(INCINSTDIR)/",$(HEADERS) $(BUILT_HEADERS))
97         $(RM) "$(PKGCONFIGDIR)/lib$(FULLNAME).pc"
98         -rmdir "$(INCINSTDIR)"
99 endef
100
101 $(eval $(RULES))
102
103 $(TOOLS):     $(DEP_LIBS) $(SUBDIR)$($(CONFIG_SHARED:yes=S)LIBNAME)
104 $(TESTPROGS): $(DEP_LIBS) $(SUBDIR)$(LIBNAME)
105
106 testprogs: $(TESTPROGS)