Makefile 14 KB

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