cosmetix in Jambase: use single-quoted string where appropriate
[k8jam.git] / defaults / configure / Jambase.configure
blob92a1ec6ce75bfb35947a8a85b3c441e304240f3a
1 # This program is free software: you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation, either version 3 of the License, or
4 # (at your option) any later version.
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9 # GNU General Public License for more details.
11 # You should have received a copy of the GNU General Public License
12 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
14 #  # "auto": check with pkg-config or so, show '--disable-xxx'
15 #  # "": disabled by default, show '--enable-xxx'
16 #  # non-empty string: enabled by default, show '--disable-xxx'
17 #  -configure-enable-disable-vars- +=
18 #    "sqlite"    USE_SQLITE    "auto"  "don't use sqlite"
19 #    "gtkhtml"   USE_GTKHTML   "auto"  "don't use GTKHTML"
20 #    "gtkspell"  USE_GTKSPELL  "auto"  "don't use GTKSpell"
21 #    "svg"       USE_RSVG      "auto"  "don't use librsvg"
22 #    "soup"      USE_SOUP      "auto"  "don't use libsoup"
23 #    "curl"      USE_CURL      "auto"  "don't use libcurl"
24 #    "dock"      USE_DOCK      "tan"   "disable dock icon"
25 #  ;
28 # $(1): option name
29 # $(2): option arg (if any)
30 rule -configure-show-default-help- {
31   if $(PROJECT_NAME) {
32     Echo 'jam configure for package `' $(PROJECT_NAME) ''' supports:' : -S ;
33   } else {
34     Echo 'jam configure supports:' ;
35   }
36   Echo 'common options:' ;
37   Echo '  --prefix=dir  install prefix: [/usr/local]' ;
38   if $(-configure-enable-disable-vars-) {
39     Echo 'package options:' ;
40     -configure-show-enable-disable-help- ;
41   }
42   if [ HaveRule -configure-user-help- ] { -configure-user-help- ; }
46 rule -configure-options-help- {
47   -configure-show-default-help- ;
48   Exit ;
52 rule -configure-options-prefix- {
53   if ! $(2) {
54     Exit 'ERROR: --prefix needs argument!' ;
55   }
56   -configure-add-line- "PREFIX ?= $(2) ;" ;
57   Echo "MSG: prefix set to $(2)" ;
61 # will be called before -configure-
62 # can set CONFIGURE_DONT_PARSE_OPTIONS
63 rule -configure-preinit- {
67 rule -configure-add-line- {
68   local str ;
70   if $(_CONFIGURE_FATAL_) != 'tan' {
71     str = "$(1:J= )" ;
72     Depends config : $(str) ;
73     -Action-Configure-WriteLine- $(str) ;
74   }
78 # $(1): library name to display
79 # $(2): arg to pkg-config
80 # $(3): string to write if present
81 # $(4): string to write if not present
82 # $(5): fail with this message if not present
83 # returns non-empty string if package exists
84 rule -configure-pkg-config- {
85   local flg lib ex res ;
86   res = ;
87   if $(_CONFIGURE_FATAL_) != 'tan' {
88     Echo "checking for $(1) ... " : -n ;
89     ex = [ pkg-config-exists $(2) ] ;
90     if $(ex) {
91       Echo 'found' ;
92       -configure-add-line- '#' $(1) ;
93       flg = [ lib-config-ex "pkg-config '$(2)' --cflags" ] ;
94       lib = [ lib-config-ex "pkg-config '$(2)' --libs" ] ;
95       if $(flg) {
96         -configure-add-line- 'CFLAGS.all +=' $(flg) ';' ;
97       }
98       if $(lib) {
99         -configure-add-line- 'LINKLIBS.all +=' $(lib) ';' ;
100       }
101       if $(3) { -configure-add-line- $(3) ; }
102       res = 'tan' ;
103     } else {
104       Echo 'not found' ;
105       if $(5) {
106         -configure-fatal- ;
107         Exit $(5) ;
108       } else {
109         if $(4) {
110           -configure-add-line- '#' $(1) ;
111           -configure-add-line- $(4) ;
112         }
113       }
114     }
115   }
116   return $(res) ;
120 # $(1) list of packages:
121 #   'display name' 'pkg-config-str'
122 # optional: set PROJECT_NAME to project name
123 rule -configure-pkg-config-necessary- {
124   local _dn _t _pn ;
125   _dn = ;
126   _pn = $(PROJECT_NAME) ;
127   if ! $(_pn) { _pn = 'this project' ; }
128   for _t in $(1) {
129     if $(_dn) {
130       -configure-pkg-config- $(_dn) : $(_t) : : : 'FATAL: you need' $(_t) 'to build' $(_pn) ;
131       _dn = ;
132     } else {
133       _dn = $(_t) ;
134     }
135   }
139 # $(1): library name to display
140 # $(2): arg to pkg-config
141 # $(3): fail with this message if not present
142 # $(4): flags prefix
143 # $(5): USE var; if it is set to '0' -- skip this package
144 # return empty list if package is missing, change USE-var value if necessary
146 # sample:
147 #   -configure-pkg-config-get-flags- 'PCRE' : 'libpcre' : : 'PCRE' : 'MYPKG_USE_PCRE' ;
148 #   this will write MYPKG_USE_PCRE flag, PCRE_CFLAGS and PCRE_LIBS
149 #   if MYPKG_USE_PCRE is empty at the time of call, library will be count as missing
150 rule -configure-pkg-config-get-flags- {
151   local flg lib res = ;
152   local displibname = $(1) ;
153   local pcargs = $(2) ;
154   local failmsg = $(3) ;
155   local flagspfx = $(4) ;
156   local usevar = $(5) ;
158   if $(_CONFIGURE_FATAL_) != 'tan' {
159     if $(usevar) && ! $($(usevar)) {
160       Echo "checking for $(displibname) ... disabled" ;
161       -configure-add-line- "$(usevar)" '= ;' ;
162       if $(failmsg) {
163         -configure-fatal- ;
164         Exit $(failmsg) ;
165       }
166     } else {
167       Echo "checking for $(displibname) ... " : -n ;
168       -configure-add-line- '#' $(displibname) ;
169       flg = [ lib-config-ex "pkg-config $(pcargs) --cflags" ] ;
170       lib = [ lib-config-ex "pkg-config $(pcargs) --libs" ] ;
171       if ! $(flg) && ! $(lib) {
172         # no such package
173         Echo 'not found' ;
174         if $(failmsg) {
175           -configure-fatal- ;
176           Exit $(failmsg) ;
177         } else {
178           if $(usevar) {
179             $(usevar) = ;
180             -configure-add-line- "$(usevar)" '= ;' ;
181           }
182           if $(flagspfx) {
183             -configure-add-line- "$(flagspfx)_CFLAGS = ;" ;
184             -configure-add-line- "$(flagspfx)_LIBS = ;" ;
185           }
186         }
187       } else {
188         Echo 'found' ;
189         if $(usevar) {
190           $(usevar) = tan ;
191           -configure-add-line- "$(usevar)" '= tan ;' ;
192         }
193         if $(flagspfx) {
194           -configure-add-line- "$(flagspfx)_CFLAGS =" "$(flg)" ';' ;
195           -configure-add-line- "$(flagspfx)_LIBS =" "$(lib)" ';' ;
196         }
197         res = tan ;
198       }
199     }
200   }
201   return $(res) ;
205 # $(1): action display name for 'checking XXX ...'
206 # $(2): libraries
207 # $(3): headers
208 # $(4): additional search pathes
209 # $(5): rule to call if found: $(1) will be returned prefix, $(2) -- libraries
210 # $(6): rule to call if not found
211 # $(7): 'allow-any-lib' 'allow-any-header'
212 rule -configure-detect-library- {
213   local pfx ;
215   if $(_CONFIGURE_FATAL_) != 'tan' {
216     Echo "checking for $(1) ... " : -n ;
217     -configure-add-line- '#' $(1) ;
218     pfx = [ DetectLibrary $(2) : $(3) : $(4) : $(5) ] ;
219     if $(pfx) {
220       Echo 'found' ;
221       if $(5) { [ $(5) $(pfx) : $(2) ] ; }
222     } else {
223       Echo 'not found' ;
224       if $(6) { [ $(6) $(pfx) : $(2) ] ; }
225     }
226   }
230 rule -configure-show-enable-disable-help- {
231   if ! $(-configure-enable-disable-vars-) { return ; }
232   local maxlen = 0 ;
233   local f ostr ;
234   # calculate maximum option name length
235   f = 1 ;
236   while $(-configure-enable-disable-vars-[$(f)]) {
237     local oname val help ;
238     oname = $(-configure-enable-disable-vars-[$(f)]) ;
239     f = [ ExprI1 $(f) + 3 ] ;
240     help = $(-configure-enable-disable-vars-[$(f)]) ;
241     f = [ ExprI1 $(f) + 1 ] ;
242     if $(help) {
243       # this option is not hidden
244       local len = $(oname:W) ;
245       if [ ExprI1 $(len) '>' $(maxlen) ] { maxlen = $(len) ; }
246     }
247   }
248   maxlen = [ ExprI1 $(maxlen) + 13 ] ;
249   f = 1 ;
250   while $(-configure-enable-disable-vars-[$(f)]) {
251     local oname vname val help ;
252     oname = $(-configure-enable-disable-vars-[$(f)]) ;
253     f = [ ExprI1 $(f) + 1 ] ;
254     vname = $(-configure-enable-disable-vars-[$(f)]) ;
255     f = [ ExprI1 $(f) + 1 ] ;
256     val = $(-configure-enable-disable-vars-[$(f)]) ;
257     f = [ ExprI1 $(f) + 1 ] ;
258     help = $(-configure-enable-disable-vars-[$(f)]) ;
259     f = [ ExprI1 $(f) + 1 ] ;
260     if $(help) {
261       # this option is not hidden
262       if $(val) == 'auto' {
263         help += '(default: autodetect)' ;
264         ostr = "  --disable-$(oname)" ;
265       } else if $(val) {
266         help += '(default: enabled)' ;
267         ostr = "  --disable-$(oname)" ;
268       } else {
269         help += '(default: disabled)' ;
270         ostr = "  --enable-$(oname)" ;
271       }
272       Echo $(ostr:W=$(maxlen)) $(help) ;
273     }
274   }
278 # $(1): option name without enable/disable
279 # $(2): 'enable' or 'disable'
280 rule -configure-do-enable-disable- {
281   if $(-configure-enable-disable-vars-) {
282     #Echo 'option:' $(1) 'flag:' $(2) ;
283     local f ;
284     f = 1 ;
285     while $(-configure-enable-disable-vars-[$(f)]) {
286       local oname vname val ;
287       oname = $(-configure-enable-disable-vars-[$(f)]) ;
288       f = [ ExprI1 $(f) + 1 ] ;
289       vname = $(-configure-enable-disable-vars-[$(f)]) ;
290       f = [ ExprI1 $(f) + 1 ] ;
291       val = $(-configure-enable-disable-vars-[$(f)]) ;
292       f = [ ExprI1 $(f) + 2 ] ;
293       if $(oname) == $(1) {
294         if $(2) == 'enable' { $(vname) = 'tan' ; } else { $(vname) = "" ; }
295         return ;
296       }
297     }
298   }
299   Exit 'ERROR: unknown option:' "$(ca)" ;
303 rule -configure-process-enable-disable- {
304   if ! $(-configure-enable-disable-vars-) { return ; }
305   local f = 2 ;
306   while $(-configure-enable-disable-vars-[$(f)]) {
307     local vname val ;
308     vname = $(-configure-enable-disable-vars-[$(f)]) ;
309     f = [ ExprI1 $(f) + 1 ] ;
310     val = $(-configure-enable-disable-vars-[$(f)]) ;
311     f = [ ExprI1 $(f) + 3 ] ;
312     $(vname) = $(val) ;
313     #Echo 'vname:' $(vname) 'val:' $(val) 'var:' $($(vname)) ;
314   }
318 rule -configure-fatal- {
319   _CONFIGURE_FATAL_ = tan ;
323 rule -configure-main- {
324   local ca nv rln rla rn have_val ;
326   Echo 'configuring...' ;
328   -Action-Configure-Start- ___start___ ;
329   Depends config : ___start___ ;
331   CONFIGURE_DONT_PARSE_OPTIONS = ;
333   if $(JAMCONFIGARGS) {
334     -configure-add-line- '# configure options' ;
335     -configure-add-line- '#' "$(JAMCONFIGARGS)" ;
336   }
337   -configure-add-line- "" ;
339   -configure-process-enable-disable- ;
340   -configure-preinit- ;
342   if ! $(CONFIGURE_DONT_PARSE_OPTIONS) {
343     for ca in $(JAMCONFIGARGS) {
344       nv = [ Match '^--([^=]+)=(.*)$' : $(ca) ] ;
345       if $(nv[1]) {
346         rn = $(nv[1]) ;
347         rla = $(nv[2]) ;
348         have_val = 'tan' ;
349       } else {
350         nv = [ Match '^--(.+)$' : $(ca) ] ;
351         rn = $(nv[1]) ;
352         rla = ;
353         have_val = ;
354       }
355       rln = -configure-options-$(rn)- ;
356       if [ HaveRule $(rln) ] {
357         $(rln) $(rn) : $(rla) ;
358       } else {
359         if ! $(have_val) {
360           nv = [ Match '^--(enable|disable)-(.+)$' : $(ca) ] ;
361           if $(nv[2]) {
362             -configure-do-enable-disable- $(nv[2]) : $(nv[1]) ;
363           } else {
364             Exit 'ERROR: unknown option:' "$(ca)" ;
365           }
366         } else {
367           Exit 'ERROR: unknown option:' "$(ca)" ;
368         }
369       }
370     }
371   }
373   -configure- ;
375   if $(_CONFIGURE_FATAL_) = 'tan' {
376     Exit 'FATAL: configure failed' ;
377   } else {
378     Echo "MESSAGE: Now you can run 'jam' to build software." ;
379   }
383 actions quietly -Action-Configure-Start- {
384   if [ "z$(_CONFIGURE_FATAL_)" = "ztan" ]; then
385     rm "$(K8JAM-CONFIGURE-FILE)" 2>/dev/null
386     true
387   else
388     echo "# autogenerated by 'jam configure'" >"$(K8JAM-CONFIGURE-FILE)"
389     echo "_CONFIGURE_COMPLETE_ = tan ;" >>"$(K8JAM-CONFIGURE-FILE)"
390   fi
393 actions quietly -Action-Configure-WriteLine- {
394   if [ "z$(_CONFIGURE_FATAL_)" = "zona" ]; then
395     echo '$(<)' >>"$(K8JAM-CONFIGURE-FILE)"
396   fi
400 rule configure {
401   local _doit = tan ;
402   local xtgt =
403     'gen-boiler'
404     clean
405     distclean
406   ;
407   K8JAM-CONFIGURE-FILE ?= $(TOP)/Jamrules.auto.configure ;
408   _CONFIGURE_FATAL_ = ona ;
409   Clean distclean : $(K8JAM-CONFIGURE-FILE) ;
410   if $(xtgt) anyin $(JAM_TARGETS) || $(__DO_TARGET_CLEAN__) { _doit = ; }
411   if $(_doit) {
412     xtgt = config configure ;
413     if ! ( $(xtgt) anyin $(JAM_TARGETS) ) { softinclude $(K8JAM-CONFIGURE-FILE) ; }
414     #
415     if ! $(_CONFIGURE_COMPLETE_) { JAM_TARGETS = config ; }
416     if 'configure' in $(JAM_TARGETS) { JAM_TARGETS = config ; }
417     if 'config' in $(JAM_TARGETS) {
418       JAM_OPTION_MAKE_UPDATES_SILENT = tan ;
419       JAM_TARGETS = config ;
420       K8JAM-JOBS = 1 ;
421       NotFile config ;
422       Always config ;
423       -configure-main- config ;
424     }
425   } else {
426     _CONFIGURE_COMPLETE_ = tan ;
427     #if $(__DO_CONFIG_CLEAN__) { Clean clean : $(K8JAM-CONFIGURE-FILE) ; }
428     softinclude $(K8JAM-CONFIGURE-FILE) ;
429   }
432 . Jambase.configure.compile
433 . Jambase.configure.utils