build 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 3 "char \*wbanner() {" src/misc.c | grep "switch" | sed -e "s/.*switch (randint(\(.\))) {/\1/"`
  19. bn=$[($RANDOM % ${bt})]
  20. banner=`grep -A 15 "char \*wbanner() {" 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 [-bcCdn] [-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 Used for development."
  35. }
  36. debug=0
  37. all=0
  38. hub=0
  39. leaf=0
  40. clean=0
  41. type=
  42. nopkg=0
  43. bzip=0
  44. pack=pack/pack.cfg
  45. if test -f Makefile; then
  46. pack="`grep "CFG =" Makefile | sed -e 's/CFG = \(.*\)/\1/'`"
  47. fi
  48. while getopts bCcdhnp: opt ; do
  49. case "$opt" in
  50. b) bzip=1 ;;
  51. c) clean=1 ;;
  52. C) clean=2 ;;
  53. d) debug=1 ;;
  54. h) usage; exit 0 ;;
  55. n) nopkg=1 ;;
  56. p) pack="$OPTARG" ;;
  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/dprintf(idx, STR(\"\(.*\)\"));/\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. if [ $debug = "1" ]; then
  82. d="d"
  83. else
  84. d=""
  85. fi
  86. if [ $all = "1" ]; then
  87. type="all"
  88. leaf=1
  89. hub=1
  90. fi
  91. # Figure what bins we're making
  92. case `uname` in
  93. Linux) os=Linux;;
  94. FreeBSD) os=FreeBSD;;
  95. # FreeBSD) case `uname -r` in
  96. # 5*) os=FreeBSD5;;
  97. # 4*) os=FreeBSD4;;
  98. # 3*) os=FreeBSD3;;
  99. # esac;;
  100. OpenBSD) os=OpenBSD;;
  101. esac
  102. if test -z $os
  103. then
  104. echo "[!] Automated packaging disabled, `uname` isn't recognized"
  105. fi
  106. echo "[*] Building ${PACKNAME}::${type} for $os"
  107. MAKE="`which gmake`"
  108. if test -z "${MAKE}"; then
  109. MAKE="`which make`"
  110. fi
  111. if [ $clean = "2" ]; then
  112. if test -f Makefile; then
  113. echo "[*] DistCleaning old files..."
  114. ${MAKE} distclean > /dev/null
  115. fi
  116. fi
  117. # Run ./configure, then verify it's ok
  118. echo "[*] Configuring..."
  119. umask 077 >/dev/null
  120. ./configure --silent --with-cfg=${pack}
  121. if [ $clean = "1" ]; then
  122. echo "[*] Cleaning up old binaries/files..."
  123. ${MAKE} clean > /dev/null
  124. fi
  125. _build()
  126. {
  127. if [ $[${tb}] = "1" ]; then
  128. echo "[*] Building ${d}${tb}..."
  129. ${MAKE} ${d}${tb}
  130. if ! test -f ${tb}; then
  131. echo "[!] ${d}${tb} build failed"
  132. exit 1
  133. fi
  134. fi
  135. }
  136. if [ -f stamp.hub ]; then
  137. tb="hub"
  138. _build
  139. tb="leaf"
  140. else
  141. tb="leaf"
  142. _build
  143. tb="hub"
  144. fi
  145. _build
  146. if [ $all = "1" ]; then
  147. fls="leaf hub"
  148. elif [ $leaf = "1" ]; then
  149. fls="leaf"
  150. elif [ $hub = "1" ]; then
  151. fls="hub"
  152. fi
  153. if test -n "$d"; then
  154. d="-debug"
  155. fi
  156. for bin in $fls
  157. do
  158. mv -f $bin $bin.$os-$ver${d}
  159. done
  160. # Wrap it nicely up into an archive
  161. if [ $nopkg = "0" ]; then
  162. echo "[*] Packaging..."
  163. if [ $bzip = "1" ]; then
  164. zip="j"
  165. ext="bz2"
  166. else
  167. zip="z"
  168. ext="gz"
  169. fi
  170. #This MALLOC business is to not Abort 'tar' due to some bug it has.
  171. tmp=${MALLOC_CHECK_}
  172. unset MALLOC_CHECK_
  173. tar -c${zip}f ${PACKNAME}.$os-$ver${d}.tar.${ext} *.$os-$ver${d}
  174. if test -n "$tmp"; then
  175. declare -x MALLOC_CHECK_=$tmp
  176. fi
  177. rm -f *$os-$ver${d}
  178. echo "Binaries are now in '${PACKNAME}.$os-$ver${d}.tar.${ext}'."
  179. fi
  180. exit 0