ATLAS/LAPACK Cygwin Build Script
Building ATLAS (http://math-atlas.sourceforge.net) on Windows is difficult, building it without depending on the Cygwin runtime is even more difficult. This bounty is for creating a shell script that builds a combined ATLAS/LAPACK library inside Cygwin 1.7.7-1 or newer on Windows 7 (32 and 64 bit)/Vista/XP using MinGW. Its purpose is to make building ATLAS on Windows easier. The script will be added to the Math.NET Numerics project under an X11/MIT license (http://mathnetnumerics.codeplex.com/).
Status:
[COMPLETE]The final payment was made to whaley on Mon, Jun 18, 2012. This project is complete; no new sponsorships or submissions will be accepted. You can continue to use the forums for discussion purposes.
Note: You can propose changes using the forum below.
Building ATLAS (http://math-atlas.sourceforge.net) on Windows is difficult, building it without depending on the Cygwin runtime is even more difficult. This bounty is for creating a shell script that builds a combined ATLAS/LAPACK library inside Cygwin 1.7.7-1 or newer on Windows 7 (32 and 64 bit)/Vista/XP using MinGW. Its purpose is to make building ATLAS on Windows easier. The script will be added to the Math.NET Numerics project under an X11/MIT license (http://mathnetnumerics.codeplex.com/).
The script should do the following:
1) Downloads ATLAS 3.9.35 from SourceForge if it doesn't exist in the current directory - http://sourceforge.net/projects/math-atlas/files/Developer%20%28unstable%29/3.9.35/atlas3.9.35.tar.bz2/download
2) Downloads LAPACK 3.3 from Netlib if it doesn't exist in the current directory - http://www.netlib.org/lapack/lapack-3.3.0.tgz
3) Build a combined ATLAS/LAPACK library. The script should build at static version of the library by default but have an option to build a DLL (if it is not possible to build a static version, then only building a DLL version is fine).
4) The script should build a parallel version of the library that DOES NOT use Cygwin's version pthreads (the Cygwin runtime), either use Windows threads or Mingw's version of pthreads.
5) The script must be able to build 32 bit and 64 bit versions of the combined library.
6) The resulting library must be able to link to a standard Windows program or DLL without any Cygwin dependencies.
7) The script can use the version of MinGW that ships with Cygwin, the TDM-GCC version (http://tdm-gcc.tdragon.net/), or the MinGW project (www.mingw.org).
Posts in the ATLAS Windows forum might be helpful (http://sourceforge.net/projects/math-atlas/forums/forum/1026734). Below is a script that was started but never completed. Feel free to use any part that is helpful.
#!/bin/bash
# Requires cygwin's gcc-4, gfortran, patch, wget, make
#
#
# Please modify this variables
#
# ATLAS source
ATLAS_SRC="http://downloads.sourceforge.net/project/math-atlas/Developer%20%28unstable%29/3.9.24/atlas3.9.24.tar.bz2"
ATLAS_LOCAL_SRC="`echo ${ATLAS_SRC}|awk -F'/' '{ print $NF }'`"
# LAPACK source
LAPACK_SRC="http://www.netlib.org/lapack/lapack.tgz"
LAPACK_LOCAL_SRC="`echo ${LAPACK_SRC}|awk -F'/' '{ print $NF }'`"
# Winthreads patch
# This patch no longer exists, but I think it was based on patches here:
# http://sourceforge.net/projects/math-atlas/forums/forum/1026734/topic/3440080
WTHPATCH_SRC="http://xxx.xxx.xxx/winthreads.patch"
WTHPATCH_LOCAL_SRC="`echo ${WTHPATCH_SRC}|awk -F'/' '{ print $NF }'`"
# Attention! These directories should be the same! Otherwise MinGW will execution will fail!
# e.g. C:/path1/path2/path3 -> /path1/path2/path3
BUILD_DIRECTORY_WIN="E:/build"
BUILD_DIRECTORY_CYG="/build"
# MinGW installation path
MINGW_PATH="/cygdrive/e/MinGW"
# MSVC path (optional)
MSVC_PATH=""
#MSVC_PATH="/cygdrive/e/Program Files/Microsoft Visual Studio 8"
# It is suggested that a valid frequency value was supplied while building.
# However you can leave it empty.
FREQ="2200"
#
# End of configuration
#
PATH="${MINGW_PATH}/bin:$PATH"
if [ ! -z "${MSVC_PATH}" ]; then
PATH="${MSVC_PATH}/VC/bin:$PATH"
PATH="${MSVC_PATH}/Common7/IDE:$PATH"
fi
export PATH="${PATH}"
do_cleanup() {
cd ${BUILD_DIRECTORY_CYG} && rm -rf *
}
do_download() {
echo "Downloading source"
if [ "$1" != "" ]; then
echo "Cleaning up"
do_cleanup
fi
if [ ! -f ${ATLAS_LOCAL_SRC} ]; then
wget "${ATLAS_SRC}" -O "${ATLAS_LOCAL_SRC}"
fi
if [ ! -f ${LAPACK_LOCAL_SRC} ]; then
wget "${LAPACK_SRC}" -O "${LAPACK_LOCAL_SRC}"
fi
if [ ! -f ${WTHPATCH_LOCAL_SRC} ]; then
wget "${WTHPATCH_SRC}" -O "${WTHPATCH_LOCAL_SRC}"
fi
}
do_unpack() {
echo "Unpacking sources"
tar jxf ${ATLAS_LOCAL_SRC}
patch -p0 < ${WTHPATCH_LOCAL_SRC}
}
prepare() {
echo "Setting up build env"
umount ${BUILD_DIRECTORY_CYG}
mkdir -p ${BUILD_DIRECTORY_WIN}
mkdir -p ${BUILD_DIRECTORY_CYG}
mount ${BUILD_DIRECTORY_WIN} ${BUILD_DIRECTORY_CYG}
cd ${BUILD_DIRECTORY_CYG}
do_download
do_unpack
mkdir build
cd build && rm -rf *
}
make_msvc_implibs() {
if [ ! -z "`which lib.exe`" ]; then
for i in `ls *.def`; do
lib /MACHINE:x86 /def:"$i"
done
fi
}
build_dlls() {
echo "Building libraries"
cd lib
cp libatlas.a libatlas.a.bak
ar d libatlas.a ATL_{s,d,c,z}pt{gescal,geadd,trscal,hescal,gezero}.o
# dynamic gcc
mkdir dynamic_gcc
cd dynamic_gcc && rm -rf *
cp ../*.a ./
FORTRAN_LIB="gfortran"
gcc -shared -shared-libgcc -o libatlas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive libatlas.a -Wl,--no-whole-archive -Wl,--output-def,libatlas.def -Wl,--out-implib,libatlas_gcc.lib
gcc -shared -shared-libgcc -o libcblas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive libcblas.a -Wl,--no-whole-archive libatlas_gcc.lib -Wl,--output-def,libcblas.def,--out-implib,libcblas_gcc.lib
gcc -shared -shared-libgcc -o libf77blas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive libf77blas.a -Wl,--no-whole-archive libatlas_gcc.lib -l${FORTRAN_LIB} -Wl,--output-def,libf77blas.def,--out-implib,libf77blas_gcc.lib
gcc -shared -shared-libgcc -o libf77refblas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive libf77refblas.a -Wl,--no-whole-archive libatlas_gcc.lib -l${FORTRAN_LIB} -Wl,--output-def,libf77refblas.def,--out-implib,libf77refblas_gcc.lib
gcc -shared -shared-libgcc -o liblapack.dll -Wl,--allow-multiple-definition -Wl,--whole-archive liblapack.a -Wl,--no-whole-archive libcblas_gcc.lib libf77blas_gcc.lib libatlas_gcc.lib -l${FORTRAN_LIB} -Wl,--output-def,liblapack.def,--out-implib,liblapack_gcc.lib
gcc -shared -shared-libgcc -o atlas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive *.a --Wl,--no-whole-archive -l${FORTRAN_LIB} -Wl,--output-def,atlas_gcc.def,--out-implib,atlas_gcc.lib
rm *.a
make_msvc_implibs
cd ../
# static gcc
mkdir static_gcc
cd static_gcc && rm -rf *
cp ../*.a ./
gcc -shared -o libatlas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive libatlas.a -Wl,--no-whole-archive -Wl,--output-def,libatlas.def -Wl,--out-implib,libatlas_gcc.lib
gcc -shared -o libcblas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive libcblas.a -Wl,--no-whole-archive libatlas_gcc.lib -Wl,--output-def,libcblas.def,--out-implib,libcblas_gcc.lib
gcc -shared -o libf77blas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive libf77blas.a -Wl,--no-whole-archive libatlas_gcc.lib -lgfortran -Wl,--output-def,libf77blas.def,--out-implib,libf77blas_gcc.lib
gcc -shared -o libf77refblas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive libf77refblas.a -Wl,--no-whole-archive libatlas_gcc.lib -lgfortran -Wl,--output-def,libf77refblas.def,--out-implib,libf77refblas_gcc.lib
gcc -shared -o liblapack.dll -Wl,--allow-multiple-definition -Wl,--whole-archive liblapack.a -Wl,--no-whole-archive libcblas_gcc.lib libf77blas_gcc.lib libatlas_gcc.lib -lgfortran -Wl,--output-def,liblapack.def,--out-implib,liblapack_gcc.lib
gcc -shared -o atlas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive *.a --Wl,--no-whole-archive -l${FORTRAN_LIB} -Wl,--output-def,atlas_gcc.def,--out-implib,atlas_gcc.lib
rm *.a
make_msvc_implibs
cd ../
}
build_main() {
prepare
OPTS="\"-march=native -fno-common -mpreferred-stack-boundary=2\""
CONF_PARAMS="-b 32 -D c -DWALL --with-netlib-lapack-tarfile=../${LAPACK_LOCAL_SRC} -Si latune 0 --cc=/usr/bin/gcc-4 -C xc /usr/bin/gcc-4 --shared -Fa ic ${OPTS} -Fa sk ${OPTS} -Fa dk ${OPTS} -Fa sm ${OPTS} -Fa dm ${OPTS} -Fa if ${OPTS}"
if [ ! -z "${FREQ}" ]; then
CONF_PARAMS="-m ${FREQ} -D c -DPentiumCPS=\"${FREQ}\" ${CONF_PARAMS}"
fi
echo "Beginning configuration"
../ATLAS/configure ${CONF_PARAMS}
echo "Executing make"
make
build_dlls
echo "Complete!"
echo "You can find dlls and static libraries in ${BUILD_DIRECTORY_WIN}/build/lib"
}
build_main
The script should do the following:
1) Downloads ATLAS 3.9.35 from SourceForge if it doesn't exist in the current directory - http://sourceforge.net/projects/math-atlas/files/Developer%20%28unstable%29/3.9.35/atlas3.9.35.tar.bz2/download
2) Downloads LAPACK 3.3 from Netlib if it doesn't exist in the current directory - http://www.netlib.org/lapack/lapack-3.3.0.tgz
3) Build a combined ATLAS/LAPACK library. The script should build at static version of the library by default but have an option to build a DLL (if it is not possible to build a static version, then only building a DLL version is fine).
4) The script should build a parallel version of the library that DOES NOT use Cygwin's version pthreads (the Cygwin runtime), either use Windows threads or Mingw's version of pthreads.
5) The script must be able to build 32 bit and 64 bit versions of the combined library.
6) The resulting library must be able to link to a standard Windows program or DLL without any Cygwin dependencies.
7) The script can use the version of MinGW that ships with Cygwin, the TDM-GCC version (http://tdm-gcc.tdragon.net/), or the MinGW project (www.mingw.org).
Posts in the ATLAS Windows forum might be helpful (http://sourceforge.net/projects/math-atlas/forums/forum/1026734). Below is a script that was started but never completed. Feel free to use any part that is helpful.
#!/bin/bash
# Requires cygwin's gcc-4, gfortran, patch, wget, make
#
#
# Please modify this variables
#
# ATLAS source
ATLAS_SRC="http://downloads.sourceforge.net/project/math-atlas/Developer%20%28unstable%29/3.9.24/atlas3.9.24.tar.bz2"
ATLAS_LOCAL_SRC="`echo ${ATLAS_SRC}|awk -F'/' '{ print $NF }'`"
# LAPACK source
LAPACK_SRC="http://www.netlib.org/lapack/lapack.tgz"
LAPACK_LOCAL_SRC="`echo ${LAPACK_SRC}|awk -F'/' '{ print $NF }'`"
# Winthreads patch
# This patch no longer exists, but I think it was based on patches here:
# http://sourceforge.net/projects/math-atlas/forums/forum/1026734/topic/3440080
WTHPATCH_SRC="http://xxx.xxx.xxx/winthreads.patch"
WTHPATCH_LOCAL_SRC="`echo ${WTHPATCH_SRC}|awk -F'/' '{ print $NF }'`"
# Attention! These directories should be the same! Otherwise MinGW will execution will fail!
# e.g. C:/path1/path2/path3 -> /path1/path2/path3
BUILD_DIRECTORY_WIN="E:/build"
BUILD_DIRECTORY_CYG="/build"
# MinGW installation path
MINGW_PATH="/cygdrive/e/MinGW"
# MSVC path (optional)
MSVC_PATH=""
#MSVC_PATH="/cygdrive/e/Program Files/Microsoft Visual Studio 8"
# It is suggested that a valid frequency value was supplied while building.
# However you can leave it empty.
FREQ="2200"
#
# End of configuration
#
PATH="${MINGW_PATH}/bin:$PATH"
if [ ! -z "${MSVC_PATH}" ]; then
PATH="${MSVC_PATH}/VC/bin:$PATH"
PATH="${MSVC_PATH}/Common7/IDE:$PATH"
fi
export PATH="${PATH}"
do_cleanup() {
cd ${BUILD_DIRECTORY_CYG} && rm -rf *
}
do_download() {
echo "Downloading source"
if [ "$1" != "" ]; then
echo "Cleaning up"
do_cleanup
fi
if [ ! -f ${ATLAS_LOCAL_SRC} ]; then
wget "${ATLAS_SRC}" -O "${ATLAS_LOCAL_SRC}"
fi
if [ ! -f ${LAPACK_LOCAL_SRC} ]; then
wget "${LAPACK_SRC}" -O "${LAPACK_LOCAL_SRC}"
fi
if [ ! -f ${WTHPATCH_LOCAL_SRC} ]; then
wget "${WTHPATCH_SRC}" -O "${WTHPATCH_LOCAL_SRC}"
fi
}
do_unpack() {
echo "Unpacking sources"
tar jxf ${ATLAS_LOCAL_SRC}
patch -p0 < ${WTHPATCH_LOCAL_SRC}
}
prepare() {
echo "Setting up build env"
umount ${BUILD_DIRECTORY_CYG}
mkdir -p ${BUILD_DIRECTORY_WIN}
mkdir -p ${BUILD_DIRECTORY_CYG}
mount ${BUILD_DIRECTORY_WIN} ${BUILD_DIRECTORY_CYG}
cd ${BUILD_DIRECTORY_CYG}
do_download
do_unpack
mkdir build
cd build && rm -rf *
}
make_msvc_implibs() {
if [ ! -z "`which lib.exe`" ]; then
for i in `ls *.def`; do
lib /MACHINE:x86 /def:"$i"
done
fi
}
build_dlls() {
echo "Building libraries"
cd lib
cp libatlas.a libatlas.a.bak
ar d libatlas.a ATL_{s,d,c,z}pt{gescal,geadd,trscal,hescal,gezero}.o
# dynamic gcc
mkdir dynamic_gcc
cd dynamic_gcc && rm -rf *
cp ../*.a ./
FORTRAN_LIB="gfortran"
gcc -shared -shared-libgcc -o libatlas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive libatlas.a -Wl,--no-whole-archive -Wl,--output-def,libatlas.def -Wl,--out-implib,libatlas_gcc.lib
gcc -shared -shared-libgcc -o libcblas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive libcblas.a -Wl,--no-whole-archive libatlas_gcc.lib -Wl,--output-def,libcblas.def,--out-implib,libcblas_gcc.lib
gcc -shared -shared-libgcc -o libf77blas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive libf77blas.a -Wl,--no-whole-archive libatlas_gcc.lib -l${FORTRAN_LIB} -Wl,--output-def,libf77blas.def,--out-implib,libf77blas_gcc.lib
gcc -shared -shared-libgcc -o libf77refblas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive libf77refblas.a -Wl,--no-whole-archive libatlas_gcc.lib -l${FORTRAN_LIB} -Wl,--output-def,libf77refblas.def,--out-implib,libf77refblas_gcc.lib
gcc -shared -shared-libgcc -o liblapack.dll -Wl,--allow-multiple-definition -Wl,--whole-archive liblapack.a -Wl,--no-whole-archive libcblas_gcc.lib libf77blas_gcc.lib libatlas_gcc.lib -l${FORTRAN_LIB} -Wl,--output-def,liblapack.def,--out-implib,liblapack_gcc.lib
gcc -shared -shared-libgcc -o atlas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive *.a --Wl,--no-whole-archive -l${FORTRAN_LIB} -Wl,--output-def,atlas_gcc.def,--out-implib,atlas_gcc.lib
rm *.a
make_msvc_implibs
cd ../
# static gcc
mkdir static_gcc
cd static_gcc && rm -rf *
cp ../*.a ./
gcc -shared -o libatlas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive libatlas.a -Wl,--no-whole-archive -Wl,--output-def,libatlas.def -Wl,--out-implib,libatlas_gcc.lib
gcc -shared -o libcblas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive libcblas.a -Wl,--no-whole-archive libatlas_gcc.lib -Wl,--output-def,libcblas.def,--out-implib,libcblas_gcc.lib
gcc -shared -o libf77blas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive libf77blas.a -Wl,--no-whole-archive libatlas_gcc.lib -lgfortran -Wl,--output-def,libf77blas.def,--out-implib,libf77blas_gcc.lib
gcc -shared -o libf77refblas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive libf77refblas.a -Wl,--no-whole-archive libatlas_gcc.lib -lgfortran -Wl,--output-def,libf77refblas.def,--out-implib,libf77refblas_gcc.lib
gcc -shared -o liblapack.dll -Wl,--allow-multiple-definition -Wl,--whole-archive liblapack.a -Wl,--no-whole-archive libcblas_gcc.lib libf77blas_gcc.lib libatlas_gcc.lib -lgfortran -Wl,--output-def,liblapack.def,--out-implib,liblapack_gcc.lib
gcc -shared -o atlas.dll -Wl,--allow-multiple-definition -Wl,--whole-archive *.a --Wl,--no-whole-archive -l${FORTRAN_LIB} -Wl,--output-def,atlas_gcc.def,--out-implib,atlas_gcc.lib
rm *.a
make_msvc_implibs
cd ../
}
build_main() {
prepare
OPTS="\"-march=native -fno-common -mpreferred-stack-boundary=2\""
CONF_PARAMS="-b 32 -D c -DWALL --with-netlib-lapack-tarfile=../${LAPACK_LOCAL_SRC} -Si latune 0 --cc=/usr/bin/gcc-4 -C xc /usr/bin/gcc-4 --shared -Fa ic ${OPTS} -Fa sk ${OPTS} -Fa dk ${OPTS} -Fa sm ${OPTS} -Fa dm ${OPTS} -Fa if ${OPTS}"
if [ ! -z "${FREQ}" ]; then
CONF_PARAMS="-m ${FREQ} -D c -DPentiumCPS=\"${FREQ}\" ${CONF_PARAMS}"
fi
echo "Beginning configuration"
../ATLAS/configure ${CONF_PARAMS}
echo "Executing make"
make
build_dlls
echo "Complete!"
echo "You can find dlls and static libraries in ${BUILD_DIRECTORY_WIN}/build/lib"
}
build_main