Makefile 12 KB

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