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