buildpas2js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. #!/bin/bash
  2. # Some variables
  3. BASEURL="https://svn.freepascal.org/svn/projects/pas2js/"
  4. function info {
  5. if [ -z "$QUIET" ]; then
  6. echo "Info: $*"
  7. fi
  8. }
  9. function header {
  10. if [ -z "$QUIET" ]; then
  11. echo ""
  12. echo "Info: $*"
  13. echo "---"
  14. echo ""
  15. fi
  16. }
  17. function usage {
  18. echo "usage $0 [options] [FPC [SVN]]"
  19. echo '-c compiler set compiler to use'
  20. echo '-d directory set base directory for checkout'
  21. echo '-h help this help message'
  22. echo '-o OPTS extra compiler options'
  23. echo "-q be more quiet"
  24. echo '-s name build snapshot with name'
  25. echp '-nd skip demo test compilation'
  26. echo '-z URL set url for checkout. Can be relative to pas2js repo'
  27. }
  28. function doCompile {
  29. info "Compiler command line: $*"
  30. $FPC $*
  31. }
  32. function doStrip {
  33. info "Stripping binary: $*"
  34. strip $*
  35. }
  36. set -e
  37. while test $# != 0
  38. do
  39. f=$1
  40. case $f in
  41. '-c') shift
  42. FPC="$1";;
  43. '-d') shift
  44. DIR="$1";;
  45. '-z') shift
  46. SVN="$1";;
  47. '-o') shift
  48. EXTRAOPTS="$1";;
  49. '-q') QUIET=1;;
  50. '-s') shift
  51. SNAPSHOT="$1";;
  52. '-nd') SKIPDEMO=1;;
  53. '-h') usage
  54. exit;;
  55. *)
  56. if [ -z "$FPC" ]; then
  57. FPC=$1
  58. else
  59. if [ -z "$SVN" ]; then
  60. SVN=$1
  61. else
  62. usage
  63. fi
  64. fi
  65. esac
  66. shift
  67. done
  68. #
  69. # Collect some info , set defaults
  70. #
  71. if [ -z "$FPC" ]; then
  72. FPC=fpc
  73. fi
  74. if [ -z "$SVN" ]; then
  75. SVN=${BASEURL}trunk
  76. else
  77. PROT=$(echo $SVN | sed -n '/.*:\/\//p')
  78. if [ -z "$PROT" ]; then
  79. SVN="${BASEURL}${SVN}"
  80. fi
  81. fi
  82. if [ -z "$DIR" ]; then
  83. DIR=$TMP
  84. if [ -z "$DIR" ]; then
  85. DIR=$TEMP
  86. fi
  87. if [ -z "$DIR" ]; then
  88. DIR=~/tmp
  89. fi
  90. fi
  91. FPCVER=$($FPC -iV)
  92. FPCVER30=$(echo $FPCVER | (grep '3.0' || echo))
  93. FPCCPU=$($FPC -iTP)
  94. case "$OSTYPE" in
  95. linux*)
  96. SNAPSHOTOS=linux
  97. LIBEXT=so
  98. ;;
  99. darwin*)
  100. SNAPSHOTOS=macos
  101. LIBEXT=dylib
  102. ;;
  103. *) SNAPSHOTOS=unknown
  104. LIBEXT=dll
  105. ;;
  106. esac
  107. #
  108. # Get started
  109. #
  110. info "SVN URL: $SVN"
  111. info "Compiler version: $FPCVER"
  112. info "Base directory: $DIR"
  113. info "Snaphot: $SNAPSHOT"
  114. info ""
  115. #
  116. # Change to base dir
  117. #
  118. info Changing directory to base dir $DIR
  119. mkdir -p $DIR
  120. cd $DIR
  121. if [ -d daily ]; then
  122. info Removing previous dir
  123. rm -rf daily
  124. fi
  125. #
  126. # Export sources
  127. #
  128. info "Exporting SVN $SVN to $DIR/daily"
  129. svn export -q $SVN daily
  130. BUILDDIR="$DIR/daily"
  131. PKGDIR="$BUILDDIR/compiler/packages"
  132. UNITPATH="$PKGDIR/fcl-js/src/;$PKGDIR/fcl-json/src/;$PKGDIR/fcl-passrc/src/;$PKGDIR/pastojs/src/"
  133. if [ ! -z "$FPCVER30" ]; then
  134. UNITPATH="${UNITPATH};$PKGDIR/compat"
  135. fi
  136. OPTS="-FU. -B -O1 -Schi -v0 -ve $EXTRAOPT"
  137. if [ "$FPCCPU" = "x86_64" ]; then
  138. LIBOPT="-fPIC"
  139. fi
  140. COMPDIR=$BUILDDIR/compiler/utils/pas2js
  141. #
  142. # Output dir is basis for zip
  143. #
  144. OUTDIR=$BUILDDIR/output
  145. INSTALLDIR=$OUTDIR
  146. if [ ! -z "$SNAPSHOT" ]; then
  147. SNAPSHOTDIR="pas2js-snapshot-$SNAPSHOTOS-$FPCCPU"
  148. INSTALLDIR="$OUTDIR/$SNAPSHOTDIR"
  149. fi
  150. if [ -d "$INSTALLDIR" ]; then
  151. info "Output dir $INSTALLDIR exists. Cleaning up"
  152. rm -rf "$INSTALLDIR"/*
  153. else
  154. info "Creating output dir $INSTALLDIR"
  155. mkdir -p "$INSTALLDIR"
  156. fi
  157. #
  158. # Binaries are put here
  159. #
  160. BINDIR=$INSTALLDIR/bin/
  161. if [ -d "$BINDIR" ]; then
  162. info Removing previous binaries from "$BINDIR"
  163. rm -rf "$BINDIR"/*
  164. else
  165. info Creating output dir "$BINDIR"
  166. mkdir -p "$BINDIR"
  167. fi
  168. # pas2js
  169. header Build pas2js in $COMPDIR
  170. cd "$COMPDIR"
  171. doCompile -Fu"$UNITPATH" $OPTS -FE$BINDIR pas2js.pp
  172. doStrip $BINDIR/pas2js
  173. # libpas2js
  174. header Build libpas2js in $COMPDIR
  175. cd "$COMPDIR"
  176. doCompile -Fu"$UNITPATH" $OPTS $LIBOPT -FE$BINDIR pas2jslib.pp
  177. if [ "$OSTYPE" ne "darwin" ]; then
  178. doStrip $BINDIR/libpas2jslib.$LIBEXT
  179. fi
  180. # compileserver
  181. if [ ! -z "$FPCVER30" ]; then
  182. header Version 3.0.x detected: Skipping compileserver build.
  183. else
  184. header Build compileserver in $COMPDIR
  185. cd "$COMPDIR"
  186. doCompile -Fu"$UNITPATH" $OPTS -FE$BINDIR compileserver.pp
  187. doStrip $BINDIR/compileserver
  188. fi
  189. # webidl
  190. header Build webidl2pas in $COMPDIR
  191. cd "$COMPDIR"
  192. doCompile -Fu"$UNITPATH" $OPTS -FE$BINDIR -Fu$PKGDIR/webidl/src webidl2pas.pp
  193. doStrip $BINDIR/webidl2pas
  194. # all done
  195. header Compiled binaries:
  196. ls -l $BINDIR
  197. #
  198. # Copy files for snapZip snapshot
  199. #
  200. if [ ! -z "$SNAPSHOT" ]; then
  201. header Copying packages and demos for snapshot
  202. cp -rp $BUILDDIR/demo $INSTALLDIR/demo
  203. cp -rp $BUILDDIR/packages $INSTALLDIR/packages
  204. fi
  205. #
  206. # Test demos
  207. #
  208. if [ -z "$SKIPDEMO" ]; then
  209. header Build demos in $snvdir/demo without webcompiler
  210. cd "$BUILDDIR/demo"
  211. make SKIPWEBCOMPILER=1 P2JS=$BINDIR/pas2js
  212. header Build webcompiler in demos dir
  213. cd "$BUILDDIR/demo"
  214. make demowebcompiler P2JS=$BINDIR/pas2js
  215. fi
  216. if [ -z "$SNAPSHOT" ]; then
  217. header That\'s all folks!
  218. exit;
  219. fi
  220. header Building snapshot
  221. cd $BINDIR
  222. info Creating config file
  223. cat > pas2js.cfg << EOC
  224. # Logo and options
  225. -l
  226. -vwnh
  227. # If you don't want so much verbosity use
  228. #-vw
  229. # Allow C-operators
  230. -Sc
  231. -Fu\$CfgDir/../packages/*
  232. #IFDEF nodejs
  233. -Jirtl.js
  234. #ENDIF
  235. EOC
  236. cd $OUTDIR
  237. BASENAME=pas2js-snapshot
  238. SUFFIX=$SNAPSHOT-$SNAPSHOTOS-$FPCCPU
  239. ZIPFILE=$BUILDDIR/$BASENAME-$SUFFIX.zip
  240. TSFILE=$BUILDDIR/$BASENAME-$SUFFIX-date.txt
  241. MDFILE=$BUILDDIR/$BASENAME-$SUFFIX.md5
  242. info Creating zip file $ZIPFILE
  243. zip -qr $ZIPFILE $SNAPSHOTDIR
  244. cd $BUILDDIR
  245. md5sum -b $ZIPFILE > $MDFILE
  246. date > $TSFILE
  247. info "Zip file: " $ZIPFILE
  248. info "Timestamp file: " $TSFILE
  249. info "Checksum file: " $MDFILE