Creating tag for the release of asterisk-1.6.1-beta1
[asterisk-bristuff.git] / Makefile.moddir_rules
blob18670f9a58f22dfb4afdb7fcdacb3b916553dc5b
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 ifeq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
22   ASTCFLAGS+=${GC_CFLAGS}
23 endif
25 ifneq ($(findstring STATIC_BUILD,$(MENUSELECT_CFLAGS)),)
26   STATIC_BUILD=-static
27 endif
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),)
40     ALL_C_MODS:=
41     ALL_C_MODS+=$(foreach p,$(MODULE_PREFIX),$(patsubst %.c,%,$(wildcard $(p)_*.c)))
42     ALL_CC_MODS:=
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)
51     else
52         LOADABLE_MODS:=$(C_MODS) $(CC_MODS)
53     endif
54 endif
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
66 endif
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/
88 endif
89 endif
91 ifneq ($(EMBEDDED_MODS),)
92 _all: modules.link
93 __embed_ldscript:
94         @echo "../$(SUBDIR)/modules.link"
95 __embed_ldflags:
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))"
98 __embed_libs:
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))"
101 else
102 __embed_ldscript:
103 __embed_ldflags:
104 __embed_libs:
105 endif
107 modules.link:
108         @rm -f $@
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
112 clean::
113         rm -f *.so *.o *.oo *.eo
114         rm -f .*.o.d .*.oo.d
115         rm -f *.s *.i
116         rm -f modules.link
118 install:: all
119         @echo "Installing modules from `basename $(CURDIR)`..."
120         @for x in $(LOADABLE_MODS:%=%.so); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
122 uninstall::
124 dist-clean::
125         rm -f .*.moduleinfo .moduleinfo
126         rm -f .*.makeopts .makeopts
128 .%.moduleinfo: %.c
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>" >> $@
133 .%.moduleinfo: %.cc
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\">" > $@
140         @cat $^ >> $@
141         @echo "</category>" >> $@
143 moduleinfo: .moduleinfo
144         @cat $<
146 .%.makeopts: %.c
147         @$(AWK) -f $(ASTTOPDIR)/build_tools/get_makeopts $< > $@
149 .%.makeopts: %.cc
150         @$(AWK) -f $(ASTTOPDIR)/build_tools/get_makeopts $< > $@
152 .makeopts:: $(addsuffix .makeopts,$(addprefix .,$(ALL_C_MODS) $(ALL_CC_MODS)))
153         @cat $^ > $@
155 makeopts: .makeopts
156         @cat $<
158 ifneq ($(wildcard .*.d),)
159    include .*.d
160 endif