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