Merged revisions 140817 via svnmerge from
[asterisk-bristuff.git] / Makefile.moddir_rules
blob9258e8d63bac688e75374fb3ae9a40edfd3d786a
2 # Asterisk -- A telephony toolkit for Linux.
3
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
24  endif
25 endif
27 ifeq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
28   ASTCFLAGS+=${GC_CFLAGS}
29 endif
31 ifneq ($(findstring STATIC_BUILD,$(MENUSELECT_CFLAGS)),)
32   STATIC_BUILD=-static
33 endif
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),)
46     ALL_C_MODS:=
47     ALL_C_MODS+=$(foreach p,$(MODULE_PREFIX),$(patsubst %.c,%,$(wildcard $(p)_*.c)))
48     ALL_CC_MODS:=
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)
57     else
58         LOADABLE_MODS:=$(C_MODS) $(CC_MODS)
59     endif
60 endif
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
72 endif
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/
94 endif
95 endif
97 ifneq ($(EMBEDDED_MODS),)
98 _all: modules.link
99 __embed_ldscript:
100         @echo "../$(SUBDIR)/modules.link"
101 __embed_ldflags:
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))"
104 __embed_libs:
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))"
107 else
108 __embed_ldscript:
109 __embed_ldflags:
110 __embed_libs:
111 endif
113 modules.link:
114         @rm -f $@
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
118 clean::
119         rm -f *.so *.o *.oo *.eo
120         rm -f .*.o.d .*.oo.d
121         rm -f *.s *.i
122         rm -f modules.link
124 install:: all
125         @echo "Installing modules from `basename $(CURDIR)`..."
126         @for x in $(LOADABLE_MODS:%=%.so); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
128 uninstall::
130 dist-clean::
131         rm -f .*.moduleinfo .moduleinfo
132         rm -f .*.makeopts .makeopts
134 .%.moduleinfo: %.c
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>" >> $@
139 .%.moduleinfo: %.cc
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\">" > $@
146         @cat $^ >> $@
147         @echo "</category>" >> $@
149 moduleinfo: .moduleinfo
150         @cat $<
152 .%.makeopts: %.c
153         @$(AWK) -f $(ASTTOPDIR)/build_tools/get_makeopts $< > $@
155 .%.makeopts: %.cc
156         @$(AWK) -f $(ASTTOPDIR)/build_tools/get_makeopts $< > $@
158 .makeopts:: $(addsuffix .makeopts,$(addprefix .,$(ALL_C_MODS) $(ALL_CC_MODS)))
159         @cat $^ > $@
161 makeopts: .makeopts
162         @cat $<
164 ifneq ($(wildcard .*.d),)
165    include .*.d
166 endif