#!/bin/sh
# Generates multilib.h.
-# Copyright (C) 1994, 1995, 1996, 1997, 1999, 2002 Free Software Foundation, Inc.
+# Copyright (C) 1994-2024 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, 51 Franklin Street, Fifth Floor, Boston, MA
-#02110-1301, 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
# 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 optional tenth argument specifies how to reuse multilib for different
+# option sets.
+
# 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
+multilib_reuse=${10}
+enable_multilib=${11}
echo "static const char *const multilib_raw[] = {"
all=${initial}`echo $first | sed -e 's_|_/_'g`
first=`echo $first | sed -e 's_|_ _'g`
echo ${all}/
- initial="${initial}${all}/" ./tmpmultilib $@
- ./tmpmultilib $first $@ | grep -v "^${all}"
+ initial="${initial}${all}/" ${CONFIG_SHELL-/bin/sh} ./tmpmultilib $@
+ ${CONFIG_SHELL-/bin/sh} ./tmpmultilib $first $@ | grep -v "^${all}"
;;
*)
for opt in `echo $first | sed -e 's|/| |'g`; do
echo ${initial}${opt}/
done
- ./tmpmultilib $@
+ ${CONFIG_SHELL-/bin/sh} ./tmpmultilib $@
for opt in `echo $first | sed -e 's|/| |'g`; do
- initial="${initial}${opt}/" ./tmpmultilib $@
+ initial="${initial}${opt}/" ${CONFIG_SHELL-/bin/sh} ./tmpmultilib $@
done
esac
fi
EOF
chmod +x tmpmultilib
-combinations=`initial=/ ./tmpmultilib ${options}`
+combinations=`initial=/ ${CONFIG_SHELL-/bin/sh} ./tmpmultilib ${options}`
# If there exceptions, weed them out now
if [ -n "${exceptions}" ]; then
done
EOF
chmod +x tmpmultilib2
- combinations=`./tmpmultilib2 ${combinations}`
+ combinations=`${CONFIG_SHELL-/bin/sh} ./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=`${CONFIG_SHELL-/bin/sh} ./tmpmultilib2 ${combinations}`
+
fi
# Construct a sed pattern which will convert option names to directory
for opts in `echo ${set} | sed -e 's|/| |'g`; do
patt="/"
for opt in `echo ${opts} | sed -e 's_|_ _'g`; do
+ if [ -z "$1" ]; then
+ echo 1>&2 "Error calling $0: No dirname for option: $opt"
+ exit 1
+ fi
if [ "$1" != "${opt}" ]; then
todirnames="${todirnames} -e s|/${opt}/|/${1}/|g"
patt="${patt}${1}/"
# names.
toosdirnames=
defaultosdirname=
+defaultosdirname2=
+if [ -n "${multiarch}" ]; then
+ defaultosdirname=::${multiarch}
+fi
if [ -n "${osdirnames}" ]; then
set x ${osdirnames}
shift
case "$1" in
.=*)
defaultosdirname=`echo $1 | sed 's|^.=|:|'`
+ if [ -n "${multiarch}" ]; then
+ defaultosdirname=${defaultosdirname}:${multiarch}
+ fi
+ case "$defaultosdirname" in
+ ::*) ;;
+ *)
+ defaultosdirname2=${defaultosdirname}
+ defaultosdirname=
+ ;;
+ esac
shift
;;
*=*)
for opts in `echo ${set} | sed -e 's|/| |'g`; do
patt="/"
for opt in `echo ${opts} | sed -e 's_|_ _'g`; do
+ if [ -z "$1" ]; then
+ echo 1>&2 "Error calling $0: No osdirname for option: $opt"
+ exit 1
+ fi
if [ "$1" != "${opt}" ]; then
toosdirnames="${toosdirnames} -e s|/${opt}/|/${1}/|g"
patt="${patt}${1}/"
else
first=$1
shift
- dirout="${dirout}" optout="${optout}" ./tmpmultilib2 $@
+ dirout="${dirout}" optout="${optout}" ${CONFIG_SHELL-/bin/sh} ./tmpmultilib2 $@
l=`echo ${first} | sed -e 's/=.*$//' -e 's/?/=/g'`
r=`echo ${first} | sed -e 's/^.*=//' -e 's/?/=/g'`
if expr " ${optout} " : ".* ${l} .*" > /dev/null; then
newopt=`echo " ${optout} " | sed -e "s/ ${l} / ${r} /" -e 's/^ //' -e 's/ $//'`
- dirout="${dirout}" optout="${newopt}" ./tmpmultilib2 $@
+ dirout="${dirout}" optout="${newopt}" ${CONFIG_SHELL-/bin/sh} ./tmpmultilib2 $@
fi
fi
EOF
done
optout=`echo ${optout} | sed -e 's/^ //'`
echo "\".${defaultosdirname} ${optout};\","
+[ -n "${defaultosdirname2}" ] && echo "\".${defaultosdirname2} ${optout};\","
+
+# This part of code convert an option combination to
+# its corresponding directory names.
+# The directory names will be deduced from MULTILIB_DIRNAMES,
+# MULTILIB_OSDIRNAMES or the option combination itself.
+rm -rf tmpmultilib3
+cat >tmpmultilib3 <<\EOF
+#!/bin/sh
+
+dirout=
+combo=$1
+todirnames=$2
+toosdirnames=$3
+enable_multilib=$4
+
+if [ -n "${todirnames}" ]; then
+ dirout=`echo ${combo} | sed ${todirnames}`
+else
+ dirout=`echo ${combo} | sed -e 's/=/-/g'`
+fi
+# Remove the leading and trailing slashes.
+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|/*:/*|:|' -e 's|/$||g'`
+ if [ "x${enable_multilib}" != xyes ]; then
+ dirout=".:${osdirout}"
+ disable_multilib=yes
+ else
+ case "${osdirout}" in
+ !*)
+ dirout=`echo ${osdirout} | sed 's/^!//'`
+ ;;
+ *)
+ dirout="${dirout}:${osdirout}"
+ ;;
+ esac
+ fi
+else
+ if [ "x${enable_multilib}" != xyes ]; then
+ # genmultilib with --disable-multilib should be
+ # called with '' '' '' '' '' '' '' no
+ # if MULTILIB_OSDIRNAMES is empty.
+ exit 1
+ fi
+fi
+echo "${dirout}"
+EOF
+chmod +x tmpmultilib3
+
+# Script to look through the options and output each option that is present,
+# and negate each option that is not present.
+rm -rf tmpmultilib4
+cat > tmpmultilib4 <<\EOF
+#!/bin/sh
+
+optout=
+combo=$1
+options=$2
+
+for set in ${options}; do
+ setopts=`echo ${set} | sed -e 's_[/|]_ _g'`
+ for opt in ${setopts}; do
+ if expr "${combo} " : ".*/${opt}/.*" > /dev/null; then
+ optout="${optout} ${opt}"
+ else
+ optout="${optout} !${opt}"
+ fi
+ done
+done
+optout=`echo ${optout} | sed -e 's/^ //'`
+echo "${optout}"
+EOF
+chmod +x tmpmultilib4
# 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
# correct list of options and negations.
for combo in ${combinations}; do
# Use the directory names rather than the option names.
- if [ -n "${todirnames}" ]; then
- dirout=`echo ${combo} | sed ${todirnames}`
- else
- dirout=`echo ${combo} | sed -e 's/=/-/g'`
- fi
- # Remove the leading and trailing slashes.
- dirout=`echo ${dirout} | sed -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'`
- if [ "x${enable_multilib}" != xyes ]; then
- dirout=".:${osdirout}"
- disable_multilib=yes
- else
- case "${osdirout}" in
- !*)
- dirout=`echo ${osdirout} | sed 's/^!//'`
- ;;
- *)
- dirout="${dirout}:${osdirout}"
- ;;
- esac
- fi
- else
- if [ "x${enable_multilib}" != xyes ]; then
- # genmultilib with --disable-multilib should be
- # called with '' '' '' '' '' '' '' no
- # if MULTILIB_OSDIRNAMES is empty.
- exit 1
- fi
- fi
+ dirout=`${CONFIG_SHELL-/bin/sh} ./tmpmultilib3 "${combo}" "${todirnames}" "${toosdirnames}" "${enable_multilib}"`
# Look through the options. We must output each option that is
# present, and negate each option that is not present.
- optout=
- for set in ${options}; do
- setopts=`echo ${set} | sed -e 's_[/|]_ _g'`
- for opt in ${setopts}; do
- if expr "${combo} " : ".*/${opt}/.*" > /dev/null; then
- optout="${optout} ${opt}"
- else
- optout="${optout} !${opt}"
- fi
- done
- done
- optout=`echo ${optout} | sed -e 's/^ //'`
+ optout=`${CONFIG_SHELL-/bin/sh} ./tmpmultilib4 "${combo}" "${options}"`
# Output the line with all appropriate matches.
- dirout="${dirout}" optout="${optout}" ./tmpmultilib2
+ dirout="${dirout}" optout="${optout}" ${CONFIG_SHELL-/bin/sh} ./tmpmultilib2
+done
+
+# Terminate the list of string.
+echo "NULL"
+echo "};"
+
+# Generate a regular expression to validate option combinations.
+options_re=
+for set in ${options}; do
+ for opt in `echo ${set} | sed -e 's_[/|]_ _g' -e 's/+/./g' `; do
+ options_re="${options_re}${options_re:+|}${opt}"
+ done
+done
+options_re="^/((${options_re})/)*\$"
+
+# Output rules used for multilib reuse.
+echo ""
+echo "static const char *const multilib_reuse_raw[] = {"
+for rrule in ${multilib_reuse}; do
+ # The left part of the rule are the options we used to build multilib.
+ # The right part of the rule are the options that can reuse this multilib.
+ combo=`echo ${rrule} | sed -e 's/=.*$//' -e 's/\([^\\]\)\./\1=/g' -e 's/\\\././g'`
+ copts=`echo ${rrule} | sed -e 's/^.*=//' -e 's/\([^\\]\)\./\1=/g' -e 's/\\\././g'`
+ # The variable ${combinations} are the option combinations we will build
+ # multilib from. If the combination in the left part of reuse rule isn't
+ # in this variable, it means no multilib will be built for current reuse
+ # rule. Thus the reuse purpose specified by current rule is meaningless.
+ if expr "${combinations} " : ".*/${combo}/.*" > /dev/null; then
+ if echo "/${copts}/" | grep -E "${options_re}" > /dev/null; then
+ combo="/${combo}/"
+ dirout=`${CONFIG_SHELL-/bin/sh} ./tmpmultilib3 "${combo}" "${todirnames}" "${toosdirnames}" "${enable_multilib}"`
+ copts="/${copts}/"
+ optout=`${CONFIG_SHELL-/bin/sh} ./tmpmultilib4 "${copts}" "${options}"`
+ # Output the line with all appropriate matches.
+ dirout="${dirout}" optout="${optout}" ${CONFIG_SHELL-/bin/sh} ./tmpmultilib2
+ else
+ echo "The rule ${rrule} contains an option absent from MULTILIB_OPTIONS." >&2
+ exit 1
+ fi
+ else
+ echo "The rule ${rrule} is trying to reuse nonexistent multilib." >&2
+ exit 1
+ fi
done
# Terminate the list of string.