Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ######################################################################################
- # This script was originally created by Fritigern Gothly in 2013
- # It was donated on 12-22-2013 to the Singularity Viewer Project under
- # the Stone Soup License. See http://en.wikipedia.org/wiki/Stone_Soup
- #
- # Add your name below if you have made a change or improvement to this script.
- # Name Date Summary
- # Fritigern Gothly 12-22-2013 Removed some useless commented code
- # Fritigern Gothly 06-11-2015 Added "clean" option
- # Fritigern Gothly 09-01-2015 Allow -d to build RelWithDebInfo
- # Fritigern Gothly 01-21-2016 Singularity got restructured so the configure
- # method had to be changed to Autobuild.
- # Fritigern Gothly 06-10-2016 Created a companion script which should install
- # dependencies and other essentials.
- ######################################################################################
- #=======================================
- # START CONFIGURATION
- ###########################
- #### USE -d TO BUILD DEBUG VIEWER, THEN START WITH
- #### export ASCENDED_DEVELOPER=1 && ./singularity
- #### -----------------------------------------------------
- #### Use the --clean switch to clean your build dir if
- #### building fails when you know it works for others!
- #### Example: ./build_singu.sh Singularity --clean
- ###########################
- # Where is your local Git folder?
- MyGit='/home/<SOME_PLACE>/git'
- # Don't change this part unless you know exactly what you are doing!
- # This is needed so you can mention the repo to build from on the command line.
- Repository=$1
- # Destination folder prefix
- # Adds an optional prefix to the output folder. Default:"Singularity"
- # Change to "" if you only ever build from a repo called Singularity, or
- # you'll end up with a folder named "SingularitySingularity" and that would be silly.
- Prefix="Singularity"
- # Where do you want the newly built Singularity to be put?
- Destination='/home/<SOME_PLACE>/'$Prefix$Repository
- # Compiler version config. Edit as needed.
- # Note that Singularity won't build with C++ 5.0 or higher!
- export CC=/usr/bin/gcc-4.9
- export CXX=/usr/bin/g++-4.9
- # END CONFIGURATION
- #=======================================
- #=======================================
- ##### DO NOT EDIT BELOW THIS LINE #####
- #=======================================
- #=======================================
- #=======================================
- #=======================================
- #=======================================
- #=======================================
- #=======================================
- #=======================================
- #=======================================
- #=======================================
- #=======================================
- #=======================================
- #=======================================
- #=======================================
- # My list of stuff to add to this script, to help me remember.
- # TODO: compare prefix to repo and if duplicated, ignore one of the two.
- # TODO: check path and return error if paths are defaults
- # TODO: Check cc and cxx and if <4.9, suggest installation of 4.9. (move to deps script)
- # TODO: Check for presence of $1, else error
- #=======================================
- #=======================================
- # First, some functions to add color and stuff.
- function c_clr() { echo -en "\e[0m" ; }
- function c_ansi() { [ $1 -lt 16 ] && echo -en "\e[38;5;$1m" || c_clr ; }
- function c_grey() { [ $1 -lt 24 ] && echo -en "\e[38;5;$(($1+232))m" || c_clr ; }
- function c_rgb() { [ $1 -lt 6 -a $2 -lt 6 -a $3 -lt 6 ] && echo -en "\e[38;5;$((16+(36*$1)+(6*$2)+$3))m" || c_clr ; }
- function cb_ansi() { [ $1 -lt 16 ] && echo -en "\e[48;5;$1m" || c_clr ; }
- function cb_grey() { [ $1 -lt 24 ] && echo -en "\e[48;5;$(($1+232))m" || c_clr ; }
- function cb_rgb() { [ $1 -lt 6 -a $2 -lt 6 -a $3 -lt 6 ] && echo -en "\e[48;5;$((16+(36*$1)+(6*$2)+$3))m" || c_clr ; }
- function f() { case $1 in b)echo -e "\e[1m";; u)echo -e "\e[4m";; bl)echo -e "\e[5m";; i)echo -e "\e[7m";; *)esac }
- ##======
- ## Autodetecting stuffs
- # Detect 32 or 64 bit processor
- Bits=`getconf LONG_BIT` # Not using uname -m, because that reportedly will return x86_64 in a chrooted i686 system. This needs confirmation but better safe than sorry!
- #Bits="32"
- if [ $Bits == "64" ]
- then
- Arch="x86_64"
- else
- Arch="i686"
- fi
- # Detect the number of cores that this processor has
- UseNumCores=$(nproc)
- # Was a debug (RelWithDebinfo) build requested?
- if [[ $2 == "-d" || $2 == "-debug" || $2 == "--debug" || $2 == "debug" ]]; then
- Type=RelWithDebInfo
- Destination=$Destination'_DEBUG'
- else
- Type=Release
- fi
- # Convert build Type string to lowercase for use in the target path
- TargetType=${Type,,}
- # Line for debug purposes. Not really needed, but i find it reassuring.
- echo "$(c_rgb 5 3 0)*** Detected $Bits-bit system with $UseNumCores cores. Building an $Arch version of the viewer of the $Type ($TargetType) variant...$(c_clr)"
- # End autodetecting stuffs
- #======
- #Timer, so that we know how long the compilation takes.
- function timer()
- {
- if [[ $# -eq 0 ]]; then
- echo $(date '+%s')
- else
- local stime=$1
- etime=$(date '+%s')
- if [[ -z "$stime" ]]; then stime=$etime; fi
- dt=$((etime - stime))
- ds=$((dt % 60))
- dm=$(((dt / 60) % 60))
- dh=$((dt / 3600))
- printf '%d:%02d:%02d' $dh $dm $ds
- fi
- }
- #Define Repo, for brevity. Friti logic. Don't even try to understand.
- Repo="$MyGit/$Repository"
- if [[ ${Repo: -1} == "/" ]]; then # remove a trailing slash if there is one, or suffer!
- Repo=${Repo::-1}
- fi
- # Now, let's start with pulling in updates, if any.
- cd $Repo/
- git_status=`git pull` # I know I could choose to use git fetch, but this kills two birds with one stone if git IS updated
- # If git is up-to-date, then ask if building is desired anyway
- if [[ $git_status == "Already up-to-date." ]]; then
- echo
- echo "$(f i)****************************************$(c_clr)"
- echo "$(f i)*$(c_clr) $(c_rgb 0 5 0)$(f b)Repository up-to-date. Build anyway? $(c_clr)$(f i)*"
- echo -e "$(f i)****************************************$(c_clr)\n\n"
- read -p "(y/n) : " yn
- if [[ ${yn,,} != "y" ]]; then
- echo "Build canceled. Have a nice day!"
- echo
- exit
- fi
- fi
- # If switch clean was given, clean the build dir!
- if [[ $2 == "clean" || $2 == "-clean" || $2 == "--clean" || $2 == "-c" ]]; then
- echo
- echo "Build script recieved the command line option "$2"."
- echo "Removing prebuilt packages"
- rm /var/tmp/$USER/install.cache/*
- echo "Removing $Repo/build-linux-$Arch/"
- rm -r $Repo/build-linux-$Arch/
- echo "Done cleaning. Time to build anew!"
- fi
- #Start measuring used time....
- t=$(timer)
- # Build as usual.
- echo "*** [ DEBUG ] Changing to $Repo/indra"
- cd $Repo/indra
- echo "*** [ DEBUG ] Running autobuild configure -c $Type -p linux$Bits -- -DFMODSTUDIO:BOOL=ON -DPACKAGE:BOOL=ON -Wno-dev"
- autobuild configure -c $Type -p linux$Bits -- -DFMODSTUDIO:BOOL=ON -DPACKAGE:BOOL=ON -Wno-dev
- # Retrieve the version number and keep it. We'll be using it later!
- # Why now? Because we're already in the right folder, might as well do it now.
- echo "*** [ DEBUG ] Getting $Repo/indra/newview/VIEWER_VERSION.txt for version"
- VERSION=$(cat $Repo/indra/newview/VIEWER_VERSION.txt)' ('$(git rev-list HEAD|wc -l)')'
- # Change into the build folder and let's get cracking!
- echo "*** [ DEBUG ] Changing to $Repo/build-linux-$Arch/"
- cd $Repo/build-linux-$Arch/
- make -j$UseNumCores
- # Error trap, more or less.
- if [[ $? -ne 0 ]]; then
- ENDTIME=$(timer $t)
- echo
- echo "$(c_rgb 5 5 0)Error $? after $ENDTIME of compilation time. $(f bl)Script halted.$(c_clr)" #Protect existing Singu from being removed after compilation fails.
- echo " "
- echo "$(c_rgb 0 3 0) Try running the dependencies installer from http://pastebin.com/Z7pYyear to make sure you have all the dependencies that you need (needs to be done only once).$(c_clr)"
- echo "$(c_rgb 0 3 0) *** TIP *** : Start the build script with './build_singu.sh $Repository --clean' to make sure that no old code is contaminating your build process.$(c_clr)"
- exit
- fi
- # Get the time before we start copying stuff around, we want the time it took to compile, not the time it took to compile and do the rest too!
- ENDTIME=$(timer $t)
- # Remove and recreate destination dir to ensure freshness
- echo
- echo "$(c_rgb 5 5 0)********************* $(c_clr)$(f b)Removing and recreating destination dir to ensure freshness$(c_clr)"
- rm -Rfv $Destination > /dev/null
- mkdir $Destination
- # Copy newly built and packaged Singu to new destination dir.
- #echo
- echo "$(c_rgb 5 5 0)********************* $(c_clr)$(f b)Copying newly built and packaged Singu to new destination dir.$(c_clr)"
- cd $Repo/build-linux-$Arch/newview/packaged/
- cp -R * $Destination
- # Copy skins too, because Classic, Dark and Gemini were feeling a little lonely.
- echo "$(c_rgb 5 5 0)********************* $(c_clr)$(f b)Copying skins too, because classic and dark were feeling a bit lonely.$(c_clr)"
- cd $Repo/indra/newview/skins/
- cp -R * $Destination/skins/ # Skins dir already exists after copy of singu to new destination.
- echo
- echo "$(f i)*****************$(c_clr)"
- echo "$(f i)**$(c_clr) $(c_rgb 5 5 0)$(f bl)Done!$(c_clr) $(f i)**$(c_clr)"
- echo "$(f i)*****************$(c_clr)"
- echo
- echo "$(c_rgb 0 5 5)Compilation of build-linux-$Arch-$TargetType version $VERSION was completed in "$ENDTIME $(c_clr)
- echo
- if [[ $Type == RelWithDebInfo ]]; then
- echo "Start Singularity as follows :"
- echo -e "\tcd $Destination && export ASCENDED_DEVELOPER=1 && ./singularity"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement