library.mak 3.6 KB

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