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