added -configure-enable-disable-vars- feature to configure
[k8jam.git] / defaults / configure / Jambase.configure
blob74c5941551e27acd2c854afd0d2225e89dc200cd
1 #  # "auto": check with pkg-config or so, show '--disable-xxx'
2 #  # "": disabled by default, show '--enable-xxx'
3 #  # non-empty string: enabled by default, show '--disable-xxx'
4 #  -configure-enable-disable-vars- +=
5 #    "sqlite"    USE_SQLITE    "auto"  "don't use sqlite"
6 #    "gtkhtml"   USE_GTKHTML   "auto"  "don't use GTKHTML"
7 #    "gtkspell"  USE_GTKSPELL  "auto"  "don't use GTKSpell"
8 #    "svg"       USE_RSVG      "auto"  "don't use librsvg"
9 #    "soup"      USE_SOUP      "auto"  "don't use libsoup"
10 #    "curl"      USE_CURL      "auto"  "don't use libcurl"
11 #    "dock"      USE_DOCK      "tan"   "disable dock icon"
12 #  ;
15 # $(1): option name
16 # $(2): option arg (if any)
17 rule -configure-show-default--help- {
18   if $(PROJECT_NAME) {
19     Echo "jam configure for package" $(PROJECT_NAME) "supports:" ;
20   } else {
21     Echo "jam configure supports:" ;
22   }
23   Echo "common options:" ;
24   Echo "  --prefix=dir  install prefix: [/usr/local]" ;
25   if $(-configure-enable-disable-vars-) {
26     Echo "package options:" ;
27     -configure-show-enable-disable-help- ;
28   }
29   Exit ;
33 rule -configure-options-help- {
34   -configure-show-default--help- ;
38 rule -configure-options-prefix- {
39   if ! $(2) {
40     Exit "ERROR: --prefix needs argument!" ;
41   }
42   -configure-add-line- "PREFIX ?= $(2) ;" ;
43   Echo "MSG: prefix set to $(2)" ;
47 # will be called before -configure-
48 # can set CONFIGURE_DONT_PARSE_OPTIONS
49 rule -configure-preinit- {
53 rule -configure-add-line- {
54   local str ;
56   if $(_CONFIGURE_FATAL_) != "tan" {
57     str = $(1:J=|space|) ;
58     Depends config : $(str) ;
59     -Action-Configure-WriteLine- $(str) ;
60   }
64 # $(1): library name to display
65 # $(2): arg to pkg-config
66 # $(3): string to write if present
67 # $(4): string to write if not present
68 # $(5): fail with this message if not present
69 # returns non-empty string if package exists
70 rule -configure-pkg-config- {
71   local flg lib ex res ;
72   res = ;
73   if $(_CONFIGURE_FATAL_) != "tan" {
74     Echo-n "checking for $(1) ..." ;
75     ex = [ pkg-config-exists $(2) ] ;
76     if $(ex) {
77       Echo "found" ;
78       -configure-add-line- "#" $(1) ;
79       flg = [ lib-config-ex "pkg-config '$(2)' --cflags" ] ;
80       lib = [ lib-config-ex "pkg-config '$(2)' --libs" ] ;
81       if $(flg) {
82         -configure-add-line- "CFLAGS.all +=" $(flg) ";" ;
83       }
84       if $(lib) {
85         -configure-add-line- "LINKLIBS.all +=" $(lib) ";" ;
86       }
87       if $(3) { -configure-add-line- $(3) ; }
88       res = "tan" ;
89     } else {
90       Echo "not found" ;
91       if $(5) {
92         -configure-fatal- ;
93         Exit $(5) ;
94       } else {
95         if $(4) {
96           -configure-add-line- "#" $(1) ;
97           -configure-add-line- $(4) ;
98         }
99       }
100     }
101   }
102   return $(res) ;
106 # $(1) list of packages:
107 #   "display name" "pkg-config-str"
108 # optional: set PROJECT_NAME to project name
109 rule -configure-pkg-config-necessary- {
110   local _dn _t _pn ;
111   _dn = ;
112   _pn = $(PROJECT_NAME) ;
113   if ! $(_pn) { _pn = "this project" ; }
114   for _t in $(1) {
115     if $(_dn) {
116       -configure-pkg-config- $(_dn) : $(_t) : : : "FATAL: you need" $(_t) "to build" $(_pn) ;
117       _dn = ;
118     } else {
119       _dn = $(_t) ;
120     }
121   }
125 # $(1): library name to display
126 # $(2): arg to pkg-config
127 # $(3): fail with this message if not present
128 # $(4): flags prefix
129 # $(5): USE var; if it is set to "0" -- skip this package
131 # sample:
132 #   -configure-pkg-config-get-flags- "PCRE" : "libpcre" : : "PCRE" : "MYPKG_USE_PCRE" ;
133 #   this will write MYPKG_USE_PCRE flag, PCRE_CFLAGS and PCRE_LIBS
134 #   if MYPKG_USE_PCRE is "0" at the time of call, library will be count as missing
135 rule -configure-pkg-config-get-flags- {
136   local flg lib ;
137   local displibname = $(1) ;
138   local pcargs = $(2) ;
139   local failmsg = $(3) ;
140   local flagspfx = $(4) ;
141   local usevar = $(5) ;
143   if $(_CONFIGURE_FATAL_) != "tan" {
144     if $(usevar) && $($(usevar)) == "0" {
145       Echo "checking for $(displibname) ... disabled" ;
146       -configure-add-line- "$(usevar)" "= ;" ;
147       if $(failmsg) {
148         -configure-fatal- ;
149         Exit $(failmsg) ;
150       }
151     } else {
152       Echo-n "checking for $(displibname) ..." ;
153       -configure-add-line- "#" $(displibname) ;
154       flg = [ lib-config-ex "pkg-config $(pcargs) --cflags" ] ;
155       lib = [ lib-config-ex "pkg-config $(pcargs) --libs" ] ;
156       if ! $(flg) && ! $(lib) {
157         # no such package
158         Echo "not found" ;
159         if $(failmsg) {
160           -configure-fatal- ;
161           Exit $(failmsg) ;
162         } else {
163           if $(usevar) { -configure-add-line- "$(usevar)" "= ;" ; }
164           if $(flagspfx) {
165             -configure-add-line- "$(flagspfx)_CFLAGS = ;" ;
166             -configure-add-line- "$(flagspfx)_LIBS = ;" ;
167           }
168         }
169       } else {
170         Echo "found" ;
171         if $(usevar) { -configure-add-line- "$(usevar)" "= tan ;" ; }
172         if $(flagspfx) {
173           -configure-add-line- "$(flagspfx)_CFLAGS =" "$(flg)" ";" ;
174           -configure-add-line- "$(flagspfx)_LIBS =" "$(lib)" ";" ;
175         }
176       }
177     }
178   }
182 # $(1): action display name for 'checking XXX ...'
183 # $(2): libraries
184 # $(3): headers
185 # $(4): additional search pathes
186 # $(5): rule to call if found: $(1) will be returned prefix, $(2) -- libraries
187 # $(6): rule to call if not found
188 # $(7): 'allow-any-lib' 'allow-any-header'
189 rule -configure-detect-library- {
190   local pfx ;
192   if $(_CONFIGURE_FATAL_) != "tan" {
193     Echo-n "checking for $(1) ..." ;
194     -configure-add-line- "#" $(1) ;
195     pfx = [ DetectLibrary $(2) : $(3) : $(4) : $(5) ] ;
196     if $(pfx) {
197       Echo "found" ;
198       if $(5) { [ $(5) $(pfx) : $(2) ] ; }
199     } else {
200       Echo "not found" ;
201       if $(6) { [ $(6) $(pfx) : $(2) ] ; }
202     }
203   }
207 rule -configure-show-enable-disable-help- {
208   if ! $(-configure-enable-disable-vars-) { return ; }
209   local maxlen = 0 ;
210   local f len ostr ;
211   # calculate maximum option name length
212   f = 1 ;
213   while $(-configure-enable-disable-vars-[$(f)]) {
214     local oname val help ;
215     oname = $(-configure-enable-disable-vars-[$(f)]) ;
216     f = [ ExprI1 $(f) + 3 ] ;
217     help = $(-configure-enable-disable-vars-[$(f)]) ;
218     f = [ ExprI1 $(f) + 1 ] ;
219     if $(help) {
220       # this option is not hidden
221       len = [ ExprI1 "#" $(oname) ] ;
222       if [ ExprI1 $(len) ">" $(maxlen) ] { maxlen = $(len) ; }
223     }
224   }
225   maxlen = [ ExprI1 $(maxlen) + 14 ] ;
226   f = 1 ;
227   while $(-configure-enable-disable-vars-[$(f)]) {
228     local oname vname val help ;
229     oname = $(-configure-enable-disable-vars-[$(f)]) ;
230     f = [ ExprI1 $(f) + 1 ] ;
231     vname = $(-configure-enable-disable-vars-[$(f)]) ;
232     f = [ ExprI1 $(f) + 1 ] ;
233     val = $(-configure-enable-disable-vars-[$(f)]) ;
234     f = [ ExprI1 $(f) + 1 ] ;
235     help = $(-configure-enable-disable-vars-[$(f)]) ;
236     f = [ ExprI1 $(f) + 1 ] ;
237     if $(help) {
238       # this option is not hidden
239       if ($val) == "auto" {
240         help += "(default: autodetect)" ;
241         ostr = "  --disable-$(oname)" ;
242       } else if $(val) {
243         help += "(default: enabled)" ;
244         ostr = "  --disable-$(oname)" ;
245       } else {
246         help += "(default: disabled)" ;
247         ostr = "  --enable-$(oname)" ;
248       }
249       len = [ ExprI1 "#" $(ostr) ] ;
250       Echo-n $(ostr) ;
251       while [ ExprI1 $(len) "<" $(maxlen) ] {
252         Echo-n "" ;
253         len = [ ExprI1 $(len) + 1 ] ;
254       }
255       Echo $(help) ;
256     }
257   }
261 # $(1): option name without enable/disable
262 # $(2): "enable" or "disable"
263 rule -configure-do-enable-disable- {
264   if $(-configure-enable-disable-vars-) {
265     #Echo "option:" $(1) "flag:" $(2) ;
266     local f ;
267     f = 1 ;
268     while $(-configure-enable-disable-vars-[$(f)]) {
269       local oname vname val ;
270       oname = $(-configure-enable-disable-vars-[$(f)]) ;
271       f = [ ExprI1 $(f) + 1 ] ;
272       vname = $(-configure-enable-disable-vars-[$(f)]) ;
273       f = [ ExprI1 $(f) + 1 ] ;
274       val = $(-configure-enable-disable-vars-[$(f)]) ;
275       f = [ ExprI1 $(f) + 2 ] ;
276       if $(oname) == $(1) {
277         if $(2) == "enable" { $(vname) = "tan" ; } else { $(vname) = "" ; }
278         return ;
279       }
280     }
281   }
282   Exit "ERROR: unknown option:" "$(ca)" ;
286 rule -configure-process-enable-disable- {
287   if ! $(-configure-enable-disable-vars-) { return ; }
288   local f = 2 ;
289   while $(-configure-enable-disable-vars-[$(f)]) {
290     local vname val ;
291     vname = $(-configure-enable-disable-vars-[$(f)]) ;
292     f = [ ExprI1 $(f) + 1 ] ;
293     val = $(-configure-enable-disable-vars-[$(f)]) ;
294     f = [ ExprI1 $(f) + 3 ] ;
295     $(vname) = $(val) ;
296     #Echo "vname:" $(vname) "val:" $(val) "var:" $($(vname)) ;
297   }
301 rule -configure-fatal- {
302   _CONFIGURE_FATAL_ = tan ;
306 rule -configure-main- {
307   local ca nv rln rla rn have_val ;
309   Echo "configuring..." ;
311   -Action-Configure-Start- ___start___ ;
312   Depends config : ___start___ ;
314   CONFIGURE_DONT_PARSE_OPTIONS = ;
316   -configure-process-enable-disable- ;
317   -configure-preinit- ;
319   if ! $(CONFIGURE_DONT_PARSE_OPTIONS) {
320     for ca in $(JAMCONFIGARGS) {
321       nv = [ Match "^--([^=]+)=(.*)\$" : $(ca) : regexp ] ;
322       if $(nv[1]) {
323         rn = $(nv[1]) ;
324         rla = $(nv[2]) ;
325         have_val = "tan" ;
326       } else {
327         nv = [ Match "^--(.+)\$" : $(ca) : regexp ] ;
328         rn = $(nv[1]) ;
329         rla = ;
330         have_val = ;
331       }
332       rln = -configure-options-$(rn)- ;
333       if [ HaveRule $(rln) ] {
334         $(rln) $(rn) : $(rla) ;
335       } else {
336         if ! $(have_val) {
337           nv = [ Match "^--(enable|disable)-(.+)\$" : $(ca) : regexp ] ;
338           if $(nv[2]) {
339             -configure-do-enable-disable- $(nv[2]) : $(nv[1]) ;
340           } else {
341             Exit "ERROR: unknown option:" "$(ca)" ;
342           }
343         } else {
344           Exit "ERROR: unknown option:" "$(ca)" ;
345         }
346       }
347     }
348   }
350   -configure- ;
352   if $(_CONFIGURE_FATAL_) = "tan" {
353     Echo "FATAL: configure failed" ;
354   } else {
355     Echo "MESSAGE: Now you can run 'jam' to build software." ;
356   }
360 actions quietly -Action-Configure-Start- {
361   if [ "z$(_CONFIGURE_FATAL_)" = "ztan" ]; then
362     rm "$(K8JAM-CONFIGURE-FILE)" 2>/dev/null
363     true
364   else
365     echo "# autogenerated by 'jam configure'" >"$(K8JAM-CONFIGURE-FILE)"
366     echo "_CONFIGURE_COMPLETE_ = tan ;" >>"$(K8JAM-CONFIGURE-FILE)"
367     echo "" >>"$(K8JAM-CONFIGURE-FILE)"
368   fi
371 actions quietly -Action-Configure-WriteLine- {
372   if [ "z$(_CONFIGURE_FATAL_)" = "zona" ]; then
373     echo '$(<)' >>"$(K8JAM-CONFIGURE-FILE)"
374   fi
378 rule configure {
379   local _doit = tan ;
380   K8JAM-CONFIGURE-FILE ?= $(TOP)/Jamrules.auto.configure ;
381   _CONFIGURE_FATAL_ = ona ;
382   Clean distclean : $(K8JAM-CONFIGURE-FILE) ;
383   if "gen-boiler" in $(JAM_TARGETS) || "clean" in $(JAM_TARGETS) || "distclean" in $(JAM_TARGETS) || $(__DO_TARGET_CLEAN__) { _doit = ; }
384   if $(_doit) {
385     if ! "config" in $(JAM_TARGETS) {
386       softinclude $(K8JAM-CONFIGURE-FILE) ;
387     }
388     #
389     if ! $(_CONFIGURE_COMPLETE_) { JAM_TARGETS = config ; }
390     if "configure" in $(JAM_TARGETS) { JAM_TARGETS = config ; }
391     if "config" in $(JAM_TARGETS) {
392       JAM_TARGETS = config ;
393       K8JAM-JOBS = 1 ;
394       NotFile config ;
395       Always config ;
396       -configure-main- config ;
397     }
398   } else {
399     _CONFIGURE_COMPLETE_ = tan ;
400     #if $(__DO_CONFIG_CLEAN__) { Clean clean : $(K8JAM-CONFIGURE-FILE) ; }
401     softinclude $(K8JAM-CONFIGURE-FILE) ;
402   }
406 # -Do-Configure- ;