Merged revisions 44055 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   ASTCFLAGS+=-include $(ASTTOPDIR)/include/asterisk/astmm.h
16 endif
17
18 ifeq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
19   ASTCFLAGS+=${GC_CFLAGS}
20 endif
21
22 ifneq ($(findstring STATIC_BUILD,$(MENUSELECT_CFLAGS)),)
23   STATIC_BUILD=-static
24 endif
25
26 include $(ASTTOPDIR)/Makefile.rules
27
28 comma:=,
29
30 $(addsuffix .o,$(C_MODS)): ASTCFLAGS+=-DAST_MODULE=\"$*\" $(MENUSELECT_OPTS_$*:%=-D%) $(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_INCLUDE))
31 $(addsuffix .oo,$(CC_MODS)): ASTCFLAGS+=-DAST_MODULE=\"$*\" $(MENUSELECT_OPTS_$*:%=-D%) $(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_INCLUDE))
32
33 $(LOADABLE_MODS:%=%.so): ASTCFLAGS+=-fPIC
34 $(LOADABLE_MODS:%=%.so): LIBS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LIB))
35 $(LOADABLE_MODS:%=%.so): ASTLDFLAGS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LDFLAGS))
36
37 $(addsuffix .so,$(filter $(LOADABLE_MODS),$(C_MODS))): %.so: %.o
38 $(addsuffix .so,$(filter $(LOADABLE_MODS),$(CC_MODS))): %.so: %.oo
39
40 modules.link: $(addsuffix .o,$(filter $(EMBEDDED_MODS),$(C_MODS)))
41 modules.link: $(addsuffix .oo,$(filter $(EMBEDDED_MODS),$(CC_MODS)))
42
43 .PHONY: clean clean-depend depend uninstall _all
44
45 ifneq ($(LOADABLE_MODS),)
46 _all: $(LOADABLE_MODS:%=%.so)
47 endif
48
49 ifneq ($(EMBEDDED_MODS),)
50 _all: modules.link
51 __embed_ldscript:
52         @echo "../$(SUBDIR)/modules.link"
53 __embed_ldflags:
54         @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
55         @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
56 __embed_libs:
57         @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
58         @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
59 else
60 __embed_ldscript:
61 __embed_ldflags:
62 __embed_libs:
63 endif
64
65 modules.link:
66         @rm -f $@
67         @for file in $(patsubst %,$(SUBDIR)/%,$(filter %.o,$^)); do echo "INPUT (../$${file})" >> $@; done
68         @for file in $(patsubst %,$(SUBDIR)/%,$(filter-out %.o,$^)); do echo "INPUT (../$${file})" >> $@; done
69
70 clean-depend::
71         rm -f .depend
72
73 clean:: clean-depend
74         rm -f *.so *.o *.oo
75         rm -f modules.link
76
77 install:: all
78         for x in $(LOADABLE_MODS:%=%.so); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
79
80 uninstall::
81
82 ifneq ($(wildcard .depend),)
83   include .depend
84 endif
85
86 depend: .depend
87
88 .depend:
89         ../build_tools/mkdep $(ASTCFLAGS) `ls *.c *.cc 2> /dev/null`