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),)
42 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)))
46 C_MODS:=$(filter-out $(MENUSELECT_$(MENUSELECT_CATEGORY)),$(ALL_C_MODS))
47 CC_MODS:=$(filter-out $(MENUSELECT_$(MENUSELECT_CATEGORY)),$(ALL_CC_MODS))
49 ifneq ($(findstring $(MENUSELECT_CATEGORY),$(MENUSELECT_EMBED)),)
50 EMBEDDED_MODS:=$(C_MODS) $(CC_MODS)
52 LOADABLE_MODS:=$(C_MODS) $(CC_MODS)
55 # Both C++ and C++ sources need their module name in AST_MODULE
56 # We also pass whatever _INCLUDE list is generated by menuselect
57 # (they are stored in file 'makeopts'). This is also necessary
58 # for components used to build modules, which can't be determined
59 # by the rules in this file, so the MOD_ASTCFLAGS definition
60 # is used to collect the required flags for a module... which can
61 # then be used any place they are required.
63 MOD_ASTCFLAGS=-DAST_MODULE=\"$(1)\" $(MENUSELECT_OPTS_$(1):%=-D%) $(foreach dep,$(MENUSELECT_DEPENDS_$(1)),$(value $(dep)_INCLUDE))
65 $(addsuffix .oo,$(CC_MODS)) $(addsuffix .o,$(C_MODS)): \
66 _ASTCFLAGS+=$(call MOD_ASTCFLAGS,$*)
68 ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
69 # don't define -fPIC on mingw32 and cygwin, it is the default
70 $(LOADABLE_MODS:%=%.so): _ASTCFLAGS+=-fPIC
73 # For loadable modules, pass _LIB and _LDFLAGS from menuselect.
74 $(LOADABLE_MODS:%=%.so): LIBS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LIB))
75 $(LOADABLE_MODS:%=%.so): _ASTLDFLAGS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LDFLAGS))
77 $(EMBEDDED_MODS:%=%.o): _ASTCFLAGS+=-DEMBEDDED_MODULE=$*
79 $(addsuffix .so,$(filter $(LOADABLE_MODS),$(C_MODS))): %.so: %.o
80 $(addsuffix .so,$(filter $(LOADABLE_MODS),$(CC_MODS))): %.so: %.oo
82 modules.link: $(addsuffix .eo,$(filter $(EMBEDDED_MODS),$(C_MODS)))
84 .PHONY: clean uninstall _all moduleinfo makeopts
86 ifneq ($(LOADABLE_MODS),)
87 _all: $(LOADABLE_MODS:%=%.so)
88 ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
89 # linker options and extra libraries for cygwin
90 SOLINK=-Wl,--out-implib=lib$@.a -shared
91 LIBS+=-L$(ASTTOPDIR)/main -lasterisk -L$(ASTTOPDIR)/res $($@_LIBS)
92 # additional libraries in res/
96 ifneq ($(EMBEDDED_MODS),)
99 @echo "../$(SUBDIR)/modules.link"
101 @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
102 @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
104 @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
105 @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
114 @for file in $(patsubst %,$(SUBDIR)/%,$(filter %.eo,$^)); do echo "INPUT (../$${file})" >> $@; done
115 @for file in $(patsubst %,$(SUBDIR)/%,$(filter-out %.eo,$^)); do echo "INPUT (../$${file})" >> $@; done
118 rm -f *.so *.o *.oo *.eo *.i *.ii
124 @echo "Installing modules from `basename $(CURDIR)`..."
125 @for x in $(LOADABLE_MODS:%=%.so); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
130 rm -f .*.moduleinfo .moduleinfo
131 rm -f .*.makeopts .makeopts
135 @echo "<member name=\"$*\" displayname=\"$(shell $(GREP) -e AST_MODULE_INFO $< | head -n 1 | cut -d '"' -f 2)\" remove_on_change=\"$(SUBDIR)/$*.o $(SUBDIR)/$*.so\">" > $@
136 $(AWK) -f $(ASTTOPDIR)/build_tools/get_moduleinfo $< >> $@
137 echo "</member>" >> $@
140 @echo "<member name=\"$*\" displayname=\"$(shell $(GREP) -e AST_MODULE_INFO $< | head -n 1 | cut -d '"' -f 2)\" remove_on_change=\"$(SUBDIR)/$*.oo $(SUBDIR)/$*.so\">" > $@
141 $(AWK) -f $(ASTTOPDIR)/build_tools/get_moduleinfo $< >> $@
142 echo "</member>" >> $@
144 .moduleinfo:: $(addsuffix .moduleinfo,$(addprefix .,$(ALL_C_MODS) $(ALL_CC_MODS)))
145 @echo "<category name=\"MENUSELECT_$(MENUSELECT_CATEGORY)\" displayname=\"$(MENUSELECT_DESCRIPTION)\" remove_on_change=\"$(SUBDIR)/modules.link\">" > $@
147 @echo "</category>" >> $@
149 moduleinfo: .moduleinfo
153 @$(AWK) -f $(ASTTOPDIR)/build_tools/get_makeopts $< > $@
156 @$(AWK) -f $(ASTTOPDIR)/build_tools/get_makeopts $< > $@
158 .makeopts:: $(addsuffix .makeopts,$(addprefix .,$(ALL_C_MODS) $(ALL_CC_MODS)))
164 ifneq ($(wildcard .*.d),)