/var/lib/sorcery/modules/libgcc

     1	#!/bin/bash
     2	#---------------------------------------------------------------------
     3	##
     4	## @Synopsis Set of functions for dealing with the problem of having to
     5	## @Synopsis use different version of the gcc compilers.
     6	##
     7	## The basic usage is as follows:
     8	## <pre>
     9	## - If a spell works with the latest version of gcc, do nothing.
    10	## - To change the compiler version for a spell, add a GCC_VERSION field
    11	##   to the spells DETAILS specifying major.minor version of gcc it needs,
    12	##   e.g. GCC_VERSION=3.4
    13	## - add a 'depends  gccXX' to the spell where XX == majorminor,
    14	##   e.g. 'depends  gcc34'
    15	## - add 'invoke_gcc' to the top of PRE_BUILD if the spell has a
    16	##   custom PRE_BUILD file
    17	## </pre>
    18	##
    19	## @Implementation These functions were added to allow the use of
    20	## @Implementation several versions of gcc in parallel.
    21	##
    22	##
    23	##  @Copyright Copyright 2005 by the Source Mage Team
    24	##
    25	##
    26	#---------------------------------------------------------------------
    27	
    28	#---------------------------------------------------------------------
    29	## @param gcc version (digits and dots, followed by an optional +)
    30	## @return 0 if the version of the installed gcc that will be used is equal
    31	##             to the passed version
    32	## @return 0 if the parameter is of the form "version+" and the version of the
    33	##             installed gcc is at least "version"
    34	## @return 1 otherwise
    35	#---------------------------------------------------------------------
    36	function real_using_gcc()  {
    37	  local needed_version=${1%+}
    38	  local installed_version=$(gcc -dumpversion)
    39	
    40	  if [[ "$needed_version" == "$1" ]]; then
    41	    grep -qE "^$(esc_str $needed_version)(\.0)*$" <<< "$installed_version"
    42	  else
    43	    local i=0 needed_version2 installed_version2
    44	    explode "$needed_version" . needed_version2
    45	    explode "$installed_version" . installed_version2
    46	
    47	    while [[ ${needed_version2[$i]} ]] || [[ ${installed_version2[$i]} ]]; do
    48	      if [[ ${needed_version2[$i]:-0} == ${installed_version2[$i]:-0} ]]; then
    49	        let i++
    50	        continue
    51	      fi
    52	      # capturing the return value of arithmetic comparison inverts it
    53	      return $(( ${needed_version2[$i]:-0} > ${installed_version2[$i]:-0} ))
    54	    done
    55	  fi
    56	}
    57	
    58	#---------------------------------------------------------------------
    59	## @param path
    60	##
    61	## Alters the environment so that the gcc in the specified directory
    62	## will be used for compiling
    63	##
    64	#---------------------------------------------------------------------
    65	function gcc_add_paths()  {
    66	  export PATH=$(envar_prepend_path $1/bin $PATH)
    67	  export LD_LIBRARY_PATH=$(envar_prepend_path $1/lib $LD_LIBRARY_PATH)
    68	  export LD_RUN_PATH=$(envar_prepend_path $1/lib $LD_RUN_PATH)
    69	  export INFOPATH=$(envar_prepend_path $1/info $INFOPATH)
    70	  export CPPFLAGS="-I $1/include  $CPPFLAGS"
    71	}
    72	
    73	#---------------------------------------------------------------------
    74	##
    75	## Determines if the spell specifies a gcc version to use. If so, it
    76	## alters the environment so that that gcc version is used for compilation.
    77	##
    78	#---------------------------------------------------------------------
    79	function invoke_gcc()  {
    80	  # $GCC_VERSION contains only two of the version fields, but any patchlevel
    81	  # will do, so we pass a regex to the otherwise stricter real_using_gcc
    82	  if [[ $GCC_VERSION ]] && ! real_using_gcc "$GCC_VERSION(\.[0-9])?"; then
    83	    gcc_add_paths /opt/gcc${GCC_VERSION//.}
    84	  elif [[ -f $SCRIPT_DIRECTORY/USEGCC2 ]]; then
    85	    gcc_add_paths /opt/gcc2
    86	  fi
    87	  echo  "Using gcc version: $(gcc -dumpversion)"
    88	}
    89	
    90	# backward compatibility functions; currently still used in archspecs,
    91	# since they were part of sorcery before
    92	function use_gcc() {
    93	  real_using_gcc "$@"
    94	}
    95	function use_gcc2() {
    96	  real_using_gcc 2.95
    97	}
    98	
    99	#---------------------------------------------------------------------
   100	##
   101	## This software is free software; you can redistribute it and/or modify
   102	## it under the terms of the GNU General Public License as published by
   103	## the Free Software Foundation; either version 2 of the License, or
   104	## (at your option) any later version.
   105	##
   106	## This software is distributed in the hope that it will be useful,
   107	## but WITHOUT ANY WARRANTY; without even the implied warranty of
   108	## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   109	## GNU General Public License for more details.
   110	##
   111	## You should have received a copy of the GNU General Public License
   112	## along with this software; if not, write to the Free Software
   113	## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   114	##
   115	#---------------------------------------------------------------------