[sr-dev] git:andrei/cdefs2doc: doc: added makefiles for auto-gen. rpc and cfg vars lists

Andrei Pelinescu-Onciul andrei at iptel.org
Mon Oct 19 18:47:37 CEST 2009


Module: sip-router
Branch: andrei/cdefs2doc
Commit: 8de15e2147533941b18a1ea1c018b420a667a374
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8de15e2147533941b18a1ea1c018b420a667a374

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Mon Oct 19 18:36:52 2009 +0200

doc: added makefiles for auto-gen. rpc and cfg vars lists

---

 doc/cfg_list/Makefile |  145 +++++++++++++++++++++++++++++++++++++++++++++++++
 doc/rpc_list/Makefile |  144 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 289 insertions(+), 0 deletions(-)

diff --git a/doc/cfg_list/Makefile b/doc/cfg_list/Makefile
new file mode 100644
index 0000000..881f735
--- /dev/null
+++ b/doc/cfg_list/Makefile
@@ -0,0 +1,145 @@
+
+COREPATH=../..
+
+#include $(COREPATH)/Makefile.defs
+
+CFG2TXT=../scripts/cdefs2doc/dump_cfg_defs.pl
+
+# list of files contanining cfg defs in the following format:
+# <filename>:<cfg_grp_name> 
+files_list=$(COREPATH)/cfg_core.c:core $(COREPATH)/tcp_options.c:tcp \
+			$(COREPATH)/sctp_options.c:sctp \
+			$(COREPATH)/modules_s/maxfwd/maxfwd.c:maxfwd \
+			$(COREPATH)/modules/tm/config.c:tm
+
+# list of excluded groups
+grp_exclude=pa
+# list of file prefixes to exclude (full path needed)
+file_exclude= $(COREPATH)/modules_s/tls/
+
+# special per file group overrides
+# format= grp_filename=... ,where filename does not contain the extension
+# e.g.:
+#     grp_f_tcp_options=tcp
+#     grp_f_sctp_options=sctp
+
+# special per group group name overrides
+# e.g.:
+#      grp_g_maxfwd=mf
+
+# override auto-detected group if set to 1 (else the group is used inside the
+# file only if it cannot be aut-odetected)
+ifeq ($(group_override),1)
+override force_grp=force-
+else
+override force_grp=
+endif
+
+# command used for gcc (contains extra includes)
+gcc=gcc -I$(COREPATH)/lib -I/usr/include/libxml2
+
+#filtered files list
+flist=$(filter-out $(join $(file_exclude),%),\
+			$(filter-out $(join %:,$(grp_exclude)),$(files_list)) )
+
+# throws an error if input is not in the format filename:grp
+check_fname_grp=$(if $(filter-out 2,$(words $(subst :, ,$(1)))),\
+					$(error bad format "$(1)", it should be filename:grp))
+
+# get prereq from file:grp (get_prereq(file:grp) => file)
+get_prereq=$(firstword $(subst :, ,$(1)))
+
+# get grp from file:grp (get_grp(file:grp) => grp)
+get_listed_grp=$(word 2, $(subst :, ,$(1)))
+
+# get base file name from file:grp: get_bname(file:grp) 
+# => basename(file) without extension (e.g. get_bname(foo/bar.c:x) => bar)
+# 
+get_bname=$(basename $(notdir $(call get_prereq,$(1))))
+
+#get grp from file:grp, using the overrides
+get_grp=$(strip $(if $(grp_f_$(call get_bname,$(1))), \
+					$(grp_f_$(call get_bname,$(1))),\
+					$(if $(grp_g_$(call get_listed_grp,$(1))),\
+						$(grp_g_$(call get_listed_grp,$(1))),\
+						$(call get_listed_grp,$(1))) ) )
+
+# get target from file:grp (get_target(file:grp) => cfg_grp.txt)
+get_target=cfg_$(call get_grp,$(1)).txt
+
+define  mk_rules
+
+$(call check_fname_grp, $(1))
+
+#$$(info generating cfg_$$(call get_grp,$(1)).txt: $$(call get_prereq,$(1)))
+
+$$(call get_target,$(1)): $$(call get_prereq,$(1)) Makefile $(CFG2TXT)
+	$(CFG2TXT) --file $$< --$(force_grp)grp=$$(call get_grp,$(1)) \
+		--gcc="$(gcc)"  > "$$@" ||  (rm -f "$$@"; exit 1)
+
+
+clean_$$(call get_target,$(1)):
+	rm -f "$$(call get_target,$(1))"
+
+all: $$(call get_target,$(1))
+
+clean: clean_$$(call get_target,$(1))
+
+
+endef
+
+
+# help will be the default rule (on-purpose since without having a patched
+# GCC:TranslationUnit module, make all won't work)
+.PHONY: help
+help:
+	@echo "To regenerate $(foreach f,$(flist),$(call get_target,$f) )"
+	@echo "type: $(MAKE) all ."
+	@echo "or to regenerate all the cfg documentation by searching all"
+	@echo " the source files for definitions, type: $(MAKE) autogen ."
+	@echo "NOTE: you need the GCC:TranslationUnit perl module with an "
+	@echo "extra patch applied (see $(CFG2TXT) --patch)."
+
+.PHONY: all
+all:
+
+.PHONY: clean
+clean:
+
+.PHONY: proper
+proper:
+	@rm -f cfg_*.txt
+
+find_cfg_files_cmd= find $(COREPATH) -type f -name "*.c" \
+		-exec grep "cfg_def_t[	 ][a-zA-Z0-9_]*\[\][	 ]*=" /dev/null {} \; \
+		| cut -d: -f1
+
+# shell command to generate a file:grp list from a list of files
+# grp will be the modulename if the file is in a module directory or
+# the file name with the extension and _cfg, cfg_ or _options stripped out of
+# it.
+# output: list of  " "filename":"grpname
+gen_file_grp_cmd=\
+sed -e "s!\(.*/modules[^/]*/\([^/][^/]*\)/.*\)! \1:\2!" \
+    -e "s!^\([^ ].*/\([^/.]*\)[^/]*$$\)!\1:\2!" \
+    -e "s!^\([^ :]*\):\(.*\)_cfg[_]*!:\1:\2!" \
+    -e "s!^\([^ :]*\):\(.*\)cfg[_]*!\1:\2!" \
+    -e "s!^\([^ :]*\):\(.*\)_options[_]*!\1:\2!"
+
+# finds all the files containing cfg defs
+.PHONY: find
+find:
+	@$(find_cfg_files_cmd)
+
+# print the list of the autogenerated files
+.PHONY: print-lst
+print-lst:
+	@$(find_cfg_files_cmd) | $(gen_file_grp_cmd)
+
+# try to generate the docs from all the sources
+.PHONY: autogen
+autogen:
+	LST=`$(find_cfg_files_cmd)| $(gen_file_grp_cmd) | xargs echo` && \
+	[ -n "$$LST" ] && $(MAKE) all files_list="$$LST"
+
+$(foreach f,$(flist),$(eval $(call mk_rules,$(f))))
diff --git a/doc/rpc_list/Makefile b/doc/rpc_list/Makefile
new file mode 100644
index 0000000..18d6918
--- /dev/null
+++ b/doc/rpc_list/Makefile
@@ -0,0 +1,144 @@
+
+COREPATH=../..
+
+#include $(COREPATH)/Makefile.defs
+
+CFG2TXT=../scripts/cdefs2doc/dump_rpcs.pl
+
+# list of files contanining rpc defs in the following format:
+# <filename>:<cfg_grp_name> 
+# one way to quickly fill it up is pasting the output of
+# make print-lst|xargs echo
+files_list=$(COREPATH)/core_cmd.c:core
+
+# list of excluded groups
+grp_exclude=pa
+# list of file prefixes to exclude (full path needed)
+file_exclude=$(COREPATH)/modules_s/tls/
+
+# special per file group overrides
+# format= grp_filename=... ,where filename does not contain the extension
+# e.g.:
+#     grp_f_tcp_options=tcp
+#     grp_f_sctp_options=sctp
+
+# special per group group name overrides
+# e.g.:
+#      grp_g_maxfwd=mf
+
+# override auto-detected group if set to 1 (else the group is used inside the
+# file only if it cannot be aut-odetected)
+ifeq ($(group_override),1)
+override force_grp=force-
+else
+override force_grp=
+endif
+
+# command used for gcc (contains extra includes)
+gcc=gcc -I$(COREPATH)/lib -I/usr/include/libxml2
+
+#filtered files list
+flist=$(filter-out $(join $(file_exclude),%),\
+			$(filter-out $(join %:,$(grp_exclude)),$(files_list)) )
+
+# throws an error if input is not in the format filename:grp
+check_fname_grp=$(if $(filter-out 2,$(words $(subst :, ,$(1)))),\
+					$(error bad format "$(1)", it should be filename:grp))
+
+# get prereq from file:grp (get_prereq(file:grp) => file)
+get_prereq=$(firstword $(subst :, ,$(1)))
+
+# get grp from file:grp (get_grp(file:grp) => grp)
+get_listed_grp=$(word 2, $(subst :, ,$(1)))
+
+# get base file name from file:grp: get_bname(file:grp) 
+# => basename(file) without extension (e.g. get_bname(foo/bar.c:x) => bar)
+# 
+get_bname=$(basename $(notdir $(call get_prereq,$(1))))
+
+#get grp from file:grp, using the overrides
+get_grp=$(strip $(if $(grp_f_$(call get_bname,$(1))), \
+					$(grp_f_$(call get_bname,$(1))),\
+					$(if $(grp_g_$(call get_listed_grp,$(1))),\
+						$(grp_g_$(call get_listed_grp,$(1))),\
+						$(call get_listed_grp,$(1))) ) )
+
+# get target from file:grp (get_target(file:grp) => rpc_grp.txt)
+get_target=rpc_$(call get_grp,$(1)).txt
+
+define  mk_rules
+
+$(call check_fname_grp, $(1))
+
+#$$(info generating rpc_$$(call get_grp,$(1)).txt: $$(call get_prereq,$(1)))
+
+$$(call get_target,$(1)): $$(call get_prereq,$(1)) Makefile $(CFG2TXT)
+	$(CFG2TXT) --file $$< --$(force_grp)grp=$$(call get_grp,$(1)) \
+		--gcc="$(gcc)"  > "$$@" ||  (rm -f "$$@"; exit 1)
+
+
+clean_$$(call get_target,$(1)):
+	rm -f "$$(call get_target,$(1))"
+
+all: $$(call get_target,$(1))
+
+clean: clean_$$(call get_target,$(1))
+
+
+endef
+
+
+# help will be the default rule (on-purpose since without having a patched
+# GCC:TranslationUnit module, make all won't work)
+.PHONY: help
+help:
+	@echo "To regenerate $(foreach f,$(flist),$(call get_target,$f) )"
+	@echo "type: $(MAKE) all ."
+	@echo "or to regenerate all the rpc lists by searching all"
+	@echo " the source files for definitions, type: $(MAKE) autogen ."
+	@echo "NOTE: you need the GCC:TranslationUnit perl module with an "
+	@echo "extra patch applied (see $(CFG2TXT) --patch)."
+
+.PHONY: all
+all:
+
+.PHONY: clean
+clean:
+
+.PHONY: proper
+proper:
+	@rm -f rpc_*.txt
+
+find_rpc_files_cmd= find $(COREPATH) -type f -name "*.c" \
+		-exec grep "rpc_export_t[	 ][a-zA-Z0-9_]*\[\][	 ]*=" /dev/null {} \; \
+		| cut -d: -f1
+
+# shell command to generate a file:grp list from a list of files
+# grp will be the modulename if the file is in a module directory or
+# the file name with the extension and _cmd, cmd_ or _rpc stripped out of
+# it.
+# output: list of  " "filename":"grpname
+gen_file_grp_cmd=\
+sed -e "s!\(.*/modules[^/]*/\([^/][^/]*\)/.*\)! \1:\2!" \
+    -e "s!^\([^ ].*/\([^/.]*\)[^/]*$$\)!\1:\2!" \
+    -e "s!^\([^ :]*\):\(.*\)_cmd[_]*!\1:\2!" \
+    -e "s!^\([^ :]*\):\(.*\)cmd[_]*!\1:\2!" \
+    -e "s!^\([^ :]\):\(.*\)_rpc[_]*!\1:\2!"
+
+# finds all the files containing cfg defs
+.PHONY: find
+find:
+	@$(find_rpc_files_cmd)
+
+# print the list of the autogenerated files
+.PHONY: print-lst
+print-lst:
+	@$(find_rpc_files_cmd) | $(gen_file_grp_cmd)
+
+# try to generate the docs from all the sources
+.PHONY: autogen
+autogen:
+	LST=`$(find_rpc_files_cmd)| $(gen_file_grp_cmd) | xargs echo` && \
+	[ -n "$$LST" ] && $(MAKE) all files_list="$$LST"
+
+$(foreach f,$(flist),$(eval $(call mk_rules,$(f))))




More information about the sr-dev mailing list