build 4.3 KB

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