|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 6 | +YICES_SRC="$(cygpath -u "${YICES_SRC:?set YICES_SRC}")" |
| 7 | +YICES_PREFIX="${YICES_PREFIX:?set YICES_PREFIX}" |
| 8 | +JAVA_HOME_UNIX="$(cygpath -u "${JAVA_HOME:?set JAVA_HOME}")" |
| 9 | +JAVAC="${JAVA_HOME_UNIX}/bin/javac" |
| 10 | +JAVA="${JAVA_HOME_UNIX}/bin/java" |
| 11 | +JAR="${JAVA_HOME_UNIX}/bin/jar" |
| 12 | + |
| 13 | +win_path() { |
| 14 | + cygpath -w "$1" |
| 15 | +} |
| 16 | + |
| 17 | +win_path_list() { |
| 18 | + cygpath -wp "$1" |
| 19 | +} |
| 20 | + |
| 21 | +build_gmp() { |
| 22 | + mkdir -p /tools/dynamic_gmp /tools/static_gmp |
| 23 | + pushd /tools >/dev/null |
| 24 | + |
| 25 | + local archive=gmp-6.3.0.tar.xz |
| 26 | + if [[ ! -f "${archive}" ]]; then |
| 27 | + curl -fL --retry 5 --retry-delay 2 --connect-timeout 20 --max-time 600 \ |
| 28 | + https://ftp.gnu.org/gnu/gmp/${archive} -o "${archive}" || \ |
| 29 | + wget --tries=5 --timeout=20 -O "${archive}" https://ftp.gnu.org/gnu/gmp/${archive} || \ |
| 30 | + curl -fL --retry 5 --retry-delay 2 --connect-timeout 20 --max-time 600 \ |
| 31 | + https://mirrors.kernel.org/gnu/gmp/${archive} -o "${archive}" || \ |
| 32 | + wget --tries=5 --timeout=20 -O "${archive}" https://mirrors.kernel.org/gnu/gmp/${archive} || \ |
| 33 | + curl -fL --retry 5 --retry-delay 2 --connect-timeout 20 --max-time 600 \ |
| 34 | + https://gmplib.org/download/gmp/${archive} -o "${archive}" || \ |
| 35 | + wget --tries=5 --timeout=20 -O "${archive}" https://gmplib.org/download/gmp/${archive} |
| 36 | + fi |
| 37 | + |
| 38 | + rm -rf gmp-6.3.0 |
| 39 | + tar xf "${archive}" |
| 40 | + cd gmp-6.3.0 |
| 41 | + ./configure --host=x86_64-w64-mingw32 --build=i686-pc-cygwin --enable-cxx --enable-shared --disable-static --prefix=/tools/dynamic_gmp |
| 42 | + make |
| 43 | + make install |
| 44 | + make clean |
| 45 | + ./configure --host=x86_64-w64-mingw32 --build=i686-pc-cygwin --enable-cxx --enable-static --disable-shared --prefix=/tools/static_gmp |
| 46 | + make |
| 47 | + make install |
| 48 | + |
| 49 | + popd >/dev/null |
| 50 | +} |
| 51 | + |
| 52 | +build_yices() { |
| 53 | + pushd "${YICES_SRC}" >/dev/null |
| 54 | + autoconf |
| 55 | + ./configure \ |
| 56 | + --host=x86_64-w64-mingw32 \ |
| 57 | + --enable-thread-safety \ |
| 58 | + CPPFLAGS="-I/tools/dynamic_gmp/include" \ |
| 59 | + LDFLAGS="-L/tools/dynamic_gmp/lib" \ |
| 60 | + --with-static-gmp=/tools/static_gmp/lib/libgmp.a \ |
| 61 | + --with-static-gmp-include-dir=/tools/static_gmp/include |
| 62 | + export LD_LIBRARY_PATH="/usr/local/lib/:${LD_LIBRARY_PATH:-}" |
| 63 | + make OPTION=mingw64 MODE=release dist |
| 64 | + |
| 65 | + local dist_dir |
| 66 | + dist_dir="$(find build -type d -path '*/release/dist' | head -n 1)" |
| 67 | + if [[ -z "${dist_dir}" ]]; then |
| 68 | + echo "failed to locate Yices dist directory" >&2 |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | + |
| 72 | + rm -rf "${YICES_PREFIX}" |
| 73 | + mkdir -p "${YICES_PREFIX}" |
| 74 | + cp -R "${dist_dir}/." "${YICES_PREFIX}/" |
| 75 | + popd >/dev/null |
| 76 | +} |
| 77 | + |
| 78 | +build_java_bindings() { |
| 79 | + mkdir -p "${REPO_ROOT}/build/classes" "${REPO_ROOT}/build/test_classes" "${REPO_ROOT}/dist/lib" |
| 80 | + |
| 81 | + pushd "${REPO_ROOT}" >/dev/null |
| 82 | + find src/main/java/com/sri/yices -name '*.java' | sort > build/main-sources.txt |
| 83 | + "${JAVAC}" \ |
| 84 | + -d "$(win_path "${REPO_ROOT}/build/classes")" \ |
| 85 | + -h "$(win_path "${REPO_ROOT}/src/main/java/com/sri/yices")" \ |
| 86 | + @"build/main-sources.txt" |
| 87 | + |
| 88 | + x86_64-w64-mingw32-g++ \ |
| 89 | + -I "${JAVA_HOME_UNIX}/include" \ |
| 90 | + -I "${JAVA_HOME_UNIX}/include/win32" \ |
| 91 | + -I "${YICES_PREFIX}/include" \ |
| 92 | + -I /tools/dynamic_gmp/include \ |
| 93 | + -g -Wall -fpermissive \ |
| 94 | + -c src/main/java/com/sri/yices/yicesJNIforWindows.cpp \ |
| 95 | + -o build/yicesJNIforWindows.o |
| 96 | + |
| 97 | + x86_64-w64-mingw32-g++ \ |
| 98 | + -shared \ |
| 99 | + -o dist/lib/yices2java.dll \ |
| 100 | + build/yicesJNIforWindows.o \ |
| 101 | + -L "${YICES_PREFIX}/lib" \ |
| 102 | + -L /tools/dynamic_gmp/lib \ |
| 103 | + -lyices -lgmp |
| 104 | + |
| 105 | + "${JAR}" -cvfm \ |
| 106 | + "$(win_path "${REPO_ROOT}/dist/lib/yices.jar")" \ |
| 107 | + "$(win_path "${REPO_ROOT}/MANIFEST.txt")" \ |
| 108 | + -C "$(win_path "${REPO_ROOT}/build/classes")" . |
| 109 | + popd >/dev/null |
| 110 | +} |
| 111 | + |
| 112 | +stage_runtime_dlls() { |
| 113 | + cp "${YICES_PREFIX}/bin/libyices.dll" "${REPO_ROOT}/dist/lib/" |
| 114 | + cp /tools/dynamic_gmp/bin/libgmp-10.dll "${REPO_ROOT}/dist/lib/" |
| 115 | + cp /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libstdc++-6.dll "${REPO_ROOT}/dist/lib/" |
| 116 | + cp /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libgcc_s_seh-1.dll "${REPO_ROOT}/dist/lib/" |
| 117 | + cp /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libwinpthread-1.dll "${REPO_ROOT}/dist/lib/" |
| 118 | +} |
| 119 | + |
| 120 | +run_tests() { |
| 121 | + pushd "${REPO_ROOT}" >/dev/null |
| 122 | + find src/test/java -name '*.java' | sort > build/test-sources.txt |
| 123 | + |
| 124 | + local compile_cp |
| 125 | + compile_cp="$(win_path_list "${REPO_ROOT}/dist/lib/yices.jar:${REPO_ROOT}/lib/junit-4.12.jar:${REPO_ROOT}/lib/hamcrest-core-1.3.jar")" |
| 126 | + "${JAVAC}" \ |
| 127 | + -cp "${compile_cp}" \ |
| 128 | + -d "$(win_path "${REPO_ROOT}/build/test_classes")" \ |
| 129 | + @"build/test-sources.txt" |
| 130 | + |
| 131 | + local runtime_cp runtime_path |
| 132 | + runtime_cp="$(win_path_list "${REPO_ROOT}/build/test_classes:${REPO_ROOT}/dist/lib/yices.jar:${REPO_ROOT}/lib/junit-4.12.jar:${REPO_ROOT}/lib/hamcrest-core-1.3.jar")" |
| 133 | + runtime_path="$(win_path_list "${REPO_ROOT}/dist/lib:/tools/dynamic_gmp/bin:/usr/x86_64-w64-mingw32/sys-root/mingw/bin")" |
| 134 | + |
| 135 | + env PATH="${runtime_path}" \ |
| 136 | + "${JAVA}" \ |
| 137 | + "-Djava.library.path=$(win_path "${REPO_ROOT}/dist/lib")" \ |
| 138 | + -cp "${runtime_cp}" \ |
| 139 | + org.junit.runner.JUnitCore \ |
| 140 | + com.sri.yices.TestBigRationals \ |
| 141 | + com.sri.yices.TestConstructor \ |
| 142 | + com.sri.yices.TestContext \ |
| 143 | + com.sri.yices.TestStatus \ |
| 144 | + com.sri.yices.TestTypes \ |
| 145 | + com.sri.yices.TestYices \ |
| 146 | + com.sri.yices.TestModels \ |
| 147 | + com.sri.yices.TestTermComponents \ |
| 148 | + com.sri.yices.TestThreads |
| 149 | + popd >/dev/null |
| 150 | +} |
| 151 | + |
| 152 | +build_gmp |
| 153 | +build_yices |
| 154 | +build_java_bindings |
| 155 | +stage_runtime_dlls |
| 156 | +run_tests |
0 commit comments