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