1
0

build.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #! /bin/sh
  2. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:${HOME}/bin
  3. if [ -d .git ]; then
  4. BUILDTS=$(git log -1 --pretty=format:%ct HEAD)
  5. ver=$(git describe --candidates=2)
  6. else
  7. ver=$(awk '/^VERSION/ {print $3}' Makefile.in)
  8. BUILDTS=`grep -m 1 "BUILDTS = " Makefile.in | awk '{print $3}'`
  9. fi
  10. # Convert timestamp into readable format
  11. rm -f ts > /dev/null 2>&1
  12. cc -o ts src/timestamp.c > /dev/null 2>&1
  13. builddate=`./ts ${BUILDTS}`
  14. rm -f ts > /dev/null 2>&1
  15. #Display banner
  16. clear
  17. head -n 8 README
  18. echo -e "Version: ${ver}\nBuild: ${builddate}"
  19. echo ""
  20. usage()
  21. {
  22. echo "Usage: $0 [-bcCdnP] pack.cfg"
  23. echo
  24. echo " The options are as follows:"
  25. echo " -b Use bzip2 instead of gzip when packaging."
  26. echo " -c Cleans up old binaries/files before compile."
  27. echo " -C Preforms a distclean before making."
  28. echo " -d Builds a debug package."
  29. echo " -n Do not package the binaries."
  30. echo " -P For development (Don't compile/rm binaries)"
  31. }
  32. debug=0
  33. clean=0
  34. nopkg=0
  35. bzip=0
  36. pkg=0
  37. while getopts bCcdhnP: opt ; do
  38. case "$opt" in
  39. b) bzip=1 ;;
  40. c) clean=1 ;;
  41. C) clean=2 ;;
  42. d) debug=1 ;;
  43. h) usage; exit 0 ;;
  44. n) nopkg=1 ;;
  45. P) pkg=1 ;;
  46. *) usage; exit 1 ;;
  47. esac
  48. done
  49. shift $(($OPTIND - 1))
  50. pack=$1
  51. if ! [ -f $pack ]; then
  52. echo "Cannot read $pack" >&2
  53. exit 1
  54. fi
  55. if test -z "$1"; then
  56. usage
  57. exit 1
  58. fi
  59. PACKNAME=`grep "PACKNAME " ${pack} | awk '/PACKNAME/ {print $2}'`
  60. rm=1
  61. compile=1
  62. if [ $pkg = "1" ]; then
  63. rm=0
  64. compile=0
  65. fi
  66. if [ $debug = "1" ]; then
  67. dmake="d"
  68. d="-debug"
  69. else
  70. dmake=""
  71. d=""
  72. fi
  73. # Figure what bins we're making
  74. case `uname` in
  75. Linux) os=Linux;;
  76. FreeBSD) os=FreeBSD;;
  77. # FreeBSD) case `uname -r` in
  78. # 5*) os=FreeBSD5;;
  79. # 4*) os=FreeBSD4;;
  80. # 3*) os=FreeBSD3;;
  81. # esac;;
  82. OpenBSD) os=OpenBSD;;
  83. NetBSD) os=NetBSD;;
  84. SunOS) os=Solaris;;
  85. esac
  86. if test -z $os
  87. then
  88. echo "[!] Automated packaging disabled, `uname` isn't recognized"
  89. fi
  90. if [ $compile = "1" ]; then
  91. echo "[*] Building ${PACKNAME} for $os"
  92. if [ $clean = "2" ]; then
  93. if test -f Makefile; then
  94. echo "[*] DistCleaning old files..."
  95. make distclean > /dev/null
  96. fi
  97. fi
  98. # Run ./configure, then verify it's ok
  99. echo "[*] Configuring..."
  100. umask 077 >/dev/null
  101. ./configure --silent
  102. if [ $clean = "1" ]; then
  103. echo "[*] Cleaning up old binaries/files..."
  104. make clean > /dev/null
  105. fi
  106. fi
  107. _build()
  108. {
  109. if [ $compile = "1" ]; then
  110. echo "[*] Building ${dmake}${tb}..."
  111. make ${dmake}${tb}
  112. if ! test -f ${tb}; then
  113. echo "[!] ${dmake}${tb} build failed"
  114. exit 1
  115. fi
  116. fi
  117. if [ $nopkg = "0" -o $pkg = "1" ]; then
  118. echo "[*] Hashing and initializing settings in binary"
  119. cp ${tb} ${tb}.$os-$ver${d} > /dev/null 2>&1
  120. ./${tb}.$os-$ver${d} -q ${pack}
  121. rm=1
  122. elif [ $nopkg = "0" ]; then
  123. mv ${tb} ${tb}.$os-$ver${d} > /dev/null 2>&1
  124. fi
  125. }
  126. tb="wraith"
  127. _build
  128. if [ $bzip = "1" ]; then
  129. zip="j"
  130. ext="bz2"
  131. else
  132. zip="z"
  133. ext="gz"
  134. fi
  135. # Wrap it nicely up into an archive
  136. if [ $nopkg = "0" -o $pkg = "1" ]; then
  137. echo "[*] Packaging..."
  138. tar -c${zip}f ${PACKNAME}.$os-$ver${d}.tar.${ext} wraith.$os-$ver${d}
  139. chmod 0644 ${PACKNAME}.$os-$ver${d}.tar.${ext}
  140. if [ $rm = "1" ]; then
  141. rm -f *$os-$ver${d}
  142. fi
  143. echo "Binaries are now in '${PACKNAME}.$os-$ver${d}.tar.${ext}'."
  144. fi