build 4.4 KB

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