Blame SOURCES/gts-annobin-plugin-select.sh

f99a1c
#!/usr/bin/sh
f99a1c
# This is a script to switch the symlinks in a GTS gcc's plugin
f99a1c
# directory so that they select either the GTS-annobin provided
f99a1c
# plugin or the GTS-gcc provided plugin.
f99a1c
f99a1c
# Author: Nick Clifton  <nickc@redhat.com>
f99a1c
# Copyright (c) 2021-2022 Red Hat.
f99a1c
#
f99a1c
# This is free software; you can redistribute it and/or modify it
f99a1c
# under the terms of the GNU General Public License as published
f99a1c
# by the Free Software Foundation; either version 2, or (at your
f99a1c
# option) any later version.
f99a1c
f99a1c
# It is distributed in the hope that it will be useful, but
f99a1c
# WITHOUT ANY WARRANTY; without even the implied warranty of
f99a1c
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f99a1c
# GNU General Public License for more details.
f99a1c
#
f99a1c
# Usage:
f99a1c
#   gts-annobin-plugin-select scl_root
f99a1c
#
f99a1c
f99a1c
# Set this variable to non-zero to enable the generation of debugging
f99a1c
# messages.
f99a1c
debug=0
f99a1c
f99a1c
if test "x$1" = "x" ;
f99a1c
then
f99a1c
    if [ $debug -eq 1 ]
f99a1c
    then
f99a1c
	echo "  gts-annobin-plugin-select: Must provide a root directory"
f99a1c
    fi
f99a1c
    exit 1
f99a1c
else
f99a1c
    scl_root=$1
f99a1c
fi
f99a1c
f99a1c
# This script is similar to the redhat-annobin-plugin-select.sh script which
f99a1c
# is part of the redhat-rpm-config package.  That scripts decides between two
f99a1c
# versions of the annobin plugin for the system compiler and stores it choice
f99a1c
# in a symlink in the /usr/lib/rpm/redhat directory.  The choice eventually
f99a1c
# resolves into the system gcc attempting to load either a plugin called
f99a1c
# annobin.so or a plugin called gcc-annobin.so.
f99a1c
f99a1c
# In a GTS environment the choice made by redhat-annobin-plugin-select.sh
f99a1c
# might not be appropriate (or even possible).  The choice cannot be changed
f99a1c
# because the system compilation environment must remain instact.  So instead
f99a1c
# the GTS versions of gcc and annobin install plugins called gts-annobin.so
f99a1c
# and gts-gcc-annobin.so (into the GTS gcc's plugin directory) and this script
f99a1c
# creates a pair of symlinks called annobin.so and gcc-annobin.so.  In this
f99a1c
# way the decision made by redhat-annobin-plugin-select.sh is overridden
f99a1c
# without affecting any system files.
f99a1c
f99a1c
# We cannot be sure that this script will run inside a GTS enabled shell,
f99a1c
# so we have to use absolute paths.
f99a1c
gts_gcc=$scl_root/usr/bin/gcc
f99a1c
f99a1c
if [ ! -x $gts_gcc ]
f99a1c
then
f99a1c
    if [ $debug -eq 1 ]
f99a1c
    then
f99a1c
	echo "  gts-annobin-plugin-select: Could not find gcc.  Expected: $gts_gcc"
f99a1c
    fi
f99a1c
    exit 0
f99a1c
fi
f99a1c
f99a1c
# This is where the annobin package stores the information on the version
f99a1c
# of gcc that built the annobin plugin.
f99a1c
aver=`$gts_gcc --print-file-name=plugin`/annobin-plugin-version-info
f99a1c
f99a1c
# This is where the gcc package stores its version information.
f99a1c
gver=`$gts_gcc --print-file-name=rpmver`
f99a1c
f99a1c
aplugin=`$gts_gcc --print-file-name=plugin`/gts-annobin.so.0.0.0
f99a1c
gplugin=`$gts_gcc --print-file-name=plugin`/gts-gcc-annobin.so.0.0.0
f99a1c
f99a1c
install_annobin_version=0
f99a1c
install_gcc_version=0
f99a1c
f99a1c
if [ -f $aplugin ]
f99a1c
then
f99a1c
    if [ -f $gplugin ]
f99a1c
    then
f99a1c
	if [ $debug -eq 1 ]
f99a1c
	then
f99a1c
	    echo "  gts-annobin-plugin-select: Both plugins exist, checking version information"
f99a1c
	fi
f99a1c
f99a1c
	if [ -f $gver ]
f99a1c
	then
f99a1c
	    if [ -f $aver ]
f99a1c
	    then
f99a1c
		if [ $debug -eq 1 ]
f99a1c
		then
f99a1c
		    echo "  gts-annobin-plugin-select: Both plugin version files exist - comparing..."
f99a1c
		fi
f99a1c
f99a1c
		# Get the first line from the version info files.  This is just in
f99a1c
		# case there are extra lines in the files.
f99a1c
		avers=`head --lines=1 $aver`
f99a1c
		gvers=`head --lines=1 $gver`
f99a1c
f99a1c
		if [ $debug -eq 1 ]
f99a1c
		then
f99a1c
		    echo "  gts-annobin-plugin-select: Annobin plugin built by gcc $avers"
f99a1c
		    echo "  gts-annobin-plugin-select: GCC     plugin built by gcc $gvers"
f99a1c
		fi
f99a1c
f99a1c
		# If both plugins were built by the same version of gcc then select
f99a1c
		# the one from the annobin package (in case it is built from newer
f99a1c
		# sources).  If the plugin builder versions differ, select the gcc
f99a1c
		# built version instead.  This assumes that the gcc built version
f99a1c
		# always matches the installed gcc, which should be true.
f99a1c
		if [ $avers = $gvers ]
f99a1c
		then
f99a1c
		    if [ $debug -eq 1 ]
f99a1c
		    then
f99a1c
			echo "  gts-annobin-plugin-select: Both plugins built by the same compiler - using annobin-built plugin"
f99a1c
		    fi
f99a1c
		    install_annobin_version=1
f99a1c
		else
f99a1c
		    if [ $debug -eq 1 ]
f99a1c
		    then
f99a1c
			echo "  gts-annobin-plugin-select: Versions differ - using gcc-built plugin"
f99a1c
		    fi
f99a1c
		    install_gcc_version=1
f99a1c
		fi
f99a1c
	    else
f99a1c
		if [ $debug -eq 1 ]
f99a1c
		then
f99a1c
		    echo "  gts-annobin-plugin-select: Annobin version file does not exist, using gcc-built plugin"
f99a1c
		fi
f99a1c
		install_gcc_version=1
f99a1c
	    fi
f99a1c
	else
f99a1c
	    if [ -f $aver ]
f99a1c
	    then
f99a1c
		# FIXME: This is suspicious.  If the installed GCC does not supports plugins
f99a1c
		# then enabling the annobin plugin will not work.
f99a1c
		if [ $debug -eq 1 ]
f99a1c
		then
f99a1c
		    echo "  gts-annobin-plugin-select: GCC plugin version file does not exist, using annobin-built plugin"
f99a1c
		fi
f99a1c
		install_annobin_version=1
f99a1c
	    else
f99a1c
		if [ $debug -eq 1 ]
f99a1c
		then
f99a1c
		    echo "  gts-annobin-plugin-select: Neither version file exists - playing safe and using gcc-built plugin"
f99a1c
		    echo "  gts-annobin-plugin-select: Note: expected to find $aver and/or $gver"
f99a1c
		fi
f99a1c
		install_gcc_version=1
f99a1c
	    fi
f99a1c
	fi
f99a1c
    else
f99a1c
	if [ $debug -eq 1 ]
f99a1c
	then
f99a1c
	    echo "  gts-annobin-plugin-select: Only the annobin plugin exists - using that"
f99a1c
	fi
f99a1c
	install_annobin_version=1
f99a1c
    fi
f99a1c
else
f99a1c
    if [ -f $gplugin ]
f99a1c
    then
f99a1c
	if [ $debug -eq 1 ]
f99a1c
	then
f99a1c
	    echo "  gts-annobin-plugin-select: Only the gcc plugin exists - using that"
f99a1c
	fi
f99a1c
	install_gcc_version=1
f99a1c
    else
f99a1c
	aplugin=`$gts_gcc --print-file-name=plugin`/annobin.so.0.0.0
f99a1c
f99a1c
	if [ -f $aplugin ]
f99a1c
	then
f99a1c
	    if [ $debug -eq 1 ]
f99a1c
	    then
f99a1c
		echo "  gts-annobin-plugin-select: Original annobin plugin exists - renaming"
f99a1c
		echo "  gts-annobin-plugin-select: Using renamed original annobin plugin"
f99a1c
	    fi
f99a1c
	    pushd `$gts_gcc --print-file-name=plugin` > /dev/null
f99a1c
	    mv annobin.so.0.0.0 gts-annobin.so.0.0.0
f99a1c
	    popd > /dev/null
f99a1c
	    install_annobin_version=1
f99a1c
	else
f99a1c
	    if [ $debug -eq 1 ]
f99a1c
	    then
f99a1c
		echo "  gts-annobin-plugin-select: Neither plugin exists - playing safe and not changing anything"
f99a1c
		echo "  gts-annobin-plugin-select: Note: expected to find $aplugin and/or $gplugin"
f99a1c
	    fi
f99a1c
	fi
f99a1c
    fi
f99a1c
fi
f99a1c
f99a1c
if [ $install_annobin_version -eq 1 ]
f99a1c
then
f99a1c
    if [ $debug -eq 1 ]
f99a1c
    then
f99a1c
	echo "  gts-annobin-plugin-select: Setting symlinks for the annobin version of the plugin"
f99a1c
    fi
f99a1c
    pushd `$gts_gcc --print-file-name=plugin` > /dev/null
f99a1c
    rm -f gcc-annobin.so.0.0.0 annobin.so.0.0.0 gcc-annobin.so annobin.so
f99a1c
    ln -s gts-annobin.so.0.0.0 annobin.so
f99a1c
    ln -s gts-annobin.so.0.0.0 gcc-annobin.so
f99a1c
    ln -s gts-annobin.so.0.0.0 annobin.so.0.0.0
f99a1c
    ln -s gts-annobin.so.0.0.0 gcc-annobin.so.0.0.0
f99a1c
    popd > /dev/null
f99a1c
    
f99a1c
else if [ $install_gcc_version -eq 1 ]
f99a1c
then
f99a1c
    if [ $debug -eq 1 ]
f99a1c
    then
f99a1c
	echo "  gts-annobin-plugin-select: Setting symlinks for the gcc version of the plugin"
f99a1c
    fi
f99a1c
    pushd `$gts_gcc --print-file-name=plugin` > /dev/null
f99a1c
    rm -f gcc-annobin.so.0.0.0     annobin.so.0.0.0 gcc-annobin.so annobin.so
f99a1c
    ln -s gts-gcc-annobin.so.0.0.0 annobin.so
f99a1c
    ln -s gts-gcc-annobin.so.0.0.0 gcc-annobin.so
f99a1c
    ln -s gts-gcc-annobin.so.0.0.0 annobin.so.0.0.0
f99a1c
    ln -s gts-gcc-annobin.so.0.0.0 gcc-annobin.so.0.0.0
f99a1c
    popd > /dev/null
f99a1c
else
f99a1c
    if [ $debug -eq 1 ]
f99a1c
    then
f99a1c
	echo "  gts-annobin-plugin-select: NOT CHANGING SYMLINKS"
f99a1c
    fi
f99a1c
fi
f99a1c
fi