Makefile.moddir_rules 5.8 KB

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