1
0

build.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. #! /bin/sh
  2. # We want to use BASH, not whatever /bin/sh points to.
  3. if test -z "$BASH"; then
  4. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  5. bash="`which bash`"
  6. ${bash} $0 ${1+"$@"}
  7. exit 0
  8. fi
  9. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:${HOME}/bin
  10. # Awk out the version from source
  11. AWK="`which awk`"
  12. if test -z "${AWK}"; then
  13. AWK="`which gawk`"
  14. fi
  15. ver="?.?.?"
  16. ver=`grep "char" src/main.c | $AWK '/egg_version/ {print $5}' | sed -e 's/\"//g' | sed -e 's/\;//g'`
  17. echo $ver | grep "devel" > /dev/null 2>&1
  18. if [ $? -eq 0 ]; then
  19. devel="1"
  20. else
  21. devel="0"
  22. fi
  23. rm -f ts ts.exe
  24. gcc -o ts src/timestamp.c > /dev/null 2>&1
  25. if [ -d .git ]; then
  26. BUILDTS=$(git log -1 --pretty=format:%ct HEAD)
  27. else
  28. BUILDTS=`grep -m 1 "BUILDTS = " Makefile.in | ${AWK} '{print $3}'`
  29. fi
  30. builddate=`./ts ${BUILDTS}`
  31. rm -f ts ts.exe
  32. clear
  33. #Display a banner
  34. #bt=`grep -A 5 "char \*wbanner(void) {" src/misc.c | grep "switch" | sed -e "s/.*switch (randint(\(.\))) {/\1/"`
  35. #bn=$[($RANDOM % ${bt})]
  36. bn=0
  37. banner=`grep -A 15 "char \*wbanner(void) {" src/misc.c | grep "case ${bn}:" | sed -e "s/.*case ${bn}: return STR(\"\(.*\)\");/\1/"`
  38. echo -e "${banner}"
  39. echo -e "Version: ${ver}\nBuild: ${builddate}"
  40. usage()
  41. {
  42. echo
  43. echo "Usage: $0 [-bcCdnP] [-q FILE]"
  44. echo
  45. echo " The options are as follows:"
  46. echo " -b Use bzip2 instead of gzip when packaging."
  47. echo " -c Cleans up old binaries/files before compile."
  48. echo " -C Preforms a distclean before making."
  49. echo " -d Builds a debug package."
  50. echo " -n Do not package the binaries."
  51. echo " -q FILE What file to use as the cfg file."
  52. echo " -P For development (Don't compile/rm binaries)"
  53. echo " -s scp target."
  54. }
  55. debug=0
  56. clean=0
  57. nopkg=0
  58. bzip=0
  59. pkg=0
  60. scp=0
  61. nightly=0
  62. pack=pack/pack.cfg
  63. while getopts bCcdhnNPq:s: opt ; do
  64. case "$opt" in
  65. b) bzip=1 ;;
  66. c) clean=1 ;;
  67. C) clean=2 ;;
  68. d) debug=1 ;;
  69. h) usage; exit 0 ;;
  70. n) nopkg=1 ;;
  71. N) nightly=1 ;;
  72. q) pack="$OPTARG" ;;
  73. P) pkg=1 ;;
  74. s) scp="$OPTARG" ;;
  75. *) usage; exit 1 ;;
  76. esac
  77. done
  78. shift $(($OPTIND - 1))
  79. PACKNAME=`grep "PACKNAME " ${pack} | $AWK '/PACKNAME/ {print $2}'`
  80. echo "Packname: ${PACKNAME} (${pack})"
  81. echo -e `grep -m 1 "http://" src/misc.c | sed -e "s/.*\- \(.*\) \-.*/\1/"`
  82. echo
  83. if test -z "$1"; then
  84. usage
  85. exit 1
  86. fi
  87. rm=1
  88. compile=1
  89. if [ $pkg = "1" ]; then
  90. rm=0
  91. compile=0
  92. fi
  93. if [ $debug = "1" ]; then
  94. dmake="d"
  95. d="-debug"
  96. else
  97. dmake=""
  98. d=""
  99. fi
  100. # Figure what bins we're making
  101. case `uname` in
  102. Linux) os=Linux;;
  103. FreeBSD) os=FreeBSD;;
  104. # FreeBSD) case `uname -r` in
  105. # 5*) os=FreeBSD5;;
  106. # 4*) os=FreeBSD4;;
  107. # 3*) os=FreeBSD3;;
  108. # esac;;
  109. OpenBSD) os=OpenBSD;;
  110. NetBSD) os=NetBSD;;
  111. SunOS) os=Solaris;;
  112. CYGWIN*) os=Cygwin; extras="/bin/cygwin1.dll"; exe=".exe";;
  113. esac
  114. if test -z $os
  115. then
  116. echo "[!] Automated packaging disabled, `uname` isn't recognized"
  117. fi
  118. if [ $nightly = "1" ]; then
  119. chmod 0700 private/id_dsa
  120. remotedate="`ssh -q -i private/id_dsa bdrewery@endurance.quadspeedi.net ls -al public_html/nightly/${os}-stable.tar.gz | \
  121. sed -e 's/.*\-> \([0-1][0-2]\.[0-3][0-9]\.[0-9][0-9][0-9][0-9]\)\-.*/\1/'`"
  122. if [ "${remotedate}" = "${builddate}" ]; then
  123. exit 0
  124. fi
  125. fi
  126. if [ $compile = "1" ]; then
  127. echo "[*] Building ${PACKNAME} for $os"
  128. MAKE="`which gmake`"
  129. if test -z "${MAKE}"; then
  130. MAKE="`which make`"
  131. fi
  132. if [ $clean = "2" ]; then
  133. if test -f Makefile; then
  134. echo "[*] DistCleaning old files..."
  135. ${MAKE} distclean > /dev/null
  136. fi
  137. fi
  138. # Run ./configure, then verify it's ok
  139. echo "[*] Configuring..."
  140. umask 077 >/dev/null
  141. ./configure --silent
  142. if [ $clean = "1" ]; then
  143. echo "[*] Cleaning up old binaries/files..."
  144. ${MAKE} clean > /dev/null
  145. fi
  146. fi
  147. _build()
  148. {
  149. if [ $compile = "1" ]; then
  150. echo "[*] Building ${dmake}${tb}..."
  151. ${MAKE} ${dmake}${tb}
  152. if ! test -f ${tb}; then
  153. echo "[!] ${dmake}${tb} build failed"
  154. exit 1
  155. fi
  156. fi
  157. if [ $nopkg = "0" -o $pkg = "1" ]; then
  158. echo "[*] Hashing and initializing settings in binary"
  159. cp ${tb} ${tb}.$os-$ver${d} > /dev/null 2>&1
  160. ./${tb}.$os-$ver${d} -q ${pack}
  161. rm=1
  162. elif [ $nopkg = "0" ]; then
  163. mv ${tb} ${tb}.$os-$ver${d} > /dev/null 2>&1
  164. fi
  165. }
  166. tb="wraith"
  167. _build
  168. if [ $bzip = "1" ]; then
  169. zip="j"
  170. ext="bz2"
  171. else
  172. zip="z"
  173. ext="gz"
  174. fi
  175. # Wrap it nicely up into an archive
  176. if [ $nopkg = "0" -o $pkg = "1" ]; then
  177. echo "[*] Packaging..."
  178. #This MALLOC business is to not Abort 'tar' due to some bug it has.
  179. tmp=${MALLOC_CHECK_}
  180. unset MALLOC_CHECK_
  181. tar -c${zip}f ${PACKNAME}.$os-$ver${d}.tar.${ext} wraith.$os-$ver${d}
  182. chmod 0644 ${PACKNAME}.$os-$ver${d}.tar.${ext}
  183. if test -n "$tmp"; then
  184. declare -x MALLOC_CHECK_=$tmp
  185. fi
  186. if [ $rm = "1" ]; then
  187. rm -f *$os-$ver${d}
  188. fi
  189. echo "Binaries are now in '${PACKNAME}.$os-$ver${d}.tar.${ext}'."
  190. if ! [ $scp = 0 ]; then
  191. chmod 0700 private/id_dsa
  192. scp -i private/id_dsa -B -p -C ${PACKNAME}.$os-$ver${d}.tar.${ext} $scp
  193. scp_target=`echo $scp | cut -d : -f 1`
  194. dir=`echo $scp | cut -d : -f 2`
  195. if [ "$devel" = "1" ]; then
  196. ssh -i private/id_dsa $scp_target ln -fs ${PACKNAME}.$os-$ver${d}.tar.${ext} ${dir}/${PACKNAME}.${os}-devel.tar.gz
  197. else
  198. ssh -i private/id_dsa $scp_target ln -fs ${PACKNAME}.$os-$ver${d}.tar.${ext} ${dir}/${PACKNAME}.${os}-stable.tar.gz
  199. ssh -i private/id_dsa $scp_target ln -fs ${PACKNAME}.$os-$ver${d}.tar.${ext} ${dir}/${PACKNAME}.${os}-base.tar.gz
  200. fi
  201. fi
  202. elif ! [ $scp = "0" ]; then
  203. cp wraith wraith.$os-$ver${d} > /dev/null 2>&1
  204. cp ChangeLog ChangeLog-${builddate}
  205. gzip -9 ChangeLog-${builddate}
  206. #This MALLOC business is to not Abort 'tar' due to some bug it has.
  207. tmp=${MALLOC_CHECK_}
  208. unset MALLOC_CHECK_
  209. cp ${extras} .
  210. for file in $extras
  211. do
  212. extras_local="${extras_local} `basename $file`"
  213. done
  214. tar -c${zip}f ${builddate}-$os-$ver${d}.tar.${ext} wraith.$os-$ver${d}${exe} ChangeLog-${builddate}.gz ${extras_local}
  215. chmod 0644 ${builddate}-$os-$ver${d}.tar.${ext}
  216. if test -n "$tmp"; then
  217. declare -x MALLOC_CHECK_=$tmp
  218. fi
  219. chmod 0700 private/id_dsa
  220. scp -i private/id_dsa -B -p -C ${builddate}-$os-$ver${d}.tar.${ext} $scp
  221. rm -rf ${builddate}-$os-$ver${d}.tar.${ext} wraith.$os-$ver${d}${exe} ChangeLog-${builddate}.gz ${extras_local}
  222. if [ "$devel" = "1" ]; then
  223. ssh -i private/id_dsa shatow@wraith.shatow.net ln -fs ${builddate}-$os-$ver${d}.tar.${ext} public_html/nightly/${os}-devel.tar.gz
  224. else
  225. ssh -i private/id_dsa shatow@wraith.shatow.net ln -fs ${builddate}-$os-$ver${d}.tar.${ext} public_html/nightly/${os}-stable.tar.gz
  226. ssh -i private/id_dsa shatow@wraith.shatow.net ln -fs ${builddate}-$os-$ver${d}.tar.${ext} public_html/nightly/${os}.tar.gz
  227. fi
  228. fi
  229. exit 0