* trans-mem.c (execute_tm_mark): Release bb_regions.
[official-gcc.git] / gcc / genmultilib
blob09b63465b26a6e35d7e91f256137085958ed62c5
1 #!/bin/sh
2 # Generates multilib.h.
3 # Copyright (C) 1994, 1995, 1996, 1997, 1999, 2002, 2007, 2012
4 # Free Software Foundation, Inc.
6 #This file is part of GCC.
8 #GCC is free software; you can redistribute it and/or modify it under
9 #the terms of the GNU General Public License as published by the Free
10 #Software Foundation; either version 3, or (at your option) any later
11 #version.
13 #GCC is distributed in the hope that it will be useful, but WITHOUT
14 #ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 #FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #for more details.
18 #You should have received a copy of the GNU General Public License
19 #along with GCC; see the file COPYING3. If not see
20 #<http://www.gnu.org/licenses/>.
22 # This shell script produces a header file which the gcc driver
23 # program uses to pick which library to use based on the machine
24 # specific options that it is given.
26 # The first argument is a list of sets of options. The elements in
27 # the list are separated by spaces. Within an element, the options
28 # are separated by slashes or pipes. No leading dash is used on the
29 # options.
30 # Each option in a set separated by slashes is mutually incompatible
31 # with all other options
32 # in the set.
33 # Each option in a set separated by pipes will be used for the library
34 # compilation and any of the options in the set will be sufficient
35 # for it to be triggered.
37 # The optional second argument is a list of subdirectory names. If
38 # the second argument is non-empty, there must be as many elements in
39 # the second argument as there are options in the first argument. The
40 # elements in the second list are separated by spaces. If the second
41 # argument is empty, the option names will be used as the directory
42 # names.
44 # The optional third argument is a list of options which are
45 # identical. The elements in the list are separated by spaces. Each
46 # element must be of the form OPTION=OPTION. The first OPTION should
47 # appear in the first argument, and the second should be a synonym for
48 # it. Question marks are replaced with equal signs in both options.
50 # The optional fourth argument is a list of multilib directory
51 # combinations that should not be built.
53 # The optional fifth argument is a list of options that should be
54 # used whenever building multilib libraries.
56 # The optional sixth argument is a list of exclusions used internally by
57 # the compiler similar to exceptions. The difference being that exclusions
58 # allow matching default options that genmultilib does not know about and
59 # is done at runtime as opposed to being sorted out at compile time.
60 # Each element in the list is a separate exclusion rule. Each rule is
61 # a list of options (sans preceding '-') separated by a '/'. The options
62 # on the rule are grouped as an AND operation, and all options much match
63 # for the rule to exclude a set. Options can be preceded with a '!' to
64 # match a logical NOT.
66 # The optional seventh argument is a list of OS subdirectory names.
67 # The format is either the same as of the second argument, or a set of
68 # mappings. When it is the same as the second argument, it describes
69 # the multilib directories using OS conventions, rather than GCC
70 # conventions. When it is a set of mappings of the form gccdir=osdir,
71 # the left side gives the GCC convention and the right gives the
72 # equivalent OS defined location. If the osdir part begins with a !,
73 # the os directory names are used exclusively. Use the mapping when
74 # there is no one-to-one equivalence between GCC levels and the OS.
76 # The optional eighth argument which intends to reduce the effort to write
77 # so many MULTILIB_EXCEPTIONS rules. This option defines a series of option
78 # combinations that we actually required.
79 # For some cases, the generated option combinations are far more than what
80 # we need, we have to write a lot of rules to screen out combinations we
81 # don't need. If we missed some rules, the unexpected libraries will be built.
82 # Now with this argument, one can simply give what combinations are needed.
83 # It is pretty straigtforward.
84 # This argument can be used together with MULTILIB_EXCEPTIONS and will take
85 # effect after the MULTILIB_EXCEPTIONS.
87 # The optional ninth argument is the multiarch name.
89 # The last option should be "yes" if multilibs are enabled. If it is not
90 # "yes", all GCC multilib dir names will be ".".
92 # The output looks like
93 # #define MULTILIB_MATCHES "\
94 # SUBDIRECTORY OPTIONS;\
95 # ...
96 # "
97 # The SUBDIRECTORY is the subdirectory to use. The OPTIONS are
98 # multiple options separated by spaces. Each option may start with an
99 # exclamation point. gcc will consider each line in turn. If none of
100 # the options beginning with an exclamation point are present, and all
101 # of the other options are present, that subdirectory will be used.
102 # The order of the subdirectories is such that they can be created in
103 # order; that is, a subdirectory is preceded by all its parents.
105 # Here is an example (this is from the actual sparc64 case):
106 # genmultilib 'm64/m32 mno-app-regs|mcmodel=medany' '64 32 alt'
107 # 'mcmodel?medany=mcmodel?medmid' 'm32/mno-app-regs* m32/mcmodel=*'
108 # '' 'm32/!m64/mno-app-regs m32/!m64/mcmodel=medany'
109 # '../lib64 ../lib32 alt' '' yes
110 # This produces:
111 # ". !m64 !m32 !mno-app-regs !mcmodel=medany;",
112 # "64:../lib64 m64 !m32 !mno-app-regs !mcmodel=medany;",
113 # "32:../lib32 !m64 m32 !mno-app-regs !mcmodel=medany;",
114 # "alt !m64 !m32 mno-app-regs mcmodel=medany;",
115 # "alt !m64 !m32 mno-app-regs !mcmodel=medany;",
116 # "alt !m64 !m32 !mno-app-regs mcmodel=medany;",
117 # "64/alt:../lib64/alt m64 !m32 mno-app-regs mcmodel=medany;",
118 # "64/alt:../lib64/alt m64 !m32 mno-app-regs !mcmodel=medany;",
119 # "64/alt:../lib64/alt m64 !m32 !mno-app-regs mcmodel=medany;",
121 # The effect is that `gcc -mno-app-regs' (for example) will append "alt"
122 # to the directory name when searching for libraries or startup files and
123 # `gcc -m32 -mcmodel=medany' (for example) will append "32/alt". Also note
124 # that exclusion above is moot, unless the compiler had a default of -m32,
125 # which would mean that all of the "alt" directories (not the 64/alt ones)
126 # would be ignored (not generated, nor used) since the exclusion also
127 # matches the multilib_default args.
129 # Copy the positional parameters into variables.
130 options=$1
131 dirnames=$2
132 matches=$3
133 exceptions=$4
134 extra=$5
135 exclusions=$6
136 osdirnames=$7
137 multilib_required=$8
138 multiarch=$9
139 enable_multilib=${10}
141 echo "static const char *const multilib_raw[] = {"
143 mkdir tmpmultilib.$$ || exit 1
144 # Use cd ./foo to avoid CDPATH output.
145 cd ./tmpmultilib.$$ || exit 1
147 # What we want to do is select all combinations of the sets in
148 # options. Each combination which includes a set of mutually
149 # exclusive options must then be output multiple times, once for each
150 # item in the set. Selecting combinations is a recursive process.
151 # Since not all versions of sh support functions, we achieve recursion
152 # by creating a temporary shell script which invokes itself.
153 rm -f tmpmultilib
154 cat >tmpmultilib <<\EOF
155 #!/bin/sh
156 # This recursive script basically outputs all combinations of its
157 # input arguments, handling mutually exclusive sets of options by
158 # repetition. When the script is called, ${initial} is the list of
159 # options which should appear before all combinations this will
160 # output. The output looks like a list of subdirectory names with
161 # leading and trailing slashes.
162 if [ "$#" != "0" ]; then
163 first=$1
164 shift
165 case "$first" in
166 *\|*)
167 all=${initial}`echo $first | sed -e 's_|_/_'g`
168 first=`echo $first | sed -e 's_|_ _'g`
169 echo ${all}/
170 initial="${initial}${all}/" ./tmpmultilib $@
171 ./tmpmultilib $first $@ | grep -v "^${all}"
174 for opt in `echo $first | sed -e 's|/| |'g`; do
175 echo ${initial}${opt}/
176 done
177 ./tmpmultilib $@
178 for opt in `echo $first | sed -e 's|/| |'g`; do
179 initial="${initial}${opt}/" ./tmpmultilib $@
180 done
181 esac
184 chmod +x tmpmultilib
186 combinations=`initial=/ ./tmpmultilib ${options}`
188 # If there exceptions, weed them out now
189 if [ -n "${exceptions}" ]; then
190 cat >tmpmultilib2 <<\EOF
191 #!/bin/sh
192 # This recursive script weeds out any combination of multilib
193 # switches that should not be generated. The output looks like
194 # a list of subdirectory names with leading and trailing slashes.
196 for opt in $@; do
197 case "$opt" in
200 for except in ${exceptions}; do
201 echo " /${except}/) : ;;" >> tmpmultilib2
202 done
204 cat >>tmpmultilib2 <<\EOF
205 *) echo ${opt};;
206 esac
207 done
209 chmod +x tmpmultilib2
210 combinations=`./tmpmultilib2 ${combinations}`
213 # If the MULTILIB_REQUIRED list are provided,
214 # filter out combinations not in this list.
215 if [ -n "${multilib_required}" ]; then
216 cat >tmpmultilib2 <<\EOF
217 #!/bin/sh
218 # This recursive script weeds out any combination of multilib
219 # switches that not in the expected list.
221 for opt in $@; do
222 case "$opt" in
225 for expect in ${multilib_required}; do
226 echo " /${expect}/) echo \${opt};;" >> tmpmultilib2
227 done
229 cat >>tmpmultilib2 <<\EOF
230 *) ;;
231 esac
232 done
235 chmod +x tmpmultilib2
236 combinations=`./tmpmultilib2 ${combinations}`
240 # Construct a sed pattern which will convert option names to directory
241 # names.
242 todirnames=
243 if [ -n "${dirnames}" ]; then
244 set x ${dirnames}
245 shift
246 for set in ${options}; do
247 for opts in `echo ${set} | sed -e 's|/| |'g`; do
248 patt="/"
249 for opt in `echo ${opts} | sed -e 's_|_ _'g`; do
250 if [ "$1" != "${opt}" ]; then
251 todirnames="${todirnames} -e s|/${opt}/|/${1}/|g"
252 patt="${patt}${1}/"
253 if [ "${patt}" != "/${1}/" ]; then
254 todirnames="${todirnames} -e s|${patt}|/${1}/|g"
257 done
258 shift
259 done
260 done
263 # Construct a sed pattern which will convert option names to OS directory
264 # names.
265 toosdirnames=
266 defaultosdirname=
267 if [ -n "${multiarch}" ]; then
268 defaultosdirname=::${multiarch}
270 if [ -n "${osdirnames}" ]; then
271 set x ${osdirnames}
272 shift
273 while [ $# != 0 ] ; do
274 case "$1" in
275 .=*)
276 defaultosdirname=`echo $1 | sed 's|^.=|:|'`
277 if [ -n "${multiarch}" ]; then
278 defaultosdirname=${defaultosdirname}:${multiarch}
280 shift
282 *=*)
283 patt=`echo $1 | sed -e 's|=|/$=/|'`
284 toosdirnames="${toosdirnames} -e s=^/${patt}/="
285 shift
288 break
290 esac
291 done
293 if [ $# != 0 ]; then
294 for set in ${options}; do
295 for opts in `echo ${set} | sed -e 's|/| |'g`; do
296 patt="/"
297 for opt in `echo ${opts} | sed -e 's_|_ _'g`; do
298 if [ "$1" != "${opt}" ]; then
299 toosdirnames="${toosdirnames} -e s|/${opt}/|/${1}/|g"
300 patt="${patt}${1}/"
301 if [ "${patt}" != "/${1}/" ]; then
302 toosdirnames="${toosdirnames} -e s|${patt}|/${1}/|g"
305 done
306 shift
307 done
308 done
312 # We need another recursive shell script to correctly handle positive
313 # matches. If we are invoked as
314 # genmultilib "opt1 opt2" "" "opt1=nopt1 opt2=nopt2"
315 # we must output
316 # opt1/opt2 opt1 opt2
317 # opt1/opt2 nopt1 opt2
318 # opt1/opt2 opt1 nopt2
319 # opt1/opt2 nopt1 nopt2
320 # In other words, we must output all combinations of matches.
321 rm -f tmpmultilib2
322 cat >tmpmultilib2 <<\EOF
323 #!/bin/sh
324 # The positional parameters are a list of matches to consider.
325 # ${dirout} is the directory name and ${optout} is the current list of
326 # options.
327 if [ "$#" = "0" ]; then
328 echo "\"${dirout} ${optout};\","
329 else
330 first=$1
331 shift
332 dirout="${dirout}" optout="${optout}" ./tmpmultilib2 $@
333 l=`echo ${first} | sed -e 's/=.*$//' -e 's/?/=/g'`
334 r=`echo ${first} | sed -e 's/^.*=//' -e 's/?/=/g'`
335 if expr " ${optout} " : ".* ${l} .*" > /dev/null; then
336 newopt=`echo " ${optout} " | sed -e "s/ ${l} / ${r} /" -e 's/^ //' -e 's/ $//'`
337 dirout="${dirout}" optout="${newopt}" ./tmpmultilib2 $@
341 chmod +x tmpmultilib2
343 # Start with the current directory, which includes only negations.
344 optout=
345 for set in ${options}; do
346 for opt in `echo ${set} | sed -e 's_[/|]_ _g'`; do
347 optout="${optout} !${opt}"
348 done
349 done
350 optout=`echo ${optout} | sed -e 's/^ //'`
351 echo "\".${defaultosdirname} ${optout};\","
353 # Work over the list of combinations. We have to translate each one
354 # to use the directory names rather than the option names, we have to
355 # include the information in matches, and we have to generate the
356 # correct list of options and negations.
357 for combo in ${combinations}; do
358 # Use the directory names rather than the option names.
359 if [ -n "${todirnames}" ]; then
360 dirout=`echo ${combo} | sed ${todirnames}`
361 else
362 dirout=`echo ${combo} | sed -e 's/=/-/g'`
364 # Remove the leading and trailing slashes.
365 dirout=`echo ${dirout} | sed -e 's|^/||' -e 's|/*:/*|:|' -e 's|/$||g'`
367 # Use the OS directory names rather than the option names.
368 if [ -n "${toosdirnames}" ]; then
369 osdirout=`echo ${combo} | sed ${toosdirnames}`
370 # Remove the leading and trailing slashes.
371 osdirout=`echo ${osdirout} | sed -e 's|^/||' -e 's|/*:/*|:|' -e 's|/$||g'`
372 if [ "x${enable_multilib}" != xyes ]; then
373 dirout=".:${osdirout}"
374 disable_multilib=yes
375 else
376 case "${osdirout}" in
378 dirout=`echo ${osdirout} | sed 's/^!//'`
381 dirout="${dirout}:${osdirout}"
383 esac
385 else
386 if [ "x${enable_multilib}" != xyes ]; then
387 # genmultilib with --disable-multilib should be
388 # called with '' '' '' '' '' '' '' no
389 # if MULTILIB_OSDIRNAMES is empty.
390 exit 1
394 # Look through the options. We must output each option that is
395 # present, and negate each option that is not present.
396 optout=
397 for set in ${options}; do
398 setopts=`echo ${set} | sed -e 's_[/|]_ _g'`
399 for opt in ${setopts}; do
400 if expr "${combo} " : ".*/${opt}/.*" > /dev/null; then
401 optout="${optout} ${opt}"
402 else
403 optout="${optout} !${opt}"
405 done
406 done
407 optout=`echo ${optout} | sed -e 's/^ //'`
409 # Output the line with all appropriate matches.
410 dirout="${dirout}" optout="${optout}" ./tmpmultilib2
411 done
413 # Terminate the list of string.
414 echo "NULL"
415 echo "};"
417 # Output all of the matches now as option and that is the same as that, with
418 # a semicolon trailer. Include all of the normal options as well.
419 # Note, the format of the matches is reversed compared
420 # to what we want, so switch them around.
421 echo ""
422 echo "static const char *const multilib_matches_raw[] = {"
423 for match in ${matches}; do
424 l=`echo ${match} | sed -e 's/=.*$//' -e 's/?/=/g'`
425 r=`echo ${match} | sed -e 's/^.*=//' -e 's/?/=/g'`
426 echo "\"${r} ${l};\","
427 done
428 for set in ${options}; do
429 for opt in `echo ${set} | sed -e 's_[/|]_ _'g`; do
430 echo "\"${opt} ${opt};\","
431 done
432 done
433 echo "NULL"
434 echo "};"
436 # Output the default options now
437 echo ""
438 echo "static const char *multilib_extra = \"${extra}\";"
440 # Output the exclusion rules now
441 echo ""
442 echo "static const char *const multilib_exclusions_raw[] = {"
443 for rule in ${exclusions}; do
444 s=`echo ${rule} | sed -e 's,/, ,g'`
445 echo "\"${s};\","
446 done
447 echo "NULL"
448 echo "};"
450 # Output the options now
451 moptions=`echo ${options} | sed -e 's,[ ][ ]*, ,g'`
452 echo ""
453 echo "static const char *multilib_options = \"${moptions}\";"
455 # Finally output the disable flag if specified
456 if [ "x${disable_multilib}" = xyes ]; then
457 echo ""
458 echo "#define DISABLE_MULTILIB 1"
461 cd ..
462 rm -r tmpmultilib.$$
464 exit 0