Debian Codegraph @

doc/tutorials/rpc_list/Makefile

raw symbols SCIP
1
2 COREPATH=../../../src
3
4 #include $(COREPATH)/Makefile.defs
5
6 CFG2TXT=../../scripts/cdefs2doc/dump_rpcs.pl
7 CFG2DOCBOOK=../../scripts/cdefs2doc/dump_rpcs.pl
8
9 # output directory for generated txt files
10 txt_output_dir=.
11 # output directory for generated docbook xml files
12 docbook_output_dir=docbook
13
14 # list of files containing rpc defs in the following format:
15 # <filename>:<cfg_grp_name>
16 # can be easily updated by adding the output of:
17 # make diff-list (which obeys grp_exclude and file_exclude)
18 # or completely regenerated by replacing files_list with the output of:
19 # make gen-files-list
20 # NOTE: suffix duplicated modules located in modules_s with '_s' to
21 # avoid file naming conflicts
22 #
23 files_list= \
24 $(COREPATH)/core/core_cmd.c:core \
25 $(COREPATH)/modules/app_jsdt/app_jsdt_api.c:app_jsdt \
26 $(COREPATH)/modules/app_lua/app_lua_mod.c:app_lua \
27 $(COREPATH)/modules/app_perl/app_perl_mod.c:app_perl \
28 $(COREPATH)/modules/app_sqlang/app_sqlang_api.c:app_sqlang \
29 $(COREPATH)/modules/auth_ephemeral/auth_ephemeral_mod.c:auth_ephemeral \
30 $(COREPATH)/modules/auth_xkeys/auth_xkeys.c:auth_xkeys \
31 $(COREPATH)/modules/benchmark/benchmark.c:benchmark \
32 $(COREPATH)/modules/call_obj/call_obj_mod.c:call_obj \
33 $(COREPATH)/modules/carrierroute/carrierroute.c:carrierroute \
34 $(COREPATH)/modules/cdp/cdp_rpc.c:cdp \
35 $(COREPATH)/modules/cfg_rpc/cfg_rpc.c:cfg_rpc \
36 $(COREPATH)/modules/cfgt/cfgt_int.c:cfgt \
37 $(COREPATH)/modules/cfgutils/cfgutils.c:cfgutils \
38 $(COREPATH)/modules/cnxcc/cnxcc_mod.c:cnxcc \
39 $(COREPATH)/modules/corex/corex_rpc.c:corex \
40 $(COREPATH)/modules/counters/counters.c:counters \
41 $(COREPATH)/modules/cplc/cpl_loader.c:cplc \
42 $(COREPATH)/modules/ctl/ctl.c:ctl \
43 $(COREPATH)/modules/db_flatstore/flat_rpc.c:db_flatstore \
44 $(COREPATH)/modules/db_flatstore/km_flatstore_mod.c:db_flatstore \
45 $(COREPATH)/modules/db_text/db_text.c:db_text \
46 $(COREPATH)/modules/debugger/debugger_api.c:debugger \
47 $(COREPATH)/modules/dialog/dialog.c:dialog \
48 $(COREPATH)/modules/dialplan/dialplan.c:dialplan \
49 $(COREPATH)/modules/dispatcher/dispatcher.c:dispatcher \
50 $(COREPATH)/modules/dmq/dmq.c:dmq \
51 $(COREPATH)/modules/domain/domain_mod.c:domain \
52 $(COREPATH)/modules/drouting/drouting.c:drouting \
53 $(COREPATH)/modules/htable/htable.c:htable \
54 $(COREPATH)/modules/http_client/curlrpc.c:http_client \
55 $(COREPATH)/modules/imc/imc.c:imc \
56 $(COREPATH)/modules/ims_dialog/ims_dialog.c:ims_dialog \
57 $(COREPATH)/modules/ims_registrar_scscf/reg_rpc.c:ims_registrar_scscf \
58 $(COREPATH)/modules/ims_usrloc_pcscf/ul_rpc.c:ims_usrloc_pcscf \
59 $(COREPATH)/modules/ims_usrloc_scscf/ul_rpc.c:ims_usrloc_scscf \
60 $(COREPATH)/modules/jsonrpcs/jsonrpcs_mod.c:jsonrpcs \
61 $(COREPATH)/modules/keepalive/keepalive_rpc.c:keepalive \
62 $(COREPATH)/modules/kex/core_stats.c:kex \
63 $(COREPATH)/modules/kex/mod_stats.c:kex \
64 $(COREPATH)/modules/kex/pkg_stats.c:kex \
65 $(COREPATH)/modules/lcr/lcr_rpc.c:lcr \
66 $(COREPATH)/modules/malloc_test/malloc_test.c:malloc_test \
67 $(COREPATH)/modules/matrix/matrix.c:matrix \
68 $(COREPATH)/modules/mqueue/mqueue_mod.c:mqueue \
69 $(COREPATH)/modules/msrp/msrp_cmap.c:msrp \
70 $(COREPATH)/modules/mtree/mtree_mod.c:mtree \
71 $(COREPATH)/modules/nathelper/nathelper.c:nathelper \
72 $(COREPATH)/modules/pdb/pdb.c:pdb \
73 $(COREPATH)/modules/pdt/pdt.c:pdt \
74 $(COREPATH)/modules/permissions/permissions.c:permissions \
75 $(COREPATH)/modules/pike/pike_rpc.c:pike \
76 $(COREPATH)/modules/pipelimit/pipelimit.c:pipelimit \
77 $(COREPATH)/modules/prefix_route/pr_rpc.c:prefix_route \
78 $(COREPATH)/modules/presence/presence.c:presence \
79 $(COREPATH)/modules/pua/pua.c:pua \
80 $(COREPATH)/modules/pua_rpc/pua_rpc.c:pua_rpc \
81 $(COREPATH)/modules/pv/pv.c:pv \
82 $(COREPATH)/modules/ratelimit/ratelimit.c:ratelimit \
83 $(COREPATH)/modules/regex/regex_mod.c:regex \
84 $(COREPATH)/modules/rls/rls.c:rls \
85 $(COREPATH)/modules/rtpengine/rtpengine.c:rtpengine \
86 $(COREPATH)/modules/rtpproxy/rtpproxy.c:rtpproxy \
87 $(COREPATH)/modules/sca/sca.c:sca \
88 $(COREPATH)/modules/sctp/sctp_rpc.c:sctp \
89 $(COREPATH)/modules/sipcapture/sipcapture.c:sipcapture \
90 $(COREPATH)/modules/siptrace/siptrace.c:siptrace \
91 $(COREPATH)/modules/sl/sl_stats.c:sl \
92 $(COREPATH)/modules/statsc/statsc_mod.c:statsc \
93 $(COREPATH)/modules/tls/tls_rpc.c:tls \
94 $(COREPATH)/modules/tm/tm.c:tm \
95 $(COREPATH)/modules/tsilo/ts_rpc.c:tsilo \
96 $(COREPATH)/modules/uac/uac_reg.c:uac \
97 $(COREPATH)/modules/uid_domain/domain_rpc.c:uid_domain \
98 $(COREPATH)/modules/uid_gflags/uid_gflags.c:uid_gflags \
99 $(COREPATH)/modules/userblacklist/userblacklist.c:userblacklist \
100 $(COREPATH)/modules/usrloc/ul_rpc.c:usrloc \
101 $(COREPATH)/modules/websocket/websocket.c:websocket \
102 $(COREPATH)/modules/xcap_client/xcap_client.c:xcap_client \
103 $(COREPATH)/modules/xhttp_pi/xhttp_pi.c:xhttp_pi
104
105
106 # list of excluded groups
107 grp_exclude=pa
108 # list of file prefixes to exclude (full path needed)
109 file_exclude=$(COREPATH)/obsolete
110
111 # special per file group overrides
112 # format= grp_filename=... ,where filename does not contain the extension
113 # e.g.:
114 # grp_f_tcp_options=tcp
115 # grp_f_sctp_options=sctp
116
117 # special per group group name overrides
118 # e.g.:
119 # grp_g_maxfwd=mf
120
121 # override auto-detected group if set to 1 (else the group is used inside the
122 # file only if it cannot be aut-odetected)
123 ifeq ($(group_override),1)
124 override force_grp=force-
125 else
126 override force_grp=
127 endif
128
129 # command used for gcc (contains extra includes)
130 gcc=gcc
131 #-I$(COREPATH)/lib -I$(COREPATH) -I/usr/include/libxml2
132
133 # defines used by gcc
134 c_defsX=-DNAME='\"kamailio\"' -DVERSION='\"5.1.0-dev3\"' -DARCH='\"x86_64\"' \
135 -DOS='linux_' -DOS_QUOTED='\"linux\"' -DCOMPILER='\"gcc 4.9.2\"' \
136 -D__CPU_x86_64 -D__OS_linux -DSER_VER=5001000 \
137 -DCFG_DIR='\"/usr/local/etc/kamailio/\"' \
138 -DRUN_DIR='\"/run/kamailio/\"' -DPKG_MALLOC -DSHM_MEM -DSHM_MMAP \
139 -DDNS_IP_HACK -DUSE_MCAST -DUSE_TCP -DDISABLE_NAGLE -DHAVE_RESOLV_RES \
140 -DUSE_DNS_CACHE -DUSE_DNS_FAILOVER -DUSE_DST_BLOCKLIST -DUSE_NAPTR \
141 -DMEM_JOIN_FREE -DF_MALLOC -DQ_MALLOC -DTLSF_MALLOC \
142 -DDBG_SR_MEMORY -DUSE_TLS -DTLS_HOOKS -DUSE_CORE_STATS -DSTATISTICS \
143 -DMALLOC_STATS -DWITH_AS_SUPPORT -DUSE_SCTP -DFAST_LOCK -DADAPTIVE_WAIT \
144 -DADAPTIVE_WAIT_LOOPS=1024 -DCC_GCC_LIKE_ASM -DHAVE_GETHOSTBYNAME2 \
145 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD -DHAVE_MSG_NOSIGNAL \
146 -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H -DHAVE_TIMEGM \
147 -DHAVE_SCHED_SETSCHEDULER -DHAVE_IP_MREQN -DHAVE_EPOLL -DHAVE_SIGIO_RT \
148 -DSIGINFO64_WORKAROUND -DUSE_FUTEX -DHAVE_SELECT
149
150 c_defs=$(subst ^^,='\",$(subst ",\"',$(subst =",^^,$(shell $(MAKE) -s -C ../../../src printcdefs))))
151
152 c_defs+= -DMOD_NAME='\"rpcgen\"'
153 c_defs+= -I$(COREPATH)/modules/app_sqlang/squirrel/include
154
155 # common makefile vars used in defs
156 LOCALBASE=/usr/local
157 SYSBASE=/usr
158
159 filter_files=$(filter-out $(addsuffix %,$(file_exclude)),\
160 $(filter-out $(addprefix %:,$(grp_exclude)),$(1)))
161
162 #filtered files list
163 flist=$(call filter_files,$(files_list))
164
165 # throws an error if input is not in the format filename:grp
166 check_fname_grp=$(if $(filter-out 2,$(words $(subst :, ,$(1)))),\
167 $(error bad format "$(1)", it should be filename:grp))
168
169 # get prereq from file:grp (get_prereq(file:grp) => file)
170 get_prereq=$(firstword $(subst :, ,$(1)))
171
172 # get grp from file:grp (get_grp(file:grp) => grp)
173 get_listed_grp=$(word 2, $(subst :, ,$(1)))
174
175 # get module interface define
176 get_modiface=$(word 3, $(subst :, ,$(1)))
177
178 find_modiface=$(if $(findstring modules,$(1)),$(shell $(MAKE) -s -C $(dir $(1)) printmiface),-DNONE)
179
180 # get base file name from file:grp: get_bname(file:grp)
181 # => basename(file) without extension (e.g. get_bname(foo/bar.c:x) => bar)
182 #
183 get_bname=$(basename $(notdir $(call get_prereq,$(1))))
184
185 #get grp from file:grp, using the overrides
186 get_grp=$(strip $(if $(grp_f_$(call get_bname,$(1))), \
187 $(grp_f_$(call get_bname,$(1))),\
188 $(if $(grp_g_$(call get_listed_grp,$(1))),\
189 $(grp_g_$(call get_listed_grp,$(1))),\
190 $(call get_listed_grp,$(1))) ) )
191
192 # get target from file:grp (get_target(file:grp) => rpc_grp.txt)
193 get_target=rpc_$(call get_grp,$(1))
194
195
196 # $(LF) definition (do not remove)
197 define LF
198
199
200 endef
201
202 # get all the lines containing DEFS or INCLUDES definitions from the Makefile.
203 # WARNING: does not work with all sed implementation (tested with GNU sed).
204 # It uses a hack to restore the LFs (LFs are removed by $(shell)): LFs are
205 # replaced with '^LF^' and then ^LF^ is subst'ed back to a real LF.
206 get_make_idefs=$(subst ^LF^,$(LF),$(shell sed \
207 -ne '/^[\t ]*\(DEFS\|INCLUDES\)[\t ]*[+:]\?=.*[^\]$$/H'\
208 -ne '/^[\t ]*\(DEFS\|INCLUDES\)[\t ]*[+:]\?=.*\\$$/,/\(^$$\)\|\([^\]$$\)/H'\
209 -ne '$${g;s/\n/^LF^/g;p}'\
210 < $(1)/Makefile ))
211
212
213 # get all the lines from the makefile containing variable definitions.
214 # It will also return conditionals and try to filter out possible rules.
215 # WARNING: does not work with all sed implementation (tested with GNU sed).
216 # It uses a hack to restore the LFs (LFs are removed by $(shell)): LFs are
217 # replaced with '^LF^' and then ^LF^ is subst'ed back to a real LF.
218 get_make_vars=$(subst ^LF^,$(LF),$(shell sed -n \
219 -e ': start' \
220 -e '/^\(ifeq\|ifneq\|else\|endif\)[\t ]*\($$\|.*[^\]$$\)/{H;b end}' \
221 -e '/^\(ifeq\|ifneq\|else\|endif\)[\t ]\+.*[\]$$/,/[^\]$$/{H;b end}' \
222 -e '/^[a-zA-Z._/$$][a-zA-Z0-9._()/$$ \t-]*:\([^=]\|$$\)/b eat_rule' \
223 -e '/^[\t ]*[A-Za-z._][A-Za-z0-9._-]*[\t ]*[+:]\?=.*[^\]$$/{H;b end}' \
224 -e '/^[\t ]*[A-Za-z._][A-Za-z0-9._-]*[\t ]*[+:]\?=.*\\$$/,/\(^$$\)\|\([^\]$$\)/{H;b end}' \
225 -e ': end' \
226 -e '$${g;s/\n/^LF^/g;p}'\
227 -e 'b' \
228 -e ': eat_rule' \
229 -e '$$b end' \
230 -e 'n' \
231 -e '/^[a-zA-Z._/$$][a-zA-Z0-9._()/$$ \t-]*:\([^=]\|$$\)/b eat_rule' \
232 -e '/^[\t]/b eat_rule' \
233 -e 'b start' \
234 < $(1)/Makefile ))
235
236
237 define mk_rules
238
239 $(call check_fname_grp, $(1))
240
241 #$$(info generating rpc_$$(call get_grp,$(1)).txt: $$(call get_prereq,$(1)))
242
243
244 DEFS:=
245 INCLUDES:=
246 # extract all the includes and defs from the module makefile and
247 # evaluate them
248 $$(eval $$(call get_make_vars,$$(dir $$(call get_prereq,$(1)))))
249 # override COREPATH (we know better)
250 COREPATH=../../../src
251 # save the result in a per group e_idefs_<grp_name> var
252 $$(eval e_idefs_$$(call get_grp,$(1)):=$$(DEFS) $$(INCLUDES))
253
254 # debugging:
255 #$$(info eval: $$(call get_make_vars,$$(dir $$(call get_prereq,$(1)))))
256 #$$(info e_idefs_$$(call get_grp,$(1))=$$(e_idefs_$$(call get_grp,$(1))))
257
258 $(txt_output_dir)/$$(call get_target,$(1)).txt: \
259 $$(call get_prereq,$(1)) Makefile $(CFG2TXT)
260 $(CFG2TXT) --file $$< --$(force_grp)grp=$$(call get_grp,$(1)) \
261 --gcc="$(gcc)" --txt \
262 --defs="$(c_defs) $$(call get_modiface,$(1)) $$(e_idefs_$$(call get_grp,$(1)))" \
263 > "$$@" || (rm -f "$$@"; exit 1)
264
265 $(docbook_output_dir)/$$(call get_target,$(1)).xml: \
266 $$(call get_prereq,$(1)) Makefile $(CFG2TXT)
267 $(CFG2DOCBOOK) --file $$< --$(force_grp)grp=$$(call get_grp,$(1)) \
268 --gcc="$(gcc)" --docbook \
269 --defs="$(c_defs) $$(e_idefs_$$(call get_grp,$(1)))" \
270 > "$$@" || (rm -f "$$@"; exit 1)
271
272
273 clean_$$(call get_target,$(1)).txt:
274 rm -f "$(txt_output_dir)/$$(call get_target,$(1)).txt"
275
276 clean_$$(call get_target,$(1)).xml:
277 rm -f "$(docbook_output_dir)/$$(call get_target,$(1)).xml"
278
279 txt: $(txt_output_dir)/$$(call get_target,$(1)).txt
280
281 docbook: $(docbook_output_dir)/$$(call get_target,$(1)).xml
282
283 clean_txt: clean_$$(call get_target,$(1)).txt
284
285 clean_docbook: clean_$$(call get_target,$(1)).xml
286
287
288 endef
289
290 find_rpc_files_cmd= find $(COREPATH) -type f -name "*.c" \
291 -exec grep "rpc_export_t[ ][a-zA-Z0-9_]*\[\][ ]*=" /dev/null {} \; \
292 | cut -d: -f1
293
294 # shell command to generate a file:grp list from a list of files
295 # grp will be the modulename if the file is in a module directory or
296 # the file name with the extension and _cmd, cmd_ or _rpc stripped out of
297 # it.
298 # output: list of " "filename":"grpname
299 gen_file_grp_cmd=\
300 sed -e "s!\(.*/modules[^/]*/\([^/][^/]*\)/.*\)! \1:\2!" \
301 -e "s!^\([^ ].*/\([^/.]*\)[^/]*$$\)!\1:\2!" \
302 -e "s!^\([^ :]*\):\(.*\)_cmd[_]*!\1:\2!" \
303 -e "s!^\([^ :]*\):\(.*\)cmd[_]*!\1:\2!" \
304 -e "s!^\([^ :]*\):\(.*\)_rpc[_]*!\1:\2!"
305
306 # special vars for generating the list of files or updates
307 found_lst=$(shell $(find_rpc_files_cmd) | $(gen_file_grp_cmd))
308 # filtered found lst
309 f_found_lst=$(call filter_files,$(found_lst))
310 diff_lst=$(filter-out $(flist),$(f_found_lst))
311
312
313 get_core_files=$(filter-out $(COREPATH)/modules% $(COREPATH)/lib%,$(1))
314 sort_files=$(sort $(call get_core_files,$(1)))\
315 $(sort $(filter-out $(call get_core_files,$(1)),$(1)))
316
317 # replace $(COREPATH) with the text "$(COREPATH)"
318 subst_corepath=$(patsubst $(patsubst %/,%,$(COREPATH))/%,\$$(COREPATH)/%,$(1))
319
320
321 # help will be the default rule (on-purpose since without having a patched
322 # GCC:TranslationUnit module, make all won't work)
323 .PHONY: help
324 help:
325 @echo "To regenerate $(foreach f,$(flist),$(call get_target,$f).{txt,xml})"
326 @echo "type: $(MAKE) all ."
327 @echo "or to regenerate all the rpc lists by searching all"
328 @echo " the source files for definitions, type: $(MAKE) autogen ."
329 @echo "NOTE: you need the GCC:TranslationUnit perl module with an "
330 @echo "extra patch applied (see $(CFG2TXT) --patch)."
331
332 .PHONY: txt
333 txt:
334
335 .PHONY: docbook
336 docbook:
337
338 .PHONY: clean_txt
339 clean_txt:
340
341 .PHONY: clean_docbook
342 clean_docbook:
343
344
345 .PHONY: all
346 all: txt $(docbook_output_dir)/rpc_list.xml
347
348 .PHONY: clean
349 clean: clean_txt clean_docbook
350 @rm -f $(docbook_output_dir)/rpc_list.xml
351
352 .PHONY: proper
353 proper:
354 @rm -f $(txt_output_dir)/rpc_*.txt
355 @rm -f $(docbook_output_dir)/rpc_*.xml
356
357 repo_ver="Kamailio "\
358 "git-$(shell git rev-parse --verify --short=6 HEAD 2>/dev/null)"
359 ifeq ($(repo_ver),git-)
360 repo_ver="Kamailio unknown"
361 endif
362
363 $(docbook_output_dir)/rpc_list.xml: Makefile \
364 $(foreach f,$(flist),$(docbook_output_dir)/$(call get_target,$f).xml)
365 @echo '<?xml version="1.0" encoding="UTF-8"?>' >$@
366 @echo '<!-- this file is autogenerated, do not edit! -->' >>$@
367 @echo '<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"' >>$@
368 @echo ' "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"' >>$@
369 @echo ' [ <!ENTITY % local.common.attrib' >>$@
370 @echo " \"xmlns:xi CDATA #FIXED 'http://www.w3.org/2001/XInclude'\">]">>$@
371 @echo '>' >>$@
372 @echo '<book id="rpc_list"'\
373 'xmlns:xi="http://www.w3.org/2001/XInclude">' >>$@
374 @echo ' <title>RPC Commands List</title>' >>$@
375 @echo ' <bookinfo>' >>$@
376 @echo ' <productname class="trade">kamailio.org</productname>' >>$@
377 @echo ' <authorgroup>' >>$@
378 @echo ' <author>' >>$@
379 @echo ' <firstname>Kamailio</firstname>' >>$@
380 @echo ' <surname>Development Team</surname>' >>$@
381 @echo ' <affiliation><orgname>https://www.kamailio.org</orgname></affiliation>' >>$@
382 @echo ' <address>[email protected]</address>' >>$@
383 @echo ' </author>' >>$@
384 @echo ' </authorgroup>' >>$@
385 @echo ' <copyright>' >>$@
386 @echo ' <year>2008-2017</year>' >>$@
387 @echo ' <holder>Kamailio Project</holder>' >>$@
388 @echo ' </copyright>' >>$@
389 @echo ' </bookinfo>' >>$@
390 @$(foreach f,$(flist),\
391 echo ' <xi:include'\
392 'href="'$(call get_target,$f).xml'"/>' \
393 >>$@ ; )
394 @echo '</book>' >>$@
395
396 # finds all the files containing cfg defs
397 .PHONY: find
398 find:
399 @$(find_rpc_files_cmd)
400
401 # print the list of the autogenerated files
402 .PHONY: print-lst
403 print-lst:
404 @$(find_rpc_files_cmd) | $(gen_file_grp_cmd)
405
406 #
407 .PHONY: gen-file-list
408 .PHONY: gen-files_list
409 .PHONY: gen_files_list
410 gen-file-list gen-files-list gen_files_list:
411 @$(foreach f,$(call subst_corepath,$(call sort_files,$(f_found_lst))),\
412 echo "$f \\";)
413
414 print-modifaces:
415 @$(foreach f,$(call sort_files,$(f_found_lst)),\
416 echo "$(call subst_corepath,$(f)):$(call find_modiface, $(f)) \\";)
417
418 .PHONY: check-list
419 .PHONY: update-list
420 .PHONY: diff-list
421 check-list update-list diff-list:
422 @$(foreach f,$(call subst_corepath,$(call sort_files,$(diff_lst))),\
423 echo "$f \\";)
424
425
426 # try to generate the docs from all the sources
427 .PHONY: autogen
428 autogen:
429 @$(MAKE) all files_list="$(call sort_files,$(f_found_lst))"
430
431 $(foreach f,$(flist),$(eval $(call mk_rules,$(f))))