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_ ...).
41 # Use MODULE_EXCLUDE to specify additional modules to exclude.
43 ifneq ($(MODULE_PREFIX),)
44 # Compute the lowercase and uppercase directory name. The former
45 # is used as a key in MENUSELECT_EMBED, the latter is part of
46 # the name of the MENUSELECT_* variable containing the exclude list
47 # generated by menuselect.
48 A:=$(notdir $(CURDIR))
49 B:=$(shell echo $A | tr "[a-z]" "[A-Z]")
50 # MENUSELECT_$(L) contains the list of modules excluded by menuselect.
51 # MODULE_EXCLUDE contains the locally generated exclude list
52 L:=$(MENUSELECT_$(B)) $(MODULE_EXCLUDE)
53 # construct the list of C and CC modules from the content of the directory
56 C_MODS+=$(foreach pre,$(MODULE_PREFIX),$(filter-out $(L),$(patsubst %.c,%,$(wildcard $(pre)*.c))))
57 CC_MODS+=$(foreach pre,$(MODULE_PREFIX),$(filter-out $(L),$(patsubst %.cc,%,$(wildcard $(pre)*.cc))))
59 # and store in the list of embedded or loadable modules
60 ifneq ($(findstring $(A),$(MENUSELECT_EMBED)),)
61 EMBEDDED_MODS:=$(C_MODS) $(CC_MODS)
63 LOADABLE_MODS:=$(C_MODS) $(CC_MODS)
67 # x:=$(shell echo 'in $(B)' >&2)
68 # x:=$(shell echo 'filtered out $(L)' >&2)
69 # x:=$(shell echo 'C_MODS= $(C_MODS)' >&2)
72 # Both C++ and C++ sources need their module name in AST_MODULE
73 # We also pass whatever _INCLUDE list is generated by menuselect
74 # (they are stored in file 'makeopts')
76 $(addsuffix .oo,$(CC_MODS)) $(addsuffix .o,$(C_MODS)): \
77 ASTCFLAGS+= -DAST_MODULE=\"$*\" $(MENUSELECT_OPTS_$*:%=-D%) $(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_INCLUDE))
79 ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
80 # don't define -fPIC on mingw32 and cygwin, it is the default
81 $(LOADABLE_MODS:%=%.so): ASTCFLAGS+=-fPIC
84 # For loadable modules, pass _LIB and _LDFLAGS from menuselect.
85 $(LOADABLE_MODS:%=%.so): LIBS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LIB))
86 $(LOADABLE_MODS:%=%.so): ASTLDFLAGS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LDFLAGS))
88 $(EMBEDDED_MODS:%=%.o): ASTCFLAGS+=-DEMBEDDED_MODULE=$*
90 $(addsuffix .so,$(filter $(LOADABLE_MODS),$(C_MODS))): %.so: %.o
91 $(addsuffix .so,$(filter $(LOADABLE_MODS),$(CC_MODS))): %.so: %.oo
93 modules.link: $(addsuffix .eo,$(filter $(EMBEDDED_MODS),$(C_MODS)))
95 .PHONY: clean uninstall _all
97 ifneq ($(LOADABLE_MODS),)
98 _all: $(LOADABLE_MODS:%=%.so)
99 ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
100 # linker options and extra libraries for cygwin
101 SOLINK=-Wl,--out-implib=lib$@.a -shared
102 LIBS+=-L$(ASTTOPDIR)/main -lasterisk -L$(ASTTOPDIR)/res $($@_LIBS)
103 # additional libraries in res/
107 ifneq ($(EMBEDDED_MODS),)
110 @echo "../$(SUBDIR)/modules.link"
112 @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
113 @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
115 @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
116 @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
125 @for file in $(patsubst %,$(SUBDIR)/%,$(filter %.eo,$^)); do echo "INPUT (../$${file})" >> $@; done
126 @for file in $(patsubst %,$(SUBDIR)/%,$(filter-out %.eo,$^)); do echo "INPUT (../$${file})" >> $@; done
129 rm -f *.so *.o *.oo *.eo
135 @echo "Installing modules from `basename $(CURDIR)`..."
136 @for x in $(LOADABLE_MODS:%=%.so); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
140 ifneq ($(wildcard .*.d),)