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