Merged revisions 60603 via svnmerge from
[asterisk/asterisk.git] / Makefile.moddir_rules
1 #
2 # Asterisk -- A telephony toolkit for Linux.
3
4 # Makefile rules for subdirectories containing modules
5 #
6 # Copyright (C) 2006, Digium, Inc.
7 #
8 # Kevin P. Fleming <kpfleming@digium.com>
9 #
10 # This program is free software, distributed under the terms of
11 # the GNU General Public License
12 #
13
14 ifneq ($(findstring MALLOC_DEBUG,$(MENUSELECT_CFLAGS)),)
15  ifeq ($(findstring astmm.h,$(ASTCFLAGS)),)
16   ASTCFLAGS+=-include $(ASTTOPDIR)/include/asterisk/astmm.h
17  endif
18 endif
19
20 ifeq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
21   ASTCFLAGS+=${GC_CFLAGS}
22 endif
23
24 ifneq ($(findstring STATIC_BUILD,$(MENUSELECT_CFLAGS)),)
25   STATIC_BUILD=-static
26 endif
27
28 include $(ASTTOPDIR)/Makefile.rules
29
30 comma:=,
31
32 $(addsuffix .o,$(C_MODS)): ASTCFLAGS+=-DAST_MODULE=\"$*\" $(MENUSELECT_OPTS_$*:%=-D%) $(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_INCLUDE))
33 $(addsuffix .oo,$(CC_MODS)): ASTCFLAGS+=-DAST_MODULE=\"$*\" $(MENUSELECT_OPTS_$*:%=-D%) $(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_INCLUDE))
34
35 $(LOADABLE_MODS:%=%.so): ASTCFLAGS+=-fPIC
36 $(LOADABLE_MODS:%=%.so): LIBS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LIB))
37 $(LOADABLE_MODS:%=%.so): ASTLDFLAGS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LDFLAGS))
38
39 $(EMBEDDED_MODS:%=%.o): ASTCFLAGS+=-DEMBEDDED_MODULE=$*
40
41 $(addsuffix .so,$(filter $(LOADABLE_MODS),$(C_MODS))): %.so: %.o
42 $(addsuffix .so,$(filter $(LOADABLE_MODS),$(CC_MODS))): %.so: %.oo
43
44 modules.link: $(addsuffix .eo,$(filter $(EMBEDDED_MODS),$(C_MODS)))
45 modules.link: $(addsuffix .eoo,$(filter $(EMBEDDED_MODS),$(CC_MODS)))
46
47 .PHONY: clean uninstall _all
48
49 ifneq ($(LOADABLE_MODS),)
50 _all: $(LOADABLE_MODS:%=%.so)
51 endif
52
53 ifneq ($(EMBEDDED_MODS),)
54 _all: modules.link
55 __embed_ldscript:
56         @echo "../$(SUBDIR)/modules.link"
57 __embed_ldflags:
58         @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
59         @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
60 __embed_libs:
61         @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
62         @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
63 else
64 __embed_ldscript:
65 __embed_ldflags:
66 __embed_libs:
67 endif
68
69 modules.link:
70         @rm -f $@
71         @for file in $(patsubst %,$(SUBDIR)/%,$(filter %.eo %.eoo,$^)); do echo "INPUT (../$${file})" >> $@; done
72         @for file in $(patsubst %,$(SUBDIR)/%,$(filter-out %.eo %.eoo,$^)); do echo "INPUT (../$${file})" >> $@; done
73
74 clean::
75         rm -f *.so *.o *.oo *.eo *.eoo
76         rm -f .*.o.d .*.oo.d
77         rm -f modules.link
78
79 install:: all
80         for x in $(LOADABLE_MODS:%=%.so); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
81
82 uninstall::
83
84 ifneq ($(wildcard .*.d),)
85    include .*.d
86 endif