]>
Commit | Line | Data |
---|---|---|
08b28cd3 DE |
1 | #!/bin/sh |
2 | # Generates multilib.h. | |
a945c346 | 3 | # Copyright (C) 1994-2024 Free Software Foundation, Inc. |
08b28cd3 | 4 | |
1322177d | 5 | #This file is part of GCC. |
08b28cd3 | 6 | |
1322177d LB |
7 | #GCC is free software; you can redistribute it and/or modify it under |
8 | #the terms of the GNU General Public License as published by the Free | |
9dcd6f09 | 9 | #Software Foundation; either version 3, or (at your option) any later |
1322177d | 10 | #version. |
08b28cd3 | 11 | |
1322177d LB |
12 | #GCC is distributed in the hope that it will be useful, but WITHOUT |
13 | #ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | #FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | #for more details. | |
08b28cd3 DE |
16 | |
17 | #You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
18 | #along with GCC; see the file COPYING3. If not see |
19 | #<http://www.gnu.org/licenses/>. | |
08b28cd3 DE |
20 | |
21 | # This shell script produces a header file which the gcc driver | |
22 | # program uses to pick which library to use based on the machine | |
23 | # specific options that it is given. | |
24 | ||
25 | # The first argument is a list of sets of options. The elements in | |
26 | # the list are separated by spaces. Within an element, the options | |
699a42a6 JJ |
27 | # are separated by slashes or pipes. No leading dash is used on the |
28 | # options. | |
29 | # Each option in a set separated by slashes is mutually incompatible | |
30 | # with all other options | |
08b28cd3 | 31 | # in the set. |
699a42a6 JJ |
32 | # Each option in a set separated by pipes will be used for the library |
33 | # compilation and any of the options in the set will be sufficient | |
34 | # for it to be triggered. | |
08b28cd3 DE |
35 | |
36 | # The optional second argument is a list of subdirectory names. If | |
37 | # the second argument is non-empty, there must be as many elements in | |
38 | # the second argument as there are options in the first argument. The | |
39 | # elements in the second list are separated by spaces. If the second | |
40 | # argument is empty, the option names will be used as the directory | |
41 | # names. | |
42 | ||
43 | # The optional third argument is a list of options which are | |
44 | # identical. The elements in the list are separated by spaces. Each | |
45 | # element must be of the form OPTION=OPTION. The first OPTION should | |
46 | # appear in the first argument, and the second should be a synonym for | |
75814ad4 | 47 | # it. Question marks are replaced with equal signs in both options. |
08b28cd3 | 48 | |
e09150c7 MM |
49 | # The optional fourth argument is a list of multilib directory |
50 | # combinations that should not be built. | |
51 | ||
961b7009 MM |
52 | # The optional fifth argument is a list of options that should be |
53 | # used whenever building multilib libraries. | |
54 | ||
0a8d6618 BC |
55 | # The optional sixth argument is a list of exclusions used internally by |
56 | # the compiler similar to exceptions. The difference being that exclusions | |
57 | # allow matching default options that genmultilib does not know about and | |
58 | # is done at runtime as opposed to being sorted out at compile time. | |
cc712abf JM |
59 | # Each element in the list is a separate exclusion rule. Each rule is |
60 | # a list of options (sans preceding '-') separated by a '/'. The options | |
0a8d6618 BC |
61 | # on the rule are grouped as an AND operation, and all options much match |
62 | # for the rule to exclude a set. Options can be preceded with a '!' to | |
63 | # match a logical NOT. | |
64 | ||
55047c9d PE |
65 | # The optional seventh argument is a list of OS subdirectory names. |
66 | # The format is either the same as of the second argument, or a set of | |
67 | # mappings. When it is the same as the second argument, it describes | |
68 | # the multilib directories using OS conventions, rather than GCC | |
69 | # conventions. When it is a set of mappings of the form gccdir=osdir, | |
70 | # the left side gives the GCC convention and the right gives the | |
71 | # equivalent OS defined location. If the osdir part begins with a !, | |
72 | # the os directory names are used exclusively. Use the mapping when | |
73 | # there is no one-to-one equivalence between GCC levels and the OS. | |
5bbcd587 | 74 | |
43661dc4 TG |
75 | # The optional eighth argument which intends to reduce the effort to write |
76 | # so many MULTILIB_EXCEPTIONS rules. This option defines a series of option | |
77 | # combinations that we actually required. | |
78 | # For some cases, the generated option combinations are far more than what | |
79 | # we need, we have to write a lot of rules to screen out combinations we | |
80 | # don't need. If we missed some rules, the unexpected libraries will be built. | |
81 | # Now with this argument, one can simply give what combinations are needed. | |
82 | # It is pretty straigtforward. | |
83 | # This argument can be used together with MULTILIB_EXCEPTIONS and will take | |
84 | # effect after the MULTILIB_EXCEPTIONS. | |
85 | ||
e0cdc09f MK |
86 | # The optional ninth argument is the multiarch name. |
87 | ||
e7f49d92 TG |
88 | # The optional tenth argument specifies how to reuse multilib for different |
89 | # option sets. | |
90 | ||
c49d2df6 JJ |
91 | # The last option should be "yes" if multilibs are enabled. If it is not |
92 | # "yes", all GCC multilib dir names will be ".". | |
93 | ||
08b28cd3 DE |
94 | # The output looks like |
95 | # #define MULTILIB_MATCHES "\ | |
96 | # SUBDIRECTORY OPTIONS;\ | |
97 | # ... | |
98 | # " | |
99 | # The SUBDIRECTORY is the subdirectory to use. The OPTIONS are | |
100 | # multiple options separated by spaces. Each option may start with an | |
101 | # exclamation point. gcc will consider each line in turn. If none of | |
102 | # the options beginning with an exclamation point are present, and all | |
103 | # of the other options are present, that subdirectory will be used. | |
104 | # The order of the subdirectories is such that they can be created in | |
105 | # order; that is, a subdirectory is preceded by all its parents. | |
106 | ||
0a8d6618 BC |
107 | # Here is an example (this is from the actual sparc64 case): |
108 | # genmultilib 'm64/m32 mno-app-regs|mcmodel=medany' '64 32 alt' | |
109 | # 'mcmodel?medany=mcmodel?medmid' 'm32/mno-app-regs* m32/mcmodel=*' | |
5bbcd587 | 110 | # '' 'm32/!m64/mno-app-regs m32/!m64/mcmodel=medany' |
e7f49d92 | 111 | # '../lib64 ../lib32 alt' '' '' '' yes |
08b28cd3 | 112 | # This produces: |
0a8d6618 | 113 | # ". !m64 !m32 !mno-app-regs !mcmodel=medany;", |
5bbcd587 JJ |
114 | # "64:../lib64 m64 !m32 !mno-app-regs !mcmodel=medany;", |
115 | # "32:../lib32 !m64 m32 !mno-app-regs !mcmodel=medany;", | |
0a8d6618 BC |
116 | # "alt !m64 !m32 mno-app-regs mcmodel=medany;", |
117 | # "alt !m64 !m32 mno-app-regs !mcmodel=medany;", | |
118 | # "alt !m64 !m32 !mno-app-regs mcmodel=medany;", | |
5bbcd587 JJ |
119 | # "64/alt:../lib64/alt m64 !m32 mno-app-regs mcmodel=medany;", |
120 | # "64/alt:../lib64/alt m64 !m32 mno-app-regs !mcmodel=medany;", | |
121 | # "64/alt:../lib64/alt m64 !m32 !mno-app-regs mcmodel=medany;", | |
87e24276 | 122 | # |
0a8d6618 BC |
123 | # The effect is that `gcc -mno-app-regs' (for example) will append "alt" |
124 | # to the directory name when searching for libraries or startup files and | |
125 | # `gcc -m32 -mcmodel=medany' (for example) will append "32/alt". Also note | |
126 | # that exclusion above is moot, unless the compiler had a default of -m32, | |
127 | # which would mean that all of the "alt" directories (not the 64/alt ones) | |
128 | # would be ignored (not generated, nor used) since the exclusion also | |
129 | # matches the multilib_default args. | |
08b28cd3 DE |
130 | |
131 | # Copy the positional parameters into variables. | |
132 | options=$1 | |
133 | dirnames=$2 | |
134 | matches=$3 | |
e09150c7 | 135 | exceptions=$4 |
961b7009 | 136 | extra=$5 |
0a8d6618 | 137 | exclusions=$6 |
5bbcd587 | 138 | osdirnames=$7 |
43661dc4 | 139 | multilib_required=$8 |
e0cdc09f | 140 | multiarch=$9 |
e7f49d92 TG |
141 | multilib_reuse=${10} |
142 | enable_multilib=${11} | |
961b7009 | 143 | |
3b304f5b | 144 | echo "static const char *const multilib_raw[] = {" |
08b28cd3 | 145 | |
c79d892f | 146 | mkdir tmpmultilib.$$ || exit 1 |
e489a31f JM |
147 | # Use cd ./foo to avoid CDPATH output. |
148 | cd ./tmpmultilib.$$ || exit 1 | |
c79d892f | 149 | |
08b28cd3 DE |
150 | # What we want to do is select all combinations of the sets in |
151 | # options. Each combination which includes a set of mutually | |
152 | # exclusive options must then be output multiple times, once for each | |
153 | # item in the set. Selecting combinations is a recursive process. | |
154 | # Since not all versions of sh support functions, we achieve recursion | |
155 | # by creating a temporary shell script which invokes itself. | |
156 | rm -f tmpmultilib | |
157 | cat >tmpmultilib <<\EOF | |
158 | #!/bin/sh | |
159 | # This recursive script basically outputs all combinations of its | |
160 | # input arguments, handling mutually exclusive sets of options by | |
161 | # repetition. When the script is called, ${initial} is the list of | |
162 | # options which should appear before all combinations this will | |
163 | # output. The output looks like a list of subdirectory names with | |
164 | # leading and trailing slashes. | |
165 | if [ "$#" != "0" ]; then | |
166 | first=$1 | |
167 | shift | |
699a42a6 JJ |
168 | case "$first" in |
169 | *\|*) | |
170 | all=${initial}`echo $first | sed -e 's_|_/_'g` | |
171 | first=`echo $first | sed -e 's_|_ _'g` | |
172 | echo ${all}/ | |
b5f04a4d AO |
173 | initial="${initial}${all}/" ${CONFIG_SHELL-/bin/sh} ./tmpmultilib $@ |
174 | ${CONFIG_SHELL-/bin/sh} ./tmpmultilib $first $@ | grep -v "^${all}" | |
699a42a6 JJ |
175 | ;; |
176 | *) | |
177 | for opt in `echo $first | sed -e 's|/| |'g`; do | |
178 | echo ${initial}${opt}/ | |
179 | done | |
b5f04a4d | 180 | ${CONFIG_SHELL-/bin/sh} ./tmpmultilib $@ |
699a42a6 | 181 | for opt in `echo $first | sed -e 's|/| |'g`; do |
b5f04a4d | 182 | initial="${initial}${opt}/" ${CONFIG_SHELL-/bin/sh} ./tmpmultilib $@ |
699a42a6 JJ |
183 | done |
184 | esac | |
08b28cd3 DE |
185 | fi |
186 | EOF | |
187 | chmod +x tmpmultilib | |
188 | ||
b5f04a4d | 189 | combinations=`initial=/ ${CONFIG_SHELL-/bin/sh} ./tmpmultilib ${options}` |
08b28cd3 | 190 | |
e09150c7 MM |
191 | # If there exceptions, weed them out now |
192 | if [ -n "${exceptions}" ]; then | |
e09150c7 MM |
193 | cat >tmpmultilib2 <<\EOF |
194 | #!/bin/sh | |
195 | # This recursive script weeds out any combination of multilib | |
196 | # switches that should not be generated. The output looks like | |
197 | # a list of subdirectory names with leading and trailing slashes. | |
198 | ||
199 | for opt in $@; do | |
200 | case "$opt" in | |
201 | EOF | |
202 | ||
203 | for except in ${exceptions}; do | |
204 | echo " /${except}/) : ;;" >> tmpmultilib2 | |
205 | done | |
206 | ||
207 | cat >>tmpmultilib2 <<\EOF | |
208 | *) echo ${opt};; | |
209 | esac | |
210 | done | |
211 | EOF | |
212 | chmod +x tmpmultilib2 | |
b5f04a4d | 213 | combinations=`${CONFIG_SHELL-/bin/sh} ./tmpmultilib2 ${combinations}` |
e09150c7 MM |
214 | fi |
215 | ||
43661dc4 TG |
216 | # If the MULTILIB_REQUIRED list are provided, |
217 | # filter out combinations not in this list. | |
218 | if [ -n "${multilib_required}" ]; then | |
219 | cat >tmpmultilib2 <<\EOF | |
220 | #!/bin/sh | |
221 | # This recursive script weeds out any combination of multilib | |
222 | # switches that not in the expected list. | |
223 | ||
224 | for opt in $@; do | |
225 | case "$opt" in | |
226 | EOF | |
227 | ||
228 | for expect in ${multilib_required}; do | |
229 | echo " /${expect}/) echo \${opt};;" >> tmpmultilib2 | |
230 | done | |
231 | ||
232 | cat >>tmpmultilib2 <<\EOF | |
233 | *) ;; | |
234 | esac | |
235 | done | |
236 | EOF | |
237 | ||
238 | chmod +x tmpmultilib2 | |
b5f04a4d | 239 | combinations=`${CONFIG_SHELL-/bin/sh} ./tmpmultilib2 ${combinations}` |
43661dc4 TG |
240 | |
241 | fi | |
242 | ||
08b28cd3 DE |
243 | # Construct a sed pattern which will convert option names to directory |
244 | # names. | |
245 | todirnames= | |
246 | if [ -n "${dirnames}" ]; then | |
247 | set x ${dirnames} | |
248 | shift | |
249 | for set in ${options}; do | |
699a42a6 JJ |
250 | for opts in `echo ${set} | sed -e 's|/| |'g`; do |
251 | patt="/" | |
252 | for opt in `echo ${opts} | sed -e 's_|_ _'g`; do | |
ccb9c7b1 CL |
253 | if [ -z "$1" ]; then |
254 | echo 1>&2 "Error calling $0: No dirname for option: $opt" | |
255 | exit 1 | |
256 | fi | |
699a42a6 JJ |
257 | if [ "$1" != "${opt}" ]; then |
258 | todirnames="${todirnames} -e s|/${opt}/|/${1}/|g" | |
259 | patt="${patt}${1}/" | |
260 | if [ "${patt}" != "/${1}/" ]; then | |
261 | todirnames="${todirnames} -e s|${patt}|/${1}/|g" | |
262 | fi | |
263 | fi | |
264 | done | |
08b28cd3 DE |
265 | shift |
266 | done | |
267 | done | |
268 | fi | |
269 | ||
5bbcd587 JJ |
270 | # Construct a sed pattern which will convert option names to OS directory |
271 | # names. | |
272 | toosdirnames= | |
55047c9d | 273 | defaultosdirname= |
df2dfaea | 274 | defaultosdirname2= |
e0cdc09f MK |
275 | if [ -n "${multiarch}" ]; then |
276 | defaultosdirname=::${multiarch} | |
277 | fi | |
5bbcd587 JJ |
278 | if [ -n "${osdirnames}" ]; then |
279 | set x ${osdirnames} | |
280 | shift | |
55047c9d PE |
281 | while [ $# != 0 ] ; do |
282 | case "$1" in | |
283 | .=*) | |
284 | defaultosdirname=`echo $1 | sed 's|^.=|:|'` | |
e0cdc09f MK |
285 | if [ -n "${multiarch}" ]; then |
286 | defaultosdirname=${defaultosdirname}:${multiarch} | |
287 | fi | |
df2dfaea JJ |
288 | case "$defaultosdirname" in |
289 | ::*) ;; | |
290 | *) | |
291 | defaultosdirname2=${defaultosdirname} | |
292 | defaultosdirname= | |
293 | ;; | |
294 | esac | |
55047c9d PE |
295 | shift |
296 | ;; | |
297 | *=*) | |
298 | patt=`echo $1 | sed -e 's|=|/$=/|'` | |
299 | toosdirnames="${toosdirnames} -e s=^/${patt}/=" | |
300 | shift | |
301 | ;; | |
302 | *) | |
303 | break | |
304 | ;; | |
305 | esac | |
306 | done | |
307 | ||
308 | if [ $# != 0 ]; then | |
309 | for set in ${options}; do | |
310 | for opts in `echo ${set} | sed -e 's|/| |'g`; do | |
311 | patt="/" | |
312 | for opt in `echo ${opts} | sed -e 's_|_ _'g`; do | |
ccb9c7b1 CL |
313 | if [ -z "$1" ]; then |
314 | echo 1>&2 "Error calling $0: No osdirname for option: $opt" | |
315 | exit 1 | |
316 | fi | |
55047c9d PE |
317 | if [ "$1" != "${opt}" ]; then |
318 | toosdirnames="${toosdirnames} -e s|/${opt}/|/${1}/|g" | |
319 | patt="${patt}${1}/" | |
320 | if [ "${patt}" != "/${1}/" ]; then | |
321 | toosdirnames="${toosdirnames} -e s|${patt}|/${1}/|g" | |
322 | fi | |
5bbcd587 | 323 | fi |
55047c9d PE |
324 | done |
325 | shift | |
5bbcd587 | 326 | done |
5bbcd587 | 327 | done |
55047c9d | 328 | fi |
5bbcd587 JJ |
329 | fi |
330 | ||
08b28cd3 DE |
331 | # We need another recursive shell script to correctly handle positive |
332 | # matches. If we are invoked as | |
333 | # genmultilib "opt1 opt2" "" "opt1=nopt1 opt2=nopt2" | |
334 | # we must output | |
335 | # opt1/opt2 opt1 opt2 | |
336 | # opt1/opt2 nopt1 opt2 | |
337 | # opt1/opt2 opt1 nopt2 | |
338 | # opt1/opt2 nopt1 nopt2 | |
339 | # In other words, we must output all combinations of matches. | |
340 | rm -f tmpmultilib2 | |
341 | cat >tmpmultilib2 <<\EOF | |
342 | #!/bin/sh | |
343 | # The positional parameters are a list of matches to consider. | |
344 | # ${dirout} is the directory name and ${optout} is the current list of | |
345 | # options. | |
346 | if [ "$#" = "0" ]; then | |
87e24276 | 347 | echo "\"${dirout} ${optout};\"," |
08b28cd3 DE |
348 | else |
349 | first=$1 | |
350 | shift | |
b5f04a4d | 351 | dirout="${dirout}" optout="${optout}" ${CONFIG_SHELL-/bin/sh} ./tmpmultilib2 $@ |
75814ad4 MM |
352 | l=`echo ${first} | sed -e 's/=.*$//' -e 's/?/=/g'` |
353 | r=`echo ${first} | sed -e 's/^.*=//' -e 's/?/=/g'` | |
eedea0f2 | 354 | if expr " ${optout} " : ".* ${l} .*" > /dev/null; then |
08b28cd3 | 355 | newopt=`echo " ${optout} " | sed -e "s/ ${l} / ${r} /" -e 's/^ //' -e 's/ $//'` |
b5f04a4d | 356 | dirout="${dirout}" optout="${newopt}" ${CONFIG_SHELL-/bin/sh} ./tmpmultilib2 $@ |
eedea0f2 | 357 | fi |
08b28cd3 DE |
358 | fi |
359 | EOF | |
360 | chmod +x tmpmultilib2 | |
361 | ||
08b28cd3 DE |
362 | # Start with the current directory, which includes only negations. |
363 | optout= | |
364 | for set in ${options}; do | |
699a42a6 | 365 | for opt in `echo ${set} | sed -e 's_[/|]_ _g'`; do |
08b28cd3 DE |
366 | optout="${optout} !${opt}" |
367 | done | |
368 | done | |
369 | optout=`echo ${optout} | sed -e 's/^ //'` | |
55047c9d | 370 | echo "\".${defaultosdirname} ${optout};\"," |
df2dfaea | 371 | [ -n "${defaultosdirname2}" ] && echo "\".${defaultosdirname2} ${optout};\"," |
08b28cd3 | 372 | |
e7f49d92 TG |
373 | # This part of code convert an option combination to |
374 | # its corresponding directory names. | |
375 | # The directory names will be deduced from MULTILIB_DIRNAMES, | |
376 | # MULTILIB_OSDIRNAMES or the option combination itself. | |
377 | rm -rf tmpmultilib3 | |
378 | cat >tmpmultilib3 <<\EOF | |
379 | #!/bin/sh | |
380 | ||
381 | dirout= | |
382 | combo=$1 | |
383 | todirnames=$2 | |
384 | toosdirnames=$3 | |
385 | enable_multilib=$4 | |
386 | ||
387 | if [ -n "${todirnames}" ]; then | |
388 | dirout=`echo ${combo} | sed ${todirnames}` | |
389 | else | |
390 | dirout=`echo ${combo} | sed -e 's/=/-/g'` | |
391 | fi | |
392 | # Remove the leading and trailing slashes. | |
393 | dirout=`echo ${dirout} | sed -e 's|^/||' -e 's|/*:/*|:|' -e 's|/$||g'` | |
394 | ||
395 | # Use the OS directory names rather than the option names. | |
396 | if [ -n "${toosdirnames}" ]; then | |
397 | osdirout=`echo ${combo} | sed ${toosdirnames}` | |
398 | # Remove the leading and trailing slashes. | |
399 | osdirout=`echo ${osdirout} | sed -e 's|^/||' -e 's|/*:/*|:|' -e 's|/$||g'` | |
400 | if [ "x${enable_multilib}" != xyes ]; then | |
401 | dirout=".:${osdirout}" | |
402 | disable_multilib=yes | |
403 | else | |
404 | case "${osdirout}" in | |
405 | !*) | |
406 | dirout=`echo ${osdirout} | sed 's/^!//'` | |
407 | ;; | |
408 | *) | |
409 | dirout="${dirout}:${osdirout}" | |
410 | ;; | |
411 | esac | |
412 | fi | |
413 | else | |
414 | if [ "x${enable_multilib}" != xyes ]; then | |
415 | # genmultilib with --disable-multilib should be | |
416 | # called with '' '' '' '' '' '' '' no | |
417 | # if MULTILIB_OSDIRNAMES is empty. | |
418 | exit 1 | |
419 | fi | |
420 | fi | |
421 | echo "${dirout}" | |
422 | EOF | |
423 | chmod +x tmpmultilib3 | |
424 | ||
425 | # Script to look through the options and output each option that is present, | |
426 | # and negate each option that is not present. | |
427 | rm -rf tmpmultilib4 | |
428 | cat > tmpmultilib4 <<\EOF | |
429 | #!/bin/sh | |
430 | ||
431 | optout= | |
432 | combo=$1 | |
433 | options=$2 | |
434 | ||
435 | for set in ${options}; do | |
436 | setopts=`echo ${set} | sed -e 's_[/|]_ _g'` | |
437 | for opt in ${setopts}; do | |
438 | if expr "${combo} " : ".*/${opt}/.*" > /dev/null; then | |
439 | optout="${optout} ${opt}" | |
440 | else | |
441 | optout="${optout} !${opt}" | |
442 | fi | |
443 | done | |
444 | done | |
445 | optout=`echo ${optout} | sed -e 's/^ //'` | |
446 | echo "${optout}" | |
447 | EOF | |
448 | chmod +x tmpmultilib4 | |
449 | ||
08b28cd3 DE |
450 | # Work over the list of combinations. We have to translate each one |
451 | # to use the directory names rather than the option names, we have to | |
452 | # include the information in matches, and we have to generate the | |
453 | # correct list of options and negations. | |
454 | for combo in ${combinations}; do | |
455 | # Use the directory names rather than the option names. | |
b5f04a4d | 456 | dirout=`${CONFIG_SHELL-/bin/sh} ./tmpmultilib3 "${combo}" "${todirnames}" "${toosdirnames}" "${enable_multilib}"` |
5bbcd587 | 457 | |
08b28cd3 | 458 | # Look through the options. We must output each option that is |
fb685388 | 459 | # present, and negate each option that is not present. |
b5f04a4d | 460 | optout=`${CONFIG_SHELL-/bin/sh} ./tmpmultilib4 "${combo}" "${options}"` |
08b28cd3 | 461 | |
08b28cd3 | 462 | # Output the line with all appropriate matches. |
b5f04a4d | 463 | dirout="${dirout}" optout="${optout}" ${CONFIG_SHELL-/bin/sh} ./tmpmultilib2 |
08b28cd3 DE |
464 | done |
465 | ||
87e24276 JW |
466 | # Terminate the list of string. |
467 | echo "NULL" | |
961b7009 MM |
468 | echo "};" |
469 | ||
9636e806 JM |
470 | # Generate a regular expression to validate option combinations. |
471 | options_re= | |
472 | for set in ${options}; do | |
601d22f6 | 473 | for opt in `echo ${set} | sed -e 's_[/|]_ _g' -e 's/+/./g' `; do |
9636e806 JM |
474 | options_re="${options_re}${options_re:+|}${opt}" |
475 | done | |
476 | done | |
477 | options_re="^/((${options_re})/)*\$" | |
478 | ||
e7f49d92 TG |
479 | # Output rules used for multilib reuse. |
480 | echo "" | |
481 | echo "static const char *const multilib_reuse_raw[] = {" | |
482 | for rrule in ${multilib_reuse}; do | |
483 | # The left part of the rule are the options we used to build multilib. | |
484 | # The right part of the rule are the options that can reuse this multilib. | |
fa0b638f RE |
485 | combo=`echo ${rrule} | sed -e 's/=.*$//' -e 's/\([^\\]\)\./\1=/g' -e 's/\\\././g'` |
486 | copts=`echo ${rrule} | sed -e 's/^.*=//' -e 's/\([^\\]\)\./\1=/g' -e 's/\\\././g'` | |
e7f49d92 TG |
487 | # The variable ${combinations} are the option combinations we will build |
488 | # multilib from. If the combination in the left part of reuse rule isn't | |
489 | # in this variable, it means no multilib will be built for current reuse | |
490 | # rule. Thus the reuse purpose specified by current rule is meaningless. | |
491 | if expr "${combinations} " : ".*/${combo}/.*" > /dev/null; then | |
9636e806 | 492 | if echo "/${copts}/" | grep -E "${options_re}" > /dev/null; then |
0630b8ec | 493 | combo="/${combo}/" |
b5f04a4d | 494 | dirout=`${CONFIG_SHELL-/bin/sh} ./tmpmultilib3 "${combo}" "${todirnames}" "${toosdirnames}" "${enable_multilib}"` |
0630b8ec | 495 | copts="/${copts}/" |
b5f04a4d | 496 | optout=`${CONFIG_SHELL-/bin/sh} ./tmpmultilib4 "${copts}" "${options}"` |
0630b8ec | 497 | # Output the line with all appropriate matches. |
b5f04a4d | 498 | dirout="${dirout}" optout="${optout}" ${CONFIG_SHELL-/bin/sh} ./tmpmultilib2 |
0630b8ec TP |
499 | else |
500 | echo "The rule ${rrule} contains an option absent from MULTILIB_OPTIONS." >&2 | |
501 | exit 1 | |
502 | fi | |
e7f49d92 | 503 | else |
0630b8ec | 504 | echo "The rule ${rrule} is trying to reuse nonexistent multilib." >&2 |
e7f49d92 TG |
505 | exit 1 |
506 | fi | |
507 | done | |
508 | ||
509 | # Terminate the list of string. | |
510 | echo "NULL" | |
511 | echo "};" | |
512 | ||
961b7009 | 513 | # Output all of the matches now as option and that is the same as that, with |
31031edd | 514 | # a semicolon trailer. Include all of the normal options as well. |
961b7009 MM |
515 | # Note, the format of the matches is reversed compared |
516 | # to what we want, so switch them around. | |
517 | echo "" | |
3b304f5b | 518 | echo "static const char *const multilib_matches_raw[] = {" |
961b7009 MM |
519 | for match in ${matches}; do |
520 | l=`echo ${match} | sed -e 's/=.*$//' -e 's/?/=/g'` | |
521 | r=`echo ${match} | sed -e 's/^.*=//' -e 's/?/=/g'` | |
522 | echo "\"${r} ${l};\"," | |
523 | done | |
524 | for set in ${options}; do | |
699a42a6 | 525 | for opt in `echo ${set} | sed -e 's_[/|]_ _'g`; do |
961b7009 MM |
526 | echo "\"${opt} ${opt};\"," |
527 | done | |
528 | done | |
529 | echo "NULL" | |
530 | echo "};" | |
08b28cd3 | 531 | |
961b7009 MM |
532 | # Output the default options now |
533 | echo "" | |
3b304f5b | 534 | echo "static const char *multilib_extra = \"${extra}\";" |
0a8d6618 BC |
535 | |
536 | # Output the exclusion rules now | |
537 | echo "" | |
3b304f5b | 538 | echo "static const char *const multilib_exclusions_raw[] = {" |
0a8d6618 BC |
539 | for rule in ${exclusions}; do |
540 | s=`echo ${rule} | sed -e 's,/, ,g'` | |
541 | echo "\"${s};\"," | |
542 | done | |
543 | echo "NULL" | |
544 | echo "};" | |
545 | ||
5bbcd587 JJ |
546 | # Output the options now |
547 | moptions=`echo ${options} | sed -e 's,[ ][ ]*, ,g'` | |
548 | echo "" | |
549 | echo "static const char *multilib_options = \"${moptions}\";" | |
550 | ||
1713a69f EB |
551 | # Finally output the disable flag if specified |
552 | if [ "x${disable_multilib}" = xyes ]; then | |
553 | echo "" | |
554 | echo "#define DISABLE_MULTILIB 1" | |
555 | fi | |
556 | ||
c79d892f GK |
557 | cd .. |
558 | rm -r tmpmultilib.$$ | |
08b28cd3 DE |
559 | |
560 | exit 0 |