build 4.2 KB

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