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