1#!/usr/local/bin/python3.8 2 3# @HEADER 4# ************************************************************************ 5# 6# TriBITS: Tribal Build, Integrate, and Test System 7# Copyright 2013 Sandia Corporation 8# 9# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 10# the U.S. Government retains certain rights in this software. 11# 12# Redistribution and use in source and binary forms, with or without 13# modification, are permitted provided that the following conditions are 14# met: 15# 16# 1. Redistributions of source code must retain the above copyright 17# notice, this list of conditions and the following disclaimer. 18# 19# 2. Redistributions in binary form must reproduce the above copyright 20# notice, this list of conditions and the following disclaimer in the 21# documentation and/or other materials provided with the distribution. 22# 23# 3. Neither the name of the Corporation nor the names of the 24# contributors may be used to endorse or promote products derived from 25# this software without specific prior written permission. 26# 27# THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 28# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 31# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 32# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 33# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 34# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 35# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38# 39# ************************************************************************ 40# @HEADER 41 42 43# 44# Defaults 45# 46 47gccBaseName = "gcc" 48gccDefaultVersion = "4.8.3" 49gccSupportedVersions = ["4.8.3"] 50 51# 52# Script code 53# 54 55 56from InstallProgramDriver import * 57from GeneralScriptSupport import * 58 59 60class GccInstall: 61 62 def __init__(self): 63 self.dummy = None 64 65 # 66 # Called before even knowing the product version 67 # 68 69 def getScriptName(self): 70 return "install-gcc.py" 71 72 def getProductBaseName(self): 73 return gccBaseName 74 75 def getProductDefaultVersion(self): 76 return gccDefaultVersion 77 78 def getProductSupportedVersions(self): 79 return gccSupportedVersions 80 81 # 82 # Called after knowing the product version but before parsing the 83 # command-line. 84 # 85 86 def getProductName(self, version): 87 return gccBaseName+"-"+version 88 89 def getBaseDirName(self, version): 90 return gccBaseName+"-"+version+"-base" 91 92 def getExtraHelpStr(self, version): 93 return """ 94This script builds """+self.getProductName(version)+""" from source compiled with the 95configured C compilers in your path. 96 97NOTE: The assumed directory structure of the download source provided by the 98command --download-cmnd=<download-cmnd> is: 99 100 gcc-<version>-base/ 101 gcc-<full-version>.tar.gz 102""" 103 104 def injectExtraCmndLineOptions(self, clp, version): 105 setStdDownloadCmndOption(self, clp, version) 106 clp.add_option( 107 "--extra-configure-options", dest="extraConfigureOptions", type="string", \ 108 default="", \ 109 help="Extra options to add to the 'configure' command for " \ 110 + self.getProductName(version)+"." \ 111 +" Note: This does not override the hard-coded configure options." ) 112 113 def echoExtraCmndLineOptions(self, inOptions): 114 cmndLine = "" 115 cmndLine += " --download-cmnd='"+inOptions.downloadCmnd+"' \\\n" 116 cmndLine += " --extra-configure-options='"+inOptions.extraConfigureOptions+"' \\\n" 117 return cmndLine 118 119 # 120 # Called after parsing the command-line 121 # 122 123 def setup(self, inOptions): 124 self.inOptions = inOptions 125 self.baseDir = os.getcwd() 126 self.gccBaseDir = self.baseDir+"/"+self.getBaseDirName(self.inOptions.version) 127 self.gccSrcDir = "gcc-"+self.inOptions.version 128 self.gccBuildBaseDir = self.gccBaseDir+"/gcc-build" 129 self.scriptBaseDir = getScriptBaseDir() 130 131 # 132 # Called after setup() 133 # 134 135 def doDownload(self): 136 removeDirIfExists(self.gccBaseDir, True) 137 echoRunSysCmnd(self.inOptions.downloadCmnd) 138 139 def doUntar(self): 140 print "Nothing to untar!" 141 142 def doConfigure(self): 143 createDir(self.gccBuildBaseDir) 144 echoRunSysCmnd( 145 "../"+self.gccSrcDir+"/configure --disable-multilib --enable-languages='c,c++,fortran'"+\ 146 " "+self.inOptions.extraConfigureOptions+\ 147 " --prefix="+self.inOptions.installDir, 148 workingDir=self.gccBuildBaseDir, 149 extraEnv={"CFLAGS":"-O3"}, 150 ) 151 152 def doBuild(self): 153 echoChDir(self.gccBuildBaseDir) 154 echoRunSysCmnd("make " + getParallelOpt(self.inOptions, "-j") \ 155 + self.inOptions.makeOptions) 156 157 def doInstall(self): 158 echoChDir(self.gccBuildBaseDir) 159 echoRunSysCmnd("make " + getParallelOpt(self.inOptions, "-j") \ 160 + self.inOptions.makeOptions + " install") 161 162 def getFinalInstructions(self): 163 return """ 164To use the installed version of gcc-"""+self.inOptions.version+""" add the path: 165 166 """+self.inOptions.installDir+"""/bin 167 168to your path and that should be it! 169 170Also, when you link shared libs or executables, pass in: 171 172 -Wl,-rpath,"""+self.inOptions.installDir+"""/lib[64] 173 174That will make it so that you don't need to add this GCC libs to your 175LD_LIBRARY_PATH. 176""" 177 178 179# 180# Executable statements 181# 182 183gccInstaller = InstallProgramDriver(GccInstall()) 184gccInstaller.runDriver() 185