build 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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) 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. # Run ./configure, then verify it's ok
  108. echo "[*] Configuring..."
  109. umask 077 >/dev/null
  110. ./configure --silent --with-pack=${pack}
  111. MAKE="`which gmake`"
  112. if test -z "${MAKE}"; then
  113. MAKE="`which make`"
  114. fi
  115. if [ $clean = "1" ]; then
  116. echo "[*] Cleaning up old binaries/files..."
  117. ${MAKE} clean > /dev/null
  118. elif [ $clean = "2" ]; then
  119. echo "[*] DistCleaning old files..."
  120. ${MAKE} distclean > /dev/null
  121. fi
  122. _build()
  123. {
  124. if [ $[${tb}] = "1" ]; then
  125. echo "[*] Building ${d}${tb}..."
  126. ${MAKE} ${d}${tb}
  127. if ! test -f ${tb}; then
  128. echo "[!] ${d}${tb} build failed"
  129. exit 1
  130. fi
  131. fi
  132. }
  133. if [ -f stamp.hub ]; then
  134. tb="hub"
  135. _build
  136. tb="leaf"
  137. else
  138. tb="leaf"
  139. _build
  140. tb="hub"
  141. fi
  142. _build
  143. if [ $all = "1" ]; then
  144. fls="leaf hub"
  145. elif [ $leaf = "1" ]; then
  146. fls="leaf"
  147. elif [ $hub = "1" ]; then
  148. fls="hub"
  149. fi
  150. if test -n "$d"; then
  151. d="-debug"
  152. fi
  153. for bin in $fls
  154. do
  155. mv -f $bin $bin.$os.$ver${d}
  156. done
  157. # Wrap it nicely up into an archive
  158. if [ $nopkg = "0" ]; then
  159. echo "[*] Packaging..."
  160. if [ $bzip = "1" ]; then
  161. zip="j"
  162. ext="bz2"
  163. else
  164. zip="z"
  165. ext="gz"
  166. fi
  167. #This MALLOC business is to not Abort 'tar' due to some bug it has.
  168. tmp=${MALLOC_CHECK_}
  169. unset MALLOC_CHECK_
  170. tar -c${zip}f ${PACKNAME}.$os.$ver${d}.tar.${ext} *.$os.$ver${d}
  171. if test -n "$tmp"; then
  172. declare -x MALLOC_CHECK_=$tmp
  173. fi
  174. rm -f *$os.$ver${d}
  175. echo "Binaries are now in '${PACKNAME}.$os.$ver${d}.tar.${ext}'."
  176. fi
  177. exit 0