build 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. # FIXME: We need to check for the proper pack/ files no?
  92. # Figure what bins we're making
  93. case `uname` in
  94. Linux) os=Linux;;
  95. FreeBSD) os=FreeBSD;;
  96. # FreeBSD) case `uname -r` in
  97. # 5*) os=FreeBSD5;;
  98. # 4*) os=FreeBSD4;;
  99. # 3*) os=FreeBSD3;;
  100. # esac;;
  101. OpenBSD) os=OpenBSD;;
  102. esac
  103. if test -z $os
  104. then
  105. echo "[!] Automated packaging disabled, `uname` isn't recognized"
  106. fi
  107. echo "[*] Building ${PACKNAME}::${type} for $os"
  108. MAKE="`which gmake`"
  109. if test -z "${MAKE}"; then
  110. MAKE="`which make`"
  111. fi
  112. if [ $clean = "2" ]; then
  113. if test -f Makefile; then
  114. echo "[*] DistCleaning old files..."
  115. ${MAKE} distclean > /dev/null
  116. fi
  117. fi
  118. # Run ./configure, then verify it's ok
  119. echo "[*] Configuring..."
  120. umask 077 >/dev/null
  121. ./configure --silent --with-cfg=${pack}
  122. if [ $clean = "1" ]; then
  123. echo "[*] Cleaning up old binaries/files..."
  124. ${MAKE} clean > /dev/null
  125. fi
  126. _build()
  127. {
  128. if [ $[${tb}] = "1" ]; then
  129. echo "[*] Building ${d}${tb}..."
  130. ${MAKE} ${d}${tb}
  131. if ! test -f ${tb}; then
  132. echo "[!] ${d}${tb} build failed"
  133. exit 1
  134. fi
  135. fi
  136. }
  137. if [ -f stamp.hub ]; then
  138. tb="hub"
  139. _build
  140. tb="leaf"
  141. else
  142. tb="leaf"
  143. _build
  144. tb="hub"
  145. fi
  146. _build
  147. if [ $all = "1" ]; then
  148. fls="leaf hub"
  149. elif [ $leaf = "1" ]; then
  150. fls="leaf"
  151. elif [ $hub = "1" ]; then
  152. fls="hub"
  153. fi
  154. if test -n "$d"; then
  155. d="-debug"
  156. fi
  157. for bin in $fls
  158. do
  159. mv -f $bin $bin.$os-$ver${d}
  160. done
  161. # Wrap it nicely up into an archive
  162. if [ $nopkg = "0" ]; then
  163. echo "[*] Packaging..."
  164. if [ $bzip = "1" ]; then
  165. zip="j"
  166. ext="bz2"
  167. else
  168. zip="z"
  169. ext="gz"
  170. fi
  171. #This MALLOC business is to not Abort 'tar' due to some bug it has.
  172. tmp=${MALLOC_CHECK_}
  173. unset MALLOC_CHECK_
  174. tar -c${zip}f ${PACKNAME}.$os-$ver${d}.tar.${ext} *.$os-$ver${d}
  175. if test -n "$tmp"; then
  176. declare -x MALLOC_CHECK_=$tmp
  177. fi
  178. rm -f *$os.$ver${d}
  179. echo "Binaries are now in '${PACKNAME}.$os-$ver${d}.tar.${ext}'."
  180. fi
  181. exit 0