library.mak 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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) $(SHLIBOBJS) $(STLIBOBJS) $(SUBDIR)%.h.o $(TESTOBJS)
  13. $(LIBOBJS) $(LIBOBJS:.o=.s) $(LIBOBJS:.o=.i): CPPFLAGS += -DHAVE_AV_CONFIG_H
  14. ifdef CONFIG_SHARED
  15. # In case both shared libs and static libs are enabled, it can happen
  16. # that a user might want to link e.g. libavformat statically, but
  17. # libavcodec and the other libs dynamically. In this case
  18. # libavformat won't be able to access libavcodec's internal symbols,
  19. # so that they have to be duplicated into the archive just like
  20. # for purely shared builds.
  21. # Test programs are always statically linked against their library
  22. # to be able to access their library's internals, even with shared builds.
  23. # Yet linking against dependend libraries still uses dynamic linking.
  24. # This means that we are in the scenario described above.
  25. # In case only static libs are used, the linker will only use
  26. # one of these copies; this depends on the duplicated object files
  27. # containing exactly the same symbols.
  28. OBJS += $(SHLIBOBJS)
  29. endif
  30. $(SUBDIR)$(LIBNAME): $(OBJS) $(STLIBOBJS)
  31. $(RM) $@
  32. $(AR) $(ARFLAGS) $(AR_O) $^
  33. $(RANLIB) $@
  34. install-headers: install-lib$(NAME)-headers install-lib$(NAME)-pkgconfig
  35. install-libs-$(CONFIG_STATIC): install-lib$(NAME)-static
  36. install-libs-$(CONFIG_SHARED): install-lib$(NAME)-shared
  37. define RULES
  38. $(TOOLS): THISLIB = $(FULLNAME:%=$(LD_LIB))
  39. $(TESTPROGS): THISLIB = $(SUBDIR)$(LIBNAME)
  40. $(LIBOBJS): CPPFLAGS += -DBUILDING_$(NAME)
  41. $(TESTPROGS) $(TOOLS): %$(EXESUF): %.o
  42. $$(LD) $(LDFLAGS) $(LDEXEFLAGS) $$(LD_O) $$(filter %.o,$$^) $$(THISLIB) $(FFEXTRALIBS) $$(EXTRALIBS-$$(*F)) $$(ELIBS)
  43. $(SUBDIR)lib$(NAME).version: $(SUBDIR)version.h $(SUBDIR)version_major.h | $(SUBDIR)
  44. $$(M) $$(SRC_PATH)/ffbuild/libversion.sh $(NAME) $$^ > $$@
  45. $(SUBDIR)lib$(FULLNAME).pc: $(SUBDIR)version.h ffbuild/config.sh | $(SUBDIR)
  46. $$(M) $$(SRC_PATH)/ffbuild/pkgconfig_generate.sh $(NAME) "$(DESC)"
  47. $(SUBDIR)lib$(NAME).ver: $(SUBDIR)lib$(NAME).v $(OBJS)
  48. $$(M)sed 's/MAJOR/$(lib$(NAME)_VERSION_MAJOR)/' $$< | $(VERSION_SCRIPT_POSTPROCESS_CMD) > $$@
  49. $(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR)
  50. $(Q)cd ./$(SUBDIR) && $(LN_S) $(SLIBNAME_WITH_MAJOR) $(SLIBNAME)
  51. $(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SHLIBOBJS) $(SLIBOBJS) $(SUBDIR)lib$(NAME).ver
  52. $(SLIB_CREATE_DEF_CMD)
  53. $$(LD) $(SHFLAGS) $(LDFLAGS) $(LDSOFLAGS) $$(LD_O) $$(filter %.o,$$^) $(FFEXTRALIBS)
  54. $(SLIB_EXTRA_CMD)
  55. ifdef SUBDIR
  56. $(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(DEP_LIBS)
  57. endif
  58. clean::
  59. $(RM) $(addprefix $(SUBDIR),$(CLEANFILES) $(CLEANSUFFIXES) $(LIBSUFFIXES)) \
  60. $(CLEANSUFFIXES:%=$(SUBDIR)$(ARCH)/%) $(CLEANSUFFIXES:%=$(SUBDIR)tests/%)
  61. install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)
  62. $(Q)mkdir -p "$(SHLIBDIR)"
  63. $$(INSTALL) -m 755 $$< "$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"
  64. $$(STRIP) "$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"
  65. $(Q)$(foreach F,$(SLIB_INSTALL_LINKS),(cd "$(SHLIBDIR)" && $(LN_S) $(SLIB_INSTALL_NAME) $(F));)
  66. $(if $(SLIB_INSTALL_EXTRA_SHLIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_SHLIB:%=$(SUBDIR)%) "$(SHLIBDIR)")
  67. $(if $(SLIB_INSTALL_EXTRA_LIB),$(Q)mkdir -p "$(LIBDIR)")
  68. $(if $(SLIB_INSTALL_EXTRA_LIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_LIB:%=$(SUBDIR)%) "$(LIBDIR)")
  69. install-lib$(NAME)-static: $(SUBDIR)$(LIBNAME)
  70. $(Q)mkdir -p "$(LIBDIR)"
  71. $$(INSTALL) -m 644 $$< "$(LIBDIR)"
  72. $(LIB_INSTALL_EXTRA_CMD)
  73. install-lib$(NAME)-headers: $(addprefix $(SUBDIR),$(HEADERS) $(BUILT_HEADERS))
  74. $(Q)mkdir -p "$(INCINSTDIR)"
  75. $$(INSTALL) -m 644 $$^ "$(INCINSTDIR)"
  76. install-lib$(NAME)-pkgconfig: $(SUBDIR)lib$(FULLNAME).pc
  77. $(Q)mkdir -p "$(PKGCONFIGDIR)"
  78. $$(INSTALL) -m 644 $$^ "$(PKGCONFIGDIR)"
  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. uninstall-headers::
  87. $(RM) $(addprefix "$(INCINSTDIR)/",$(HEADERS) $(BUILT_HEADERS))
  88. -rmdir "$(INCINSTDIR)"
  89. uninstall-pkgconfig::
  90. $(RM) "$(PKGCONFIGDIR)/lib$(FULLNAME).pc"
  91. endef
  92. $(eval $(RULES))
  93. $(TOOLS): $(DEP_LIBS) $(SUBDIR)$($(CONFIG_SHARED:yes=S)LIBNAME)
  94. $(TESTPROGS): $(DEP_LIBS) $(SUBDIR)$(LIBNAME)
  95. testprogs: $(TESTPROGS)