build 4.3 KB

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