Advertisement
Guest User

laz_fpc_build.sh

a guest
May 10th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 14.41 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Build script for several Lazarus and Freepascal versions.
  4. # @version $Id: laz_fpc_build.sh | Sat Jul 22 19:42:24 2017 +0000 | Thierry Bothorel  $
  5.  
  6.  
  7. # USE :
  8.  
  9. # Build groups must start with number 1 (no 0) without gaps between groups numbers.
  10.  
  11. # ************ Common parameters for all builds ************
  12.  
  13. # BASEDRV=          # Root base directory (usually your home directory), ie. ~
  14. # FPCBASEDIR=       # root of freepascal fields (builds ans sources), ie. $BASEDRV/Sys/local/opt/fpc
  15. # LOGDIR=           # logs directory, ie. $BASEDRV/Sys/Logs
  16.  
  17. # ************** GROUP ****************
  18.  
  19. # GROUPNAME[x]=       # Name of you build, ie. GROUPNAME[1]="Lazarus fixes"
  20.  
  21. # FPC parameters
  22.  
  23. # FPCNEWVERSION[x]=   # Freepascal version to build and to be used to build Lazarus, ie. =2.6.1
  24. # FPCOLDVERSION[x]=   # Freepascal version used to build freepascal (i.e 2.4.5)
  25. # SRCDIR[x]=          # Freepascal new version build directory, ie. $FPCBASEDIR/fpsrc/${FPCNEWVERSION[x]}
  26. # PPCNAME[x]=         # Freepascal binary name (depends on architecture=, ie. ppcx64
  27. # FPCSTART[x]=        # Absolute freepascal binary path used to build the ne one, ie.
  28. #                         $BASEDRV/Sys/local/opt/fpc/${FPCOLDVERSION[x]}/bin/${PPCNAME[x]}
  29. #                         /usr/bin/$PPCNAME
  30. # INSTALLDIR[x]=      # Directory used to build the new Freepascal version, ie. $FPCBASEDIR/${FPCNEWVERSION[x]}
  31.  
  32. # some random opts.
  33.  
  34. # OPTS[x]=            # Option to build freepascal, ie. -g- , -gl -dSAX_HTML_DEBUG -dUSE_MINGW_GDB
  35. # COMMONOPTS[x]=
  36.  
  37. # COMMONOPTS[x]=UPXPROG=echo COPYTREE=echo OPT="${OPTS[x]}" GINSTALL=myinst.exe
  38. #
  39. # Some explanations:
  40. #
  41. # UPXPROG=echo   -> makes upxing a non-op. It is not needed in general with
  42. # terabyte HDs on sale.
  43. # UPXPROG=echo avoids UPXing of the resulting binaries, so that the FPC binaries
  44. # can be debugged. If you want as small FPC bins as possible, leave it away,
  45. # and add SMART=1 to both make lines. Note that UPXing wastes memory
  46. # that is more expensive than disk.
  47. #
  48. # COPYTREE=echo  -> during install some example trees are recursively copied.
  49. # this fails on SVN dirs. This omits those copies at the expense of no
  50. # installed examples (you can still do that once in a while by exporting the
  51. # source first, since the problem is in the SVN dirs).
  52. #
  53. # INSTALL_PREFIX=d:\somedir  -> directory where to put snapshot
  54. #
  55. # GINSTALL=vistin.exe  -> vistin is "ginstall.exe" copied to vistin.exe. This
  56. # because Vista wants to UAC anything that is named "install" or "setup",
  57. # which doesn't work for console apps.
  58. #
  59. # The OPT= stuff is not fixed, but changes depending on my needs.
  60.  
  61. #  Lazarus variables
  62.  
  63. # LAZSRCDIR[x]=     # Lazarus directory, ie. $BASEDRV/Sys/local/opt/lazarus_fixes_0_9_30
  64. # OPTSLAZ[x]=       # Lazarus build options, ie. "-g- -O2 -CX -XX" , "-g- -O2 -CX -XX -Xs" # Check as -Xs use to prevent build
  65. # LAZCONFDIR[x]=    # Lazarus config dir, ie. $BASEDRV/.lazarus-stable/ . If you run several lazarus versions, you have to run
  66.                     # them with a different configuration directory with --pcp parameter (ie. --pcp=~/.lazarus-stable)
  67. # SUPCONFDIR[x]=    # If you want to KEEP your configuration directory, you HAVE to set this to 0. If you want to start with a
  68.                     # clean build (like Lazarus trunk version), set it to 1
  69.  
  70.  
  71.  
  72. # ************ Common parameters for all builds ************
  73.  
  74. BASEDRV=~
  75. FPCBASEDIR=$BASEDRV/Sys/local/opt/fpc
  76. LOGDIR=$BASEDRV/Sys/Logs/Pascal
  77.  
  78. # Type of my mainprocessor.
  79. MYINTEL=i686
  80.  
  81. # the root of all, but using it is optional.
  82. CROSSTOOLSROOT=/home/thierrybo/freepascal/binutils/cross
  83. #CROSSTOOLSROOT=~/Sys/local/opt/fpc/cross
  84.  
  85. CROSSTOOLSROOT=${CROSSTOOLSROOT%/}/
  86.  
  87. # ************** FIRST GROUP ****************
  88.  
  89. GROUPNAME[1]="Lazarus fixes"
  90.  
  91. # FPC parameters
  92.  
  93. FPCNEWVERSION[1]=3.0.3
  94. FPCOLDVERSION[1]=3.0.2
  95. SRCDIR[1]=$FPCBASEDIR/fpsrc/${FPCNEWVERSION[1]}
  96. PPCNAME[1]=ppcx64
  97. FPCSTART[1]=$BASEDRV/Sys/local/opt/fpc/${FPCOLDVERSION[1]}/bin/${PPCNAME[1]}
  98. INSTALLDIR[1]=$FPCBASEDIR/${FPCNEWVERSION[1]}
  99.  
  100. # CROSS
  101. CROSSPPCNAME[1]=ppcross386
  102. CROSSPPCLINKNAME[1]=ppc386
  103. # OSes and CPUs
  104. #TARGETS_OS[1]="linux freebsd linux  win32 go32v2 netbsd openbsd solaris darwin"
  105. TARGETS_OS[1]="linux win32"
  106. TARGETS_CPU[1]="i386"
  107. #TARGETS_CPU[1]="arm"
  108.  
  109. # some random opts.
  110.  
  111. OPTS[1]="-g- -CX -XXs -O2"
  112. COMMONOPTS[1]="UPXPROG=echo SMART=1"
  113.  
  114. #  Lazarus variables
  115.  
  116. LAZSRCDIR[1]=$BASEDRV/Sys/local/opt/lazarus_fixes
  117. OPTSLAZ[1]="-g- -O2 -CX -XX"
  118. LAZCONFDIR[1]=$BASEDRV/.lazarus-stable/
  119. SUPCONFDIR[1]=0
  120.  
  121. # ************** SECOND GROUP ****************
  122.  
  123. GROUPNAME[2]="Lazarus SVN"
  124.  
  125. # FPC parameters
  126.  
  127. FPCNEWVERSION[2]=3.0.3
  128. FPCOLDVERSION[2]=3.0.2
  129. SRCDIR[2]=$FPCBASEDIR/fpsrc/${FPCNEWVERSION[2]}
  130. PPCNAME[2]=ppcx64
  131. FPCSTART[2]=$BASEDRV/Sys/local/opt/fpc/${FPCOLDVERSION[2]}/bin/${PPCNAME[2]}
  132. INSTALLDIR[2]=$FPCBASEDIR/${FPCNEWVERSION[2]}
  133.  
  134. # CROSS
  135. CROSSPPCNAME[2]=ppcross386
  136. CROSSPPCLINKNAME[2]=ppc386
  137. # OSes and CPUs
  138. #TARGETS_OS[2]="linux freebsd linux  win32 go32v2 netbsd openbsd solaris darwin"
  139. TARGETS_OS[2]=""
  140. TARGETS_CPU[2]=""
  141. #TARGETS_CPU[2]="arm"
  142.  
  143. # some random opts.
  144.  
  145. OPTS[2]="-g- -CX -XXs -O2"
  146. COMMONOPTS[2]="UPXPROG=echo SMART=1"
  147.  
  148. # Lazarus variables
  149.  
  150. LAZSRCDIR[2]=$BASEDRV/Sys/local/opt/lazarus_svn
  151. OPTSLAZ[2]=
  152. LAZCONFDIR[2]=$BASEDRV/.lazarus-svn/
  153. SUPCONFDIR[2]=1
  154.  
  155. # ************** THIRD GROUP ****************
  156.  
  157. GROUPNAME[3]="Lazarus AND FPC : SVN"
  158.  
  159. # FPC parameters
  160.  
  161. FPCNEWVERSION[3]=3.0.3
  162. FPCOLDVERSION[3]=3.0.2
  163. SRCDIR[3]=$FPCBASEDIR/fpsrc/${FPCNEWVERSION[3]}
  164. PPCNAME[3]=ppcx64
  165. FPCSTART[3]=$BASEDRV/Sys/local/opt/fpc/${FPCOLDVERSION[3]}/bin/${PPCNAME[3]}
  166. INSTALLDIR[3]=$FPCBASEDIR/${FPCNEWVERSION[3]}
  167.  
  168. # CROSS
  169. CROSSPPCNAME[3]=ppcross386
  170. CROSSPPCLINKNAME[3]=ppc386
  171. # OSes and CPUs
  172. #TARGETS_OS[3]="linux freebsd linux  win32 go32v2 netbsd openbsd solaris darwin"
  173. TARGETS_OS[3]=""
  174. TARGETS_CPU[3]=""
  175. #TARGETS_CPU[3]="arm"
  176.  
  177. # some random opts.
  178.  
  179. OPTS[3]="-gl"
  180. COMMONOPTS[3]="UPXPROG=echo"
  181.  
  182. # Lazarus variables
  183.  
  184. LAZSRCDIR[3]=$BASEDRV/Sys/local/opt/lazarus_svn_FPC_svn
  185. OPTSLAZ[3]=
  186. LAZCONFDIR[3]=$BASEDRV/.lazarus/
  187. SUPCONFDIR[3]=1
  188.  
  189. #  ===  invariant  part  ===
  190. ###########################################################################
  191. # don't edit below
  192.  
  193. MYHOSTARCH=`uname -p | tr "[:upper:]" "[:lower:]"`
  194. MYHOSTOS=`uname -s | tr "[:upper:]" "[:lower:]"`
  195. echo HOST platform is ${MYHOSTARCH}-${MYHOSTOS}
  196.  
  197. # ********** QUESTIONS *************
  198.  
  199. echo "Which version to build?"
  200. len=${#GROUPNAME[*]}
  201. i=0
  202. while [ "$i" -lt "$len" ]
  203. do
  204.   CHOICES="${CHOICES} ${GROUPNAME[$i+1]},"
  205.   let "i = $i + 1"
  206. done
  207. IFS=','    # New IFS
  208. LIST=(${CHOICES[@]})  # available choices list
  209. select CHOICE in "${LIST[@]}" ; do
  210.     case $REPLY in
  211.         0|1|2|3|4|5|6|7|8|9)
  212.           i=$REPLY
  213.         break
  214.         ;;
  215.     esac
  216. done
  217. unset IFS  # set IFS back ti default
  218.  
  219. echo "Subversion update working copy Yes/NO"
  220. LIST=("[y] yes" "[n]  no")  # available choices list
  221. select CHOICE in "${LIST[@]}" ; do
  222.     case $REPLY in
  223.         1|y)
  224.           CHOICESVNUPDATE=1
  225.         break
  226.         ;;
  227.         2|n)
  228.           CHOICESVNUPDATE=0
  229.         break
  230.         ;;
  231.     esac
  232. done
  233.  
  234. echo "Build FPC ${FPCNEWVERSION[$i]} Yes/NO"
  235. LIST=("[y] yes" "[n]  no")  # available choices list
  236. select CHOICE in "${LIST[@]}" ; do
  237.     case $REPLY in
  238.         1|y)
  239.           BUILDFPC=1
  240.         break
  241.         ;;
  242.         2|n)
  243.           BUILDFPC=0
  244.         break
  245.         ;;
  246.     esac
  247. done
  248.  
  249. echo "Build ${GROUPNAME[$i]} ? YES/No"
  250. LIST=("[y] yes" "[n]  no")  # available choices list
  251. select CHOICE in "${LIST[@]}" ; do
  252.     case $REPLY in
  253.         1|y)
  254.           BUILDLAZARUS=1
  255.         break
  256.         ;;
  257.         2|n)
  258.           BUILDLAZARUS=0
  259.         break
  260.         ;;
  261.     esac
  262. done
  263.  
  264. if [[ "$BUILDLAZARUS" == 1 ]]
  265. then
  266.     echo "Build Lazarus with LAZBUILD instead of MAKE (not for an new svn checkout) ? Yes/No"
  267.     LIST=("[y] yes" "[n]  no")  # available choices list
  268.     select CHOICE in "${LIST[@]}" ; do
  269.         case $REPLY in
  270.             1|y)
  271.               BUILDLAZARUSWITHLAZBUILD=1
  272.             break
  273.             ;;
  274.             2|n)
  275.               BUILDLAZARUSWITHLAZBUILD=0
  276.             break
  277.             ;;
  278.         esac
  279.     done
  280. fi
  281.  
  282. # ************* START BUILDS ***********************
  283.  
  284. # add fpcres to path, allowing to build FPC 2.6.1 and later, avoiding :
  285.  
  286. # make[3]: entrant dans le répertoire « /home/thierrybo/Sys/local/opt/fpc/fpsrc/2.6.1/utils/fpcmkcfg »
  287. # /bin/mkdir -p units/x86_64-linux
  288. # __missing_command_DATA2INC -b -s fppkg.cfg fppkg.inc fppkg
  289. # make[3]: __missing_command_DATA2INC : commande introuvable
  290. # make[3]: *** [fppkg.inc] Erreur 127
  291.  
  292. ###############################################################
  293.  
  294. export PATH=$PATH:$BASEDRV/Sys/local/opt/fpc/${FPCOLDVERSION[$i]}/bin/
  295.  
  296. # Previous logs deletion
  297.  
  298. #rm -f ${LOGDIR}/fpc_build_log.txt
  299. #rm -f ${LOGDIR}/fpc_crossbuild_log.txt
  300. #rm -f ${LOGDIR}/fpc_install_log.txt
  301. #rm -f ${LOGDIR}/fpc_crossinstall_log.txt
  302. #rm -f ${LOGDIR}/laz_install_log.txt
  303. #rm -f ${LOGDIR}/outcome.txt
  304. #rm -f ${LOGDIR}/crossoutcome.txt
  305. rm -f ${LOGDIR}/*
  306.  
  307. #          FREEPASCAL
  308.  
  309.  if [[ "$BUILDFPC" = 1 ]]
  310.  then
  311.      cd $FPCBASEDIR/fpsrc/${FPCNEWVERSION[$i]}/
  312.  
  313.      make clean
  314.  
  315. ###########################################################################
  316. # Boucle par CPU puis par OS pour make clean
  317. #
  318.  
  319. for CPU in ${TARGETS_CPU[$i]}; do
  320.  
  321. # CPU xlat. translate from FPC cpu designation to binutil's;
  322.  
  323. MCPU=${CPU}
  324. if [ "${CPU}" = "i386" ]; then
  325. MCPU=${MYINTEL}
  326. fi
  327.  
  328. for OS in ${TARGETS_OS[$i]}; do
  329.  
  330. # xlat for OS
  331.  
  332. MOS=${OS}
  333. if [ "${OS}" = "sunos" ]; then
  334. MOS=solaris
  335. fi
  336.  
  337. if [ "${OS}" = "win32" ]; then
  338. MOS=mingw32
  339. fi
  340.  
  341. if [ "${OS}" = "go32v2" ]; then
  342. MOS=msdosdjgpp
  343. fi
  344.  
  345. dothisbuild=1
  346. if [ "${CPU}" = "${MYHOSTARCH}" ]; then
  347. if [ "${OS}" = "${MYHOSTOS}" ]; then
  348. dothisbuild=0
  349. fi
  350. fi
  351.  
  352. if [ $dothisbuild -eq 1 ]; then
  353. make clean OS_TARGET=${OS} CPU_TARGET=${CPU}
  354. fi
  355.  
  356. done;
  357. done;
  358.  
  359. # FIN Boucle par CPU puis par OS pour make clean
  360. ###################################################################
  361.  
  362.      rm -f --recursive ${INSTALLDIR[$i]}/lib/
  363.      rm -f --recursive ${INSTALLDIR[$i]}/share/
  364.      rm -f --recursive ${INSTALLDIR[$i]}/bin/
  365.  
  366.      if [ $CHOICESVNUPDATE = 1 ] ; then    
  367.          svn up $FPCBASEDIR/fpsrc/${FPCNEWVERSION[$i]}
  368.      fi
  369.  
  370.      make all ${COMMONOPTS[$i]} OPT="${OPTS[$i]}" PP=${FPCSTART[$i]} > ${LOGDIR}/fpc_build_log.txt 2>&1
  371.      if [ ! $? = 0 ] ; then
  372.          echo Grrr, failed again
  373.      else
  374.          make install ${COMMONOPTS[$i]} OPT="${OPTS[$i]}" INSTALL_PREFIX=${INSTALLDIR[$i]} PP=${SRCDIR[$i]}/compiler/${PPCNAME[$i]} > ${LOGDIR}/fpc_install_log.txt 2>&1
  375.          if [ ! $? = 0 ] ; then
  376.              echo INSTALL failed | tee -a ${LOGDIR}/outcome.txt
  377.          else
  378.              ln --symbolic ${INSTALLDIR[$i]}/lib/fpc/${FPCNEWVERSION[$i]}/${PPCNAME[$i]} ${INSTALLDIR[$i]}/bin/${PPCNAME[$i]}
  379.              echo Everything _should_ be fine.| tee -a ${LOGDIR}/outcome.txt
  380.          fi
  381.      fi
  382.  fi
  383.  
  384. #                      CROSS FREEPASCAL
  385.  
  386. if [[ "$BUILDFPC" = 1 ]]
  387. then
  388.  
  389. ###########################################################################
  390. # Boucle par CPU puis par OS
  391. #
  392.  
  393. for CPU in ${TARGETS_CPU[$i]}; do
  394.  
  395. # CPU xlat. translate from FPC cpu designation to binutil's;
  396.  
  397. MCPU=${CPU}
  398. if [ "${CPU}" = "i386" ]; then
  399. MCPU=${MYINTEL}
  400. fi
  401.  
  402. for OS in ${TARGETS_OS[$i]}; do
  403.  
  404. # xlat for OS
  405.  
  406. MOS=${OS}
  407. if [ "${OS}" = "sunos" ]; then
  408. MOS=solaris
  409. fi
  410.  
  411. if [ "${OS}" = "win32" ]; then
  412. MOS=mingw32
  413. fi
  414.  
  415. if [ "${OS}" = "go32v2" ]; then
  416. MOS=msdosdjgpp
  417. fi
  418.  
  419. dothisbuild=1
  420. if [ "${CPU}" = "${MYHOSTARCH}" ]; then
  421. if [ "${OS}" = "${MYHOSTOS}" ]; then
  422. dothisbuild=0
  423. fi
  424. fi
  425.  
  426. ###################################################################
  427.     if [ $dothisbuild -eq 1 ]; then
  428.  
  429.     cd $FPCBASEDIR/fpsrc/${FPCNEWVERSION[$i]}/
  430.  
  431. ### 201603 : si je laisse make clean, cross compile ne va pas au bout
  432.     #make clean OS_TARGET=${OS} CPU_TARGET=${CPU}
  433. # Ne pas supprimer le résultat de l'installation normale de freepascal juste avant !
  434. #    rm -f --recursive ${INSTALLDIR[$i]}/lib/
  435. #    rm -f --recursive ${INSTALLDIR[$i]}/share/
  436. #    rm -f --recursive ${INSTALLDIR[$i]}/bin/
  437.  
  438. # Pas besoin de Crossbindir ni Binutilsprefix pour linux-32bits, la simple
  439. # création manuelle des fichiers as et ar dans le wiki suffit. 201603 cross bindir
  440. # devrait marcher mais pas la création manuelle de as et ar
  441.     make all OS_TARGET=${OS} CPU_TARGET=${CPU} BINUTILSPREFIX=${MCPU}-${MOS}- CROSSBINDIR=${CROSSTOOLSROOT}bin ${COMMONOPTS[$i]} OPT="${OPTS[$i]}" PP=${FPCSTART[$i]} > ${LOGDIR}/fpc_crossbuild_log_${OS}-${CPU}.txt 2>&1
  442.     if [ ! $? = 0 ] ; then
  443.         echo Grrr, failed CROSS ${OS}-${CPU} again
  444.     else
  445.         make crossinstall OS_TARGET=${OS} CPU_TARGET=${CPU} BINUTILSPREFIX=${MCPU}-${MOS}- CROSSBINDIR=${CROSSTOOLSROOT}bin ${COMMONOPTS[$i]} OPT="${OPTS[$i]}" INSTALL_PREFIX=${INSTALLDIR[$i]} PP=${SRCDIR[$i]}/compiler/${PPCNAME[$i]} > ${LOGDIR}/fpc_crossinstall_log-${OS}-${CPU}.txt 2>&1
  446.         if [ ! $? = 0 ] ; then
  447.             echo CROSS ${OS}-${CPU} INSTALL failed | tee -a ${LOGDIR}/crossoutcome.txt
  448.         else
  449.             ln --symbolic ${INSTALLDIR[$i]}/lib/fpc/${FPCNEWVERSION[$i]}/${CROSSPPCNAME[$i]} ${INSTALLDIR[$i]}/bin/${CROSSPPCLINKNAME[$i]}
  450.             echo CROSS ${OS}-${CPU} Everything _should_ be fine.| tee -a ${LOGDIR}/crossoutcome.txt
  451.         fi
  452.     fi
  453.     fi # if [ $dothisbuild -eq 1 ]; then
  454.  
  455.     #################################################### Fin boucle
  456.     done; # for OS in $TARGETS_OS[$i]; do
  457.     done; # for CPU in $TARGETS_CPU[$i]; do
  458.  
  459. fi # if [[ "$BUILDFPC" = 1 ]]
  460.  
  461. #           LAZARUS +++++++++++++++++++++++++++++++
  462.  
  463. if [[ "$BUILDLAZARUS" == 1 ]]
  464. then
  465.     cd ${LAZSRCDIR[$i]}
  466.  
  467.     make clean
  468.     rm -f --recursive ${LAZSRCDIR[$i]}/units
  469.  
  470.     if [ $CHOICESVNUPDATE = 1 ] ; then
  471.         svn up ${LAZSRCDIR[$i]}
  472.     fi
  473.    
  474.     if [[ "$BUILDLAZARUSWITHLAZBUILD" == 1 ]]
  475.     then
  476.         ./lazbuild --build-ide="${OPTSLAZ[$i]}" --build-mode= --primary-config-path="${LAZCONFDIR[$i]}" --secondary-config-path="${LAZCONFDIR[$i]}" > ${LOGDIR}/laz_install_log.txt 2>&1
  477.     else
  478.         make bigide OPT="${OPTSLAZ[$i]}" FPC=${INSTALLDIR[$i]}/bin/fpc INSTALL_PREFIX=${LAZSRCDIR[$i]} > ${LOGDIR}/laz_install_log.txt 2>&1
  479.     fi
  480.     if [ ! $? = 0 ] ; then
  481.         echo Grrr, failed Lazarus
  482.     else
  483.         echo Lazarus Everything _should_ be fine
  484.         if [[ "${SUPCONFDIR[$i]}" == 1 ]] ; then
  485.             rm -f --recursive ${LAZCONFDIR[$i]}
  486.         fi
  487.     fi
  488. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement