build 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. PACKNAME=`grep "PACKNAME " pack/pack.cfg | $AWK '/PACKNAME/ {print $2}'`
  15. BUILDTS=`cat src/build.h | $AWK '{print $3}'`
  16. builddate=`perl -e "use POSIX 'strftime';print strftime(\"%m.%d.%Y\n\",gmtime(${BUILDTS}));"`
  17. clear
  18. #Display a banner
  19. bt=`grep -A 3 "char \*wbanner() {" src/misc.c | grep "switch" | sed -e "s/.*switch (r % \(.\)) {/\1/"`
  20. bn=$[($RANDOM % ${bt})]
  21. banner=`grep -A 15 "char \*wbanner() {" src/misc.c | grep "case ${bn}:" | sed -e "s/.*case ${bn}: return STR(\"\(.*\)\");/\1/"`
  22. echo -e "${banner}"
  23. echo -e "Version: ${ver}\nBuild: ${builddate}"
  24. echo -e `grep -r "http://" src/misc.c | sed -e "s/dprintf(idx, STR(\"\(.*\)\"));/\1/"`
  25. echo
  26. usage()
  27. {
  28. echo "Usage: $0 [-bcdn] [all|hub|leaf]"
  29. echo
  30. echo " The options are as follows:"
  31. echo " -b Use bzip2 instead of gzip when packaging."
  32. echo " -c Cleans up old binaries/files before compile."
  33. echo " -d Builds a debug package."
  34. echo " -n Do not package the binaries."
  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. while getopts bcdhn opt ; do
  45. case "$opt" in
  46. b) bzip=1 ;;
  47. c) clean=1 ;;
  48. d) debug=1 ;;
  49. h) usage; exit 0 ;;
  50. n) nopkg=1 ;;
  51. # t) tcldir="$OPTARG" ;;
  52. *) usage; exit 1 ;;
  53. esac
  54. done
  55. shift $(($OPTIND - 1))
  56. if test -z "$1"; then
  57. usage
  58. exit 1
  59. else
  60. if [ $1 = "all" ]; then
  61. all=1
  62. elif [ $1 = "leaf" ]; then
  63. leaf=1
  64. type="leaf"
  65. elif [ $1 = "hub" ]; then
  66. hub=1
  67. type="hub"
  68. else
  69. all=1
  70. fi
  71. fi
  72. if [ $debug = "1" ]; then
  73. d="d"
  74. else
  75. d=""
  76. fi
  77. if [ $all = "1" ]; then
  78. type="all"
  79. leaf=1
  80. hub=1
  81. fi
  82. # FIXME: We need to check for the proper pack/ files no?
  83. # Figure what bins we're making
  84. case `uname` in
  85. Linux) os=Linux;;
  86. FreeBSD) case `uname -r` in
  87. 5*) os=FreeBSD5;;
  88. 4*) os=FreeBSD4;;
  89. 3*) os=FreeBSD3;;
  90. esac;;
  91. OpenBSD) os=OpenBSD;;
  92. esac
  93. if test -z $os
  94. then
  95. echo "[!] Automated packaging disabled, `uname` isn't recognized"
  96. fi
  97. echo "[*] Building ${PACKNAME}::${type} for $os"
  98. # Run ./configure, then verify it's ok
  99. echo "[*] Configuring..."
  100. umask 077 >/dev/null
  101. ./configure --silent
  102. MAKE="`which gmake`"
  103. if test -z "${MAKE}"; then
  104. MAKE="`which make`"
  105. fi
  106. if [ $clean = "1" ]; then
  107. echo "[*] Cleaning up old binaries/files..."
  108. ${MAKE} clean > /dev/null
  109. fi
  110. _build()
  111. {
  112. if [ $[${tb}] = "1" ]; then
  113. echo "[*] Building ${d}${tb}..."
  114. ${MAKE} ${d}${tb}
  115. if ! test -f ${tb}; then
  116. echo "[!] ${d}${tb} build failed"
  117. exit 1
  118. fi
  119. fi
  120. }
  121. if [ -f stamp.hub ]; then
  122. tb="hub"
  123. _build
  124. tb="leaf"
  125. else
  126. tb="leaf"
  127. _build
  128. tb="hub"
  129. fi
  130. _build
  131. if [ $all = "1" ]; then
  132. fls="leaf hub"
  133. elif [ $leaf = "1" ]; then
  134. fls="leaf"
  135. elif [ $hub = "1" ]; then
  136. fls="hub"
  137. fi
  138. if test -n "$d"; then
  139. d="-debug"
  140. fi
  141. for bin in $fls
  142. do
  143. mv -f $bin $bin.$os.$ver${d}
  144. done
  145. # Wrap it nicely up into an archive
  146. if [ $nopkg = "0" ]; then
  147. echo "[*] Packaging..."
  148. if [ $bzip = "1" ]; then
  149. zip="j"
  150. ext="bz2"
  151. else
  152. zip="z"
  153. ext="gz"
  154. fi
  155. #This MALLOC business is to not Abort 'tar' due to some bug it has.
  156. tmp=${MALLOC_CHECK_}
  157. unset MALLOC_CHECK_
  158. tar -c${zip}f ${PACKNAME}.$os.$ver${d}.tar.${ext} *.$os.$ver${d}
  159. if test -n "$tmp"; then
  160. declare -x MALLOC_CHECK_=$tmp
  161. fi
  162. rm -f *$os.$ver${d}
  163. echo "Binaries are now in '${PACKNAME}.$os.$ver${d}.tar.${ext}'."
  164. fi
  165. exit 0