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