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

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