2 # Asterisk -- A telephony toolkit for Linux.
4 # Makefile rules for subdirectories containing modules
6 # Copyright (C) 2006, Digium, Inc.
8 # Kevin P. Fleming <kpfleming@digium.com>
10 # This program is free software, distributed under the terms of
11 # the GNU General Public License
14 # Makefile rules for building modules.
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.
21 ifeq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
22 ASTCFLAGS+=${GC_CFLAGS}
25 ifneq ($(findstring STATIC_BUILD,$(MENUSELECT_CFLAGS)),)
29 include $(ASTTOPDIR)/Makefile.rules
31 # If MODULE_PREFIX is defined, use it to run the standard functions to set
32 # C_MODS, CC_MODS, LOADABLE_MODS and EMBEDDED_MODS.
33 # Each word of MODULE_PREFIX is a prefix for filenames that we consider
34 # valid C or CC modules (eg. app, func ...). Note that the underscore
35 # is added here, and does not need to be in MODULE_PREFIX
37 # Use MODULE_EXCLUDE to specify additional modules to exclude.
39 ifneq ($(MODULE_PREFIX),)
41 ALL_C_MODS+=$(foreach p,$(MODULE_PREFIX),$(patsubst %.c,%,$(wildcard $(p)_*.c)))
43 ALL_CC_MODS+=$(foreach p,$(MODULE_PREFIX),$(patsubst %.cc,%,$(wildcard $(p)_*.cc)))
45 C_MODS:=$(filter-out $(MENUSELECT_$(MENUSELECT_CATEGORY)),$(ALL_C_MODS))
46 CC_MODS:=$(filter-out $(MENUSELECT_$(MENUSELECT_CATEGORY)),$(ALL_CC_MODS))
48 # and store in the list of embedded or loadable modules
49 ifneq ($(findstring $(MENUSELECT_CATEGORY),$(MENUSELECT_EMBED)),)
50 EMBEDDED_MODS:=$(C_MODS) $(CC_MODS)
52 LOADABLE_MODS:=$(C_MODS) $(CC_MODS)
56 # Both C++ and C++ sources need their module name in AST_MODULE
57 # We also pass whatever _INCLUDE list is generated by menuselect
58 # (they are stored in file 'makeopts')
60 $(addsuffix .oo,$(CC_MODS)) $(addsuffix .o,$(C_MODS)): \
61 ASTCFLAGS+= -DAST_MODULE=\"$*\" $(MENUSELECT_OPTS_$*:%=-D%) $(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_INCLUDE))
63 ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
64 # don't define -fPIC on mingw32 and cygwin, it is the default
65 $(LOADABLE_MODS:%=%.so): ASTCFLAGS+=-fPIC
68 # For loadable modules, pass _LIB and _LDFLAGS from menuselect.
69 $(LOADABLE_MODS:%=%.so): LIBS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LIB))
70 $(LOADABLE_MODS:%=%.so): ASTLDFLAGS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LDFLAGS))
72 $(EMBEDDED_MODS:%=%.o): ASTCFLAGS+=-DEMBEDDED_MODULE=$*
74 $(addsuffix .so,$(filter $(LOADABLE_MODS),$(C_MODS))): %.so: %.o
75 $(addsuffix .so,$(filter $(LOADABLE_MODS),$(CC_MODS))): %.so: %.oo
77 modules.link: $(addsuffix .eo,$(filter $(EMBEDDED_MODS),$(C_MODS)))
79 .PHONY: clean uninstall _all moduleinfo makeopts
81 ifneq ($(LOADABLE_MODS),)
82 _all: $(LOADABLE_MODS:%=%.so)
83 ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
84 # linker options and extra libraries for cygwin
85 SOLINK=-Wl,--out-implib=lib$@.a -shared
86 LIBS+=-L$(ASTTOPDIR)/main -lasterisk -L$(ASTTOPDIR)/res $($@_LIBS)
87 # additional libraries in res/
91 ifneq ($(EMBEDDED_MODS),)
94 @echo "../$(SUBDIR)/modules.link"
96 @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
97 @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
99 @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
100 @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
109 @for file in $(patsubst %,$(SUBDIR)/%,$(filter %.eo,$^)); do echo "INPUT (../$${file})" >> $@; done
110 @for file in $(patsubst %,$(SUBDIR)/%,$(filter-out %.eo,$^)); do echo "INPUT (../$${file})" >> $@; done
113 rm -f *.so *.o *.oo *.eo
119 @echo "Installing modules from `basename $(CURDIR)`..."
120 @for x in $(LOADABLE_MODS:%=%.so); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
125 rm -f .*.moduleinfo .moduleinfo
126 rm -f .*.makeopts .makeopts
129 @echo "<member name=\"$*\" displayname=\"$(shell $(GREP) -e AST_MODULE_INFO $< | head -n 1 | cut -d '"' -f 2)\" remove_on_change=\"$(SUBDIR)/$*.o $(SUBDIR)/$*.so\">" > $@
130 $(AWK) -f $(ASTTOPDIR)/build_tools/get_moduleinfo $< >> $@
131 echo "</member>" >> $@
134 @echo "<member name=\"$*\" displayname=\"$(shell $(GREP) -e AST_MODULE_INFO $< | head -n 1 | cut -d '"' -f 2)\" remove_on_change=\"$(SUBDIR)/$*.oo $(SUBDIR)/$*.so\">" > $@
135 $(AWK) -f $(ASTTOPDIR)/build_tools/get_moduleinfo $< >> $@
136 echo "</member>" >> $@
138 .moduleinfo:: $(addsuffix .moduleinfo,$(addprefix .,$(ALL_C_MODS) $(ALL_CC_MODS)))
139 @echo "<category name=\"MENUSELECT_$(MENUSELECT_CATEGORY)\" displayname=\"$(MENUSELECT_DESCRIPTION)\" remove_on_change=\"$(SUBDIR)/modules.link\">" > $@
141 @echo "</category>" >> $@
143 moduleinfo: .moduleinfo
147 @$(AWK) -f $(ASTTOPDIR)/build_tools/get_makeopts $< > $@
150 @$(AWK) -f $(ASTTOPDIR)/build_tools/get_makeopts $< > $@
152 .makeopts:: $(addsuffix .makeopts,$(addprefix .,$(ALL_C_MODS) $(ALL_CC_MODS)))
158 ifneq ($(wildcard .*.d),)