Makefile.moddir_rules 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #
  2. # Asterisk -- An open source telephony toolkit.
  3. #
  4. # Makefile rules for subdirectories containing modules
  5. #
  6. # Copyright (C) 2006, Digium, Inc.
  7. #
  8. # Kevin P. Fleming <kpfleming@digium.com>
  9. #
  10. # This program is free software, distributed under the terms of
  11. # the GNU General Public License
  12. #
  13. # Makefile rules for building modules.
  14. # In most cases, we set target-specific variables for certain targets
  15. # (remember that they apply recursively to prerequisites).
  16. # Also note that we can only set one variable per rule, so we have to
  17. # repeat the left hand side to set multiple variables.
  18. include $(ASTTOPDIR)/Makefile.rules
  19. # If MODULE_PREFIX is defined, use it to run the standard functions to set
  20. # C_MODS, CC_MODS and LOADABLE_MODS
  21. # Each word of MODULE_PREFIX is a prefix for filenames that we consider
  22. # valid C or CC modules (eg. app, func ...). Note that the underscore
  23. # is added here, and does not need to be in MODULE_PREFIX
  24. #
  25. # Use MODULE_EXCLUDE to specify additional modules to exclude.
  26. ifneq ($(MODULE_PREFIX),)
  27. ALL_C_MODS:=
  28. ALL_CC_MODS:=
  29. ALL_C_MODS+=$(foreach p,$(MODULE_PREFIX),$(patsubst %.c,%,$(wildcard $(p)_*.c)))
  30. ALL_CC_MODS+=$(foreach p,$(MODULE_PREFIX),$(patsubst %.cc,%,$(wildcard $(p)_*.cc)))
  31. endif
  32. C_MODS:=$(filter-out $(MENUSELECT_$(MENUSELECT_CATEGORY)),$(ALL_C_MODS))
  33. CC_MODS:=$(filter-out $(MENUSELECT_$(MENUSELECT_CATEGORY)),$(ALL_CC_MODS))
  34. LOADABLE_MODS:=$(C_MODS) $(CC_MODS)
  35. # Both C++ and C++ sources need their module name in AST_MODULE
  36. # We also pass whatever _INCLUDE list is generated by menuselect
  37. # (they are stored in file 'makeopts'). This is also necessary
  38. # for components used to build modules, which can't be determined
  39. # by the rules in this file, so the MOD_ASTCFLAGS definition
  40. # is used to collect the required flags for a module... which can
  41. # then be used any place they are required.
  42. MOD_ASTCFLAGS=\
  43. -DAST_MODULE=\"$(1)\" \
  44. -DAST_MODULE_SELF_SYM=__internal_$(1)_self \
  45. $(MENUSELECT_OPTS_$(1):%=-D%) \
  46. $(foreach dep,$(MENUSELECT_DEPENDS_$(1)),$(value $(dep)_INCLUDE))
  47. define MOD_ADD_SOURCE
  48. $(1).so: $$(subst $(3),$(5),$(2))
  49. $$(subst $(3),$(5),$(2)): _ASTCFLAGS+=$$(call MOD_ASTCFLAGS,$(1))
  50. .$(1).moduleinfo: MODULEINFO_EXTRA_OUTPUT=" $$(addprefix $$(SUBDIR)/,$$(subst $(3),$(5),$(2)) $$(subst $(3),$(4),$(2)))"
  51. # The use of wildcard ensures that 'make menuselect' will not fail for modules that
  52. # require additional source downloads.
  53. .$(1).moduleinfo: $(wildcard $(2))
  54. clean:: clean-$(1)$(3)
  55. clean-$(1)$(3):
  56. rm -f $$(subst $(3),$(4),$(2)) $$(subst $(3),$(5),$(2)) $$(subst $(3),$(6),$(2)) $$(subst $(3),$(7),$(2))
  57. endef
  58. MOD_ADD_C=$(eval $(call MOD_ADD_SOURCE,$(1),$(2),.c,.i,.o,.gcda,.gcno))
  59. MOD_ADD_CC=$(eval $(call MOD_ADD_SOURCE,$(1),$(2),.cc,.ii,.oo,.gcda,.gcno))
  60. $(addsuffix .oo,$(CC_MODS)) $(addsuffix .o,$(C_MODS)): \
  61. _ASTCFLAGS+=$(call MOD_ASTCFLAGS,$*)
  62. ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
  63. # don't define -fPIC on mingw32 and cygwin, it is the default
  64. $(LOADABLE_MODS:%=%.so): _ASTCFLAGS+=-fPIC
  65. endif
  66. # For loadable modules, pass _LIB and _LDFLAGS from menuselect.
  67. $(LOADABLE_MODS:%=%.so): LIBS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LIB))
  68. $(LOADABLE_MODS:%=%.so): _ASTLDFLAGS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LDFLAGS))
  69. $(addsuffix .so,$(filter $(LOADABLE_MODS),$(C_MODS))): %.so: %.o
  70. $(addsuffix .so,$(filter $(LOADABLE_MODS),$(CC_MODS))): %.so: %.oo
  71. .PHONY: clean uninstall _all moduleinfo makeopts
  72. _all: $(LOADABLE_MODS:%=%.so)
  73. ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
  74. # linker options and extra libraries for cygwin
  75. SOLINK=-Wl,--out-implib=lib$@.a -shared
  76. LIBS+=-L$(ASTTOPDIR)/main -lasterisk -L$(ASTTOPDIR)/res $($@_LIBS)
  77. # additional libraries in res/
  78. endif
  79. clean::
  80. rm -f *.so *.o *.oo *.eo *.i *.ii
  81. rm -f .*.d
  82. rm -f *.s *.i
  83. rm -f *.gcda *.gcno
  84. rm -f modules.link
  85. install:: all
  86. @echo "Installing modules from `basename $(CURDIR)`..."
  87. @for x in $(LOADABLE_MODS:%=%.so); do $(INSTALL) -m 755 $$x "$(DESTDIR)$(ASTMODDIR)" ; done
  88. ifneq ($(findstring :,$(XMLSTARLET)$(BASH)),:)
  89. @if [ -f .moduleinfo ] ; then \
  90. declare -A DISABLED_MODS ;\
  91. for x in $(MENUSELECT_$(MENUSELECT_CATEGORY)) ; do DISABLED_MODS[$${x}]=1 ; done ;\
  92. EXTERNAL_MODS=$$($(XMLSTARLET) sel -t -m "/category/member[support_level = 'external']" -v "@name" -n .moduleinfo) ;\
  93. for x in $${EXTERNAL_MODS} ; do \
  94. if [ -z "$${DISABLED_MODS[$${x}]}" ] ; then \
  95. PJPROJECT_BUNDLED=${PJPROJECT_BUNDLED} $(ASTTOPDIR)/build_tools/download_externals $${x} ;\
  96. fi ;\
  97. done ;\
  98. fi
  99. endif
  100. uninstall::
  101. dist-clean::
  102. rm -f .*.moduleinfo .moduleinfo
  103. rm -f .*.makeopts .makeopts
  104. rm -f *.exports
  105. .%.moduleinfo: %.c
  106. @echo "<member name=\"$*\" displayname=\"$(shell $(GREP) -e AST_MODULE_INFO $< | head -n 1 | cut -d '"' -f 2)\" remove_on_change=\"$(SUBDIR)/$*.o $(SUBDIR)/$*.i $(SUBDIR)/$*.so$(MODULEINFO_EXTRA_OUTPUT)\">" > $@
  107. $(AWK) -f $(ASTTOPDIR)/build_tools/get_moduleinfo $^ >> $@
  108. echo "</member>" >> $@
  109. .%.moduleinfo: %.cc
  110. @echo "<member name=\"$*\" displayname=\"$(shell $(GREP) -e AST_MODULE_INFO $< | head -n 1 | cut -d '"' -f 2)\" remove_on_change=\"$(SUBDIR)/$*.oo $(SUBDIR)/$*.ii $(SUBDIR)/$*.so$(MODULEINFO_EXTRA_OUTPUT)\">" > $@
  111. $(AWK) -f $(ASTTOPDIR)/build_tools/get_moduleinfo $^ >> $@
  112. echo "</member>" >> $@
  113. .moduleinfo:: $(addsuffix .moduleinfo,$(addprefix .,$(sort $(ALL_C_MODS) $(ALL_CC_MODS)))) $(wildcard $(call tolower,$(MENUSELECT_CATEGORY)).xml)
  114. @echo "<category name=\"MENUSELECT_$(MENUSELECT_CATEGORY)\" displayname=\"$(MENUSELECT_DESCRIPTION)\">" > $@
  115. @cat $^ >> $@
  116. @echo "</category>" >> $@
  117. moduleinfo: .moduleinfo
  118. @cat $<
  119. .%.makeopts: %.c
  120. @$(AWK) -f $(ASTTOPDIR)/build_tools/get_makeopts $< > $@
  121. .%.makeopts: %.cc
  122. @$(AWK) -f $(ASTTOPDIR)/build_tools/get_makeopts $< > $@
  123. .makeopts:: $(addsuffix .makeopts,$(addprefix .,$(ALL_C_MODS) $(ALL_CC_MODS)))
  124. @cat $^ > $@
  125. makeopts: .makeopts
  126. @cat $<
  127. ifneq ($(wildcard .*.d),)
  128. include .*.d
  129. endif