Makefile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. COREPATH=../../../src
  2. #include $(COREPATH)/Makefile.defs
  3. CFG2TXT=../../scripts/cdefs2doc/dump_cfg_defs.pl
  4. CFG2DOCBOOK=../../scripts/cdefs2doc/dump_cfg_defs.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 cfg 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. files_list= \
  16. $(COREPATH)/core/cfg_core.c:core \
  17. $(COREPATH)/core/tcp_options.c:tcp \
  18. $(COREPATH)/modules/carrierroute/config.c:carrierroute \
  19. $(COREPATH)/modules/debugger/debugger_config.c:debugger \
  20. $(COREPATH)/modules/dispatcher/config.c:dispatcher \
  21. $(COREPATH)/modules/ims_registrar_scscf/config.c:ims_registrar_scscf \
  22. $(COREPATH)/modules/malloc_test/malloc_test.c:malloc_test \
  23. $(COREPATH)/modules/maxfwd/maxfwd.c:maxfwd \
  24. $(COREPATH)/modules/outbound/config.c:outbound \
  25. $(COREPATH)/modules/registrar/config.c:registrar \
  26. $(COREPATH)/modules/rtpengine/config.c:rtpengine \
  27. $(COREPATH)/modules/sctp/sctp_options.c:sctp \
  28. $(COREPATH)/modules/siputils/config.c:siputils \
  29. $(COREPATH)/modules/stun/config.c:stun \
  30. $(COREPATH)/modules/tls/tls_cfg.c:tls \
  31. $(COREPATH)/modules/tm/config.c:tm \
  32. $(COREPATH)/modules/websocket/config.c:websocket \
  33. $(COREPATH)/modules/xlog/xlog.c:xlog
  34. # list of excluded groups
  35. grp_exclude=pa
  36. # list of file prefixes to exclude (full path needed)
  37. file_exclude= $(COREPATH)/obsolete/
  38. # special per file group overrides
  39. # format= grp_filename=... ,where filename does not contain the extension
  40. # e.g.:
  41. # grp_f_tcp_options=tcp
  42. # grp_f_sctp_options=sctp
  43. # special per group group name overrides
  44. # e.g.:
  45. # grp_g_maxfwd=mf
  46. # override auto-detected group if set to 1 (else the group is used inside the
  47. # file only if it cannot be aut-odetected)
  48. ifeq ($(group_override),1)
  49. override force_grp=force-
  50. else
  51. override force_grp=
  52. endif
  53. # command used for gcc (contains extra includes)
  54. gcc=gcc
  55. #-I$(COREPATH)/lib -I$(COREPATH) -I/usr/include/libxml2
  56. # defines used by gcc
  57. c_defs=-DNAME='\"kamailio\"' -DVERSION='\"5.1.0-dev3\"' -DARCH='\"x86_64\"' \
  58. -DOS='linux_' -DOS_QUOTED='\"linux\"' -DCOMPILER='\"gcc 4.9.2\"' \
  59. -D__CPU_x86_64 -D__OS_linux -DSER_VER=5001000 \
  60. -DCFG_DIR='\"/usr/local/etc/kamailio/\"' \
  61. -DRUN_DIR='\"/var/run/kamailio/\"' -DPKG_MALLOC -DSHM_MEM -DSHM_MMAP \
  62. -DDNS_IP_HACK -DUSE_MCAST -DUSE_TCP -DDISABLE_NAGLE -DHAVE_RESOLV_RES \
  63. -DUSE_DNS_CACHE -DUSE_DNS_FAILOVER -DUSE_DST_BLACKLIST -DUSE_NAPTR \
  64. -DWITH_XAVP -DMEM_JOIN_FREE -DF_MALLOC -DQ_MALLOC -DTLSF_MALLOC \
  65. -DDBG_SR_MEMORY -DUSE_TLS -DTLS_HOOKS -DUSE_CORE_STATS -DSTATISTICS \
  66. -DMALLOC_STATS -DWITH_AS_SUPPORT -DUSE_SCTP -DFAST_LOCK -DADAPTIVE_WAIT \
  67. -DADAPTIVE_WAIT_LOOPS=1024 -DCC_GCC_LIKE_ASM -DHAVE_GETHOSTBYNAME2 \
  68. -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD -DHAVE_MSG_NOSIGNAL \
  69. -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H -DHAVE_TIMEGM \
  70. -DHAVE_SCHED_SETSCHEDULER -DHAVE_IP_MREQN -DHAVE_EPOLL -DHAVE_SIGIO_RT \
  71. -DSIGINFO64_WORKARROUND -DUSE_FUTEX -DHAVE_SELECT
  72. # common makefile vars used in defs
  73. LOCALBASE=/usr/local
  74. SYSBASE=/usr
  75. filter_files=$(filter-out $(addsuffix %,$(file_exclude)),\
  76. $(filter-out $(addprefix %:,$(grp_exclude)),$(1)))
  77. #filtered files list
  78. flist=$(call filter_files,$(files_list))
  79. # throws an error if input is not in the format filename:grp
  80. check_fname_grp=$(if $(filter-out 2,$(words $(subst :, ,$(1)))),\
  81. $(error bad format "$(1)", it should be filename:grp))
  82. # get prereq from file:grp (get_prereq(file:grp) => file)
  83. get_prereq=$(firstword $(subst :, ,$(1)))
  84. # get grp from file:grp (get_grp(file:grp) => grp)
  85. get_listed_grp=$(word 2, $(subst :, ,$(1)))
  86. # get base file name from file:grp: get_bname(file:grp)
  87. # => basename(file) without extension (e.g. get_bname(foo/bar.c:x) => bar)
  88. #
  89. get_bname=$(basename $(notdir $(call get_prereq,$(1))))
  90. #get grp from file:grp, using the overrides
  91. get_grp=$(strip $(if $(grp_f_$(call get_bname,$(1))), \
  92. $(grp_f_$(call get_bname,$(1))),\
  93. $(if $(grp_g_$(call get_listed_grp,$(1))),\
  94. $(grp_g_$(call get_listed_grp,$(1))),\
  95. $(call get_listed_grp,$(1))) ) )
  96. # get target from file:grp (get_target(file:grp) => cfg_grp.txt)
  97. get_target=cfg_$(call get_grp,$(1))
  98. # $(LF) definition (do not remove)
  99. define LF
  100. endef
  101. # get all the lines containing DEFS or INCLUDES definitions from the Makefile.
  102. # WARNING: does not work with all sed implementation (tested with GNU sed).
  103. # It uses a hack to restore the LFs (LFs are removed by $(shell)): LFs are
  104. # replaced with '^LF^' and then ^LF^ is subst'ed back to a real LF.
  105. get_make_idefs=$(subst ^LF^,$(LF),$(shell sed \
  106. -ne '/^[\t ]*\(DEFS\|INCLUDES\)[\t ]*[+:]\?=.*[^\]$$/H'\
  107. -ne '/^[\t ]*\(DEFS\|INCLUDES\)[\t ]*[+:]\?=.*\\$$/,/\(^$$\)\|\([^\]$$\)/H'\
  108. -ne '$${g;s/\n/^LF^/g;p}'\
  109. < $(1)/Makefile ))
  110. # get all the lines from the makefile containing variable definitions.
  111. # It will also return conditionals and try to filter out possible rules.
  112. # WARNING: does not work with all sed implementation (tested with GNU sed).
  113. # It uses a hack to restore the LFs (LFs are removed by $(shell)): LFs are
  114. # replaced with '^LF^' and then ^LF^ is subst'ed back to a real LF.
  115. get_make_vars=$(subst ^LF^,$(LF),$(shell sed -n \
  116. -e ': start' \
  117. -e '/^\(ifeq\|ifneq\|else\|endif\)[\t ]*\($$\|.*[^\]$$\)/{H;b end}' \
  118. -e '/^\(ifeq\|ifneq\|else\|endif\)[\t ]\+.*[\]$$/,/[^\]$$/{H;b end}' \
  119. -e '/^[a-zA-Z._/$$][a-zA-Z0-9._()/$$ \t-]*:\([^=]\|$$\)/b eat_rule' \
  120. -e '/^[\t ]*[A-Za-z._][A-Za-z0-9._-]*[\t ]*[+:]\?=.*[^\]$$/{H;b end}' \
  121. -e '/^[\t ]*[A-Za-z._][A-Za-z0-9._-]*[\t ]*[+:]\?=.*\\$$/,/\(^$$\)\|\([^\]$$\)/{H;b end}' \
  122. -e ': end' \
  123. -e '$${g;s/\n/^LF^/g;p}'\
  124. -e 'b' \
  125. -e ': eat_rule' \
  126. -e '$$b end' \
  127. -e 'n' \
  128. -e '/^[a-zA-Z._/$$][a-zA-Z0-9._()/$$ \t-]*:\([^=]\|$$\)/b eat_rule' \
  129. -e '/^[\t]/b eat_rule' \
  130. -e 'b start' \
  131. < $(1)/Makefile ))
  132. define mk_rules
  133. $(call check_fname_grp, $(1))
  134. #$$(info generating cfg_$$(call get_grp,$(1)).txt: $$(call get_prereq,$(1)))
  135. DEFS:=
  136. INCLUDES:=
  137. # extract all the includes and defs from the module makefile and
  138. # evaluate them
  139. $$(eval $$(call get_make_vars,$$(dir $$(call get_prereq,$(1)))))
  140. # override COREPATH (we know better)
  141. COREPATH=../../../src
  142. # save the result in a per group e_idefs_<grp_name> var
  143. $$(eval e_idefs_$$(call get_grp,$(1)):=$$(DEFS) $$(INCLUDES))
  144. # debugging:
  145. #$$(info eval: $$(call get_make_vars,$$(dir $$(call get_prereq,$(1)))))
  146. #$$(info e_idefs_$$(call get_grp,$(1))=$$(e_idefs_$$(call get_grp,$(1))))
  147. $(txt_output_dir)/$$(call get_target,$(1)).txt: \
  148. $$(call get_prereq,$(1)) Makefile $(CFG2TXT)
  149. $(CFG2TXT) --file $$< --$(force_grp)grp=$$(call get_grp,$(1)) \
  150. --gcc="$(gcc)" --txt \
  151. --defs="$(c_defs) $$(e_idefs_$$(call get_grp,$(1)))" \
  152. > "$$@" || (rm -f "$$@"; exit 1)
  153. $(docbook_output_dir)/$$(call get_target,$(1)).xml: \
  154. $$(call get_prereq,$(1)) Makefile $(CFG2TXT)
  155. $(CFG2DOCBOOK) --file $$< --$(force_grp)grp=$$(call get_grp,$(1)) \
  156. --gcc="$(gcc)" --docbook \
  157. --defs="$(c_defs) $$(e_idefs_$$(call get_grp,$(1)))" \
  158. > "$$@" || (rm -f "$$@"; exit 1)
  159. clean_$$(call get_target,$(1)).txt:
  160. rm -f "$(txt_output_dir)/$$(call get_target,$(1)).txt"
  161. clean_$$(call get_target,$(1)).xml:
  162. rm -f "$(docbook_output_dir)/$$(call get_target,$(1)).xml"
  163. txt: $(txt_output_dir)/$$(call get_target,$(1)).txt
  164. docbook: $(docbook_output_dir)/$$(call get_target,$(1)).xml
  165. clean_txt: clean_$$(call get_target,$(1)).txt
  166. clean_docbook: clean_$$(call get_target,$(1)).xml
  167. endef
  168. find_cfg_files_cmd= find $(COREPATH) -type f -name "*.c" \
  169. -exec grep "cfg_def_t[ ][a-zA-Z0-9_]*\[\][ ]*=" /dev/null {} \; \
  170. | cut -d: -f1
  171. # shell command to generate a file:grp list from a list of files
  172. # grp will be the modulename if the file is in a module directory or
  173. # the file name with the extension and _cfg, cfg_ or _options stripped out of
  174. # it.
  175. # output: list of " "filename":"grpname
  176. gen_file_grp_cmd=\
  177. sed -e "s!\(.*/modules[^/]*/\([^/][^/]*\)/.*\)! \1:\2!" \
  178. -e "s!^\([^ ].*/\([^/.]*\)[^/]*$$\)!\1:\2!" \
  179. -e "s!^\([^ :]*\):\(.*\)_cfg[_]*!\1:\2!" \
  180. -e "s!^\([^ :]*\):\(.*\)cfg[_]*!\1:\2!" \
  181. -e "s!^\([^ :]*\):\(.*\)_options[_]*!\1:\2!"
  182. # special vars for generating the list of files or updates
  183. found_lst=$(shell $(find_cfg_files_cmd) | $(gen_file_grp_cmd))
  184. # filtered found lst
  185. f_found_lst=$(call filter_files,$(found_lst))
  186. diff_lst=$(filter-out $(flist),$(f_found_lst))
  187. get_core_files=$(filter-out $(COREPATH)/modules% $(COREPATH)/lib%,$(1))
  188. sort_files=$(sort $(call get_core_files,$(1))) \
  189. $(sort $(filter-out $(call get_core_files,$(1)),$(1)))
  190. # replace $(COREPATH) with the text "$(COREPATH)"
  191. subst_corepath=$(patsubst $(patsubst %/,%,$(COREPATH))/%,\$$(COREPATH)/%,$(1))
  192. # help will be the default rule (on-purpose since without having a patched
  193. # GCC:TranslationUnit module, make all won't work)
  194. .PHONY: help
  195. help:
  196. @echo "To regenerate $(foreach f,$(flist),$(call get_target,$f).{txt,xml})"
  197. @echo "type: $(MAKE) all ."
  198. @echo "or to regenerate all the cfg documentation by searching all"
  199. @echo " the source files for definitions, type: $(MAKE) autogen ."
  200. @echo "NOTE: you need the GCC:TranslationUnit perl module with an "
  201. @echo "extra patch applied (see $(CFG2TXT) --patch)."
  202. .PHONY: txt
  203. txt:
  204. .PHONY: docbook
  205. docbook:
  206. .PHONY: clean_txt
  207. clean_txt:
  208. .PHONY: clean_docbook
  209. clean_docbook:
  210. .PHONY: all
  211. all: txt $(docbook_output_dir)/cfg_var_list.xml
  212. .PHONY: clean
  213. clean: clean_txt clean_docbook
  214. @rm -f $(docbook_output_dir)/cfg_var_list.xml
  215. .PHONY: proper
  216. proper:
  217. @rm -f $(txt_output_dir)/cfg_*.txt
  218. @rm -f $(docbook_output_dir)/cfg_*.xml
  219. repo_ver="kamailio"\
  220. "git-$(shell git rev-parse --verify --short=6 HEAD 2>/dev/null)"
  221. ifeq ($(repo_ver),git-)
  222. repo_ver="kamailio unknown"
  223. endif
  224. $(docbook_output_dir)/cfg_var_list.xml: Makefile \
  225. $(foreach f,$(flist),$(docbook_output_dir)/$(call get_target,$f).xml)
  226. @echo '<?xml version="1.0" encoding="UTF-8"?>' >$@
  227. @echo '<!-- this file is autogenerated, do not edit! -->' >>$@
  228. @echo '<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"' >>$@
  229. @echo ' "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"' >>$@
  230. @echo ' [ <!ENTITY % local.common.attrib' >>$@
  231. @echo " \"xmlns:xi CDATA #FIXED 'http://www.w3.org/2001/XInclude'\">]">>$@
  232. @echo '>' >>$@
  233. @echo '<book id="cfg_var_list"'\
  234. 'xmlns:xi="http://www.w3.org/2001/XInclude">' >>$@
  235. @echo ' <title>Runtime Configuration Variables List</title>' >>$@
  236. @echo ' <bookinfo>' >>$@
  237. @echo ' <productname class="trade">kamailio.org</productname>' >>$@
  238. @echo ' <authorgroup>' >>$@
  239. @echo ' <author>' >>$@
  240. @echo ' <firstname>Kamailio</firstname>' >>$@
  241. @echo ' <surname>Development Team</surname>' >>$@
  242. @echo ' <affiliation><orgname>https://www.kamailio.org</orgname></affiliation>' >>$@
  243. @echo ' <address>[email protected]</address>' >>$@
  244. @echo ' </author>' >>$@
  245. @echo ' </authorgroup>' >>$@
  246. @echo ' <copyright>' >>$@
  247. @echo ' <year>2008-2017</year>' >>$@
  248. @echo ' <holder>Kamailio Project</holder>' >>$@
  249. @echo ' </copyright>' >>$@
  250. @echo ' </bookinfo>' >>$@
  251. @$(foreach f,$(flist),\
  252. echo ' <xi:include'\
  253. 'href="'$(call get_target,$f).xml'"/>' \
  254. >>$@ ; )
  255. @echo '</book>' >>$@
  256. # finds all the files containing cfg defs
  257. .PHONY: find
  258. find:
  259. @$(find_cfg_files_cmd)
  260. # print the list of the autogenerated files
  261. .PHONY: print-lst
  262. print-lst:
  263. @$(find_cfg_files_cmd) | $(gen_file_grp_cmd)
  264. #
  265. .PHONY: gen-file-list
  266. .PHONY: gen-files_list
  267. .PHONY: gen_files_list
  268. gen-file-list gen-files-list gen_files_list:
  269. @$(foreach f,$(call subst_corepath,$(call sort_files,$(f_found_lst))),\
  270. echo "$f \\";)
  271. .PHONY: check-list
  272. .PHONY: update-list
  273. .PHONY: diff-list
  274. check-list update-list diff-list:
  275. @$(foreach f,$(call subst_corepath,$(call sort_files,$(diff_lst))),\
  276. echo "$f \\";)
  277. # try to generate the docs from all the sources
  278. .PHONY: autogen
  279. autogen:
  280. @$(MAKE) all files_list="$(call sort_files,$(f_found_lst))"
  281. $(foreach f,$(flist),$(eval $(call mk_rules,$(f))))