make the install target a bit less noisy
[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 # Makefile rules for building modules.
15
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.
20
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
26
27 ifeq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
28   ASTCFLAGS+=${GC_CFLAGS}
29 endif
30
31 ifneq ($(findstring STATIC_BUILD,$(MENUSELECT_CFLAGS)),)
32   STATIC_BUILD=-static
33 endif
34
35 include $(ASTTOPDIR)/Makefile.rules
36
37 # Both C++ and C++ sources need their module name in AST_MODULE
38 # We also pass whatever _INCLUDE list is generated by menuselect
39 # (they are stored in file 'makeopts')
40
41 $(addsuffix .oo,$(CC_MODS)) $(addsuffix .o,$(C_MODS)):  \
42         ASTCFLAGS+= -DAST_MODULE=\"$*\" $(MENUSELECT_OPTS_$*:%=-D%) $(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_INCLUDE))
43
44 ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
45    # don't define -fPIC on mingw32 and cygwin, it is the default
46    $(LOADABLE_MODS:%=%.so): ASTCFLAGS+=-fPIC
47 endif
48
49 # For loadable modules, pass _LIB and _LDFLAGS from menuselect.
50 $(LOADABLE_MODS:%=%.so): LIBS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LIB))
51 $(LOADABLE_MODS:%=%.so): ASTLDFLAGS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LDFLAGS))
52
53 $(EMBEDDED_MODS:%=%.o): ASTCFLAGS+=-DEMBEDDED_MODULE=$*
54
55 $(addsuffix .so,$(filter $(LOADABLE_MODS),$(C_MODS))): %.so: %.o
56 $(addsuffix .so,$(filter $(LOADABLE_MODS),$(CC_MODS))): %.so: %.oo
57
58 modules.link: $(addsuffix .eo,$(filter $(EMBEDDED_MODS),$(C_MODS)))
59
60 .PHONY: clean uninstall _all
61
62 ifneq ($(LOADABLE_MODS),)
63 _all: $(LOADABLE_MODS:%=%.so)
64 ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
65   # linker options and extra libraries for cygwin
66   SOLINK=-Wl,--out-implib=lib$@.a -shared
67   LIBS+=-L$(ASTTOPDIR)/main -lasterisk -L$(ASTTOPDIR)/res $($@_LIBS)
68   # additional libraries in res/
69 endif
70 endif
71
72 ifneq ($(EMBEDDED_MODS),)
73 _all: modules.link
74 __embed_ldscript:
75         @echo "../$(SUBDIR)/modules.link"
76 __embed_ldflags:
77         @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
78         @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))"
79 __embed_libs:
80         @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
81         @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))"
82 else
83 __embed_ldscript:
84 __embed_ldflags:
85 __embed_libs:
86 endif
87
88 modules.link:
89         @rm -f $@
90         @for file in $(patsubst %,$(SUBDIR)/%,$(filter %.eo,$^)); do echo "INPUT (../$${file})" >> $@; done
91         @for file in $(patsubst %,$(SUBDIR)/%,$(filter-out %.eo,$^)); do echo "INPUT (../$${file})" >> $@; done
92
93 clean::
94         rm -f *.so *.o *.oo *.eo
95         rm -f .*.o.d .*.oo.d
96         rm -f *.s *.i
97         rm -f modules.link
98
99 install:: all
100         @echo "Installing modules from `basename $(CURDIR)`..."
101         @for x in $(LOADABLE_MODS:%=%.so); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
102
103 uninstall::
104
105 ifneq ($(wildcard .*.d),)
106    include .*.d
107 endif