Makefile 11 KB

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