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

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