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