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