build 3.8 KB

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