1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
|
#!/bin/bash
# Compiling SWI-Prolog using MinGW
# --------------------------------
#
# This file provides an overview for building SWI-Prolog using MinGW, in
# particular using the cross-compilers that are distributed with most
# todays Linux distributions. This work is mostly done by Roberto
# Bagnara (initial port of the Prolog kernel), Abramo Bagnara and Keri
# Harris.
#
# The current releases are configured and build using CMake. As a
# result, this README only applies for building the PREREQUISITES. See
# CMAKE.md and/or scripts/make-distribution for configuring and building
# SWI-Prolog.
#
# USE DOCKER INSTEAD
#
# These instructions are only required if you want to build in your
# local (Linux) environment. We have created a Docker image for doing
# the build which is a lot easier to manage. See:
#
# https://github.com/SWI-Prolog/docker-swipl-build-mingw.git
#
# USAGE
#
# You have been warned! Make sure to have a lot of time and coffee
# before proceeding.
#
# The remainder of the file is an executable specification of the
# installation process. The setup is designed to create ~/mingw32 and/or
# ~/mingw64 for building and installing the prerequisites. We describe
# the setup for Win64. Simply replace 64 with 32 to build for 32-bit
# Windows. First, install the requires tools from the Linux packages:
#
# % sudo apt-get install wine wine-binfmt mingw-w64
# % sudo apt-get install cmake ninja-build nsis
#
# Next, create and prepare the prerequisite location (the script changes
# your prompt to `W64`
#
# % cd ~
# % mkdir -p mingw64/src
# % cd mingw64/src
# % source <path/to/swipl-devel/README.mingw win64
# W64 download_prerequisites
#
# Unfortunately some of the download locations tend to be unreliable or
# require some registration or acceptance of license. So, check for
# empty .tar.gz files and try to get the archive by hand from the
# internet. Than re-run ``download_<package>`` to extract the archive.
#
# Once all is there, get the MinGW runtime libs in `bin`. The details
# may depend on exact versions of MinGW, so please check.
#
# % mkdir -p ~/mingw64/bin
# % cd ~/mingw64/bin
# % cp /usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll .
# % cp /usr/lib/gcc/x86_64-w64-mingw32/9.2-win32/libgcc_s_seh-1.dll .
#
# Now, build the prerequisites:
#
# W64 build_prerequisites
#
# If this worked successfully, build SWI-Prolog. Below is the default
# command, see CMAKE.md for various options:
#
# % cd /path/to/swipl-devel
# % mkdir build.win64
# % cd build.win64
# % cmake -DCMAKE_BUILD_TYPE=Release \
# -DCMAKE_TOOLCHAIN_FILE=../cmake/cross/linux_win64.cmake \
# -DJAVA_COMPATIBILITY=ON \
# -G Ninja ..
# % ninja
#
# If this succeeds you should be able to run `./src/swipl-win.exe` or
# `./src/swipl.exe`
#
# To build an installer for installation on other systems, run
#
# % cpack
#
#
# PREREQUISITES
#
# The open source libraries on which SWI-Prolog depends are downloaded
# and built using the functions download_prerequisites() and
# build_prerequisites(). In addition, the following need to be
# installed:
#
# - The Oracle Java SDK for building JPL
# - jdk-<version>-windows-i586.exe into
# /C/Program Files (x86)/... (default on 64-bit Windows)
# - jdk-<version>-windows-x64.exe into
# /C/Program Files/... (default on 64-bit Windows)
TARGETHOST="$1"
MAKE="make -j 4"
case "$TARGETHOST" in
win64) BITS=64
;;
win32) BITS=32
;;
*) echo "Please run as . $BASH_SOURCE 'win32|win64'"
return
esac
PS1=W$BITS' (\W\[\e[36m\]$(__git_ps1 "; %s")\[\e[0m\]) \!_> '
export BUILDARCH=$TARGETHOST
# Versions of prerequisite packages. Used to download the right release
# file.
GMP_VERSION=6.1.2
PTHREADS_VERSION=2-9-1-release
LIBDWARF_VERSION=20120410
SSL_VERSION=1.1.1d
JPEG_VERSION=9b
ZLIB_VERSION=1.2.12
ARCHIVE_VERSION=3.4.0
UUID_VERSION=1.6.2
BDB_VERSION=6.1.26
PCRE_VERSION=8.45 # TODO: update for PCRE2
FFI_VERSION=3.3
YAML_VERSION=0.2.2
PLDIR=pl-devel
# installation prefix. This path should not have spaces in one of the
# directory names.
install="${install-$HOME/mingw$BITS}"
src="$(pwd)"
PATH=$install/swipl/bin:$PATH
# Check whether we are cross-compiling or running under MSYS in Windows.
# Note that the MSYS version has not yet been tested.
case "$(uname)" in
MINGW*)
CROSSCOMPILING=no
export PATH=$install/bin:$PATH
DRIVEC="/C"
MINGWGCC=gcc
;;
*)
export CROSSCOMPILING=yes
export WINEDEBUG=-all
DRIVEC="$HOME/.wine/drive_c"
export WINEPATH="$(winepath -w $install/bin)"
;;
esac
if [ "$CROSSCOMPILING" = yes ]; then
if [ -z "$CROSS" ]; then
case $TARGETHOST in
win64)
CROSS=x86_64-w64-mingw32
;;
win32)
if [ -r /usr/bin/i686-w64-mingw32-gcc ]; then
CROSS=i686-w64-mingw32
else
CROSS=i586-mingw32msvc
fi
;;
esac
fi
MINGWGCC=$CROSS-gcc
export WINDRES=$CROSS-windres
fi
# See whether pthread is built-in
if [ -r "$($MINGWGCC -print-file-name=libwinpthread-1.dll)" ]; then
PTHREADS_VERSION=
fi
# Java configuration
# Note that Win64 javac and javadoc crash under Wine (1.5.6). But, we
# can use the native Linux versions
if [ -z "$JAVAROOT" ]; then
case $TARGETHOST in
win64)
JAVAROOT="$DRIVEC/Program Files/Java"
if [ "$CROSSCOMPILING" = yes ]; then
export JAVAC=javac
export JAVADOC=javadoc
fi
;;
win32)
JAVAROOT="$DRIVEC/Program Files (x86)/Java"
;;
esac
fi
JAVAPREFIX="$(echo "$JAVAROOT"/jdk*)/bin"
export JAVAPREFIX
# Set some variables to find the Windows libraries and include files
# export COFLAGS=-g
export CIFLAGS="-I$install/include"
export CPPFLAGS=-I$install/include
export LDFLAGS="-L$install/lib"
export PKGLDFLAGS=-I$install/lib
################################################################
# end of gathering info about the environment; the remainder are
# functions that perform steps of the build process
################################################################
################
# Handy for running autoconf from a directory
config()
{ if [ -r ./configure ]; then
./configure --host=$CROSS --prefix=$install
elif [ -r ../src/configure ]; then
./configure --host=$CROSS --prefix=$install
fi
}
################
# Create target directories
make_mingw_dirs()
{ mkdir -p $install/include
mkdir -p $install/lib
mkdir -p $install/bin
}
###########################
# Download and install the GMP library.
download_gmp()
{ GMP_FILE=gmp-$GMP_VERSION.tar.bz2
[ -f $GMP_FILE ] || \
wget ftp://ftp.gmplib.org/pub/gmp-$GMP_VERSION/$GMP_FILE
tar jxf $GMP_FILE
}
build_gmp()
{ ( cd gmp-$GMP_VERSION
./configure --host=$CROSS --prefix=$install \
--enable-shared --disable-static
make
make install
)
}
###########################
# Download and install the Pthreads-win32 library. Only if PTHREADS_VERSION
# is set. Else we assume a recent MinGW64, which ships with
# libwinpthread
download_pthread_win32()
{ if [ ! -z "$PTHREADS_VERSION" ]; then
PTHREADS_FILE=pthreads-w32-$PTHREADS_VERSION.tar.gz
cd $src
[ -f $PTHREADS_FILE ] || \
wget ftp://sourceware.org/pub/pthreads-win32/$PTHREADS_FILE
tar xzf $PTHREADS_FILE
fi
}
build_pthread_win32()
{ if [ -d pthreads-w32-$PTHREADS_VERSION ]; then
( cd pthreads-w32-$PTHREADS_VERSION
make -f GNUmakefile CROSS=$CROSS- \
LFLAGS="-lwsock32 -Wl,--out-implib=libpthreadGC2.dll.a" GC
cp pthread.h semaphore.h sched.h $install/include/
cp pthreadGC2.dll $install/bin/
cp libpthreadGC2.dll.a $install/lib/
)
fi
}
###########################
# Download and install the DWARF debugging library.
download_libdwarf()
{ LIBDWARF_FILE=libdwarf-$LIBDWARF_VERSION.tar.gz
[ -f $LIBDWARF_FILE ] || \
wget http://www.prevanders.net/$LIBDWARF_FILE
tar xzf $LIBDWARF_FILE
}
build_libdwarf()
{ ( cd dwarf-$LIBDWARF_VERSION/libdwarf
./configure --host=$CROSS --enable-shared
sed -i -e "s|libdwarf.so|libdwarf.dll|" \
-e "s|\$(CFLAGS) -shared|\$(LDFLAGS) -shared|" \
-e "/_elf_/d" -e "/[ \t]pro_/d" -e "/dwarf_addr_finder/d" Makefile
make PRELIBS="-Wl,--out-implib=libdwarf.dll.a"
mkdir -p $install/bin
cp libdwarf.dll $install/bin/
mkdir -p $install/lib
cp libdwarf.a libdwarf.dll.a $install/lib/
mkdir -p $install/include
cp dwarf.h libdwarf.h $install/include
)
}
###########################
# Download and install ssl
download_ssl()
{ SSL_FILE=openssl-$SSL_VERSION.tar.gz
[ -f $SSL_FILE ] || wget http://www.openssl.org/source/$SSL_FILE
tar xzf $SSL_FILE
}
build_ssl()
{ ( cd openssl-$SSL_VERSION
export CC=$MINGWGCC
case $CROSS in
i?86*) MINGW=mingw
;;
x86_64*) MINGW=mingw64
;;
*) echo "SSL: Unknown CROSS: $CROSS"
exit 1
;;
esac;
./Configure $MINGW --prefix=$install shared threads
make depend
make
make install_sw
)
}
###########################
# Download and install BerkeleyDB
# http://www.oracle.com/technetwork/database/database-technologies/berkeleydb/overview/index.html
download_libdb()
{ BDB_FILE=db-$BDB_VERSION.tar.gz
[ -f $BDB_FILE ] || \
curl http://download.oracle.com/berkeley-db/$BDB_FILE > $BDB_FILE
tar zxvf $BDB_FILE
}
build_libdb()
{ ( cd db-$BDB_VERSION/build_unix
sed -i -e "s:WinIoCtl.h:winioctl.h:" ../src/dbinc/win_db.h
../dist/configure --enable-mingw --host=$CROSS --prefix=$install \
--enable-shared --disable-static
make library_build
make install_lib install_include
( cd $install/lib
[ -f libdb.dll.a ] || ln -s libdb-*.dll.a libdb.dll.a
[ -f libdb.la ] || ln -s libdb-*.la libdb.la
)
)
}
###########################
# Download and install jpeg
download_jpeg()
{ JPEG_FILE=jpegsrc.v$JPEG_VERSION.tar.gz
[ -f $JPEG_FILE ] || wget http://www.ijg.org/files/$JPEG_FILE
tar xzf $JPEG_FILE
}
build_jpeg()
{ ( cd jpeg-$JPEG_VERSION
./configure --host=$CROSS --prefix=$install --enable-shared
make
make install
)
}
###########################
# Download and install libXpm
download_libxpm()
{ if [ -d libXpm ]; then
(cd libXpm && git pull)
else
git clone https://github.com/SWI-Prolog/libXpm.git
fi
}
build_libxpm()
{ ( cd libXpm/lib
autoconf
./configure --host=$CROSS --prefix=$install
make -f Makefile.mingw
make -f Makefile.mingw install
)
}
###########################
# Download and install zlib
download_zlib()
{ ZLIB_FILE=zlib-$ZLIB_VERSION.tar.gz
[ -f $ZLIB_FILE ] || wget http://zlib.net/$ZLIB_FILE
tar xzf $ZLIB_FILE
}
build_zlib()
{ ( cd zlib-$ZLIB_VERSION
make -f win32/Makefile.gcc PREFIX=$CROSS- BINARY_PATH=$install/bin INCLUDE_PATH=$install/include LIBRARY_PATH=$install/lib SHARED_MODE=1 IMPLIB=libz.dll.a install
)
}
#################################
# Download and install libarchive
download_libarchive()
{ ARCHIVE_FILE=libarchive-$ARCHIVE_VERSION.tar.gz
[ -f $ARCHIVE_FILE ] || \
wget http://www.libarchive.org/downloads/$ARCHIVE_FILE
tar xzf $ARCHIVE_FILE
}
# lt_cv_deplibs_check_method=pass_all works around a bug in libtool
# causing: "linker path does not have real file for library" error on MinGW
# See http://lists.cairographics.org/archives/cairo/2009-July/017686.html
build_libarchive()
{ ( cd libarchive-$ARCHIVE_VERSION
export CFLAGS="-I$install/include"
export LDFLAGS="-L$install/lib"
export lt_cv_deplibs_check_method='pass_all'
export ac_cv_func__localtime64_s='no'
export ac_cv_func__ctime64_s='no'
./configure --host=$CROSS --prefix=$install --with-pic --with-zlib \
--without-iconv --without-openssl --without-nettle --without-xml2 \
--without-expat --without-libregex --without-bz2lib \
--without-lzmadec --without-lzma --without-lzo2
make
make install
)
}
#################################
# Download and install libpcre
# TODO: update for PCRE2
download_libpcre()
{ PCRE_FILE=pcre-$PCRE_VERSION.tar.gz
[ -f $PCRE_FILE ] || \
wget https://ftp.pcre.org/pub/pcre/$PCRE_FILE
tar xzf $PCRE_FILE
}
build_libpcre()
{ ( cd pcre-$PCRE_VERSION
./configure --host=$CROSS --prefix=$install \
--disable-static --disable-cpp --enable-utf8 --enable-unicode-properties
make pcre.dll
make install
)
}
#################################
# Download and install libuuid
download_libuuid()
{ UUID_FILE=uuid-$UUID_VERSION.tar.gz
[ -f $UUID_FILE ] || \
curl ftp://ftp.ossp.org/pkg/lib/uuid/$UUID_FILE > $UUID_FILE
tar zxvf $UUID_FILE
}
build_libuuid()
{ ( cd uuid-$UUID_VERSION
./configure --host=$CROSS --prefix=$install
make
make install
)
}
################################
# Download and install libffi
download_libffi()
{ FFI_FILE=libffi-$FFI_VERSION.tar.gz
[ -f $FFI_FILE ] || \
curl ftp://sourceware.org/pub/libffi/$FFI_FILE > $FFI_FILE
tar zxvf $FFI_FILE
}
build_libffi()
{ ( cd libffi-$FFI_VERSION
./configure --host=$CROSS --prefix=$install
make
make install
# Bit strange location for the headers
cp $install/lib/libffi-$FFI_VERSION/include/*.h $install/include
)
}
################################
# Download and install libyaml
download_libyaml()
{ #tested 01f3a8786127748b5bbd4614880c4484570bbd44
git clone https://github.com/yaml/libyaml
}
build_libyaml()
{ ( cd libyaml
./bootstrap
./configure --host=$CROSS --prefix=$install
make
make install
)
}
###########################
# Do the whole lot for all prerequisites
clean_prerequisites()
{ ( cd gmp-$GMP_VERSION && make distclean )
( cd openssl-$SSL_VERSION && make distclean )
( cd jpeg-$JPEG_VERSION && make distclean )
( cd libXpm/lib && make distclean )
( cd zlib-$ZLIB_VERSION && make distclean )
( cd libarchive-$ARCHIVE_VERSION && make distclean )
( cd uuid-$UUID_VERSION && make distclean )
( cd ffi-$FFI_VERSION && make distclean )
if [ -d pthreads-w32-$PTHREADS_VERSION ]; then
( cd pthreads-w32-$PTHREADS_VERSION && make distclean )
fi
}
download_prerequisites()
{ download_gmp
download_pthread_win32
download_libdwarf
download_ssl
download_jpeg
download_libxpm
download_zlib
download_libarchive
download_libuuid
download_libdb
download_libpcre
download_libffi
download_libyaml
}
build_prerequisites()
{ build_gmp
build_pthread_win32
build_libdwarf
build_ssl
build_jpeg
build_libxpm
build_zlib
build_libarchive
build_libuuid
build_libdb
build_libpcre
build_libffi
build_libyaml
}
|