run_release.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. #!/bin/bash
  2. # Run from the source dir.
  3. SRCDIR=${PWD}
  4. # TODO replace w/ wget
  5. LZMA="xz-5.2.1"
  6. LZMA_FILE="${SRCDIR}/../${LZMA}.tar.gz"
  7. MAKEFLAGS="-j 10"
  8. BUILDDIR=${SRCDIR}/build
  9. LZMASRC=${BUILDDIR}/${LZMA}
  10. NONWIN_CFLAGS=""
  11. MINGW_CFLAGS="-DEXTERNAL_COMPRESSION=0 -DXD3_WIN32=1 -DSHELL_TESTS=0"
  12. MYOS=`uname`
  13. DATE=`date`
  14. CLEAN=""
  15. LINUXTGTS=""
  16. LINUXTEST1=""
  17. LINUXTEST2=""
  18. WINTGTS=""
  19. WINTEST1=""
  20. WINTEST2=""
  21. OSXTGTS=""
  22. OSXTEST1=""
  23. OSXTEST2=""
  24. XTMP="/tmp"
  25. if [ "${TMP}" != "" ]; then
  26. XTMP="${TMP}"
  27. fi
  28. if [ "${TMPDIR}" != "" ]; then
  29. XTMP="${TMPDIR}"
  30. fi
  31. BUILDFILES=`ls -A ${BUILDDIR} 2> /dev/null`
  32. if [ -d "${BUILDDIR}" ]; then
  33. if [ -n "${BUILDFILES}" ]; then
  34. echo "Directory ${BUILDDIR} should be empty"
  35. exit 1
  36. fi
  37. else
  38. mkdir "${BUILDDIR}"
  39. fi
  40. function setup {
  41. libtoolize || glibtoolize
  42. automake --add-missing
  43. aclocal -I m4
  44. autoheader
  45. automake
  46. autoconf
  47. }
  48. function try {
  49. local w=$1
  50. shift
  51. local dir=$1
  52. shift
  53. echo -n " ${w} ... "
  54. (cd "${dir}" && "$@" >${w}.stdout 2>${w}.stderr)
  55. local s=$?
  56. if [ ${s} -eq 0 ]; then
  57. echo " success"
  58. else
  59. echo " failed!"
  60. echo "Error $1 in ${dir}" >&2
  61. fi
  62. return ${s}
  63. }
  64. function buildlzma {
  65. host=$1
  66. march=$2
  67. local target="${BUILDDIR}/lib-${host}${march}"
  68. echo " ... liblzma"
  69. mkdir -p ${target}
  70. try configure-lzma ${target} ${LZMASRC}/configure \
  71. --host=${host} \
  72. --prefix=${target} \
  73. --disable-shared \
  74. "CC=${CC}" \
  75. "CXX=${CXX}" \
  76. "CFLAGS=${march}" \
  77. "CXXFLAGS=${march}" \
  78. "LDFLAGS=${march}"
  79. if [ $? -ne 0 ]; then
  80. return
  81. fi
  82. try build-lzma ${target} make ${MAKEFLAGS}
  83. if [ $? -ne 0 ]; then
  84. return
  85. fi
  86. try install-lzma ${target} make install
  87. if [ $? -ne 0 ]; then
  88. return
  89. fi
  90. }
  91. function buildit {
  92. local host=$1
  93. local march=$2
  94. local usizebits=$3
  95. local offsetbits=$4
  96. local cargs=$5
  97. local afl=$6
  98. local BM="${host}${march}"
  99. local USECC="${CC}"
  100. local USECXX="${CXX}"
  101. local LIBBM="${BM}"
  102. if [ "${afl}" = "1" ]; then
  103. USECC="afl-gcc"
  104. USECXX="afl-g++"
  105. BM="${BM}-afl"
  106. fi
  107. local D="build/${BM}/usize${usizebits}/xoff${offsetbits}"
  108. local BMD="${BM}-${usizebits}-${offsetbits}"
  109. local FULLD="${SRCDIR}/${D}"
  110. local CFLAGS="${march} ${cargs} -I${SRCDIR}/build/lib-${LIBBM}/include"
  111. local CXXFLAGS="${march} ${cargs} -I${SRCDIR}/build/lib-${LIBBM}/include"
  112. local CPPFLAGS="-I${SRCDIR}/build/lib-${LIBBM}/include"
  113. local LDFLAGS="${march} -L${SRCDIR}/build/lib-${LIBBM}/lib"
  114. local EXEC_PREAMBLE=""
  115. local EXEC_SUFFIX=""
  116. case ${host} in
  117. *mingw*)
  118. EXEC_PREAMBLE="wine"
  119. EXEC_SUFFIX=".exe"
  120. ;;
  121. esac
  122. mkdir -p ${D}
  123. echo " ... ${BMD}"
  124. cat >> Makefile.test <<EOF
  125. # ${BMD}
  126. # ${CFLAGS}
  127. .PHONY: build-${BMD}
  128. build-${BMD}:
  129. (cd ${D} && make all && make install)
  130. .PHONY: clean-${BMD}
  131. clean-${BMD}:
  132. (cd ${D} && make clean)
  133. .PHONY: regtest-${BMD}
  134. regtest-${BMD}:
  135. (cd ${D} && ${EXEC_PREAMBLE} ./bin/xdelta3regtest${EXEC_SUFFIX} 1> \${TMP}/regtest.${BMD}.stdout 2> \${TMP}/regtest.${BMD}.stderr)
  136. .PHONY: selftest-${BMD}
  137. selftest-${BMD}:
  138. (cd ${D} && ${EXEC_PREAMBLE} ./bin/xdelta3${EXEC_SUFFIX} test 1> \${TMP}/selftest.${BMD}.stdout 2> \${TMP}/selftest.${BMD}.stderr)
  139. EOF
  140. case ${host} in
  141. *linux*)
  142. LINUXTGTS="${LINUXTGTS} build-${BMD}"
  143. LINUXTEST1="${LINUXTEST1} selftest-${BMD}"
  144. LINUXTEST2="${LINUXTEST2} regtest-${BMD}"
  145. ;;
  146. *mingw*)
  147. WINTGTS="${WINTGTS} build-${BMD}"
  148. WINTEST1="${WINTEST1} selftest-${BMD}"
  149. WINTEST2="${WINTEST2} regtest-${BMD}"
  150. ;;
  151. *apple*)
  152. OSXTGTS="${OSXTGTS} build-${BMD}"
  153. OSXTEST1="${OSXTEST1} selftest-${BMD}"
  154. OSXTEST2="${OSXTEST2} regtest-${BMD}"
  155. ;;
  156. esac
  157. CLEAN="${CLEAN} clean-${BMD}"
  158. try configure-xdelta ${FULLD} ${SRCDIR}/configure \
  159. --host=${host} \
  160. --prefix=${FULLD} \
  161. --enable-static \
  162. --disable-shared \
  163. --enable-debug-symbols \
  164. "CFLAGS=${CFLAGS}" \
  165. "CXXFLAGS=${CXXFLAGS}" \
  166. "CPPFLAGS=${CPPFLAGS}" \
  167. "LDFLAGS=${LDFLAGS}" \
  168. "CC=${USECC}" \
  169. "CXX=${USECXX}"
  170. if [ $? -ne 0 ]; then
  171. return
  172. fi
  173. # try build-xdelta ${FULLD} make ${MAKEFLAGS} all
  174. # if [ $? -ne 0 ]; then
  175. # return
  176. # fi
  177. # try install-xdelta ${FULLD} make install
  178. }
  179. function buildall {
  180. echo ""
  181. echo "Host $1$2 afl=$4"
  182. echo ""
  183. buildlzma "$1" "$2"
  184. buildit "$1" "$2" 32 32 "-DXD3_USE_LARGESIZET=0 -DXD3_USE_LARGEFILE64=0 $3" "$4"
  185. buildit "$1" "$2" 32 64 "-DXD3_USE_LARGESIZET=0 -DXD3_USE_LARGEFILE64=1 $3" "$4"
  186. buildit "$1" "$2" 64 64 "-DXD3_USE_LARGESIZET=1 -DXD3_USE_LARGEFILE64=1 $3" "$4"
  187. }
  188. setup
  189. try untar-lzma ${BUILDDIR} tar -xvf "${LZMA_FILE}"
  190. if [ $? -ne 0 ]; then
  191. exit $?
  192. fi
  193. cat > Makefile.test <<EOF
  194. # Auto-generated ${DATE} -*- Mode: Makefile -*-
  195. TMP = ${XTMP}
  196. all: linux windows apple
  197. EOF
  198. # Native compiles
  199. if [ "${MYOS}" == "Linux" ]; then
  200. # Linux
  201. buildall x86_64-pc-linux-gnu -m32 "${NONWIN_CFLAGS}" "0"
  202. buildall x86_64-pc-linux-gnu -m32 "${NONWIN_CFLAGS}" "1"
  203. buildall x86_64-pc-linux-gnu -m64 "${NONWIN_CFLAGS}" "0"
  204. buildall x86_64-pc-linux-gnu -m64 "${NONWIN_CFLAGS}" "1"
  205. fi
  206. if [ "${MYOS}" == "Darwin" ]; then
  207. # OS X
  208. buildall x86_64-apple-darwin -m32 "${NONWIN_CFLAGS}" "0"
  209. buildall x86_64-apple-darwin -m64 "${NONWIN_CFLAGS}" "0"
  210. fi
  211. # Cross compile
  212. buildall i686-w64-mingw32 -mconsole "${MINGW_CFLAGS}" "0"
  213. buildall x86_64-w64-mingw32 -mconsole "${MINGW_CFLAGS}" "0"
  214. cat >> Makefile.test <<EOF
  215. clean: ${CLEAN}
  216. .PHONY: linux windows apple
  217. .PHONY: linux-build windows-build apple-build
  218. .PHONY: linux-selftest windows-selftest apple-selftest
  219. .PHONY: linux-regtest windows-regtest apple-regtest
  220. linux: linux-build linux-selftest linux-regtest
  221. windows: windows-build windows-selftest windows-regtest
  222. apple: apple-build apple-selftest apple-regtest
  223. linux-build: ${LINUXTGTS}
  224. linux-selftest: ${LINUXTEST1}
  225. linux-regtest: ${LINUXTEST2}
  226. windows-build: ${WINTGTS}
  227. windows-selftest: ${WINTEST1}
  228. windows-regtest: ${WINTEST2}
  229. apple-build: ${OSXTGTS}
  230. apple-selftest: ${OSXTEST1}
  231. apple-regtest: ${OSXTEST2}
  232. EOF