| 1 |
#!/bin/sh |
| 2 |
# Create MinGW binary distribution. |
| 3 |
# Run this script on topsrcdir |
| 4 |
# You need MinGW and MSYS. (You no longer need Cygwin.) |
| 5 |
# The compiled binary is installed in ../Gauche-mingw-dist. You can just |
| 6 |
# zip it and distribute. |
| 7 |
# See doc/HOWTO-mingw.adoc for the details. |
| 8 |
|
| 9 |
set -e |
| 10 |
|
| 11 |
# TRANSIENT: Disabled version specification of Gauche for build. |
| 12 |
# Consider to enable it after 0.9.14 release. |
| 13 |
DISABLE_BUILD_GOSH_FLAGS="BUILD_GOSH_FLAGS=" |
| 14 |
|
| 15 |
# Set MINGWDIR if MinGW is installed in different place. |
| 16 |
case "$MSYSTEM" in |
| 17 |
MINGW64) |
| 18 |
mingwdir=${MINGWDIR:-/mingw64} |
| 19 |
mingwarch="x86_64" |
| 20 |
;; |
| 21 |
MINGW32) |
| 22 |
mingwdir=${MINGWDIR:-/mingw32} |
| 23 |
mingwarch="i686" |
| 24 |
;; |
| 25 |
*) |
| 26 |
echo 'WARNING: $MSYSTEM is neither "MINGW32" or "MINGW64".' |
| 27 |
mingwdir=${MINGWDIR:-/mingw} |
| 28 |
mingwarch="unknown" |
| 29 |
;; |
| 30 |
esac |
| 31 |
|
| 32 |
# Setting PATH to make sure the build process find right tools. |
| 33 |
# NB: We don't use CC=/path/to/gcc trick for ./configure, since |
| 34 |
# the gcc path embedded in gauche-config should be Windows path. |
| 35 |
export PATH=$mingwdir/bin:$PATH |
| 36 |
|
| 37 |
## Build architecture |
| 38 |
# Mingw-w64 automatically identifies this by default if you're in an |
| 39 |
# appropriate shell, but we sometimes need to cross-build (meaning, |
| 40 |
# building i686 binary on x86_64 shell, for example), so this setting |
| 41 |
# makes things easier. |
| 42 |
case "$MSYSTEM" in |
| 43 |
MINGW64) |
| 44 |
buildopt=--build=x86_64-w64-mingw32;; |
| 45 |
MINGW32) |
| 46 |
buildopt=--build=i686-w64-mingw32;; |
| 47 |
*) |
| 48 |
buildopt=--build=i686-pc-mingw32;; |
| 49 |
esac |
| 50 |
|
| 51 |
# Process Options: |
| 52 |
while [ "$#" -gt 0 ]; do |
| 53 |
case $1 in |
| 54 |
--with-gl) WITH_GL=yes; shift;; |
| 55 |
--with-installer) INSTALLER=yes; shift;; |
| 56 |
--with-mbedtls) MBEDTLS=yes; shift;; |
| 57 |
--with-mbedtls=dll) MBEDTLS=dll; shift;; |
| 58 |
--with-zip) ZIP_ARCHIVE=yes; shift;; |
| 59 |
--without-axtls) shift;; # Ignore this not to reject legacy scripts |
| 60 |
--skip-config) SKIP_CONFIG=yes; shift;; |
| 61 |
-*) |
| 62 |
echo "Options:" |
| 63 |
echo " --with-gl: Include Gauche-gl. Gauche-gl source must be in ../Gauche-gl." |
| 64 |
echo " --with-installer: Creates binary installer using Wix. 'candle.exe' and" |
| 65 |
echo " 'light.exe' must be visible in PATH." |
| 66 |
echo " --with-mbedtls: Include MbedTLS." |
| 67 |
echo " If you create an installer with this option, the binary" |
| 68 |
echo " will also be covered by Apache License 2.0 for MbedTLS." |
| 69 |
echo " This option comes with two flavors:" |
| 70 |
echo " * If you simply say --with-mbedtls, we build MbedTLS from source" |
| 71 |
echo " and bundle it with extension modules, so you don't need MbedTLS" |
| 72 |
echo " DLL on the system. You need CMake, though." |
| 73 |
echo " * If you say --with-mbedtls=dll, we build to link with MbedTLS" |
| 74 |
echo " DLL installed on the system. You need mingw-w64-{i686|x86_64}-mbedtls." |
| 75 |
echo " If you choose this option, those DLLs in turn depends on libgcc DLL." |
| 76 |
echo " --with-zip: Creates Zip archive using p7zip. '7z.exe' must be visible" |
| 77 |
echo " in PATH." |
| 78 |
echo " --skip-config: Skip cleanup and configuration." |
| 79 |
exit 1;; |
| 80 |
esac |
| 81 |
done |
| 82 |
|
| 83 |
if [ "$WITH_GL" = yes ]; then |
| 84 |
if [ -d ../Gauche-gl ]; then echo "Found Gauche-gl source." |
| 85 |
else echo "--with-gl: Cannot find ../Gauche-gl. Aborting."; exit 1 |
| 86 |
fi |
| 87 |
fi |
| 88 |
|
| 89 |
if [ "$INSTALLER" = yes ]; then |
| 90 |
wix_path=`which candle.exe 2> /dev/null` |
| 91 |
if test -e "$wix_path"; then echo "Wix SDK found: $wix_path" |
| 92 |
else echo "--installer: Cannot find Wix SDK. Aborting."; exit 1 |
| 93 |
fi |
| 94 |
fi |
| 95 |
|
| 96 |
if [ "$MBEDTLS" = yes ]; then |
| 97 |
tlslibs=${tlslibs}mbedtls-internal |
| 98 |
elif [ "$MBEDTLS" = dll ]; then |
| 99 |
tlslibs=${tlslibs}mbedtls |
| 100 |
fi |
| 101 |
|
| 102 |
# check gosh |
| 103 |
gosh_path=`which gosh.exe 2> /dev/null` |
| 104 |
if test -e "$gosh_path"; then |
| 105 |
echo "Using $gosh_path: " `gosh -V` |
| 106 |
else |
| 107 |
echo "Cannot find gosh.exe. Aborting." |
| 108 |
exit 1 |
| 109 |
fi |
| 110 |
|
| 111 |
# build |
| 112 |
if [ "$SKIP_CONFIG" != yes ]; then |
| 113 |
if [ -f Makefile ]; then make distclean; fi |
| 114 |
if [ -f examples/spigot/Makefile ]; then |
| 115 |
(cd examples/spigot; make maintainer-clean); |
| 116 |
fi |
| 117 |
if [ -f examples/mqueue-cpp/Makefile ]; then |
| 118 |
(cd examples/mqueue-cpp; make maintainer-clean); |
| 119 |
fi |
| 120 |
fi |
| 121 |
|
| 122 |
if [ "$INSTALLER" = yes ]; then |
| 123 |
distdir=`pwd`/winnt/wix/Gauche |
| 124 |
else |
| 125 |
distdir=`pwd`/../Gauche-mingw-dist/Gauche-${mingwarch} |
| 126 |
fi |
| 127 |
|
| 128 |
if [ "$SKIP_CONFIG" != yes ]; then |
| 129 |
rm -rf $distdir |
| 130 |
./configure --prefix=$distdir \ |
| 131 |
--with-tls=$tlslibs \ |
| 132 |
--with-dbm=ndbm,odbm $buildopt |
| 133 |
fi |
| 134 |
make $DISABLE_BUILD_GOSH_FLAGS |
| 135 |
|
| 136 |
if [ $? -ne 0 ]; then |
| 137 |
echo "Build failed. Aborting packaging." |
| 138 |
exit 1 |
| 139 |
fi |
| 140 |
|
| 141 |
# prepare precompiled directory tree. |
| 142 |
make install $DISABLE_BUILD_GOSH_FLAGS |
| 143 |
(cd src; make install-mingw $DISABLE_BUILD_GOSH_FLAGS) |
| 144 |
make install-examples $DISABLE_BUILD_GOSH_FLAGS |
| 145 |
rm -rf $distdir/lib/libgauche.dll* |
| 146 |
case "$MSYSTEM" in |
| 147 |
MINGW64|MINGW32) |
| 148 |
mingw_dll="libwinpthread-1.dll";; |
| 149 |
*) |
| 150 |
mingw_dll="mingwm10.dll";; |
| 151 |
esac |
| 152 |
|
| 153 |
# If we use external mbedtls, we need these DLLs. |
| 154 |
# NB: those dlls also depend on libgcc. |
| 155 |
if [ "$MBEDTLS" = dll ]; then |
| 156 |
mingw_dll="$mingw_dll libmbedcrypto.dll libmbedtls.dll libmbedx509.dll" |
| 157 |
fi |
| 158 |
|
| 159 |
if [ -n "$mingw_dll" ]; then |
| 160 |
for dll in $mingw_dll; do |
| 161 |
if [ -f $mingwdir/bin/$dll ]; then |
| 162 |
cp $mingwdir/bin/$dll $distdir/bin |
| 163 |
fi |
| 164 |
done |
| 165 |
fi |
| 166 |
|
| 167 |
# Enable using freshly-built gosh for the subsequent operations. |
| 168 |
PATH=$distdir/bin:$PATH |
| 169 |
|
| 170 |
# Build GL |
| 171 |
if [ "$WITH_GL" = "yes" ]; then |
| 172 |
if [ "$SKIP_CONFIG" != yes ]; then |
| 173 |
(cd ../Gauche-gl; ./DIST gen; ./configure --prefix=$distdir --with-glut=mingw-static $buildopt) |
| 174 |
fi |
| 175 |
(cd ../Gauche-gl; make clean; make; make install install-examples) |
| 176 |
fi |
| 177 |
|
| 178 |
# Build installer |
| 179 |
if [ "$INSTALLER" = "yes" ]; then |
| 180 |
(cd winnt/wix; make) |
| 181 |
cp winnt/wix/Gauche-mingw-*.msi .. |
| 182 |
fi |
| 183 |
|
| 184 |
# Build zip archive |
| 185 |
if [ "$ZIP_ARCHIVE" = "yes" ]; then |
| 186 |
VERSION=$(cat VERSION) |
| 187 |
ZIP_FILE="Gauche-mingw-${VERSION}.zip" |
| 188 |
|
| 189 |
(cd "${distdir}/../" && rm -f "./${ZIP_FILE}" && 7z a "./${ZIP_FILE}" $(basename "${distdir}")) |
| 190 |
cp "${distdir}/../${ZIP_FILE}" .. |
| 191 |
fi |