Скрипт для сборки SBCL под MinGW+MSYS
Feb. 15th, 2012 09:38 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Использовать например так:
Работает в любой директории, но если не указаны sbcl-srcdir и win32-srcdir, то скрипту требуется Git, для скачивания последних версий исходников из соответствующих репозиториев.
Также, Git нужен для определения версии SBCL.
Git для Windows можно взять тут: http://code.google.com/p/msysgit/
Кроме того, для сборки требуются более-менее новые GCC и SBCL.
Естественно, так как скрипт работает под MSYS, ему нужна более-менее полная среда MSYS.
Для поддержки SBCL core compression(SBCL умеет сжимать образы лиспа, т.е. ".core"-файлы) также нужна zlib, установленная там, где GCC сможет ее найти, т.е. например в c:/mingw. Причем, в этом билд-скрипте используется статическая версия, т.е. gcc должен суметь найти libz.a
Для сборки .MSI-пакета также необходим Windows Installer XML
build-sbcl.sh --with-git=/c/Git
Работает в любой директории, но если не указаны sbcl-srcdir и win32-srcdir, то скрипту требуется Git, для скачивания последних версий исходников из соответствующих репозиториев.
Также, Git нужен для определения версии SBCL.
Git для Windows можно взять тут: http://code.google.com/p/msysgit/
Кроме того, для сборки требуются более-менее новые GCC и SBCL.
Естественно, так как скрипт работает под MSYS, ему нужна более-менее полная среда MSYS.
Для поддержки SBCL core compression(SBCL умеет сжимать образы лиспа, т.е. ".core"-файлы) также нужна zlib, установленная там, где GCC сможет ее найти, т.е. например в c:/mingw. Причем, в этом билд-скрипте используется статическая версия, т.е. gcc должен суметь найти libz.a
Для сборки .MSI-пакета также необходим Windows Installer XML
#!/bin/bash show_help() { echo "Usage: $0 [OPTIONS]" echo "Options:" echo " --help" echo " Print this message and exit." echo " --sbcl-srcdir=[DIR]" echo " Source directory for upstream SBCL" echo " --win32-srcdir=[DIR]" echo " Source directory for sbcl-win32-threads fork" echo " --build-dir=[DIR]" echo " Build directory" echo " --enable-runtime-optimizations[=yes/no] (default=no)" echo " Enables small config fixes for optimization." echo " Possibly makes runtime executable non-portable." echo " --enable-core-compression[=yes/no] (default=yes)" echo " Enables support for SBCL core compression." echo " Requires zlib data compression library." echo " --enable-latest[=yes/no] (default=yes)" echo " Enables fetching latest sources from git repositories." echo " --enable-tests[=yes/no] (default=no)" echo " Run included tests after building SBCL" echo " --with-git=[DIR]" echo " Search for Git in DIR." echo " --without-git" echo " Disable Git support." echo " --with-wix=[DIR]" echo " Search for WIX in DIR." echo " --without-wix" echo " Do not build windows installer package." echo " SBCL_VERSION=[VERSION]" echo " Unless Git support is enabled, assume sbcl version is VERSION." exit 0 } error() { echo "$1" >&2 exit 1 } arch= case `uname -m` in *86) arch=x86 ;; i86pc) arch=x86 ;; *x86_64) arch=x86-64 ;; amd64) arch=x86-64 ;; *) error "Unknown machine type" ;; esac root_dir=`pwd -W` git_prefix= no_git= wix_prefix= no_wix= sbcl_win32_threads_git=git://github.com/akovalenko/sbcl-win32-threads.git sbcl_git=git://sbcl.git.sourceforge.net/gitroot/sbcl/sbcl.git srcdir="${root_dir}/sbcl-win32-threads" orig_srcdir="$root_dir/sbcl" build_dir="${root_dir}/sbcl-win32-threads-build" optimize= compress=yes latest=yes tests= arg_arg= for arg in ${@} do case "$arg" in *=*) arg_arg=`expr "$arg" : '[^=]*=\(.*\)'` ;; *) arg_arg=yes ;; esac case $arg in --help) show_help ;; --sbcl-srcdir=*) orig_srcdir=`dirname "${arg_arg}/."` ;; --win32-srcdir=*) srcdir=`dirname "${arg_arg}/."` ;; --build-dir=*) build_dir=`dirname "${arg_arg}/."` ;; --enable-runtime-optimizations) optimize=yes ;; --enable-runtime-optimizations=*) optimize=`echo "$arg_arg" | tr '[:upper:]' '[:lower:]'` case "$optimize" in y*) optimize=yes ;; n*) optimize="" ;; esac ;; --disable-runtime-optimizations) optimize="" ;; --enable-core-compression) compress=yes ;; --enable-core-compression=*) compress=`echo "$arg_arg" | tr '[:upper:]' '[:lower:]'` case "$compress" in y*) compress=yes ;; n*) compress="" ;; esac ;; --disable-core-compression) compress="" ;; --enable-latest) latest=yes ;; --enable-latest=*) latest=`echo "$arg_arg" | tr '[:upper:]' '[:lower:]'` case "$latest" in y*) latest=yes ;; n*) latest="" ;; esac ;; --disable-latest) latest="" ;; --enable-tests) tests=yes ;; --enable-tests=*) tests=`echo "$arg_arg" | tr '[:upper]' '[:lower]'` case "$tests" in y*) tests=yes ;; n*) tests="" ;; esac ;; --disable-tests) tests="" ;; --with-git=*) git_prefix="$arg_arg" ;; --without-git) no_git="yes" ;; --with-wix=*) wix_prefix="$arg_arg" ;; --without-wix) no_wix="yes" ;; SBCL_VERSION=*) SBCL_VERSION="$arg_arg" ;; *) error "Unkown option: $arg" ;; esac done case "$build_dir" in "$orig_srcdir") error "Unable to build sbcl-win32-threads in original sbcl source directory" ;; "$srcdir") error "Unable to build sbcl-win32-threads in source directory" ;; esac case "$srcdir" in "$orig_srcdir") error "Upstream sbcl and sbcl-win32-threads sources must exist in different directories" ;; esac if [ "$git_prefix" ]; then cd "$git_prefix" || error "Unable to enter Git install directory" git_prefix="/`pwd -W | sed -e 's/\://'`" PATH="${PATH}:${git_prefix}/bin" fi if [ -z "$no_git" ]; then no_git=`git --version &> /dev/null || echo "yes"` if [ "$no_git" ]; then echo "Warning: unable to find working Git" >&2 fi fi if [ -z "$no_git" ]; then if [ "$latest" ]; then echo "Fetching latest sbcl sources" if [ -d "$orig_srcdir" ]; then cd "$orig_srcdir" orig_srcdir=`pwd -W` git pull || no_git=yes if [ "$no_git" ]; then echo "Warning: unable to pull updates from upstream sbcl repo" >&2 fi else git clone "$sbcl_git" "$orig_srcdir" \ || error "Unable to clone upstream sbcl repo" fi cd "$root_dir" if [ -z "$no_git" ]; then echo "Fetching latest sbcl-win32-threads sources" if [ -d "$srcdir" ]; then cd "$srcdir" srcdir=`pwd -W` git pull || no_git=yes if [ "$no_git" ]; then echo "Warning: unable to pull updates from sbcl-win32-threads repo" >&2 fi else git clone "$sbcl_win32_threads_git" "$srcdir" || \ error "Unable to clone sbcl-win32-threads repo." fi fi else cd "$srcdir" || \ error "Unable to enter sbcl-win32-threads source directory" srcdir=`pwd -W` cd "$orig_srcdir" || \ error "Unable to enter original sbcl source directory" orig_srcdir=`pwd -W` fi fi cd "$root_dir" echo Copying sources into "$build_dir" if [ -d "$build_dir" ]; then echo "Warning: build directory already exists" >&2 fi mkdir -p "$build_dir" || error "Unable to create build directory" cd "$build_dir" build_dir=`pwd -W` for f in "${srcdir}/*"; do cp -r $f "${build_dir}/"; done config="${build_dir}/src/runtime/Config.${arch}-win32" # This adds some extra optimizations. Optional step. if [ "$optimize" ]; then echo Fixing configs... cat "$config" | \ sed -e 's/-march=[^ ]*/-march=native/' | \ sed -e 's/-mtune=[^ ]*/-mtune=native/' | \ sed -e 's/\(LINKFLAGS[^\r\n]*\)/\1 -s/' > "${config}.tmp" \ || error "Unable to fix config files" mv "${config}.tmp" "$config" || error "Unable to install new config files" fi if [ "$compress" ]; then cat "$config" | \ sed -e 's/-lz/-Wl,-Bstatic,-lz/' > "${config}.tmp" \ || error "Unable to fix config files" mv "${config}.tmp" "$config" || error "Unable to install new config files" echo "(lambda (l) (pushnew :sb-core-compression l) l)" \ > "${build_dir}/customize-target-features.lisp" fi echo Resolving SBCL version... src_commits="${build_dir}/sbcl-win32-threads.commits.tmp" orig_src_commits="${build_dir}/sbcl.commits.tmp" if [ -z "$no_git" ]; then cd "$srcdir" git log -n1 &> /dev/null || no_git="yes" if [ "$no_git" ]; then echo "Warning: $srcdir is not a Git repository. Disabling Git-based version resolving" >&2 else cd "$orig_srcdir" git log -n1 &> /dev/null || no_git="yes" if [ "$no_git" ]; then echo "Warning: $orig_srcdir is not a Git repository. Disabling Git-based version resolving" >&2 fi fi fi if [ "$no_git" ]; then version="${SBCL_VERSION:-"unknown-version"}" else cd "$srcdir" git log --pretty=format:%H > "$src_commits" || error "$srcdir is not a git repo" version_head=`git rev-parse HEAD` version_head_short=`git rev-parse --short HEAD` cd "$orig_srcdir" git log --pretty=format:%H > "$orig_src_commits" || error "$orig_srcdir is not a git repo" version_base=`grep -Fxf "$orig_src_commits" "$src_commits" | head -n1` version_tag=`git describe --tags --match 'sbcl*' --abbrev=0 $version_base` version_release=`echo $version_tag | sed -e 's/sbcl[_-]//' | sed -e 's/_/\./g'` version_n_root=`git rev-list $version_base --not $version_tag | wc -l` cd "$srcdir" version_n_branch=`git rev-list $version_head --not $version_base | wc -l` version_branch=`git branch --no-color | sed -e 's/* //'` version=`printf "%s.%s.%s.%s-%s" \ "$version_release" \ "$version_n_root" \ "$version_branch" \ "$version_n_branch" \ "$version_head_short"` fi version_file="${build_dir}/version.lisp-expr" echo "\"$version\"" > "$version_file" cd "$root_dir" if [ -z "$no_wix" ]; then echo "Searching for WIX" if [ -z "$wix_prefix" ]; then if [ -z "$WIX" ]; then echo "Warning: unable to find working WIX" >&2 no_wix=yes else "$WIX/bin/candle" --version &> /dev/null || no_wix=yes if [ "$no_wix" ]; then echo "Warning: unable to find working WIX" >&2 else cd "${WIX}/bin" export WIX_PATH=`pwd -W` fi fi else cd "$wix_prefix" || error "Unable to enter WIX install directory" "bin/candle" --version &> /dev/null || no_wix=yes if [ "$no_wix" ]; then echo "Warning: unable to find WIX at $wix_prefix" >&2 else cd bin export WIX_PATH=`pwd -W` fi fi fi echo "Building sbcl-$version" echo " in $build_dir" cd "$build_dir" ./make.sh || error "Build failed" if [ "$tests" ]; then cd tests && ./run-tests.sh fi if [ -z "$no_wix" ]; then cd "$build_dir" ./make-windows-installer.sh cp output/*.msi ./ echo "MSI package: "`pwd -W`"/"`stat -c %n *.msi` fi echo "Build finished"