Makefile.moddir_rules 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #
  2. # Asterisk -- A telephony toolkit for Linux.
  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_C_MODS+=$(foreach p,$(MODULE_PREFIX),$(patsubst %.c,%,$(wildcard $(p)_*.c)))
  35. ALL_CC_MODS:=
  36. ALL_CC_MODS+=$(foreach p,$(MODULE_PREFIX),$(patsubst %.cc,%,$(wildcard $(p)_*.cc)))
  37. C_MODS:=$(filter-out $(MENUSELECT_$(MENUSELECT_CATEGORY)),$(ALL_C_MODS))
  38. CC_MODS:=$(filter-out $(MENUSELECT_$(MENUSELECT_CATEGORY)),$(ALL_CC_MODS))
  39. # and store in the list of embedded or loadable modules
  40. ifneq ($(findstring $(MENUSELECT_CATEGORY),$(MENUSELECT_EMBED)),)
  41. EMBEDDED_MODS:=$(C_MODS) $(CC_MODS)
  42. else
  43. LOADABLE_MODS:=$(C_MODS) $(CC_MODS)
  44. endif
  45. endif
  46. # Both C++ and C++ sources need their module name in AST_MODULE
  47. # We also pass whatever _INCLUDE list is generated by menuselect
  48. # (they are stored in file 'makeopts')
  49. $(addsuffix .oo,$(CC_MODS)) $(addsuffix .o,$(C_MODS)): \
  50. _ASTCFLAGS+= -DAST_MODULE=\"$*\" $(MENUSELECT_OPTS_$*:%=-D%) $(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_INCLUDE))
  51. ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
  52. # don't define -fPIC on mingw32 and cygwin, it is the default
  53. $(LOADABLE_MODS:%=%.so): _ASTCFLAGS+=-fPIC
  54. endif
  55. # For loadable modules, pass _LIB and _LDFLAGS from menuselect.
  56. $(LOADABLE_MODS:%=%.so): LIBS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LIB))
  57. $(LOADABLE_MODS:%=%.so): _ASTLDFLAGS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LDFLAGS))
  58. $(EMBEDDED_MODS:%=%.o): _ASTCFLAGS+=-DEMBEDDED_MODULE=$*
  59. $(addsuffix .so,$(filter $(LOADABLE_MODS),$(C_MODS))): %.so: %.o
  60. $(addsuffix .so,$(filter $(LOADABLE_MODS),$(CC_MODS))): %.so: %.oo
  61. modules.link: $(addsuffix .eo,$(filter $(EMBEDDED_MODS),$(C_MODS)))
  62. .PHONY: clean uninstall _all moduleinfo makeopts
  63. ifneq ($(LOADABLE_MODS),)
  64. _all: $(LOADABLE_MODS:%=%.so)
  65. ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
  66. # linker options and extra libraries for cygwin
  67. SOLINK=-Wl,--out-implib=lib$@.a -shared
  68. LIBS+=-L$(ASTTOPDIR)/main -lasterisk -L$(ASTTOPDIR)/res $($@_LIBS)
  69. # additional libraries in res/
  70. endif
  71. endif
  72. ifneq ($(EMBEDDED_MODS),)
  73. _all: modules.link
  74. __embed_ldscript:
  75. @echo "../$(SUBDIR)/modules.link"
  76. __embed_ldflags:
  77. @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
  78. @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
  79. __embed_libs:
  80. @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
  81. @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
  82. else
  83. __embed_ldscript:
  84. __embed_ldflags:
  85. __embed_libs:
  86. endif
  87. modules.link:
  88. @rm -f $@
  89. @for file in $(patsubst %,$(SUBDIR)/%,$(filter %.eo,$^)); do echo "INPUT (../$${file})" >> $@; done
  90. @for file in $(patsubst %,$(SUBDIR)/%,$(filter-out %.eo,$^)); do echo "INPUT (../$${file})" >> $@; done
  91. clean::
  92. rm -f *.so *.o *.oo *.eo *.i *.ii
  93. rm -f .*.d
  94. rm -f *.s *.i
  95. rm -f modules.link
  96. install:: all
  97. @echo "Installing modules from `basename $(CURDIR)`..."
  98. @for x in $(LOADABLE_MODS:%=%.so); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
  99. uninstall::
  100. dist-clean::
  101. rm -f .*.moduleinfo .moduleinfo
  102. rm -f .*.makeopts .makeopts
  103. .%.moduleinfo: %.c
  104. @echo "<member name=\"$*\" displayname=\"$(shell $(GREP) -e AST_MODULE_INFO $< | head -n 1 | cut -d '"' -f 2)\" remove_on_change=\"$(SUBDIR)/$*.o $(SUBDIR)/$*.so\">" > $@
  105. $(AWK) -f $(ASTTOPDIR)/build_tools/get_moduleinfo $< >> $@
  106. echo "</member>" >> $@
  107. .%.moduleinfo: %.cc
  108. @echo "<member name=\"$*\" displayname=\"$(shell $(GREP) -e AST_MODULE_INFO $< | head -n 1 | cut -d '"' -f 2)\" remove_on_change=\"$(SUBDIR)/$*.oo $(SUBDIR)/$*.so\">" > $@
  109. $(AWK) -f $(ASTTOPDIR)/build_tools/get_moduleinfo $< >> $@
  110. echo "</member>" >> $@
  111. .moduleinfo:: $(addsuffix .moduleinfo,$(addprefix .,$(ALL_C_MODS) $(ALL_CC_MODS)))
  112. @echo "<category name=\"MENUSELECT_$(MENUSELECT_CATEGORY)\" displayname=\"$(MENUSELECT_DESCRIPTION)\" remove_on_change=\"$(SUBDIR)/modules.link\">" > $@
  113. @cat $^ >> $@
  114. @echo "</category>" >> $@
  115. moduleinfo: .moduleinfo
  116. @cat $<
  117. .%.makeopts: %.c
  118. @$(AWK) -f $(ASTTOPDIR)/build_tools/get_makeopts $< > $@
  119. .%.makeopts: %.cc
  120. @$(AWK) -f $(ASTTOPDIR)/build_tools/get_makeopts $< > $@
  121. .makeopts:: $(addsuffix .makeopts,$(addprefix .,$(ALL_C_MODS) $(ALL_CC_MODS)))
  122. @cat $^ > $@
  123. makeopts: .makeopts
  124. @cat $<
  125. ifneq ($(wildcard .*.d),)
  126. include .*.d
  127. endif