library.mak 3.3 KB

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