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 ifneq ($(findstring MALLOC_DEBUG,$(MENUSELECT_CFLAGS)),)
22 ifeq ($(findstring astmm.h,$(ASTCFLAGS)),)
23 ASTCFLAGS+=-include $(ASTTOPDIR)/include/asterisk/astmm.h
27 ifeq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
28 ASTCFLAGS+=${GC_CFLAGS}
31 ifneq ($(findstring STATIC_BUILD,$(MENUSELECT_CFLAGS)),)
35 include $(ASTTOPDIR)/Makefile.rules
37 # If MODULE_PREFIX is defined, use it to run the standard functions to set
38 # C_MODS, CC_MODS, LOADABLE_MODS and EMBEDDED_MODS.
39 # Each word of MODULE_PREFIX is a prefix for filenames that we consider
40 # valid C or CC modules (eg. app, func ...). Note that the underscore
41 # is added here, and does not need to be in MODULE_PREFIX
43 # Use MODULE_EXCLUDE to specify additional modules to exclude.
45 ifneq ($(MODULE_PREFIX),)
47 ALL_C_MODS+=$(foreach p,$(MODULE_PREFIX),$(patsubst %.c,%,$(wildcard $(p)_*.c)))
49 ALL_CC_MODS+=$(foreach p,$(MODULE_PREFIX),$(patsubst %.cc,%,$(wildcard $(p)_*.cc)))
51 C_MODS:=$(filter-out $(MENUSELECT_$(MENUSELECT_CATEGORY)),$(ALL_C_MODS))
52 CC_MODS:=$(filter-out $(MENUSELECT_$(MENUSELECT_CATEGORY)),$(ALL_CC_MODS))
54 # and store in the list of embedded or loadable modules
55 ifneq ($(findstring $(MENUSELECT_CATEGORY),$(MENUSELECT_EMBED)),)
56 EMBEDDED_MODS:=$(C_MODS) $(CC_MODS)
58 LOADABLE_MODS:=$(C_MODS) $(CC_MODS)
62 # Both C++ and C++ sources need their module name in AST_MODULE
63 # We also pass whatever _INCLUDE list is generated by menuselect
64 # (they are stored in file 'makeopts')
66 $(addsuffix .oo,$(CC_MODS)) $(addsuffix .o,$(C_MODS)): \
67 ASTCFLAGS+= -DAST_MODULE=\"$*\" $(MENUSELECT_OPTS_$*:%=-D%) $(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_INCLUDE))
69 ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
70 # don't define -fPIC on mingw32 and cygwin, it is the default
71 $(LOADABLE_MODS:%=%.so): ASTCFLAGS+=-fPIC
74 # For loadable modules, pass _LIB and _LDFLAGS from menuselect.
75 $(LOADABLE_MODS:%=%.so): LIBS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LIB))
76 $(LOADABLE_MODS:%=%.so): ASTLDFLAGS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LDFLAGS))
78 $(EMBEDDED_MODS:%=%.o): ASTCFLAGS+=-DEMBEDDED_MODULE=$*
80 $(addsuffix .so,$(filter $(LOADABLE_MODS),$(C_MODS))): %.so: %.o
81 $(addsuffix .so,$(filter $(LOADABLE_MODS),$(CC_MODS))): %.so: %.oo
83 modules.link: $(addsuffix .eo,$(filter $(EMBEDDED_MODS),$(C_MODS)))
85 .PHONY: clean uninstall _all moduleinfo makeopts
87 ifneq ($(LOADABLE_MODS),)
88 _all: $(LOADABLE_MODS:%=%.so)
89 ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
90 # linker options and extra libraries for cygwin
91 SOLINK=-Wl,--out-implib=lib$@.a -shared
92 LIBS+=-L$(ASTTOPDIR)/main -lasterisk -L$(ASTTOPDIR)/res $($@_LIBS)
93 # additional libraries in res/
97 ifneq ($(EMBEDDED_MODS),)
100 @echo "../$(SUBDIR)/modules.link"
102 @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
103 @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
105 @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
106 @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
115 @for file in $(patsubst %,$(SUBDIR)/%,$(filter %.eo,$^)); do echo "INPUT (../$${file})" >> $@; done
116 @for file in $(patsubst %,$(SUBDIR)/%,$(filter-out %.eo,$^)); do echo "INPUT (../$${file})" >> $@; done
119 rm -f *.so *.o *.oo *.eo
125 @echo "Installing modules from `basename $(CURDIR)`..."
126 @for x in $(LOADABLE_MODS:%=%.so); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
131 rm -f .*.moduleinfo .moduleinfo
132 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),)