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