Advertisement
fritigern

Build_Singularity.sh

Sep 15th, 2014
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.65 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################################
  3. # This script was originally created by Fritigern Gothly in 2013
  4. # It was donated on 12-22-2013 to the Singularity Viewer Project under
  5. # the Stone Soup License. See http://en.wikipedia.org/wiki/Stone_Soup
  6. #
  7. # Add your name below if you have made a change or improvement to this script.
  8. # Name          Date        Summary
  9. # Fritigern Gothly  12-22-2013  Removed some useless commented code
  10. # Fritigern Gothly  06-11-2015  Added  "clean" option
  11. # Fritigern Gothly  09-01-2015  Allow -d to build RelWithDebInfo
  12. # Fritigern Gothly  01-21-2016  Singularity got restructured so the configure
  13. #                               method had to be changed to Autobuild.
  14. # Fritigern Gothly  06-10-2016  Created a companion script which should install
  15. #                               dependencies and other essentials.
  16. ######################################################################################
  17.  
  18. #=======================================
  19. # START CONFIGURATION
  20.  
  21. ###########################
  22. #### USE -d TO BUILD DEBUG VIEWER, THEN START WITH
  23. ####        export ASCENDED_DEVELOPER=1 && ./singularity
  24. #### -----------------------------------------------------
  25. #### Use the --clean switch to clean your build dir if
  26. #### building fails when you know it works for others!
  27. #### Example: ./build_singu.sh Singularity --clean
  28. ###########################
  29.  
  30. # Where is your local Git folder?
  31. MyGit='/home/<SOME_PLACE>/git'
  32.  
  33. # Don't change this part unless you know exactly what you are doing!
  34. # This is needed so you can mention the repo to build from on the command line.
  35. Repository=$1
  36.  
  37. # Destination folder prefix
  38. # Adds an optional prefix to the output folder. Default:"Singularity"
  39. # Change to "" if you only ever build from a repo called Singularity, or
  40. # you'll end up with a folder named "SingularitySingularity" and that would be silly.
  41. Prefix="Singularity"
  42.  
  43. # Where do you want the newly built Singularity to be put?
  44. Destination='/home/<SOME_PLACE>/'$Prefix$Repository
  45.  
  46. # Compiler version config. Edit as needed.
  47. # Note that Singularity won't build with C++ 5.0 or higher!
  48. export CC=/usr/bin/gcc-4.9
  49. export CXX=/usr/bin/g++-4.9
  50.  
  51. # END CONFIGURATION
  52. #=======================================
  53.  
  54. #=======================================
  55. ##### DO NOT EDIT BELOW THIS LINE #####
  56. #=======================================
  57. #=======================================
  58. #=======================================
  59. #=======================================
  60. #=======================================
  61. #=======================================
  62. #=======================================
  63. #=======================================
  64. #=======================================
  65. #=======================================
  66. #=======================================
  67. #=======================================
  68. #=======================================
  69. #=======================================
  70. # My list of stuff to add to this script, to help me remember.
  71. # TODO: compare prefix to repo and if duplicated, ignore one of the two.
  72. # TODO: check path and return error if paths are defaults
  73. # TODO: Check cc and cxx and if <4.9, suggest installation of 4.9. (move to deps script)
  74. # TODO: Check for presence of $1, else error
  75. #=======================================
  76.  
  77. #=======================================
  78. # First, some functions to add color and stuff.
  79. function c_clr() { echo -en "\e[0m" ; }
  80. function c_ansi() { [ $1 -lt 16 ] && echo -en "\e[38;5;$1m" || c_clr ; }
  81. function c_grey() { [ $1 -lt 24 ] && echo -en "\e[38;5;$(($1+232))m" || c_clr ; }
  82. 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 ; }
  83. function cb_ansi() { [ $1 -lt 16 ] && echo -en "\e[48;5;$1m" || c_clr ; }
  84. function cb_grey() { [ $1 -lt 24 ] && echo -en "\e[48;5;$(($1+232))m" || c_clr ; }
  85. 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 ; }
  86. 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  }
  87.  
  88. ##======
  89. ## Autodetecting stuffs
  90.  
  91. # Detect 32 or 64 bit processor
  92. 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!
  93.  
  94. #Bits="32"
  95.  
  96. if [ $Bits == "64" ]
  97. then
  98.   Arch="x86_64"
  99. else
  100.   Arch="i686"
  101. fi
  102.  
  103. # Detect the number of cores that this processor has
  104. UseNumCores=$(nproc)
  105.  
  106. # Was a debug (RelWithDebinfo) build requested?
  107. if [[ $2 == "-d" || $2 == "-debug" || $2 == "--debug" || $2 == "debug" ]]; then
  108.   Type=RelWithDebInfo
  109.   Destination=$Destination'_DEBUG'
  110. else
  111.   Type=Release
  112. fi
  113.  
  114. # Convert build Type string to lowercase for use in the target path
  115. TargetType=${Type,,}
  116.  
  117. # Line for debug purposes. Not really needed, but i find it reassuring.
  118. 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)"
  119.  
  120. # End autodetecting stuffs
  121. #======
  122.  
  123. #Timer, so that we know how long the compilation takes.
  124. function timer()
  125. {
  126.     if [[ $# -eq 0 ]]; then
  127.         echo $(date '+%s')
  128.     else
  129.         local  stime=$1
  130.         etime=$(date '+%s')
  131.  
  132.         if [[ -z "$stime" ]]; then stime=$etime; fi
  133.  
  134.         dt=$((etime - stime))
  135.         ds=$((dt % 60))
  136.         dm=$(((dt / 60) % 60))
  137.         dh=$((dt / 3600))
  138.         printf '%d:%02d:%02d' $dh $dm $ds
  139.     fi
  140. }
  141.  
  142. #Define Repo, for brevity. Friti logic. Don't even try to understand.
  143. Repo="$MyGit/$Repository"
  144.  
  145. if [[ ${Repo: -1} == "/" ]]; then # remove a trailing slash if there is one, or suffer!
  146.  Repo=${Repo::-1}
  147. fi
  148.  
  149. # Now, let's start with pulling in updates, if any.
  150. cd $Repo/
  151. 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
  152.  
  153. # If git is up-to-date, then ask if building is desired anyway
  154. if [[ $git_status == "Already up-to-date." ]]; then
  155.     echo
  156.     echo "$(f i)****************************************$(c_clr)"
  157.     echo "$(f i)*$(c_clr) $(c_rgb 0 5 0)$(f b)Repository up-to-date. Build anyway? $(c_clr)$(f i)*"
  158.     echo -e "$(f i)****************************************$(c_clr)\n\n"
  159.    
  160.     read -p "(y/n) : " yn
  161.    
  162.     if [[ ${yn,,} != "y" ]]; then
  163.       echo "Build canceled. Have a nice day!"
  164.       echo
  165.       exit
  166.     fi
  167. fi
  168.  
  169. # If switch clean was given, clean the build dir!
  170. if [[ $2 == "clean" || $2 == "-clean" || $2 == "--clean" || $2 == "-c" ]]; then
  171.     echo
  172.     echo "Build script recieved the command line option "$2"."
  173.     echo "Removing prebuilt packages"
  174.     rm /var/tmp/$USER/install.cache/*
  175.     echo "Removing $Repo/build-linux-$Arch/"
  176.     rm -r $Repo/build-linux-$Arch/
  177.     echo "Done cleaning. Time to build anew!"
  178. fi
  179.  
  180. #Start measuring used time....
  181. t=$(timer)
  182.  
  183. # Build as usual.
  184. echo "*** [ DEBUG ] Changing to $Repo/indra"
  185. cd $Repo/indra
  186. echo "*** [ DEBUG ] Running autobuild configure -c $Type -p linux$Bits -- -DFMODSTUDIO:BOOL=ON -DPACKAGE:BOOL=ON -Wno-dev"
  187. autobuild configure -c $Type -p linux$Bits -- -DFMODSTUDIO:BOOL=ON -DPACKAGE:BOOL=ON -Wno-dev
  188.  
  189. # Retrieve the version number and keep it. We'll be using it later!
  190. # Why now? Because we're already in the right folder, might as well do it now.
  191. echo "*** [ DEBUG ] Getting $Repo/indra/newview/VIEWER_VERSION.txt for version"
  192. VERSION=$(cat $Repo/indra/newview/VIEWER_VERSION.txt)' ('$(git rev-list HEAD|wc -l)')'
  193.  
  194. # Change into the build folder and let's get cracking!
  195. echo "*** [ DEBUG ] Changing to $Repo/build-linux-$Arch/"
  196. cd $Repo/build-linux-$Arch/
  197. make -j$UseNumCores
  198.  
  199. # Error trap, more or less.
  200. if [[ $? -ne 0 ]]; then
  201.  ENDTIME=$(timer $t)
  202.  echo
  203.  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.
  204.  echo " "
  205.  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)"
  206.  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)"
  207.  exit
  208. fi
  209.  
  210. # 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!
  211. ENDTIME=$(timer $t)
  212.  
  213. # Remove and recreate destination dir to ensure freshness
  214. echo
  215. echo "$(c_rgb 5 5 0)********************* $(c_clr)$(f b)Removing and recreating destination dir to ensure freshness$(c_clr)"
  216. rm -Rfv $Destination > /dev/null
  217. mkdir $Destination
  218.  
  219. # Copy newly built and packaged Singu to new destination dir.
  220. #echo
  221. echo "$(c_rgb 5 5 0)********************* $(c_clr)$(f b)Copying newly built and packaged Singu to new destination dir.$(c_clr)"
  222. cd $Repo/build-linux-$Arch/newview/packaged/
  223. cp -R * $Destination
  224.  
  225. # Copy skins too, because Classic, Dark and Gemini were feeling a little lonely.
  226. echo "$(c_rgb 5 5 0)********************* $(c_clr)$(f b)Copying skins too, because classic and dark were feeling a bit lonely.$(c_clr)"
  227. cd $Repo/indra/newview/skins/
  228. cp -R * $Destination/skins/ # Skins dir already exists after copy of singu to new destination.
  229.  
  230. echo
  231. echo "$(f i)*****************$(c_clr)"
  232. echo "$(f i)**$(c_clr)    $(c_rgb 5 5 0)$(f bl)Done!$(c_clr)    $(f i)**$(c_clr)"
  233. echo "$(f i)*****************$(c_clr)"
  234. echo
  235. echo "$(c_rgb 0 5 5)Compilation of build-linux-$Arch-$TargetType version $VERSION was completed in "$ENDTIME $(c_clr)
  236. echo
  237.  
  238. if [[ $Type == RelWithDebInfo ]]; then
  239.     echo "Start Singularity as follows :"
  240.     echo -e "\tcd $Destination && export ASCENDED_DEVELOPER=1 && ./singularity"
  241. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement