build 5.8 KB

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