Browse code

doc: select_list: parse DEFS from the modules Makefiles

Get all the variable definitions from each module Makefile and
evaluate them to get proper DEFS and INCLUDES (using sed to
extract the variable definitions, conditionals and filter-out
rules from the Makefiles, some hack to preserve the LFs and
$(eval) to evaluate the extracted stuff in the current context).
The DEFS and INCLUDES will be passed to the documentation
generating script (dump_selects.pl) as extra arguments for gcc.
This way the proper defines and includes will be used for each
module.
Fixes select list generation failure for modules with non-standard
include dirs.

Andrei Pelinescu-Onciul authored on 30/08/2010 11:32:18
Showing 1 changed files
... ...
@@ -62,7 +62,23 @@ override force_grp=
62 62
 endif
63 63
 
64 64
 # command used for gcc (contains extra includes)
65
-gcc=gcc -I$(COREPATH)/lib -I/usr/include/libxml2
65
+gcc=gcc
66
+#-I$(COREPATH)/lib -I$(COREPATH) -I/usr/include/libxml2
67
+
68
+# defines used by gcc
69
+c_defs=-D__CPU_i386 -D__OS_linux -DSER_VER=2099099 -DPKG_MALLOC -DSHM_MEM  \
70
+		-DSHM_MMAP -DDNS_IP_HACK -DUSE_IPV6 -DUSE_MCAST -DUSE_TCP \
71
+		-DUSE_DNS_CACHE -DUSE_DNS_FAILOVER -DUSE_DST_BLACKLIST -DUSE_NAPTR \
72
+		-DUSE_TLS -DTLS_HOOKS -DFAST_LOCK   -DCC_GCC_LIKE_ASM \
73
+		-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
74
+		-DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H \
75
+		-DHAVE_SCHED_SETSCHEDULER -DHAVE_EPOLL -DUSE_SCTP -DNAME='\"ser\"' \
76
+		-DVERSION='\"2.99.99-pre3\"' -DARCH='\"i386\"' -DOS_QUOTED='\"linux\"'
77
+
78
+
79
+# common makefile vars used in defs
80
+LOCALBASE=/usr/local
81
+SYSBASE=/usr
66 82
 
67 83
 filter_files=$(subst .h:,.c:, $(filter-out $(addsuffix %,$(file_exclude)),\
68 84
 				$(filter-out $(addprefix %:,$(grp_exclude)),$(1))) )
... ...
@@ -95,23 +111,82 @@ get_grp=$(strip $(if $(grp_f_$(call get_bname,$(1))), \
95 111
 # get target from file:grp (get_target(file:grp) => select_grp)
96 112
 get_target=select_$(call get_grp,$(1))
97 113
 
114
+
115
+# $(LF) definition (do not remove)
116
+define LF
117
+
118
+
119
+endef
120
+
121
+# get all the lines containing DEFS or INCLUDES definitions from the Makefile.
122
+# WARNING: does not work with all sed implementation (tested with GNU sed).
123
+# It uses a hack to restore the LFs (LFs are removed by $(shell)): LFs are
124
+# replaced with '^LF^' and then ^LF^ is subst'ed back to a real LF.
125
+get_make_idefs=$(subst ^LF^,$(LF),$(shell sed \
126
+ -ne '/^[\t ]*\(DEFS\|INCLUDES\)[\t ]*[+:]\?=.*[^\]$$/H'\
127
+ -ne '/^[\t ]*\(DEFS\|INCLUDES\)[\t ]*[+:]\?=.*\\$$/,/\(^$$\)\|\([^\]$$\)/H'\
128
+ -ne '$${g;s/\n/^LF^/g;p}'\
129
+< $(1)/Makefile ))
130
+
131
+
132
+# get all the lines from the makefile containing variable definitions.
133
+# It will also return conditionals and try to filter out possible rules.
134
+# WARNING: does not work with all sed implementation (tested with GNU sed).
135
+# It uses a hack to restore the LFs (LFs are removed by $(shell)): LFs are
136
+# replaced with '^LF^' and then ^LF^ is subst'ed back to a real LF.
137
+get_make_vars=$(subst ^LF^,$(LF),$(shell sed -n \
138
+ -e ': start' \
139
+ -e '/^\(ifeq\|ifneq\|else\|endif\)[\t ]*\($$\|.*[^\]$$\)/{H;d}' \
140
+ -e '/^\(ifeq\|ifneq\|else\|endif\)[\t ]\+.*[\]$$/,/[^\]$$/{H;d}' \
141
+ -e '/^[a-zA-Z._/$$][a-zA-Z0-9._()/$$ \t-]*:\([^=]\|$$\)/b eat_rule' \
142
+ -e '/^[\t ]*[A-Za-z._][A-Za-z0-9._-]*[\t ]*[+:]\?=.*[^\]$$/{H;d}' \
143
+ -e '/^[\t ]*[A-Za-z._][A-Za-z0-9._-]*[\t ]*[+:]\?=.*\\$$/,/\(^$$\)\|\([^\]$$\)/{H;d}' \
144
+ -e ': end' \
145
+ -e '$${g;s/\n/^LF^/g;p}'\
146
+ -e 'b' \
147
+ -e ': eat_rule' \
148
+ -e '$$b end' \
149
+ -e 'n' \
150
+ -e '/^[a-zA-Z._/$$][a-zA-Z0-9._()/$$ \t-]*:\([^=]\|$$\)/b eat_rule' \
151
+ -e '/^[\t]/b eat_rule' \
152
+ -e 'b start' \
153
+< $(1)/Makefile ))
154
+
155
+
98 156
 define  mk_rules
99 157
 
100 158
 $(call check_fname_grp, $(1))
101 159
 
102 160
 #$$(info generating select_$$(call get_grp,$(1)).txt: $$(call get_prereq,$(1)))
103 161
 
162
+
163
+DEFS:=
164
+INCLUDES:=
165
+# extract all the includes and defs from the module makefile and
166
+# evaluate them
167
+$$(eval $$(call get_make_vars,$$(dir $$(call get_prereq,$(1)))))
168
+# override COREPATH (we know better)
169
+COREPATH=../..
170
+# save the result in a per group e_idefs_<grp_name> var
171
+$$(eval e_idefs_$$(call get_grp,$(1)):=$$(DEFS) $$(INCLUDES))
172
+
173
+# debugging:
174
+#$$(info eval: $$(call get_make_vars,$$(dir $$(call get_prereq,$(1)))))
175
+#$$(info e_idefs_$$(call get_grp,$(1))=$$(e_idefs_$$(call get_grp,$(1))))
176
+
104 177
 $(txt_output_dir)/$$(call get_target,$(1)).txt: \
105 178
 								$$(call get_prereq,$(1)) Makefile $(CFG2TXT)
106 179
 	$(CFG2TXT) --file $$< --$(force_grp)grp=$$(call get_grp,$(1)) \
107
-		--gcc="$(gcc)" --txt $(CFG2TXT_EXTRA_OPTS) > "$$@" || \
108
-		(rm -f "$$@"; exit 1)
180
+		--gcc="$(gcc)" --txt  $(CFG2TXT_EXTRA_OPTS) \
181
+		--defs="$(c_defs) $$(e_idefs_$$(call get_grp,$(1)))" \
182
+		> "$$@" || (rm -f "$$@"; exit 1)
109 183
 
110 184
 $(docbook_output_dir)/$$(call get_target,$(1)).xml: \
111 185
 								$$(call get_prereq,$(1)) Makefile $(CFG2TXT)
112 186
 	$(CFG2DOCBOOK) --file $$< --$(force_grp)grp=$$(call get_grp,$(1)) \
113
-		--gcc="$(gcc)" --docbook $(CFG2DOCBOOK_EXTRA_OPTS) > "$$@" || \
114
-		(rm -f "$$@"; exit 1)
187
+		--gcc="$(gcc)" --docbook $(CFG2DOCBOOK_EXTRA_OPTS) \
188
+		--defs="$(c_defs) $$(e_idefs_$$(call get_grp,$(1)))" \
189
+		> "$$@" || (rm -f "$$@"; exit 1)
115 190
 
116 191
 
117 192
 clean_$$(call get_target,$(1)).txt: