~singpolyma/asterisk

ref: upstream/16.2.1_dfsg asterisk/Makefile.moddir_rules -rw-r--r-- 5.8 KiB
fe6d69c0Stephen Paul Weber import-tar 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#
# Asterisk -- An open source telephony toolkit.
#
# Makefile rules for subdirectories containing modules
#
# Copyright (C) 2006, Digium, Inc.
#
# Kevin P. Fleming <kpfleming@digium.com>
#
# This program is free software, distributed under the terms of
# the GNU General Public License
#

# Makefile rules for building modules.

# In most cases, we set target-specific variables for certain targets
# (remember that they apply recursively to prerequisites).
# Also note that we can only set one variable per rule, so we have to
# repeat the left hand side to set multiple variables.

include $(ASTTOPDIR)/Makefile.rules

# If MODULE_PREFIX is defined, use it to run the standard functions to set
# C_MODS, CC_MODS and LOADABLE_MODS
# Each word of MODULE_PREFIX is a prefix for filenames that we consider
# valid C or CC modules (eg. app, func ...). Note that the underscore
# is added here, and does not need to be in MODULE_PREFIX
#
# Use MODULE_EXCLUDE to specify additional modules to exclude.

ifneq ($(MODULE_PREFIX),)
    ALL_C_MODS:=
    ALL_CC_MODS:=
    ALL_C_MODS+=$(foreach p,$(MODULE_PREFIX),$(patsubst %.c,%,$(wildcard $(p)_*.c)))
    ALL_CC_MODS+=$(foreach p,$(MODULE_PREFIX),$(patsubst %.cc,%,$(wildcard $(p)_*.cc)))
endif

C_MODS:=$(filter-out $(MENUSELECT_$(MENUSELECT_CATEGORY)),$(ALL_C_MODS))
CC_MODS:=$(filter-out $(MENUSELECT_$(MENUSELECT_CATEGORY)),$(ALL_CC_MODS))

LOADABLE_MODS:=$(C_MODS) $(CC_MODS)

# Both C++ and C++ sources need their module name in AST_MODULE
# We also pass whatever _INCLUDE list is generated by menuselect
# (they are stored in file 'makeopts'). This is also necessary
# for components used to build modules, which can't be determined
# by the rules in this file, so the MOD_ASTCFLAGS definition
# is used to collect the required flags for a module... which can
# then be used any place they are required.

MOD_ASTCFLAGS=\
	-DAST_MODULE=\"$(1)\" \
	-DAST_MODULE_SELF_SYM=__internal_$(1)_self \
	$(MENUSELECT_OPTS_$(1):%=-D%) \
	$(foreach dep,$(MENUSELECT_DEPENDS_$(1)),$(value $(dep)_INCLUDE))

define MOD_ADD_SOURCE
$(1).so: $$(subst $(3),$(5),$(2))
$$(subst $(3),$(5),$(2)): _ASTCFLAGS+=$$(call MOD_ASTCFLAGS,$(1))
.$(1).moduleinfo: MODULEINFO_EXTRA_OUTPUT=" $$(addprefix $$(SUBDIR)/,$$(subst $(3),$(5),$(2)) $$(subst $(3),$(4),$(2)))"
# The use of wildcard ensures that 'make menuselect' will not fail for modules that
# require additional source downloads.
.$(1).moduleinfo: $(wildcard $(2))

clean:: clean-$(1)$(3)

clean-$(1)$(3):
	rm -f $$(subst $(3),$(4),$(2)) $$(subst $(3),$(5),$(2)) $$(subst $(3),$(6),$(2)) $$(subst $(3),$(7),$(2))

endef

MOD_ADD_C=$(eval $(call MOD_ADD_SOURCE,$(1),$(2),.c,.i,.o,.gcda,.gcno))
MOD_ADD_CC=$(eval $(call MOD_ADD_SOURCE,$(1),$(2),.cc,.ii,.oo,.gcda,.gcno))

$(addsuffix .oo,$(CC_MODS)) $(addsuffix .o,$(C_MODS)):	\
	_ASTCFLAGS+=$(call MOD_ASTCFLAGS,$*)

ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
   # don't define -fPIC on mingw32 and cygwin, it is the default
   $(LOADABLE_MODS:%=%.so): _ASTCFLAGS+=-fPIC
endif

# For loadable modules, pass _LIB and _LDFLAGS from menuselect.
$(LOADABLE_MODS:%=%.so): LIBS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LIB))
$(LOADABLE_MODS:%=%.so): _ASTLDFLAGS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LDFLAGS))

$(addsuffix .so,$(filter $(LOADABLE_MODS),$(C_MODS))): %.so: %.o
$(addsuffix .so,$(filter $(LOADABLE_MODS),$(CC_MODS))): %.so: %.oo

.PHONY: clean uninstall _all moduleinfo makeopts

_all: $(LOADABLE_MODS:%=%.so)
ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
  # linker options and extra libraries for cygwin
  SOLINK=-Wl,--out-implib=lib$@.a -shared
  LIBS+=-L$(ASTTOPDIR)/main -lasterisk -L$(ASTTOPDIR)/res $($@_LIBS)
  # additional libraries in res/
endif

clean::
	rm -f *.so *.o *.oo *.eo *.i *.ii
	rm -f .*.d
	rm -f *.s *.i
	rm -f *.gcda *.gcno
	rm -f modules.link

install:: all
	@echo "Installing modules from `basename $(CURDIR)`..."
	@for x in $(LOADABLE_MODS:%=%.so); do $(INSTALL) -m 755 $$x "$(DESTDIR)$(ASTMODDIR)" ; done
ifneq ($(findstring :,$(XMLSTARLET)$(BASH)),:)
	@if [ -f .moduleinfo ] ; then \
		declare -A DISABLED_MODS ;\
		for x in $(MENUSELECT_$(MENUSELECT_CATEGORY)) ; do DISABLED_MODS[$${x}]=1 ; done ;\
		EXTERNAL_MODS=$$($(XMLSTARLET) sel -t -m "/category/member[support_level = 'external']" -v "@name" -n .moduleinfo) ;\
		for x in $${EXTERNAL_MODS} ; do \
			if [ -z "$${DISABLED_MODS[$${x}]}" ] ; then \
				$(ASTTOPDIR)/build_tools/download_externals $${x} ;\
			fi ;\
		done ;\
	fi
endif

uninstall::

dist-clean::
	rm -f .*.moduleinfo .moduleinfo
	rm -f .*.makeopts .makeopts
	rm -f *.exports

.%.moduleinfo: %.c
	@echo "<member name=\"$*\" displayname=\"$(shell $(GREP) -e AST_MODULE_INFO $< | head -n 1 | cut -d '"' -f 2)\" remove_on_change=\"$(SUBDIR)/$*.o $(SUBDIR)/$*.i $(SUBDIR)/$*.so$(MODULEINFO_EXTRA_OUTPUT)\">" > $@
	$(AWK) -f $(ASTTOPDIR)/build_tools/get_moduleinfo $^ >> $@
	echo "</member>" >> $@

.%.moduleinfo: %.cc
	@echo "<member name=\"$*\" displayname=\"$(shell $(GREP) -e AST_MODULE_INFO $< | head -n 1 | cut -d '"' -f 2)\" remove_on_change=\"$(SUBDIR)/$*.oo $(SUBDIR)/$*.ii $(SUBDIR)/$*.so$(MODULEINFO_EXTRA_OUTPUT)\">" > $@
	$(AWK) -f $(ASTTOPDIR)/build_tools/get_moduleinfo $^ >> $@
	echo "</member>" >> $@

.moduleinfo:: $(addsuffix .moduleinfo,$(addprefix .,$(sort $(ALL_C_MODS) $(ALL_CC_MODS)))) $(wildcard $(call tolower,$(MENUSELECT_CATEGORY)).xml)
	@echo "<category name=\"MENUSELECT_$(MENUSELECT_CATEGORY)\" displayname=\"$(MENUSELECT_DESCRIPTION)\">" > $@
	@cat $^ >> $@
	@echo "</category>" >> $@

moduleinfo: .moduleinfo
	@cat $<

.%.makeopts: %.c
	@$(AWK) -f $(ASTTOPDIR)/build_tools/get_makeopts $< > $@

.%.makeopts: %.cc
	@$(AWK) -f $(ASTTOPDIR)/build_tools/get_makeopts $< > $@

.makeopts:: $(addsuffix .makeopts,$(addprefix .,$(ALL_C_MODS) $(ALL_CC_MODS)))
	@cat $^ > $@

makeopts: .makeopts
	@cat $<

ifneq ($(wildcard .*.d),)
   include .*.d
endif