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