File: Makefile

package info (click to toggle)
kamailio 6.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 70,472 kB
  • sloc: ansic: 859,394; xml: 203,514; makefile: 9,688; sh: 9,105; sql: 8,571; yacc: 4,121; python: 3,086; perl: 2,955; java: 449; cpp: 289; javascript: 270; php: 258; ruby: 248; awk: 27
file content (353 lines) | stat: -rw-r--r-- 12,232 bytes parent folder | download | duplicates (2)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353

COREPATH=../../../src

#include $(COREPATH)/Makefile.defs

CFG2TXT=../../scripts/cdefs2doc/dump_selects.pl
CFG2DOCBOOK=../../scripts/cdefs2doc/dump_selects.pl

# extra generators options
# use select_core.c to resolve possible chained select
CFG2TXT_EXTRA_OPTS=--core $(COREPATH)/core/select_core.c
CFG2DOCBOOK_EXTRA_OPTS=--core $(COREPATH)/core/select_core.c

# output directory for generated txt files
txt_output_dir=.
# output directory for generated docbook xml files
docbook_output_dir=docbook

# list of files containing selects defs in the following format:
# <filename>:<sel_grp_name>
# can be easily updated by adding the output of:
#   make diff-list   (which obeys grp_exclude and file_exclude)
# or completely regenerated by replacing files_list with the output of:
#   make gen-files-list
files_list= \
	$(COREPATH)/core/select_core.c:core \
	$(COREPATH)/modules/avp/avp.c:avp \
	$(COREPATH)/modules/cnxcc/cnxcc_mod.c:cnxcc \
	$(COREPATH)/modules/db2_ops/db2_ops.c:db2_ops \
	$(COREPATH)/modules/nathelper/nathelper.c:nathelper \
	$(COREPATH)/modules/textopsx/textopsx.c:textopsx \
	$(COREPATH)/modules/timer/timer.c:timer \
	$(COREPATH)/modules/tls/tls_select.c:tls \
	$(COREPATH)/modules/tm/select.c:tm \
	$(COREPATH)/modules/xmlrpc/xmlrpc.c:xmlrpc

grp_exclude=pa iptrtpproxy
# list of file prefixes to exclude (full path needed)
file_exclude= $(COREPATH)/obsolete/

# special per file group overrides
# format= grp_filename=... ,where filename does not contain the extension
# e.g.:
#     grp_f_tcp_options=tcp
#     grp_f_sctp_options=sctp

# special per group group name overrides
# e.g.:
#      grp_g_maxfwd=mf

# override auto-detected group if set to 1 (else the group is used inside the
# file only if it cannot be aut-odetected)
ifeq ($(group_override),1)
override force_grp=force-
else
override force_grp=
endif

# command used for gcc (contains extra includes)
gcc=gcc
#-I$(COREPATH)/lib -I$(COREPATH) -I/usr/include/libxml2

# defines used by gcc
c_defs=-DNAME='\"kamailio\"' -DVERSION='\"5.1.0-dev3\"' -DARCH='\"x86_64\"' \
	   -DOS='linux_' -DOS_QUOTED='\"linux\"' -DCOMPILER='\"gcc 4.9.2\"' \
	   -D__CPU_x86_64 -D__OS_linux -DSER_VER=5001000 \
	   -DCFG_DIR='\"/usr/local/etc/kamailio/\"' \
	   -DRUN_DIR='\"/run/kamailio/\"' -DPKG_MALLOC -DSHM_MEM -DSHM_MMAP \
	   -DDNS_IP_HACK -DUSE_MCAST -DUSE_TCP -DDISABLE_NAGLE -DHAVE_RESOLV_RES \
	   -DUSE_DNS_CACHE -DUSE_DNS_FAILOVER -DUSE_DST_BLOCKLIST -DUSE_NAPTR \
	   -DMEM_JOIN_FREE -DF_MALLOC -DQ_MALLOC -DTLSF_MALLOC \
	   -DDBG_SR_MEMORY -DUSE_TLS -DTLS_HOOKS -DUSE_CORE_STATS -DSTATISTICS \
	   -DMALLOC_STATS -DWITH_AS_SUPPORT -DUSE_SCTP -DFAST_LOCK -DADAPTIVE_WAIT \
	   -DADAPTIVE_WAIT_LOOPS=1024 -DCC_GCC_LIKE_ASM -DHAVE_GETHOSTBYNAME2 \
	   -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD -DHAVE_MSG_NOSIGNAL \
	   -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H -DHAVE_TIMEGM \
	   -DHAVE_SCHED_SETSCHEDULER -DHAVE_IP_MREQN -DHAVE_EPOLL -DHAVE_SIGIO_RT \
	   -DSIGINFO64_WORKAROUND -DUSE_FUTEX -DHAVE_SELECT


# common makefile vars used in defs
LOCALBASE=/usr/local
SYSBASE=/usr

filter_files=$(subst .h:,.c:, $(filter-out $(addsuffix %,$(file_exclude)),\
				$(filter-out $(addprefix %:,$(grp_exclude)),$(1))) )

#filtered files list
flist=$(call filter_files,$(files_list))

# throws an error if input is not in the format filename:grp
check_fname_grp=$(if $(filter-out 2,$(words $(subst :, ,$(1)))),\
					$(error bad format "$(1)", it should be filename:grp))

# get prereq from file:grp (get_prereq(file:grp) => file)
get_prereq=$(firstword $(subst :, ,$(1)))

# get grp from file:grp (get_grp(file:grp) => grp)
get_listed_grp=$(word 2, $(subst :, ,$(1)))

# get base file name from file:grp: get_bname(file:grp)
# => basename(file) without extension (e.g. get_bname(foo/bar.c:x) => bar)
#
get_bname=$(basename $(notdir $(call get_prereq,$(1))))

#get grp from file:grp, using the overrides
get_grp=$(strip $(if $(grp_f_$(call get_bname,$(1))), \
					$(grp_f_$(call get_bname,$(1))),\
					$(if $(grp_g_$(call get_listed_grp,$(1))),\
						$(grp_g_$(call get_listed_grp,$(1))),\
						$(call get_listed_grp,$(1))) ) )

# get target from file:grp (get_target(file:grp) => select_grp)
get_target=select_$(call get_grp,$(1))


# $(LF) definition (do not remove)
define LF


endef

# get all the lines containing DEFS or INCLUDES definitions from the Makefile.
# WARNING: does not work with all sed implementation (tested with GNU sed).
# It uses a hack to restore the LFs (LFs are removed by $(shell)): LFs are
# replaced with '^LF^' and then ^LF^ is subst'ed back to a real LF.
get_make_idefs=$(subst ^LF^,$(LF),$(shell sed \
 -ne '/^[\t ]*\(DEFS\|INCLUDES\)[\t ]*[+:]\?=.*[^\]$$/H'\
 -ne '/^[\t ]*\(DEFS\|INCLUDES\)[\t ]*[+:]\?=.*\\$$/,/\(^$$\)\|\([^\]$$\)/H'\
 -ne '$${g;s/\n/^LF^/g;p}'\
< $(1)/Makefile ))


# get all the lines from the makefile containing variable definitions.
# It will also return conditionals and try to filter out possible rules.
# WARNING: does not work with all sed implementation (tested with GNU sed).
# It uses a hack to restore the LFs (LFs are removed by $(shell)): LFs are
# replaced with '^LF^' and then ^LF^ is subst'ed back to a real LF.
get_make_vars=$(subst ^LF^,$(LF),$(shell sed -n \
 -e ': start' \
 -e '/^\(ifeq\|ifneq\|else\|endif\)[\t ]*\($$\|.*[^\]$$\)/{H;b end}' \
 -e '/^\(ifeq\|ifneq\|else\|endif\)[\t ]\+.*[\]$$/,/[^\]$$/{H;b end}' \
 -e '/^[a-zA-Z._/$$][a-zA-Z0-9._()/$$ \t-]*:\([^=]\|$$\)/b eat_rule' \
 -e '/^[\t ]*[A-Za-z._][A-Za-z0-9._-]*[\t ]*[+:]\?=.*[^\]$$/{H;b end}' \
 -e '/^[\t ]*[A-Za-z._][A-Za-z0-9._-]*[\t ]*[+:]\?=.*\\$$/,/\(^$$\)\|\([^\]$$\)/{H;b end}' \
 -e ': end' \
 -e '$${g;s/\n/^LF^/g;p}'\
 -e 'b' \
 -e ': eat_rule' \
 -e '$$b end' \
 -e 'n' \
 -e '/^[a-zA-Z._/$$][a-zA-Z0-9._()/$$ \t-]*:\([^=]\|$$\)/b eat_rule' \
 -e '/^[\t]/b eat_rule' \
 -e 'b start' \
< $(1)/Makefile ))


define  mk_rules

$(call check_fname_grp, $(1))

#$$(info generating select_$$(call get_grp,$(1)).txt: $$(call get_prereq,$(1)))


DEFS:=
INCLUDES:=
# extract all the includes and defs from the module makefile and
# evaluate them
$$(eval $$(call get_make_vars,$$(dir $$(call get_prereq,$(1)))))
# override COREPATH (we know better)
COREPATH=../../../src
# save the result in a per group e_idefs_<grp_name> var
$$(eval e_idefs_$$(call get_grp,$(1)):=$$(DEFS) $$(INCLUDES))

# debugging:
#$$(info eval: $$(call get_make_vars,$$(dir $$(call get_prereq,$(1)))))
#$$(info e_idefs_$$(call get_grp,$(1))=$$(e_idefs_$$(call get_grp,$(1))))

$(txt_output_dir)/$$(call get_target,$(1)).txt: \
								$$(call get_prereq,$(1)) Makefile $(CFG2TXT)
	$(CFG2TXT) --file $$< --$(force_grp)grp=$$(call get_grp,$(1)) \
		--gcc="$(gcc)" --txt  $(CFG2TXT_EXTRA_OPTS) \
		--defs="$(c_defs) $$(e_idefs_$$(call get_grp,$(1)))" \
		> "$$@" || (rm -f "$$@"; exit 1)

$(docbook_output_dir)/$$(call get_target,$(1)).xml: \
								$$(call get_prereq,$(1)) Makefile $(CFG2TXT)
	$(CFG2DOCBOOK) --file $$< --$(force_grp)grp=$$(call get_grp,$(1)) \
		--gcc="$(gcc)" --docbook $(CFG2DOCBOOK_EXTRA_OPTS) \
		--defs="$(c_defs) $$(e_idefs_$$(call get_grp,$(1)))" \
		> "$$@" || (rm -f "$$@"; exit 1)


clean_$$(call get_target,$(1)).txt:
	rm -f "$(txt_output_dir)/$$(call get_target,$(1)).txt"

clean_$$(call get_target,$(1)).xml:
	rm -f "$(docbook_output_dir)/$$(call get_target,$(1)).xml"

txt: $(txt_output_dir)/$$(call get_target,$(1)).txt

docbook: $(docbook_output_dir)/$$(call get_target,$(1)).xml

clean_txt: clean_$$(call get_target,$(1)).txt

clean_docbook: clean_$$(call get_target,$(1)).xml


endef

find_sel_files_cmd= find $(COREPATH) -type f -name "*.[ch]" \
		-exec grep "select_row_t[	 ][a-zA-Z0-9_][a-zA-Z0-9_]*\[\][	 ]*=" \
		/dev/null {} \; \
		| cut -d: -f1

# shell command to generate a file:grp list from a list of files
# grp will be the modulename if the file is in a module directory or
# the file name with the extension and _sel, sel_, select_, _select,
# _declaration or _table stripped out of it.
# output: list of  " "filename":"grpname
gen_file_grp_cmd=\
sed -e "s!\(.*/modules[^/]*/\([^/][^/]*\)/.*\)! \1:\2!" \
    -e "s!^\([^ ].*/\([^/.]*\)[^/]*$$\)!\1:\2!" \
    -e "s!^\([^ :]*\):\(.*\)_select[_]*!\1:\2!" \
    -e "s!^\([^ :]*\):\(.*\)select[_]*!\1:\2!" \
    -e "s!^\([^ :]*\):\(.*\)_declaration[_]*!\1:\2!" \
    -e "s!^\([^ :]*\):\(.*\)_table[_]*!\1:\2!" \
    -e "s!^\([^ :]*\):\(.*\)_sel[_]*!\1:\2!" \
    -e "s!^\([^ :]*\):\(.*\)sel[_]*!\1:\2!" \

# special vars for generating the list of files or updates
found_lst=$(shell $(find_sel_files_cmd) | $(gen_file_grp_cmd))
# filtered found lst
f_found_lst=$(call filter_files,$(found_lst))
diff_lst=$(filter-out $(flist),$(f_found_lst))


get_core_files=$(filter-out $(COREPATH)/modules% $(COREPATH)/lib%,$(1))
sort_files=$(sort $(call get_core_files,$(1)))\
			$(sort $(filter-out $(call get_core_files,$(1)),$(1)))

# replace $(COREPATH) with the text "$(COREPATH)"
subst_corepath=$(patsubst $(patsubst %/,%,$(COREPATH))/%,\$$(COREPATH)/%,$(1))


# help will be the default rule (on-purpose since without having a patched
# GCC:TranslationUnit module, make all won't work)
.PHONY: help
help:
	@echo "To regenerate $(foreach f,$(flist),$(call get_target,$f).{txt,xml})"
	@echo "type: $(MAKE) all ."
	@echo "or to regenerate all the select lists by searching all"
	@echo " the source files for definitions, type: $(MAKE) autogen ."
	@echo "NOTE: you need the GCC:TranslationUnit perl module with an "
	@echo "extra patch applied (see $(CFG2TXT) --patch)."

.PHONY: txt
txt:

.PHONY: docbook
docbook:

.PHONY: clean_txt
clean_txt:

.PHONY: clean_docbook
clean_docbook:


.PHONY: all
all: txt $(docbook_output_dir)/select_list.xml

.PHONY: clean
clean: clean_txt clean_docbook
	@rm -f $(docbook_output_dir)/select_list.xml

.PHONY: proper
proper:
	@rm -f $(txt_output_dir)/select_*.txt
	@rm -f $(docbook_output_dir)/select_*.xml

repo_ver="sip-router"\
	"git-$(shell  git rev-parse --verify --short=6 HEAD 2>/dev/null)"
ifeq ($(repo_ver),git-)
repo_ver="sip-router unknown"
endif

$(docbook_output_dir)/select_list.xml: Makefile \
		$(foreach f,$(flist),$(docbook_output_dir)/$(call get_target,$f).xml)
	@echo '<?xml version="1.0" encoding="UTF-8"?>' >$@
	@echo '<!-- this file is autogenerated, do not edit! -->' >>$@
	@echo '<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"' >>$@
	@echo '	"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"' >>$@
	@echo '	[ <!ENTITY % local.common.attrib' >>$@
	@echo "	 \"xmlns:xi CDATA #FIXED 'http://www.w3.org/2001/XInclude'\">]">>$@
	@echo '>' >>$@
	@echo '<book id="select_list"'\
		'xmlns:xi="http://www.w3.org/2001/XInclude">' >>$@
	@echo '	<title>Select List</title>' >>$@
	@echo '	<bookinfo>' >>$@
	@echo '   <productname class="trade">kamailio.org</productname>' >>$@
	@echo '   <authorgroup>' >>$@
	@echo '    <author>' >>$@
	@echo '      <firstname>Kamailio</firstname>' >>$@
	@echo '      <surname>Development Team</surname>' >>$@
	@echo '      <affiliation><orgname>https://www.kamailio.org</orgname></affiliation>' >>$@
	@echo '      <address>sr-dev@lists.kamailio.org</address>' >>$@
	@echo '    </author>' >>$@
	@echo '   </authorgroup>' >>$@
	@echo '   <copyright>' >>$@
	@echo '    <year>2008-2017</year>' >>$@
	@echo '    <holder>Kamailio Project</holder>' >>$@
	@echo '   </copyright>' >>$@
	@echo '	</bookinfo>' >>$@
	@echo '		<xi:include href="intro.xml"/>' >>$@
	@$(foreach f,$(flist),\
		echo '		<xi:include'\
			'href="'$(call get_target,$f).xml'"/>' \
			>>$@ ; )
	@echo '</book>' >>$@

# finds all the files containing select defs
.PHONY: find
find:
	@$(find_sel_files_cmd)

# print the list of the autogenerated files
.PHONY: print-lst
print-lst:
	@$(find_sel_files_cmd) | $(gen_file_grp_cmd)

#
.PHONY: gen-file-list
.PHONY: gen-files_list
.PHONY: gen_files_list
gen-file-list gen-files-list gen_files_list:
	@$(foreach f,$(call subst_corepath,$(call sort_files,$(f_found_lst))),\
		echo "$f \\";)

.PHONY: check-list
.PHONY: update-list
.PHONY: diff-list
check-list update-list diff-list:
	@$(foreach f,$(call subst_corepath,$(call sort_files,$(diff_lst))),\
		echo "$f \\";)


# try to generate the docs from all the sources
.PHONY: autogen
autogen:
	@$(MAKE) all files_list="$(call sort_files,$(f_found_lst))"

$(foreach f,$(flist),$(eval $(call mk_rules,$(f))))