Makefile.moddir_rules 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. ifneq ($(findstring STATIC_BUILD,$(MENUSELECT_CFLAGS)),)
  19. STATIC_BUILD=-static
  20. endif
  21. include $(ASTTOPDIR)/Makefile.rules
  22. # If MODULE_PREFIX is defined, use it to run the standard functions to set
  23. # C_MODS, CC_MODS and LOADABLE_MODS
  24. # Each word of MODULE_PREFIX is a prefix for filenames that we consider
  25. # valid C or CC modules (eg. app, func ...). Note that the underscore
  26. # is added here, and does not need to be in MODULE_PREFIX
  27. #
  28. # Use MODULE_EXCLUDE to specify additional modules to exclude.
  29. ifneq ($(MODULE_PREFIX),)
  30. ALL_C_MODS:=
  31. ALL_CC_MODS:=
  32. ALL_C_MODS+=$(foreach p,$(MODULE_PREFIX),$(patsubst %.c,%,$(wildcard $(p)_*.c)))
  33. ALL_CC_MODS+=$(foreach p,$(MODULE_PREFIX),$(patsubst %.cc,%,$(wildcard $(p)_*.cc)))
  34. endif
  35. C_MODS:=$(filter-out $(MENUSELECT_$(MENUSELECT_CATEGORY)),$(ALL_C_MODS))
  36. CC_MODS:=$(filter-out $(MENUSELECT_$(MENUSELECT_CATEGORY)),$(ALL_CC_MODS))
  37. LOADABLE_MODS:=$(C_MODS) $(CC_MODS)
  38. # Both C++ and C++ sources need their module name in AST_MODULE
  39. # We also pass whatever _INCLUDE list is generated by menuselect
  40. # (they are stored in file 'makeopts'). This is also necessary
  41. # for components used to build modules, which can't be determined
  42. # by the rules in this file, so the MOD_ASTCFLAGS definition
  43. # is used to collect the required flags for a module... which can
  44. # then be used any place they are required.
  45. MOD_ASTCFLAGS=-DAST_MODULE=\"$(1)\" $(MENUSELECT_OPTS_$(1):%=-D%) $(foreach dep,$(MENUSELECT_DEPENDS_$(1)),$(value $(dep)_INCLUDE))
  46. $(addsuffix .oo,$(CC_MODS)) $(addsuffix .o,$(C_MODS)): \
  47. _ASTCFLAGS+=$(call MOD_ASTCFLAGS,$*)
  48. ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
  49. # don't define -fPIC on mingw32 and cygwin, it is the default
  50. $(LOADABLE_MODS:%=%.so): _ASTCFLAGS+=-fPIC
  51. endif
  52. # For loadable modules, pass _LIB and _LDFLAGS from menuselect.
  53. $(LOADABLE_MODS:%=%.so): LIBS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LIB))
  54. $(LOADABLE_MODS:%=%.so): _ASTLDFLAGS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LDFLAGS))
  55. $(addsuffix .so,$(filter $(LOADABLE_MODS),$(C_MODS))): %.so: %.o
  56. $(addsuffix .so,$(filter $(LOADABLE_MODS),$(CC_MODS))): %.so: %.oo
  57. .PHONY: clean uninstall _all moduleinfo makeopts
  58. _all: $(LOADABLE_MODS:%=%.so)
  59. ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
  60. # linker options and extra libraries for cygwin
  61. SOLINK=-Wl,--out-implib=lib$@.a -shared
  62. LIBS+=-L$(ASTTOPDIR)/main -lasterisk -L$(ASTTOPDIR)/res $($@_LIBS)
  63. # additional libraries in res/
  64. endif
  65. clean::
  66. rm -f *.so *.o *.oo *.eo *.i *.ii
  67. rm -f .*.d
  68. rm -f *.s *.i
  69. rm -f *.gcda *.gcno
  70. rm -f modules.link
  71. install:: all
  72. @echo "Installing modules from `basename $(CURDIR)`..."
  73. @for x in $(LOADABLE_MODS:%=%.so); do $(INSTALL) -m 755 $$x "$(DESTDIR)$(ASTMODDIR)" ; done
  74. ifneq ($(findstring :,$(XMLSTARLET)$(BASH)),:)
  75. @if [ -f .moduleinfo ] ; then \
  76. declare -A DISABLED_MODS ;\
  77. for x in $(MENUSELECT_$(MENUSELECT_CATEGORY)) ; do DISABLED_MODS[$${x}]=1 ; done ;\
  78. EXTERNAL_MODS=$$($(XMLSTARLET) sel -t -m "/category/member[support_level = 'external']" -v "@name" -n .moduleinfo) ;\
  79. for x in $${EXTERNAL_MODS} ; do \
  80. if [ -z "$${DISABLED_MODS[$${x}]}" ] ; then \
  81. $(ASTTOPDIR)/build_tools/download_externals $${x} ;\
  82. fi ;\
  83. done ;\
  84. fi
  85. endif
  86. uninstall::
  87. dist-clean::
  88. rm -f .*.moduleinfo .moduleinfo
  89. rm -f .*.makeopts .makeopts
  90. rm -f *.exports
  91. .%.moduleinfo: %.c
  92. @echo "<member name=\"$*\" displayname=\"$(shell $(GREP) -e AST_MODULE_INFO $< | head -n 1 | cut -d '"' -f 2)\" remove_on_change=\"$(SUBDIR)/$*.o $(SUBDIR)/$*.so\">" > $@
  93. $(AWK) -f $(ASTTOPDIR)/build_tools/get_moduleinfo $^ >> $@
  94. echo "</member>" >> $@
  95. .%.moduleinfo: %.cc
  96. @echo "<member name=\"$*\" displayname=\"$(shell $(GREP) -e AST_MODULE_INFO $< | head -n 1 | cut -d '"' -f 2)\" remove_on_change=\"$(SUBDIR)/$*.oo $(SUBDIR)/$*.so\">" > $@
  97. $(AWK) -f $(ASTTOPDIR)/build_tools/get_moduleinfo $^ >> $@
  98. echo "</member>" >> $@
  99. .moduleinfo:: $(addsuffix .moduleinfo,$(addprefix .,$(sort $(ALL_C_MODS) $(ALL_CC_MODS)))) $(wildcard $(call tolower,$(MENUSELECT_CATEGORY)).xml)
  100. @echo "<category name=\"MENUSELECT_$(MENUSELECT_CATEGORY)\" displayname=\"$(MENUSELECT_DESCRIPTION)\">" > $@
  101. @cat $^ >> $@
  102. @echo "</category>" >> $@
  103. moduleinfo: .moduleinfo
  104. @cat $<
  105. .%.makeopts: %.c
  106. @$(AWK) -f $(ASTTOPDIR)/build_tools/get_makeopts $< > $@
  107. .%.makeopts: %.cc
  108. @$(AWK) -f $(ASTTOPDIR)/build_tools/get_makeopts $< > $@
  109. .makeopts:: $(addsuffix .makeopts,$(addprefix .,$(ALL_C_MODS) $(ALL_CC_MODS)))
  110. @cat $^ > $@
  111. makeopts: .makeopts
  112. @cat $<
  113. ifneq ($(wildcard .*.d),)
  114. include .*.d
  115. endif