sort - Don't live-loop threads
[dragonfly.git] / contrib / gcc-4.7 / gcc / genmultilib
blob26acf4754a979464f2d4a9f6aaedab6ab62a2082
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 is the multiarch name.
78 # The last option should be "yes" if multilibs are enabled. If it is not
79 # "yes", all GCC multilib dir names will be ".".
81 # The output looks like
82 # #define MULTILIB_MATCHES "\
83 # SUBDIRECTORY OPTIONS;\
84 # ...
85 # "
86 # The SUBDIRECTORY is the subdirectory to use. The OPTIONS are
87 # multiple options separated by spaces. Each option may start with an
88 # exclamation point. gcc will consider each line in turn. If none of
89 # the options beginning with an exclamation point are present, and all
90 # of the other options are present, that subdirectory will be used.
91 # The order of the subdirectories is such that they can be created in
92 # order; that is, a subdirectory is preceded by all its parents.
94 # Here is an example (this is from the actual sparc64 case):
95 # genmultilib 'm64/m32 mno-app-regs|mcmodel=medany' '64 32 alt'
96 # 'mcmodel?medany=mcmodel?medmid' 'm32/mno-app-regs* m32/mcmodel=*'
97 # '' 'm32/!m64/mno-app-regs m32/!m64/mcmodel=medany'
98 # '../lib64 ../lib32 alt' yes
99 # This produces:
100 # ". !m64 !m32 !mno-app-regs !mcmodel=medany;",
101 # "64:../lib64 m64 !m32 !mno-app-regs !mcmodel=medany;",
102 # "32:../lib32 !m64 m32 !mno-app-regs !mcmodel=medany;",
103 # "alt !m64 !m32 mno-app-regs mcmodel=medany;",
104 # "alt !m64 !m32 mno-app-regs !mcmodel=medany;",
105 # "alt !m64 !m32 !mno-app-regs mcmodel=medany;",
106 # "64/alt:../lib64/alt m64 !m32 mno-app-regs mcmodel=medany;",
107 # "64/alt:../lib64/alt m64 !m32 mno-app-regs !mcmodel=medany;",
108 # "64/alt:../lib64/alt m64 !m32 !mno-app-regs mcmodel=medany;",
110 # The effect is that `gcc -mno-app-regs' (for example) will append "alt"
111 # to the directory name when searching for libraries or startup files and
112 # `gcc -m32 -mcmodel=medany' (for example) will append "32/alt". Also note
113 # that exclusion above is moot, unless the compiler had a default of -m32,
114 # which would mean that all of the "alt" directories (not the 64/alt ones)
115 # would be ignored (not generated, nor used) since the exclusion also
116 # matches the multilib_default args.
118 # Copy the positional parameters into variables.
119 options=$1
120 dirnames=$2
121 matches=$3
122 exceptions=$4
123 extra=$5
124 exclusions=$6
125 osdirnames=$7
126 multiarch=$8
127 enable_multilib=$9
129 echo "static const char *const multilib_raw[] = {"
131 mkdir tmpmultilib.$$ || exit 1
132 # Use cd ./foo to avoid CDPATH output.
133 cd ./tmpmultilib.$$ || exit 1
135 # What we want to do is select all combinations of the sets in
136 # options. Each combination which includes a set of mutually
137 # exclusive options must then be output multiple times, once for each
138 # item in the set. Selecting combinations is a recursive process.
139 # Since not all versions of sh support functions, we achieve recursion
140 # by creating a temporary shell script which invokes itself.
141 rm -f tmpmultilib
142 cat >tmpmultilib <<\EOF
143 #!/bin/sh
144 # This recursive script basically outputs all combinations of its
145 # input arguments, handling mutually exclusive sets of options by
146 # repetition. When the script is called, ${initial} is the list of
147 # options which should appear before all combinations this will
148 # output. The output looks like a list of subdirectory names with
149 # leading and trailing slashes.
150 if [ "$#" != "0" ]; then
151 first=$1
152 shift
153 case "$first" in
154 *\|*)
155 all=${initial}`echo $first | sed -e 's_|_/_'g`
156 first=`echo $first | sed -e 's_|_ _'g`
157 echo ${all}/
158 initial="${initial}${all}/" ./tmpmultilib $@
159 ./tmpmultilib $first $@ | grep -v "^${all}"
162 for opt in `echo $first | sed -e 's|/| |'g`; do
163 echo ${initial}${opt}/
164 done
165 ./tmpmultilib $@
166 for opt in `echo $first | sed -e 's|/| |'g`; do
167 initial="${initial}${opt}/" ./tmpmultilib $@
168 done
169 esac
172 chmod +x tmpmultilib
174 combinations=`initial=/ ./tmpmultilib ${options}`
176 # If there exceptions, weed them out now
177 if [ -n "${exceptions}" ]; then
178 cat >tmpmultilib2 <<\EOF
179 #!/bin/sh
180 # This recursive script weeds out any combination of multilib
181 # switches that should not be generated. The output looks like
182 # a list of subdirectory names with leading and trailing slashes.
184 for opt in $@; do
185 case "$opt" in
188 for except in ${exceptions}; do
189 echo " /${except}/) : ;;" >> tmpmultilib2
190 done
192 cat >>tmpmultilib2 <<\EOF
193 *) echo ${opt};;
194 esac
195 done
197 chmod +x tmpmultilib2
198 combinations=`./tmpmultilib2 ${combinations}`
201 # Construct a sed pattern which will convert option names to directory
202 # names.
203 todirnames=
204 if [ -n "${dirnames}" ]; then
205 set x ${dirnames}
206 shift
207 for set in ${options}; do
208 for opts in `echo ${set} | sed -e 's|/| |'g`; do
209 patt="/"
210 for opt in `echo ${opts} | sed -e 's_|_ _'g`; do
211 if [ "$1" != "${opt}" ]; then
212 todirnames="${todirnames} -e s|/${opt}/|/${1}/|g"
213 patt="${patt}${1}/"
214 if [ "${patt}" != "/${1}/" ]; then
215 todirnames="${todirnames} -e s|${patt}|/${1}/|g"
218 done
219 shift
220 done
221 done
224 # Construct a sed pattern which will convert option names to OS directory
225 # names.
226 toosdirnames=
227 defaultosdirname=
228 if [ -n "${multiarch}" ]; then
229 defaultosdirname=::${multiarch}
231 if [ -n "${osdirnames}" ]; then
232 set x ${osdirnames}
233 shift
234 while [ $# != 0 ] ; do
235 case "$1" in
236 .=*)
237 defaultosdirname=`echo $1 | sed 's|^.=|:|'`
238 if [ -n "${multiarch}" ]; then
239 defaultosdirname=${defaultosdirname}:${multiarch}
241 shift
243 *=*)
244 patt=`echo $1 | sed -e 's|=|/$=/|'`
245 toosdirnames="${toosdirnames} -e s=^/${patt}/="
246 shift
249 break
251 esac
252 done
254 if [ $# != 0 ]; then
255 for set in ${options}; do
256 for opts in `echo ${set} | sed -e 's|/| |'g`; do
257 patt="/"
258 for opt in `echo ${opts} | sed -e 's_|_ _'g`; do
259 if [ "$1" != "${opt}" ]; then
260 toosdirnames="${toosdirnames} -e s|/${opt}/|/${1}/|g"
261 patt="${patt}${1}/"
262 if [ "${patt}" != "/${1}/" ]; then
263 toosdirnames="${toosdirnames} -e s|${patt}|/${1}/|g"
266 done
267 shift
268 done
269 done
273 # We need another recursive shell script to correctly handle positive
274 # matches. If we are invoked as
275 # genmultilib "opt1 opt2" "" "opt1=nopt1 opt2=nopt2"
276 # we must output
277 # opt1/opt2 opt1 opt2
278 # opt1/opt2 nopt1 opt2
279 # opt1/opt2 opt1 nopt2
280 # opt1/opt2 nopt1 nopt2
281 # In other words, we must output all combinations of matches.
282 rm -f tmpmultilib2
283 cat >tmpmultilib2 <<\EOF
284 #!/bin/sh
285 # The positional parameters are a list of matches to consider.
286 # ${dirout} is the directory name and ${optout} is the current list of
287 # options.
288 if [ "$#" = "0" ]; then
289 echo "\"${dirout} ${optout};\","
290 else
291 first=$1
292 shift
293 dirout="${dirout}" optout="${optout}" ./tmpmultilib2 $@
294 l=`echo ${first} | sed -e 's/=.*$//' -e 's/?/=/g'`
295 r=`echo ${first} | sed -e 's/^.*=//' -e 's/?/=/g'`
296 if expr " ${optout} " : ".* ${l} .*" > /dev/null; then
297 newopt=`echo " ${optout} " | sed -e "s/ ${l} / ${r} /" -e 's/^ //' -e 's/ $//'`
298 dirout="${dirout}" optout="${newopt}" ./tmpmultilib2 $@
302 chmod +x tmpmultilib2
304 # Start with the current directory, which includes only negations.
305 optout=
306 for set in ${options}; do
307 for opt in `echo ${set} | sed -e 's_[/|]_ _g'`; do
308 optout="${optout} !${opt}"
309 done
310 done
311 optout=`echo ${optout} | sed -e 's/^ //'`
312 echo "\".${defaultosdirname} ${optout};\","
314 # Work over the list of combinations. We have to translate each one
315 # to use the directory names rather than the option names, we have to
316 # include the information in matches, and we have to generate the
317 # correct list of options and negations.
318 for combo in ${combinations}; do
319 # Use the directory names rather than the option names.
320 if [ -n "${todirnames}" ]; then
321 dirout=`echo ${combo} | sed ${todirnames}`
322 else
323 dirout=`echo ${combo} | sed -e 's/=/-/g'`
325 # Remove the leading and trailing slashes.
326 dirout=`echo ${dirout} | sed -e 's|^/||' -e 's|/*:/*|:|' -e 's|/$||g'`
328 # Use the OS directory names rather than the option names.
329 if [ -n "${toosdirnames}" ]; then
330 osdirout=`echo ${combo} | sed ${toosdirnames}`
331 # Remove the leading and trailing slashes.
332 osdirout=`echo ${osdirout} | sed -e 's|^/||' -e 's|/*:/*|:|' -e 's|/$||g'`
333 if [ "x${enable_multilib}" != xyes ]; then
334 dirout=".:${osdirout}"
335 disable_multilib=yes
336 else
337 case "${osdirout}" in
339 dirout=`echo ${osdirout} | sed 's/^!//'`
342 dirout="${dirout}:${osdirout}"
344 esac
346 else
347 if [ "x${enable_multilib}" != xyes ]; then
348 # genmultilib with --disable-multilib should be
349 # called with '' '' '' '' '' '' '' no
350 # if MULTILIB_OSDIRNAMES is empty.
351 exit 1
355 # Look through the options. We must output each option that is
356 # present, and negate each option that is not present.
357 optout=
358 for set in ${options}; do
359 setopts=`echo ${set} | sed -e 's_[/|]_ _g'`
360 for opt in ${setopts}; do
361 if expr "${combo} " : ".*/${opt}/.*" > /dev/null; then
362 optout="${optout} ${opt}"
363 else
364 optout="${optout} !${opt}"
366 done
367 done
368 optout=`echo ${optout} | sed -e 's/^ //'`
370 # Output the line with all appropriate matches.
371 dirout="${dirout}" optout="${optout}" ./tmpmultilib2
372 done
374 # Terminate the list of string.
375 echo "NULL"
376 echo "};"
378 # Output all of the matches now as option and that is the same as that, with
379 # a semicolon trailer. Include all of the normal options as well.
380 # Note, the format of the matches is reversed compared
381 # to what we want, so switch them around.
382 echo ""
383 echo "static const char *const multilib_matches_raw[] = {"
384 for match in ${matches}; do
385 l=`echo ${match} | sed -e 's/=.*$//' -e 's/?/=/g'`
386 r=`echo ${match} | sed -e 's/^.*=//' -e 's/?/=/g'`
387 echo "\"${r} ${l};\","
388 done
389 for set in ${options}; do
390 for opt in `echo ${set} | sed -e 's_[/|]_ _'g`; do
391 echo "\"${opt} ${opt};\","
392 done
393 done
394 echo "NULL"
395 echo "};"
397 # Output the default options now
398 echo ""
399 echo "static const char *multilib_extra = \"${extra}\";"
401 # Output the exclusion rules now
402 echo ""
403 echo "static const char *const multilib_exclusions_raw[] = {"
404 for rule in ${exclusions}; do
405 s=`echo ${rule} | sed -e 's,/, ,g'`
406 echo "\"${s};\","
407 done
408 echo "NULL"
409 echo "};"
411 # Output the options now
412 moptions=`echo ${options} | sed -e 's,[ ][ ]*, ,g'`
413 echo ""
414 echo "static const char *multilib_options = \"${moptions}\";"
416 # Finally output the disable flag if specified
417 if [ "x${disable_multilib}" = xyes ]; then
418 echo ""
419 echo "#define DISABLE_MULTILIB 1"
422 cd ..
423 rm -r tmpmultilib.$$
425 exit 0