give embedded modules a helping hand by backing up and restoring their global variabl...
[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 $(EMBEDDED_MODS:%=%.o): ASTCFLAGS+=-DEMBEDDED_MODULE=$*
38
39 $(addsuffix .so,$(filter $(LOADABLE_MODS),$(C_MODS))): %.so: %.o
40 $(addsuffix .so,$(filter $(LOADABLE_MODS),$(CC_MODS))): %.so: %.oo
41
42 modules.link: $(addsuffix .eo,$(filter $(EMBEDDED_MODS),$(C_MODS)))
43 modules.link: $(addsuffix .eoo,$(filter $(EMBEDDED_MODS),$(CC_MODS)))
44
45 .PHONY: clean uninstall _all
46
47 ifneq ($(LOADABLE_MODS),)
48 _all: $(LOADABLE_MODS:%=%.so)
49 endif
50
51 ifneq ($(EMBEDDED_MODS),)
52 _all: modules.link
53 __embed_ldscript:
54         @echo "../$(SUBDIR)/modules.link"
55 __embed_ldflags:
56         @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
57         @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
58 __embed_libs:
59         @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
60         @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
61 else
62 __embed_ldscript:
63 __embed_ldflags:
64 __embed_libs:
65 endif
66
67 modules.link:
68         @rm -f $@
69         @for file in $(patsubst %,$(SUBDIR)/%,$(filter %.eo %.eoo,$^)); do echo "INPUT (../$${file})" >> $@; done
70         @for file in $(patsubst %,$(SUBDIR)/%,$(filter-out %.eo %.eoo,$^)); do echo "INPUT (../$${file})" >> $@; done
71
72 clean::
73         rm -f *.so *.o *.oo *.eo *.eoo
74         rm -f .*.o.d .*.oo.d
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 .*.d),)
83    include .*.d
84 endif