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