library.mak 3.7 KB

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