build 4.3 KB

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