#!/bin/sh
# Generates multilib.h.
-# Copyright (C) 1994, 1995, 1996, 1997, 1999, 2002 Free Software Foundation, Inc.
+# Copyright (C) 1994, 1995, 1996, 1997, 1999, 2002, 2007, 2012
+# Free Software Foundation, Inc.
#This file is part of GCC.
#GCC is free software; you can redistribute it and/or modify it under
#the terms of the GNU General Public License as published by the Free
-#Software Foundation; either version 2, or (at your option) any later
+#Software Foundation; either version 3, or (at your option) any later
#version.
#GCC is distributed in the hope that it will be useful, but WITHOUT
#for more details.
#You should have received a copy of the GNU General Public License
-#along with GCC; see the file COPYING. If not, write to the Free
-#Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-#02111-1307, USA.
+#along with GCC; see the file COPYING3. If not see
+#<http://www.gnu.org/licenses/>.
# This shell script produces a header file which the gcc driver
# program uses to pick which library to use based on the machine
# for the rule to exclude a set. Options can be preceded with a '!' to
# match a logical NOT.
-# The optional sevenths argument is a list of OS subdirectory names.
-# The format is the same as of the second argument.
-# The difference is that second argument describes multilib directories
-# in GCC conventions, while this one the OS multilib convention.
+# The optional seventh argument is a list of OS subdirectory names.
+# The format is either the same as of the second argument, or a set of
+# mappings. When it is the same as the second argument, it describes
+# the multilib directories using OS conventions, rather than GCC
+# conventions. When it is a set of mappings of the form gccdir=osdir,
+# the left side gives the GCC convention and the right gives the
+# equivalent OS defined location. If the osdir part begins with a !,
+# the os directory names are used exclusively. Use the mapping when
+# there is no one-to-one equivalence between GCC levels and the OS.
+
+# The optional eighth argument which intends to reduce the effort to write
+# so many MULTILIB_EXCEPTIONS rules. This option defines a series of option
+# combinations that we actually required.
+# For some cases, the generated option combinations are far more than what
+# we need, we have to write a lot of rules to screen out combinations we
+# don't need. If we missed some rules, the unexpected libraries will be built.
+# Now with this argument, one can simply give what combinations are needed.
+# It is pretty straigtforward.
+# This argument can be used together with MULTILIB_EXCEPTIONS and will take
+# effect after the MULTILIB_EXCEPTIONS.
+
+# The optional ninth argument is the multiarch name.
# The last option should be "yes" if multilibs are enabled. If it is not
# "yes", all GCC multilib dir names will be ".".
# genmultilib 'm64/m32 mno-app-regs|mcmodel=medany' '64 32 alt'
# 'mcmodel?medany=mcmodel?medmid' 'm32/mno-app-regs* m32/mcmodel=*'
# '' 'm32/!m64/mno-app-regs m32/!m64/mcmodel=medany'
-# '../lib64 ../lib32 alt' yes
+# '../lib64 ../lib32 alt' '' yes
# This produces:
# ". !m64 !m32 !mno-app-regs !mcmodel=medany;",
# "64:../lib64 m64 !m32 !mno-app-regs !mcmodel=medany;",
extra=$5
exclusions=$6
osdirnames=$7
-enable_multilib=$8
+multilib_required=$8
+multiarch=$9
+enable_multilib=${10}
echo "static const char *const multilib_raw[] = {"
mkdir tmpmultilib.$$ || exit 1
-cd tmpmultilib.$$ || exit 1
+# Use cd ./foo to avoid CDPATH output.
+cd ./tmpmultilib.$$ || exit 1
# What we want to do is select all combinations of the sets in
# options. Each combination which includes a set of mutually
combinations=`./tmpmultilib2 ${combinations}`
fi
+# If the MULTILIB_REQUIRED list are provided,
+# filter out combinations not in this list.
+if [ -n "${multilib_required}" ]; then
+ cat >tmpmultilib2 <<\EOF
+#!/bin/sh
+# This recursive script weeds out any combination of multilib
+# switches that not in the expected list.
+
+ for opt in $@; do
+ case "$opt" in
+EOF
+
+ for expect in ${multilib_required}; do
+ echo " /${expect}/) echo \${opt};;" >> tmpmultilib2
+ done
+
+cat >>tmpmultilib2 <<\EOF
+ *) ;;
+ esac
+ done
+EOF
+
+ chmod +x tmpmultilib2
+ combinations=`./tmpmultilib2 ${combinations}`
+
+fi
+
# Construct a sed pattern which will convert option names to directory
# names.
todirnames=
# Construct a sed pattern which will convert option names to OS directory
# names.
toosdirnames=
+defaultosdirname=
+if [ -n "${multiarch}" ]; then
+ defaultosdirname=::${multiarch}
+fi
if [ -n "${osdirnames}" ]; then
set x ${osdirnames}
shift
- for set in ${options}; do
- for opts in `echo ${set} | sed -e 's|/| |'g`; do
- patt="/"
- for opt in `echo ${opts} | sed -e 's_|_ _'g`; do
- if [ "$1" != "${opt}" ]; then
- toosdirnames="${toosdirnames} -e s|/${opt}/|/${1}/|g"
- patt="${patt}${1}/"
- if [ "${patt}" != "/${1}/" ]; then
- toosdirnames="${toosdirnames} -e s|${patt}|/${1}/|g"
+ while [ $# != 0 ] ; do
+ case "$1" in
+ .=*)
+ defaultosdirname=`echo $1 | sed 's|^.=|:|'`
+ if [ -n "${multiarch}" ]; then
+ defaultosdirname=${defaultosdirname}:${multiarch}
+ fi
+ shift
+ ;;
+ *=*)
+ patt=`echo $1 | sed -e 's|=|/$=/|'`
+ toosdirnames="${toosdirnames} -e s=^/${patt}/="
+ shift
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
+
+ if [ $# != 0 ]; then
+ for set in ${options}; do
+ for opts in `echo ${set} | sed -e 's|/| |'g`; do
+ patt="/"
+ for opt in `echo ${opts} | sed -e 's_|_ _'g`; do
+ if [ "$1" != "${opt}" ]; then
+ toosdirnames="${toosdirnames} -e s|/${opt}/|/${1}/|g"
+ patt="${patt}${1}/"
+ if [ "${patt}" != "/${1}/" ]; then
+ toosdirnames="${toosdirnames} -e s|${patt}|/${1}/|g"
+ fi
fi
- fi
+ done
+ shift
done
- shift
done
- done
+ fi
fi
# We need another recursive shell script to correctly handle positive
done
done
optout=`echo ${optout} | sed -e 's/^ //'`
-echo "\". ${optout};\","
+echo "\".${defaultosdirname} ${optout};\","
# Work over the list of combinations. We have to translate each one
# to use the directory names rather than the option names, we have to
if [ -n "${todirnames}" ]; then
dirout=`echo ${combo} | sed ${todirnames}`
else
- dirout=${combo}
+ dirout=`echo ${combo} | sed -e 's/=/-/g'`
fi
# Remove the leading and trailing slashes.
- dirout=`echo ${dirout} | sed -e 's|^/||' -e 's|/$||g'`
+ dirout=`echo ${dirout} | sed -e 's|^/||' -e 's|/*:/*|:|' -e 's|/$||g'`
# Use the OS directory names rather than the option names.
if [ -n "${toosdirnames}" ]; then
osdirout=`echo ${combo} | sed ${toosdirnames}`
# Remove the leading and trailing slashes.
- osdirout=`echo ${osdirout} | sed -e 's|^/||' -e 's|/$||g'`
+ osdirout=`echo ${osdirout} | sed -e 's|^/||' -e 's|/*:/*|:|' -e 's|/$||g'`
if [ "x${enable_multilib}" != xyes ]; then
dirout=".:${osdirout}"
+ disable_multilib=yes
else
- dirout="${dirout}:${osdirout}"
+ case "${osdirout}" in
+ !*)
+ dirout=`echo ${osdirout} | sed 's/^!//'`
+ ;;
+ *)
+ dirout="${dirout}:${osdirout}"
+ ;;
+ esac
fi
else
if [ "x${enable_multilib}" != xyes ]; then
echo ""
echo "static const char *multilib_options = \"${moptions}\";"
+# Finally output the disable flag if specified
+if [ "x${disable_multilib}" = xyes ]; then
+ echo ""
+ echo "#define DISABLE_MULTILIB 1"
+fi
+
cd ..
rm -r tmpmultilib.$$