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

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