]>
Commit | Line | Data |
---|---|---|
9a98a854 | 1 | #!/bin/sh |
ceec2216 RL |
2 | # |
3 | # Name: wx-config{.in,} | |
4 | # Purpose: wx configuration search and query tool {template,} | |
5 | # Author: Ron <ron@debian.org> | |
6 | # Modified by: | |
7 | # Created: 8/9/2004 | |
8 | # RCS-ID: $Id$ | |
9 | # Copyright: (c) 2004 Ron <ron@debian.org> | |
10 | # Essentially a fresh start this time around, but for maximum | |
11 | # compatibility basic code was taken from, and heavy reference | |
12 | # made to, the previously unattributed wx-config from cvs. | |
13 | # All the usual suspects contributed to the dicussion that led | |
14 | # to this new work and likewise to the ideas and content in the | |
15 | # original (which was probably influenced by gtk), among them: | |
16 | # Robert Roebling, Vadim Zeitlin, Vaclav Slavik, Robin Dunn | |
17 | # Licence: wxWindows licence | |
18 | ############################################################################ | |
19 | ||
20 | ||
21 | # Start with some basic stuff, like the ability to die gracefully, | |
22 | # and to tell people what we are about. | |
23 | # ------------------------------------------------------------------ | |
24 | ||
25 | # decho _message | |
26 | # Output a message to stderr. | |
27 | decho() { echo "$*" 1>&2; } | |
28 | ||
29 | # usage _exitcode | |
30 | # Outputs a usage message to stderr and exits with _exitcode. | |
31 | # Try to keep this to a single page. We can add alternate help | |
32 | # targets if people want more detail from interactive help. | |
33 | usage() | |
34 | { | |
35 | cat 1>&2 <<EOF | |
36 | ||
37 | wx-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--release] [--version-full] | |
38 | [--list] [--host=HOST] [--toolkit=TOOLKIT] [--universal[=yes|no]] | |
39 | [--unicode[=yes|no]] [--debug[=yes|no]] [--static[=yes|no]] | |
40 | [--version[=VERSION]] [--basename] [--cppflags] [--cflags] | |
41 | [--cxxflags] [--rezflags] [--libs] [--cc] [--cxx] [--ld] [LIB ...] | |
42 | ||
43 | wx-config returns information about the wxWidgets libraries available | |
44 | on your system. It may be used to retrieve the information you require | |
45 | to build applications using these libraries. | |
46 | ||
148e141b RL |
47 | If alternative builds of wxWidgets exist on the system, you can use the |
48 | options: --prefix, --host, --toolkit, --unicode, --debug, --static, | |
49 | --version and --universal, to select from them. Use the --list option to | |
50 | show alternatives available which match specified criteria. The unicode, | |
51 | debug, and universal options take an optional yes or no argument, while | |
52 | host and version accept posix extended regex. | |
ceec2216 RL |
53 | |
54 | Optional LIB arguments (comma or space separated) may be used to specify | |
55 | the wxWidgets libraries that you wish to use. The magic "std" label may | |
56 | be used to import all libraries that would be used by default if none were | |
57 | specified explicitly. eg. wx-config --libs core,base. | |
9a98a854 | 58 | |
ceec2216 | 59 | EOF |
33380099 | 60 | |
ceec2216 RL |
61 | exit $1 |
62 | } | |
33380099 | 63 | |
ceec2216 RL |
64 | # Unfussy people are the easiest to deal with, get them out of the way now. |
65 | [ $# -gt 0 ] || usage 1 | |
33380099 | 66 | |
33380099 | 67 | |
cf615ebb | 68 | |
ceec2216 RL |
69 | # For the people who know what they want, or think they do: |
70 | # Divide the valid arguments into functional groups for later examination, | |
71 | # then parse all command line arguments completely, deferring action on | |
72 | # output options until all significant input has been processed and any | |
73 | # decision about delegation has been taken. | |
cf615ebb | 74 | |
ceec2216 RL |
75 | # Note early, that '-' is a complete no-no for use in option names below. |
76 | # It totally falls apart as soon as it becomes part of a variable name. | |
77 | # Use '_' instead, and by the magic of it all just being bits, you'll | |
78 | # be able to use --my-option or --my_option from the command line at | |
79 | # your discretion. They are synonymous as user input, but _ALWAYS_ use | |
80 | # underscores for compound names in the code here, never a dash. | |
81 | ||
82 | ||
83 | # The list of all options we recognise. If it is not in here, then | |
84 | # it is not something we want to handle. | |
85 | # ------------------------------------------------------------------ | |
86 | ||
87 | # Options that specify a distinct library build. | |
88 | # | |
89 | # Note also that order in this list is significant later on, as this sets | |
90 | # the precedence with which we will try to gauge the similarity of other | |
91 | # configs to this one. Options earlier in the list should be more crucial | |
92 | # to match well than those that follow. Options specified by the user will | |
93 | # always take precedence and are not subject to any partial ordering here. | |
94 | wxconfig_schema="host toolkit widgetset chartype debugtype flavour version linkage" | |
95 | ||
96 | # Options that are expected to generate some output. | |
97 | wxconfig_output_options="prefix exec_prefix \ | |
98 | list \ | |
99 | release version version_full \ | |
100 | basename \ | |
101 | cppflags cflags cxxflags \ | |
102 | rezflags \ | |
103 | libs \ | |
104 | cc cxx ld \ | |
105 | gl_libs" | |
106 | ||
107 | # Options that permit the user to supply hints that may affect the output. | |
108 | # These options all accept arbitrary values, to interpret as they please. | |
109 | wxconfig_input_options="prefix exec_prefix $wxconfig_schema" | |
cf615ebb | 110 | |
ceec2216 RL |
111 | # Input options that accept only a yes or no argument. |
112 | wxconfig_yesno_options="universal unicode debug static" | |
cf615ebb | 113 | |
ceec2216 RL |
114 | # Boolean options that do something or not. |
115 | wxconfig_flag_options="$wxconfig_yesno_options inplace" | |
33380099 | 116 | |
33380099 | 117 | |
33380099 | 118 | |
ceec2216 RL |
119 | # Some simple sugar coating to keep things more readable below. |
120 | # -------------------------------------------------------------- | |
121 | ||
122 | # option_name _string | |
123 | # Returns NAME if _string is of the form: --NAME[=...] | |
124 | option_name() | |
125 | { | |
126 | _option_name_temp=${1%%=*} | |
127 | echo "${_option_name_temp#--}" | tr '-' '_' | |
128 | } | |
129 | ||
130 | # option_value _string | |
131 | # Returns FOO if _string is of the form: --option=FOO | |
132 | option_value() | |
133 | { | |
134 | echo "${1#*=}" | |
135 | } | |
136 | ||
137 | # match_field _value _list | |
138 | # Returns true if _value is a field in _list | |
139 | match_field() | |
140 | { | |
141 | _match_field_match="$1" | |
142 | shift | |
143 | for _match_field_i; do | |
144 | [ "x$_match_field_i" != "x$_match_field_match" ] || return 0 | |
145 | done | |
146 | false | |
147 | } | |
148 | ||
149 | # remove_field _value _list | |
150 | # Returns _list minus any field(s) that match _value. | |
151 | remove_field() | |
cf615ebb | 152 | { |
ceec2216 RL |
153 | _remf_value="$1" |
154 | _remf_list='' | |
cf615ebb | 155 | shift |
3950ea80 RL |
156 | if [ -n "$_remf_value" ]; then |
157 | for _remf_item; do | |
158 | [ "x$_remf_item" = "x$_remf_value" ] || \ | |
159 | _remf_list="${_remf_list:+$_remf_list }$_remf_item" | |
160 | done | |
161 | echo "$_remf_list" | |
162 | else | |
163 | echo $* | |
164 | fi | |
cf615ebb VS |
165 | } |
166 | ||
ceec2216 RL |
167 | # validate_arg _domain _set _name _value |
168 | # Boilerplate to validate an argument and initialise a psuedo-hash. | |
169 | # This one is almost reduction into absurdity, and perhaps makes the | |
170 | # precise action of the argument parser below just a little more | |
171 | # obscure, but oh so neat and compact to use for multiple option | |
172 | # groups. It expands to replace repetitive clauses of the form: | |
173 | # | |
174 | # i="$(option_name $arg)" | |
175 | # if match_field "$i" $wxconfig_input_options; then | |
176 | # input_options="${input_options:+$input_options }$i" | |
177 | # eval "input_option_$i=$(option_value $arg)" | |
178 | # continue | |
179 | # fi | |
180 | # | |
181 | # with the one liners you see on the page below. | |
182 | validate_arg() | |
cf615ebb | 183 | { |
ceec2216 RL |
184 | if match_field "$3" $(eval echo \"\$$1_$2_options\"); then |
185 | eval "$2_options=\"\${$2_options:+\$$2_options }$3\"" | |
186 | eval "$2_option_$3=\"$4\"" | |
187 | return | |
67c13b6c | 188 | fi |
ceec2216 RL |
189 | false |
190 | } | |
191 | ||
192 | # check_yesno_option _ynoption _option _yesval _noval | |
193 | # This one might be made more generic and/or incorporated into | |
194 | # validate_arg above at some later stage, but right now we just | |
195 | # condition any specialist options into a generic one for later | |
196 | # handling. Once they are sanity checked there is no difference | |
197 | # in any case. | |
198 | check_yesno_option() | |
199 | { | |
200 | eval "case \${yesno_option_$1-\${flag_option_$1-unset}} in \ | |
201 | unset) ;; \ | |
202 | y*|Y*) input_option_$2=\"$3\" ;; \ | |
203 | n*|N*) input_option_$2=\"$4\" ;; \ | |
204 | *) \ | |
205 | decho; \ | |
206 | decho \" *** Error: Invalid request '--$1=\$yesno_option_$1'\"; \ | |
207 | decho \" Valid arguments for --$1 are: [ yes, no ]\"; \ | |
208 | decho; \ | |
209 | exit 1 ;; \ | |
210 | esac" | |
211 | } | |
67c13b6c | 212 | |
67c13b6c | 213 | |
ceec2216 RL |
214 | |
215 | # Now we are ready to find out what the user wants from us. | |
216 | # -------------------------------------------------------------- | |
217 | ||
218 | # With just a little more complexity here we could have shortest | |
219 | # unique string matching for options, but that is probably overkill | |
220 | # today, so lets just get the job done. | |
221 | # | |
222 | # The important thing now then is that we simply read all input from | |
223 | # the user and don't try to act prematurely on partial information. | |
224 | # --help or an illegal argument are the only shortcuts out of here | |
225 | # at this point, otherwise, it's time to just shut up and listen for | |
226 | # a moment. | |
227 | ||
228 | for arg; do | |
229 | case "$arg" in | |
230 | --help|-h) | |
231 | usage | |
232 | ;; | |
233 | ||
234 | --*=*) | |
235 | _name=$(option_name $arg) | |
236 | _value=$(option_value $arg) | |
237 | if validate_arg wxconfig input "$_name" "$_value" \ | |
238 | || validate_arg wxconfig yesno "$_name" "$_value"; \ | |
239 | then | |
240 | continue | |
cf615ebb | 241 | fi |
ceec2216 RL |
242 | ;; |
243 | ||
244 | --*) | |
245 | _name=$(option_name $arg) | |
246 | if validate_arg wxconfig flag "$_name" yes \ | |
247 | || validate_arg wxconfig output "$_name" yes; | |
248 | then | |
249 | continue | |
fef23dd4 | 250 | fi |
ceec2216 | 251 | ;; |
cf615ebb | 252 | |
ceec2216 RL |
253 | *) |
254 | # FIXME Surely we can validate the parameters too ... | |
255 | input_parameters="${input_parameters:+$input_parameters }$arg" | |
256 | continue | |
257 | ;; | |
258 | esac | |
259 | decho " *** Error: Unrecognised option: '$arg'" | |
260 | decho "Use wx-config --help for information on command line options." | |
261 | exit 1 | |
262 | done | |
263 | ||
264 | # validate_arg only checks and decomposes form. Sanity check the yes/no | |
265 | # options now too and push their respective mask values into place. | |
266 | ||
267 | check_yesno_option universal widgetset univ | |
268 | check_yesno_option unicode chartype unicode ansi | |
269 | check_yesno_option debug debugtype debug release | |
270 | check_yesno_option static linkage '-static' | |
271 | ||
272 | ||
273 | # Dump everything we just read in debug mode. | |
274 | if [ -n "$WXDEBUG" ]; then | |
275 | ||
276 | decho | |
277 | decho " input parameters = $input_parameters" | |
278 | decho " input options = $input_options" | |
279 | for i in $input_options; do | |
280 | decho " $i = $(eval echo \"\$input_option_$i\")" | |
281 | done | |
282 | decho " yes/no options = $yesno_options" | |
283 | for y in $yesno_options; do | |
284 | decho " $y = $(eval echo \"\$yesno_option_$y\")" | |
285 | done | |
286 | decho " flag options = $flag_options" | |
287 | for f in $flag_options; do | |
288 | decho " $f = $(eval echo \"\$flag_option_$f\")" | |
cf615ebb | 289 | done |
ceec2216 RL |
290 | decho " output options = $output_options" |
291 | for o in $output_options; do | |
292 | decho " $o = $(eval echo \"\$output_option_$o\")" | |
293 | done | |
294 | ||
295 | fi | |
296 | ||
cf615ebb | 297 | |
ceec2216 RL |
298 | |
299 | # Everything came in as a legal argument then, lets put some of | |
300 | # the pieces together with a little self knowledge to see what | |
301 | # we should do next. | |
302 | # -------------------------------------------------------------- | |
303 | ||
304 | # get_mask [ _hash ] | |
305 | # Construct a config filename mask from a psuedo-hash of component variables. | |
306 | # The optional argument is the prefix of the hash to use. If not specified | |
307 | # this will return a mask derived from the command line options that were used. | |
308 | get_mask() | |
309 | { | |
310 | [ $# -gt 0 ] || set m | |
311 | eval echo "\${$1_host}\${$1_toolkit}\${$1_widgetset}-\${$1_chartype}-\${$1_debugtype}\${$1_linkage}-\${$1_version}\${$1_flavour}" | |
cf615ebb | 312 | } |
9a98a854 | 313 | |
ceec2216 RL |
314 | |
315 | # Determine the base directories we require. | |
316 | prefix=${input_option_prefix-${this_prefix:-@prefix@}} | |
0506bbbf | 317 | exec_prefix=${input_option_exec_prefix-${input_option_prefix-${this_exec_prefix:-@exec_prefix@}}} |
ceec2216 RL |
318 | wxconfdir="@libdir@/wx/config" |
319 | ||
320 | installed_configs=$( cd "$wxconfdir" 2> /dev/null && ls | grep -v "^inplace-" ) | |
321 | ||
322 | target="@host_alias@" | |
323 | ||
324 | # Define a pseudo-hash to contain the specification of this wx-config | |
325 | # instance and its associated library. | |
326 | this_host="${target:+${target}-}" | |
327 | this_toolkit="@TOOLKIT_DIR@@TOOLKIT_VERSION@" | |
328 | this_widgetset="@WIDGET_SET@" | |
329 | this_chartype="@WX_CHARTYPE@" | |
330 | this_debugtype="@WX_DEBUGTYPE@" | |
331 | this_flavour="@WX_FLAVOUR@" | |
332 | this_version="@WX_RELEASE@" | |
333 | this_linkage=$( [ @SHARED@ -eq 1 ] || echo '-static' ) | |
334 | ||
335 | this_config=$(get_mask this) | |
336 | ||
337 | # Extract the user specification from the options parsed. | |
338 | m_host=${input_option_host:+${input_option_host}-?} | |
339 | m_host=${m_host:-${input_option_host-$this_host}} | |
340 | m_toolkit=${input_option_toolkit:-[^-]+} | |
341 | m_widgetset=${input_option_widgetset-(univ)?} | |
342 | m_chartype=${input_option_chartype:-(unicode|ansi)} | |
343 | m_debugtype=${input_option_debugtype:-(debug|release)} | |
344 | m_flavour=${input_option_flavour:+-$input_option_flavour} | |
345 | m_flavour=${m_flavour:-${input_option_flavour-(-[^-]+)?}} | |
346 | m_version=${input_option_version:-[0-9]+\.[0-9]+} | |
347 | m_linkage=${input_option_linkage-(-static)?} | |
348 | ||
349 | configmask="^$(get_mask)$" | |
350 | ||
351 | ||
352 | # Dump the user specification in debug mode. | |
353 | if [ -n "$WXDEBUG" ]; then | |
354 | ||
355 | decho | |
356 | decho " prefix = '$prefix'" | |
357 | decho " exec_prefix = '$exec_prefix'" | |
358 | decho " wxconfdir = '$wxconfdir'" | |
359 | ||
360 | decho " m_host = '$m_host'" | |
361 | decho " m_toolkit = '$m_toolkit'" | |
362 | decho " m_widgetset = '$m_widgetset'" | |
363 | decho " m_chartype = '$m_chartype'" | |
364 | decho " m_debugtype = '$m_debugtype'" | |
365 | decho " m_flavour = '$m_flavour'" | |
366 | decho " m_version = '$m_version'" | |
367 | decho " m_linkage = '$m_linkage'" | |
368 | ||
369 | decho " configmask = '$configmask'" | |
370 | decho " this config = '$this_config'" | |
371 | decho | |
372 | ||
373 | fi | |
374 | ||
375 | ||
376 | ||
9a09819a RL |
377 | # From here on, we'll need to be able to figure out a delegation target. |
378 | # ----------------------------------------------------------------------- | |
ceec2216 RL |
379 | |
380 | # The rules for delegation are: | |
381 | # | |
382 | # 1. If the specification is so general that it matches the default config | |
383 | # (ie. this one on a first pass), then the default config will be used | |
384 | # even if other installed libs would also match the spec. | |
385 | # | |
386 | # 2. If the default config does not match, find a list of all installed | |
387 | # libraries that do match. | |
388 | # a. If that list is empty, the specification is incompatible | |
389 | # with any installed lib. Warn and abort. | |
390 | # b. If that list contains exactly one candidate. Delegate to | |
391 | # that candidate. | |
392 | # c. If the list contains multiple candidates, pass on to step 3. | |
393 | # | |
394 | # 3. Attempt to discriminate among rival candidates by their similarity | |
395 | # to the default configuration (ie. this one). If we can find a unique | |
396 | # candidate in this way, delegate to it. If not, present a list of | |
397 | # options to the user and request that they disambiguate it with one or | |
398 | # more additional fields. | |
399 | # | |
400 | # To refine the specified pattern, we specialise each unbound field | |
401 | # using the default value from this config file. If that results in | |
402 | # no matches, we unbind it again and try the next field. If it still | |
403 | # results in multiple matches we try binding the next field as well | |
404 | # until a unique or null result again occurs. | |
405 | # | |
406 | # A more general way to look at this, is the feature specifiers are all | |
407 | # modifiers of the wx-config you are calling. If you supply none, the | |
408 | # default for that build configuration will be used. If you supply one | |
409 | # or more that the default build cannot satisfy, it will try to find the | |
410 | # config most like itself with the desired feature(s) enabled. | |
411 | # The features configured into the first wx-config called will be taken | |
412 | # as implicitly specified if it is necessary to disambiguate likely | |
413 | # candidates from the information that was explicitly provided. | |
414 | ||
415 | ||
416 | # But first, more sugar to keep what follows clear and legible. | |
417 | # -------------------------------------------------------------- | |
418 | ||
9a09819a RL |
419 | # find_eligible_delegates _mask |
420 | # Outputs all the config files installed which match the | |
421 | # (extended regex) _mask passed as an argument. | |
422 | find_eligible_delegates() { echo "$installed_configs" | grep -E "$1" 2> /dev/null; } | |
423 | ||
424 | # user_mask_fits _config | |
425 | # Returns true if the string _config satisfies the user specified mask. | |
426 | user_mask_fits() { echo "$1" | grep -E "$configmask" > /dev/null 2>&1; } | |
427 | ||
ceec2216 RL |
428 | # count_fields _word |
429 | # Returns the number of IFS split fields in _word | |
430 | count_fields() { return $#; } | |
431 | ||
432 | # count_delegates _mask | |
433 | # Return the number of eligible config files that match _mask | |
434 | count_delegates() { count_fields $(find_eligible_delegates $1); } | |
435 | ||
436 | # is_set _variablename | |
437 | # Returns true if $_variablename is initialised. | |
438 | is_set() { [ "x$(eval echo \"\${$1-unset}\")" != "xunset" ]; } | |
439 | ||
440 | # do_find_best_delegate _unbound-options | |
441 | # The real worker part of find_best_delegate below. Recurses though all | |
442 | # unbound options binding them one at a time to the default derived from | |
443 | # this file until a unique match is made or no alternatives remain that | |
444 | # may be sensibly guessed at. It will preferentially bind the unspecified | |
445 | # options in the order they are listed in wxconfig_schema. Using this | |
446 | # partial ordering it should find the first match with the most significant | |
447 | # similarity to this file that unambiguously meets the user specification. | |
448 | # If such a match exists it will be output to stdout. | |
449 | # | |
450 | # Be careful if you modify this function. If the pruning logic is rendered | |
451 | # inoperative it will simply recurse over every permutation in the search | |
452 | # space, which may still appear to work, but add a couple more options (or | |
453 | # explicitly specify a few less) and you may not live long enough to learn | |
454 | # the result. WXDEBUG=findprogress is your friend here, it will show you | |
455 | # how many nodes get searched before a result. If you start seeing | |
456 | # increases in that number for the same input, check your work. | |
457 | # Raising the number of discriminating options from 6 to 8 raised the worst | |
458 | # case time for this to run (without pruning) from 3 to nearly 15 seconds | |
459 | # and its downhill fast from here if we have to ride that boat. | |
460 | # Early pruning still gets that down to under half a second (up from about | |
461 | # .25), so we have some breathing space yet before a different search method | |
462 | # will be called for, but lets not squander it. | |
463 | do_find_best_delegate() | |
ffef10f6 | 464 | { |
ceec2216 RL |
465 | ( |
466 | if [ "x$WXDEBUG" = "xverbose" ]; then | |
467 | _fbd_indent="${_fbd_indent}. " | |
468 | decho " $_fbd_indent---> unbound options: $*" | |
469 | fi | |
470 | ||
471 | for i; do | |
472 | ||
473 | if [ "x$WXDEBUG" = "xverbose" ]; then | |
474 | decho " ${_fbd_indent}binding '$i' with '$(remove_field $i $*)' still free" | |
475 | [ -z "$_pruned" ] || decho " ${_fbd_indent} --- pruned: $_pruned ---" | |
476 | fi | |
477 | ||
478 | if ( | |
479 | eval m_$i=\$this_$i | |
480 | _mask="^$(get_mask)$" | |
481 | ||
482 | if [ "x$WXDEBUG" = "xverbose" ]; then | |
483 | decho " ${_fbd_indent} checking: $_mask" | |
484 | count_delegates "$_mask" | |
485 | decho " $_fbd_indent $? eligible delegates" | |
486 | for d in $(find_eligible_delegates "$_mask"); do | |
487 | decho " ${_fbd_indent} $d" | |
488 | done | |
489 | fi | |
490 | ||
491 | count_delegates "$_mask" | |
492 | _still_eligible=$? | |
493 | ||
494 | if [ $_still_eligible -eq 1 ]; then | |
495 | echo $(find_eligible_delegates "$_mask") | |
496 | return | |
497 | fi | |
498 | ||
499 | [ "x$WXDEBUG" != "xfindprogress" ] || printf "." 1>&2 | |
500 | ||
501 | [ $_still_eligible -gt 1 ] && [ $# -gt 1 ] && \ | |
502 | do_find_best_delegate $(remove_field $i $*) | |
503 | ); | |
504 | then | |
505 | ||
506 | return | |
507 | ||
508 | elif [ $# -gt 1 ]; then | |
509 | ||
510 | if [ "x$WXDEBUG" = "xverbose" ]; then | |
511 | decho " ${_fbd_indent}pruning: $i" | |
512 | _pruned="${_pruned:+$_pruned }$i" | |
513 | fi | |
514 | set $(remove_field $i $*) | |
515 | ||
ffef10f6 | 516 | fi |
ceec2216 | 517 | |
ffef10f6 | 518 | done |
ceec2216 RL |
519 | false |
520 | ) | |
ffef10f6 VS |
521 | } |
522 | ||
ceec2216 RL |
523 | # find_best_delegate |
524 | # A simple wrapper around do_find_best_delegate that first determines | |
525 | # the unbound options (ie. the ones that the user did not explicitly | |
526 | # declare a preference for on the command line) | |
527 | find_best_delegate() | |
75f4be8a | 528 | { |
ceec2216 RL |
529 | for _fbdi in $wxconfig_schema; do |
530 | is_set input_option_$_fbdi || \ | |
531 | _unbound_options="${_unbound_options:+$_unbound_options }$_fbdi" | |
532 | done | |
533 | do_find_best_delegate $_unbound_options | |
534 | } | |
8708fa76 | 535 | |
75f4be8a | 536 | |
a13a7f89 RL |
537 | # Legacy wx-config helpers. |
538 | # ------------------------- | |
539 | ||
540 | # get_legacy_mask | |
541 | # Returns a mask in the format used by wx2.4. | |
542 | get_legacy_mask() | |
543 | { | |
544 | [ $# -gt 0 ] || set m | |
545 | eval [ "x\${$1_chartype}" != "xunicode" ] || _unicode_flag=u | |
546 | eval [ "x\${$1_debugtype}" != "xdebug" ] || _debug_flag=d | |
547 | eval echo "wx\${$1_toolkit}${_unicode_flag}${_debug_flag}-\${$1_version}\${$1_host}-config" | |
548 | } | |
549 | ||
550 | # find_legacy_configs | |
551 | # Returns a list of configs installed by wx2.4 releases. | |
552 | find_legacy_configs() | |
553 | { | |
554 | cd "$prefix/bin" 2> /dev/null && \ | |
555 | ls wx*-2.4-config | grep -v ^wxbase; \ | |
556 | ls wx*-2.4-config | grep ^wxbase | |
557 | } | |
558 | ||
559 | # find_best_legacy_config | |
560 | # Returns the best legacy config for a given specification. | |
561 | # This assumes no matching new style config has been found. | |
562 | find_best_legacy_config() | |
563 | { | |
564 | _legacy_configs=$(find_legacy_configs) | |
565 | if [ -n "$_legacy_configs" ]; then | |
566 | _legacy_mask=$(get_legacy_mask) | |
567 | for d in $_legacy_configs; do | |
568 | if echo $d | grep -E $_legacy_mask > /dev/null 2>&1 ; then | |
569 | echo "$d" | |
570 | return | |
571 | fi | |
572 | done | |
573 | fi | |
574 | false | |
575 | } | |
576 | ||
577 | ||
578 | ||
9a09819a RL |
579 | # The only action we can perform authoritatively prior to delegation |
580 | # is to list all the possible delegates. | |
581 | # -------------------------------------------------------------- | |
582 | ||
583 | config_spec="$0 $*" | |
584 | [ -z "$WXDEBUG" ] || config_spec=$configmask | |
585 | ||
586 | # Next chance for another satisfied customer then | |
587 | # | |
588 | # If we want to get really polished here we can do plural checking, | |
589 | # but we should probably leave that until the day we gettextise it. | |
590 | if [ -n "$output_option_list" ]; then | |
591 | ||
592 | _remains_in_prefix=$installed_configs | |
593 | _delegates=$(find_eligible_delegates $configmask) | |
594 | _best_delegate=$(find_best_delegate) | |
595 | ||
596 | if [ "x$WXDEBUG" = "xverbose" ]; then | |
a13a7f89 RL |
597 | decho |
598 | decho " all = $_remains_in_prefix" | |
599 | decho " matching = $_delegates" | |
600 | decho " best = $_best_delegate" | |
601 | decho " this = $this_config" | |
9a09819a RL |
602 | fi |
603 | ||
604 | for d in $_delegates; do | |
605 | _remains_in_prefix=$(remove_field $d $_remains_in_prefix) | |
606 | done | |
607 | ||
608 | echo | |
609 | echo " Default config is $this_config" | |
610 | echo | |
611 | ||
612 | if user_mask_fits "$this_config" ; then | |
613 | ||
614 | echo " Default config ${this_exec_prefix+in $this_exec_prefix }will be used for output" | |
615 | ||
616 | if match_field "$this_config" $_delegates ; then | |
617 | _delegates=$(remove_field $this_config $_delegates) | |
618 | else | |
619 | echo " though it is not installed in: $prefix" | |
620 | if [ -n "$_best_delegate" ] && [ "x$_best_delegate" != "x$this_config" ]; then | |
621 | echo | |
622 | echo " Best alternate in $prefix:" | |
623 | echo " $_best_delegate" | |
624 | fi | |
625 | fi | |
626 | ||
627 | elif [ -n "$_best_delegate" ]; then | |
628 | ||
629 | echo " Specification best match: $_best_delegate" | |
630 | ||
1320281c | 631 | elif [ -z "$_delegates" ]; then |
9a09819a | 632 | |
a13a7f89 RL |
633 | _last_chance=$(find_best_legacy_config) |
634 | if [ -n "$_last_chance" ]; then | |
635 | ||
636 | echo " Specification matches legacy config: $_last_chance" | |
637 | ||
638 | else | |
639 | ||
640 | cat <<-EOF | |
9a09819a RL |
641 | No config found to match: $config_spec |
642 | in $wxconfdir | |
643 | ||
644 | Please install the desired library build, or specify a different | |
645 | prefix where it may be found. If the library is not installed | |
646 | you may call its wx-config directly by specifying its full path. | |
647 | ||
648 | EOF | |
9a09819a | 649 | |
a13a7f89 RL |
650 | fi |
651 | ||
1320281c RL |
652 | else |
653 | echo " Specification was ambiguous. Use additional feature options" | |
654 | echo " to choose between alternate matches." | |
9a09819a RL |
655 | fi |
656 | ||
3950ea80 | 657 | _delegates=$(remove_field "$_best_delegate" $_delegates) |
9a09819a RL |
658 | |
659 | if [ -n "$_delegates" ]; then | |
660 | echo | |
661 | echo " Alternate matches:" | |
662 | for d in $_delegates; do | |
663 | echo " $d" | |
664 | done | |
665 | fi | |
666 | if [ -n "$_remains_in_prefix" ]; then | |
667 | echo | |
668 | echo " Also available in $prefix:" | |
669 | for d in $_remains_in_prefix; do | |
670 | echo " $d" | |
671 | done | |
672 | fi | |
673 | ||
a13a7f89 RL |
674 | _legacy_configs=$(find_legacy_configs) |
675 | if [ -n "$_legacy_configs" ]; then | |
676 | echo | |
677 | echo " Legacy configs available in $prefix:" | |
678 | for d in $_legacy_configs; do | |
679 | echo " ${d%-config}" | |
680 | done | |
681 | fi | |
682 | ||
9a09819a RL |
683 | echo |
684 | exit | |
685 | fi | |
686 | ||
687 | ||
75f4be8a | 688 | |
9a09819a RL |
689 | # ... so if that wasn't what they wanted, then we need to know for |
690 | # certain, can this config satisfy the user specification? | |
ceec2216 | 691 | # -------------------------------------------------------------- |
00c81359 | 692 | |
ceec2216 RL |
693 | if ! user_mask_fits "$this_config" ; then |
694 | ||
695 | # No? Then lets see if it knows anybody who can. | |
696 | # But first, just be sure someone hasn't typo'd us into a loop. | |
697 | # In present day wx, correct delegation should never need more | |
698 | # than one hop so this is trivial to detect. | |
699 | ||
700 | if [ -n "$WXCONFIG_DELEGATED" ]; then | |
701 | decho | |
702 | decho " *** Error: Bad config delegation" | |
703 | decho | |
704 | decho " to: $0" | |
705 | decho " ($this_config) cannot satisfy:" | |
9a09819a | 706 | decho " $config_spec" |
ceec2216 RL |
707 | decho " Someone has been terribly careless." |
708 | decho | |
709 | exit 1 | |
127e9080 VZ |
710 | fi |
711 | ||
ceec2216 RL |
712 | count_delegates "$configmask" |
713 | _numdelegates=$? | |
714 | ||
715 | if [ -n "$WXDEBUG" ]; then | |
716 | decho " must delegate to an alternate config" | |
717 | decho " potential delegates ($_numdelegates):" | |
718 | for i in $(find_eligible_delegates "$configmask"); do | |
719 | decho " $i" | |
720 | done | |
00c81359 | 721 | fi |
a43ed08a | 722 | |
ceec2216 | 723 | if [ $_numdelegates -eq 0 ]; then |
a13a7f89 RL |
724 | |
725 | _last_chance=$(find_best_legacy_config) | |
726 | if [ -n "$_last_chance" ]; then | |
727 | ||
22642fb2 RL |
728 | for arg; do |
729 | case "$arg" in | |
730 | --prefix*|--exec-prefix*| \ | |
731 | --version|--release|--basename| \ | |
732 | --static|--libs|--gl_libs| \ | |
733 | --cppflags|--cflags|--cxxflags| \ | |
734 | --cc|--cxx|--ld| \ | |
735 | --rezflags|--inplace) | |
736 | _legacy_args="$_legacy_args $arg" | |
737 | ;; | |
738 | ||
739 | --static|--static=y*|--static=Y*) | |
740 | _legacy_args="$_legacy_args --static" | |
741 | ;; | |
742 | esac | |
743 | done | |
744 | ||
a13a7f89 RL |
745 | if [ -n "$WXDEBUG" ]; then |
746 | decho " found a suitable legacy delegate: $_last_chance" | |
22642fb2 | 747 | decho "--> $prefix/bin/$_last_chance $_legacy_args" |
a13a7f89 RL |
748 | fi |
749 | ||
750 | export WXCONFIG_DELEGATED=yes | |
22642fb2 | 751 | $prefix/bin/$_last_chance $_legacy_args |
a13a7f89 RL |
752 | exit |
753 | ||
754 | else | |
755 | ||
756 | cat 1>&2 <<-EOF | |
ceec2216 | 757 | |
3950ea80 RL |
758 | Warning: No config found to match: $config_spec |
759 | in $wxconfdir | |
760 | If you require this configuration, please install the desired | |
761 | library build. If this is part of an automated configuration | |
762 | test and no other errors occur, you may safely ignore it. | |
763 | You may use wx-config --list to see all configs available in | |
764 | the default prefix. | |
ceec2216 RL |
765 | |
766 | EOF | |
767 | ||
a13a7f89 RL |
768 | # PIPEDREAM: This will probably give Vadim an aneurysm if I |
769 | # mention it out of context, but from here we are actually | |
770 | # just a teensy step from simply building the missing config | |
771 | # for the user on the fly if this is an in tree wx-config. | |
ceec2216 | 772 | |
a13a7f89 RL |
773 | exit 1 |
774 | fi | |
a43ed08a VZ |
775 | fi |
776 | ||
ceec2216 RL |
777 | if [ $_numdelegates -gt 1 ]; then |
778 | ||
779 | [ -z "$WXDEBUG" ] || decho " must prune the list of eligible delegates" | |
780 | ||
781 | best_delegate=$(find_best_delegate) | |
782 | ||
783 | if [ -n "$best_delegate" ]; then | |
784 | ||
785 | if [ -n "$WXDEBUG" ]; then | |
786 | decho " found a suitable delegate: $best_delegate" | |
787 | decho "--> $wxconfdir/$best_delegate $*" | |
788 | fi | |
789 | ||
790 | export WXCONFIG_DELEGATED=yes | |
791 | $wxconfdir/$best_delegate $* | |
792 | exit | |
793 | fi | |
794 | ||
795 | decho | |
3950ea80 RL |
796 | decho " *** Error: Specification is ambiguous" |
797 | decho " as $config_spec" | |
ceec2216 RL |
798 | decho " Use additional feature options to choose between:" |
799 | for i in $(find_eligible_delegates "$configmask"); do | |
800 | decho " $i" | |
801 | done | |
802 | decho | |
9a98a854 | 803 | |
ceec2216 RL |
804 | exit 1 |
805 | fi | |
806 | ||
807 | if [ -n "$WXDEBUG" ]; then | |
808 | decho " using the only suitable delegate" | |
809 | decho "--> $wxconfdir/$(find_eligible_delegates $configmask) $*" | |
810 | fi | |
811 | ||
812 | export WXCONFIG_DELEGATED=yes | |
813 | $wxconfdir/$(find_eligible_delegates $configmask) $* | |
814 | exit | |
9a98a854 VZ |
815 | fi |
816 | ||
251f47d1 | 817 | |
251f47d1 | 818 | |
ceec2216 RL |
819 | # If we are still here, then from now on we are responsible for |
820 | # all the user's needs. Time to rustle up some output for them. | |
821 | # -------------------------------------------------------------- | |
822 | ||
823 | [ -z "$WXDEBUG" ] || decho " using this config" | |
824 | ||
9103d280 RL |
825 | # If the user supplied a prefix, and the in tree config did not |
826 | # delegate out to anything in that prefix, then reset the build | |
827 | # tree prefix to provide the correct output for using this | |
828 | # uninstalled wx build. Or put more simply: | |
829 | prefix=${this_prefix-$prefix} | |
0506bbbf | 830 | exec_prefix=${this_exec_prefix-$exec_prefix} |
ceec2216 RL |
831 | |
832 | includedir="@includedir@" | |
833 | libdir="@libdir@" | |
834 | ||
835 | # Trivial queries we can answer now. | |
836 | [ -z "$output_option_prefix" ] || echo $prefix | |
837 | [ -z "$output_option_exec_prefix" ] || echo $exec_prefix | |
838 | [ -z "$output_option_release" ] || echo "@WX_RELEASE@" | |
839 | [ -z "$output_option_version" ] || echo "@WX_VERSION@" | |
840 | [ -z "$output_option_version_full" ] || echo "@WX_SUBVERSION@" | |
841 | [ -z "$output_option_basename" ] || echo "@WX_LIBRARY_BASENAME_GUI@" | |
842 | [ -z "$output_option_rezflags" ] || echo $(eval echo @MACRESWXCONFIG@) | |
843 | [ -z "$output_option_cc" ] || echo "@CC@" | |
844 | [ -z "$output_option_cxx" ] || echo "@CXX@" | |
845 | [ -z "$output_option_ld" ] || echo "@EXE_LINKER@" | |
846 | ||
847 | ||
848 | # The rest are going to need a little more work. | |
849 | # -------------------------------------------------------------- | |
850 | ||
851 | is_cross() { [ "x@cross_compiling@" = "xyes" ]; } | |
852 | is_monolithic() { [ @MONOLITHIC@ -eq 1 ]; } | |
853 | ||
854 | ||
855 | # Additional configuration for individual library components. | |
856 | ldflags_gl="@LDFLAGS_GL@" | |
857 | ||
858 | ldlibs_base="@WXCONFIG_EXTRALIBS@" | |
859 | ldlibs_core="@EXTRALIBS_GUI@" | |
860 | ldlibs_gl="@OPENGL_LIBS@" | |
861 | ldlibs_html="@EXTRALIBS_HTML@" | |
862 | ldlibs_xml="@EXTRALIBS_XML@" | |
863 | ldlibs_odbc="@EXTRALIBS_ODBC@" | |
864 | ldlibs_adv="@EXTRALIBS_SDL@" | |
865 | ||
866 | ||
867 | # lib_flags_for _liblist | |
868 | # This function returns a list of flags suitable to return with the | |
869 | # output of --libs for all of the libraries in _liblist. You can | |
870 | # add support for a new library by adding an entry for it in the | |
871 | # psuedo-hashes above if it requires additional linker options. | |
872 | lib_flags_for() | |
873 | { | |
874 | [ -z "$WXDEBUG" ] || decho " fetching lib flags for: '$*'" | |
875 | ||
876 | _all_ldflags='' | |
877 | _all_libs='' | |
878 | _wxlibs='' | |
879 | ||
880 | ! is_cross || _target="-${target}" | |
881 | ||
882 | for lib; do | |
883 | ||
884 | # We evidently can't trust people not to duplicate things in | |
885 | # configure, or to keep them in any sort of sane order overall, | |
886 | # so only add unique new fields here even if it takes us a while. | |
887 | # In the case of libs, we bubble any duplicates to the end, | |
888 | # because if multiple libs require it, static linking at least | |
889 | # will require it to come after all of them. So long as local | |
890 | # order is ok in configure then we should always be able to | |
891 | # massage a correct result here like this. | |
892 | # | |
893 | # FIXME: ldlibs_core is totally bogus. Fix the duplication | |
894 | # there independently of this. This covers for it, but we | |
895 | # want to do this anyway because some libs may share common | |
896 | # deps without a common ancestor in wx. This is not a licence | |
897 | # for sloppy work elsewhere though and @GUI_TK_LIBRARY should | |
898 | # be fixed. | |
899 | ||
900 | for f in $(eval echo \"\$ldflags_$lib\"); do | |
901 | match_field "$f" $_all_ldflags || _all_ldflags="$_all_ldflags $f" | |
902 | done | |
903 | ||
904 | if match_field "$lib" @CORE_BASE_LIBS@ ; then | |
905 | _libname="@WX_LIBRARY_BASENAME_NOGUI@" | |
906 | else | |
907 | _libname="@WX_LIBRARY_BASENAME_GUI@" | |
908 | fi | |
909 | [ $lib = base ] || _libname="${_libname}_$lib" | |
910 | _libname="${_libname}-@WX_RELEASE@$_target" | |
911 | ||
912 | if [ "x$this_linkage" = "x-static" ]; then | |
913 | _wxlibs="$_wxlibs ${libdir}/lib${_libname}.a" | |
914 | for f in $(eval echo \"\$ldlibs_$lib\"); do | |
915 | _all_libs="$(remove_field $f $_all_libs) $f" | |
916 | done | |
917 | else | |
918 | _wxlibs="$_wxlibs -l${_libname}" | |
919 | fi | |
920 | ||
921 | done | |
922 | ||
923 | if [ -n "$WXDEBUG" ]; then | |
924 | decho " retrieved: ldflags = $_all_ldflags" | |
925 | decho " wxlibs = $_wxlibs" | |
926 | decho " alllibs = $_all_libs" | |
927 | fi | |
928 | ||
929 | echo $_all_ldflags $_wxlibs $_all_libs | |
930 | } | |
931 | ||
932 | ||
933 | # Sanity check the list of libs the user provided us, if any. | |
934 | # -------------------------------------------------------------- | |
935 | ||
936 | wx_libs=$(echo "$input_parameters" | tr ',' ' ') | |
937 | ||
938 | [ -z "$WXDEBUG" ] || decho " user supplied libs: '$wx_libs'" | |
939 | ||
940 | if is_monolithic; then | |
941 | ||
942 | # Core libs are already built into the blob. | |
5636172b | 943 | for i in std @CORE_GUI_LIBS@ @CORE_BASE_LIBS@; do |
ceec2216 RL |
944 | wx_libs=$(remove_field $i $wx_libs) |
945 | done | |
946 | ||
947 | wx_libs="@WXCONFIG_LDFLAGS_GUI@ @WXCONFIG_RPATH@ $(lib_flags_for $wx_libs)" | |
948 | ||
949 | # We still need the core lib deps for a static build though | |
950 | if [ "x$this_linkage" = "x-static" ]; then | |
951 | wx_libs="$wx_libs ${libdir}/libwx_@TOOLCHAIN_NAME@.a $ldlibs_core @LIBS@" | |
952 | else | |
953 | wx_libs="$wx_libs -lwx_@TOOLCHAIN_NAME@" | |
954 | fi | |
955 | ||
956 | using_gui=yes | |
957 | ||
958 | else # MONOLITHIC = 0 | |
959 | ||
960 | # Import everything by default, and base if it was omitted. | |
961 | if [ -z "$wx_libs" ]; then | |
962 | wx_libs="@CORE_GUI_LIBS@ @CORE_BASE_LIBS@" | |
963 | elif ! match_field base $wx_libs ; then | |
964 | wx_libs="$wx_libs base" | |
965 | fi | |
966 | ||
967 | # Expand the magic library 'std' to the default set. | |
968 | # Only add those not already specified to future-proof | |
969 | # against changes to std which would otherwise break | |
970 | # people's builds. | |
971 | if match_field std $wx_libs; then | |
972 | wx_libs=$(remove_field std $wx_libs) | |
973 | for i in @CORE_GUI_LIBS@ @CORE_BASE_LIBS@; do | |
974 | match_field "$i" $wx_libs || wx_libs="$wx_libs $i" | |
975 | done | |
976 | fi | |
977 | ||
978 | using_gui=no | |
979 | for i in $wx_libs ; do | |
980 | if match_field "$i" @CORE_GUI_LIBS@ ; then | |
981 | _guildflags="@WXCONFIG_LDFLAGS_GUI@" | |
982 | using_gui=yes | |
983 | break | |
984 | fi | |
985 | match_field "$i" @CORE_BASE_LIBS@ || using_gui=yes | |
986 | done | |
987 | ||
988 | wx_libs="$_guildflags @WXCONFIG_RPATH@ $(lib_flags_for $wx_libs)" | |
251f47d1 VS |
989 | fi |
990 | ||
ceec2216 RL |
991 | |
992 | if [ -n "$WXDEBUG" ]; then | |
993 | decho | |
994 | decho " using libs: '$wx_libs'" | |
995 | decho " using_gui = $using_gui" | |
996 | decho | |
c39ee0ad | 997 | fi |
251f47d1 VS |
998 | |
999 | ||
ceec2216 RL |
1000 | # Endgame. Nothing left to discover now. |
1001 | # -------------------------------------------------------------- | |
251f47d1 | 1002 | |
9103d280 RL |
1003 | [ -n "$this_linkage" ] || _static_cppflags="@TOOLCHAIN_DLL_DEFS@" |
1004 | [ "$using_gui" = "yes" ] || _gui_cppflags="-DwxUSE_GUI=0" | |
ceec2216 | 1005 | |
0506bbbf RL |
1006 | if [ -n "$this_prefix" ]; then |
1007 | _include_cppflags="-I${includedir} -I${prefix}/contrib/include" | |
1008 | else | |
1009 | _include_cppflags="-I${includedir}/wx-@WX_RELEASE@@WX_FLAVOUR@" | |
1010 | fi | |
1011 | ||
1012 | _cppflags=$(echo "-I${libdir}/wx/include/@TOOLCHAIN_FULLNAME@" $_include_cppflags "@WXDEBUG_DEFINE@" "@TOOLCHAIN_DEFS@" $_static_cppflags $_gui_cppflags "@WXCONFIG_INCLUDE@" "@WX_LARGEFILE_FLAGS@" "@GCC_PRAGMA_FLAGS@") | |
ceec2216 RL |
1013 | |
1014 | # now without further ado, we can answer these too. | |
9103d280 RL |
1015 | [ -z "$output_option_cppflags" ] || echo $_cppflags |
1016 | [ -z "$output_option_cflags" ] || echo $_cppflags "@CODE_GEN_FLAGS@" | |
1017 | [ -z "$output_option_cxxflags" ] || echo $_cppflags "@CODE_GEN_FLAGS@" "@CODE_GEN_FLAGS_CXX@" | |
ceec2216 RL |
1018 | [ -z "$output_option_gl_libs" ] || echo $(lib_flags_for gl) |
1019 | ||
1020 | if [ -n "$output_option_libs" ]; then | |
1021 | ||
1022 | is_cross && [ "x$libdir" = "x/usr/${target}/lib" ] \ | |
1023 | || [ "x$libdir" = "x/usr/lib" ] \ | |
1024 | || _ldflags="-L$libdir" | |
1025 | ||
1026 | echo $_ldflags "@LDFLAGS@" $wx_libs "@DMALLOC_LIBS@" | |
1027 | fi | |
1028 | ||
1029 | # And so that's it, we're done. Have a nice build. | |
1030 | ||
1031 | exit 0 | |
9a98a854 | 1032 | |
9a98a854 | 1033 |