1
1
#! /bin/bash
2
2
# Build script for OpenBLAS on Windows
3
- # Expects environment variables:
4
- # OPENBLAS_ROOT
5
- # OPENBLAS_COMMIT
6
- # BUILD_BITS
7
- # START_DIR
8
- # Expects "lib.exe" and "gcc" to be on the path
3
+ #
4
+ # Usage: build_openblas.sh [openblas_root [build_bits [if_bits]]]
5
+ #
6
+ # e.g build_openblas.sh c:\\opt 64 32
7
+ #
8
+ # Uses the optional environment variables. We always prefer command line argument
9
+ # values above to environment variable values:
10
+ #
11
+ # OPENBLAS_ROOT (default directory root for binaries, unspecified -> c:\opt).
12
+ # BUILD_BITS (default binary architecture, 32 or 64, unspec -> 64).
13
+ # INTERFACE64 (1 for 64-bit interface, anything else or undefined for 32,
14
+ # This gives the default value if if_bits not specified above).
15
+ # START_DIR (directory containing OpenBLAS source, unspec -> .. from here)
16
+ # OPENBLAS_COMMIT (unspec -> current submodule commit)
17
+ # LDFLAGS (example: "-lucrt -static -static-libgcc")
18
+ #
19
+ # Expects at leasts these binaries on the PATH:
20
+ # realpath, cygpath, zip, gcc, make, ar, dlltool
21
+ # usually as part of an msys installation.
9
22
10
- set -ex
23
+ # Convert to Unix-style path
24
+ openblas_root=" $( cygpath ${1:- ${OPENBLAS_ROOT:- c: \\ opt} } ) "
25
+ build_bits=" ${2:- ${BUILD_BITS:- 64} } "
26
+ if [ " $INTERFACE64 " == " 1" ]; then if_default=64; else if_default=32; fi
27
+ if_bits=${3:- ${if_default} }
28
+ # Our directory for later copying
29
+ if [ -z " $START_DIR " ]; then
30
+ our_wd=" $( realpath $( dirname " ${BASH_SOURCE[0]} " ) /..) "
31
+ else
32
+ our_wd=$( cygpath " $START_DIR " )
33
+ fi
11
34
12
- # Paths in Unix format
13
- OPENBLAS_ROOT=$( cygpath " $OPENBLAS_ROOT " )
35
+ echo " Building from $our_wd , to $openblas_root "
36
+ echo " Binaries are $build_bits bit, interface is $if_bits bit"
37
+ echo " Using gcc at $( which gcc) , --version:"
38
+ gcc --version
14
39
15
- # Our directory for later copying
16
- our_wd=$( cygpath " $START_DIR " )
17
- cd $our_wd
18
40
# Make output directory for build artifacts
19
- rm -rf builds
20
- mkdir builds
41
+ builds_dir=" $our_wd /builds"
42
+ rm -rf $builds_dir
43
+ mkdir $builds_dir
21
44
22
- cd OpenBLAS
45
+ cd " ${our_wd} / OpenBLAS"
23
46
git submodule update --init --recursive
24
47
25
- # Check which gcc we're using
26
- which gcc
27
- gcc --version
28
48
29
49
# Get / clean code
30
50
git fetch origin
31
- git checkout $OPENBLAS_COMMIT
51
+ if [ -n " $OPENBLAS_COMMIT " ]; then
52
+ git checkout $OPENBLAS_COMMIT
53
+ fi
32
54
git clean -fxd
33
55
git reset --hard
34
- rm -rf $OPENBLAS_ROOT / $BUILD_BITS
56
+ rm -rf $openblas_root / $build_bits
35
57
36
58
# Set architecture flags
37
- if [ " $BUILD_BITS " == 64 ]; then
59
+ if [ " $build_bits " == 64 ]; then
38
60
march=" x86-64"
39
61
# https://csharp.wekeepcoding.com/article/10463345/invalid+register+for+.seh_savexmm+in+Cygwin
40
62
extra=" -fno-asynchronous-unwind-tables"
@@ -51,9 +73,9 @@ cflags="-O2 -march=$march -mtune=generic $extra"
51
73
fflags=" $fextra $cflags -frecursive -ffpe-summary=invalid,zero"
52
74
53
75
# Set suffixed-ILP64 flags
54
- if [ " $INTERFACE64 " == " 1 " ]; then
55
- interface64_flags= " INTERFACE64=1 SYMBOLSUFFIX=64_"
56
- SYMBOLSUFFIX=64_
76
+ if [ " $if_bits " == " 64 " ]; then
77
+ SYMBOLSUFFIX=" 64_"
78
+ interface64_flags= " INTERFACE64=1 SYMBOLSUFFIX=${SYMBOLSUFFIX} "
57
79
# We override FCOMMON_OPT, so we need to set default integer manually
58
80
fflags=" $fflags -fdefault-integer-8"
59
81
else
@@ -66,42 +88,50 @@ OPENBLAS_VERSION=$(git describe --tags)
66
88
# Build OpenBLAS
67
89
# Variable used in creating output libraries
68
90
export LIBNAMESUFFIX=${OPENBLAS_VERSION} -${GCC_TAG}
69
- make BINARY=$BUILD_BITS DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \
91
+ make BINARY=$build_bits DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \
70
92
NUM_THREADS=24 NO_WARMUP=1 NO_AFFINITY=1 CONSISTENT_FPCSR=1 \
71
93
BUILD_LAPACK_DEPRECATED=1 TARGET=PRESCOTT BUFFERSIZE=20\
94
+ LDFLAGS=" $LDFLAGS " \
72
95
COMMON_OPT=" $cflags " \
73
96
FCOMMON_OPT=" $fflags " \
74
97
MAX_STACK_ALLOC=2048 \
75
98
$interface64_flags
76
- make PREFIX=$OPENBLAS_ROOT / $BUILD_BITS $interface64_flags install
99
+ make PREFIX=$openblas_root / $build_bits $interface64_flags install
77
100
DLL_BASENAME=libopenblas${SYMBOLSUFFIX} _${LIBNAMESUFFIX}
78
- if [ " $INTERFACE64 " == " 1 " ]; then
101
+ if [ " $if_bits " == " 64 " ]; then
79
102
# OpenBLAS does not build a symbol-suffixed static library on Windows:
80
103
# do it ourselves
81
104
set -x # echo commands
82
105
static_libname=$( find . -maxdepth 1 -type f -name ' *.a' \! -name ' *.dll.a' | tail -1)
83
106
make -C exports $interface64_flags objcopy.def
84
107
objcopy --redefine-syms exports/objcopy.def " ${static_libname} " " ${static_libname} .renamed"
85
- cp -f " ${static_libname} .renamed" " $OPENBLAS_ROOT / $BUILD_BITS /lib/${static_libname} "
86
- cp -f " ${static_libname} .renamed" " $OPENBLAS_ROOT / $BUILD_BITS /lib/${DLL_BASENAME} .a"
108
+ cp -f " ${static_libname} .renamed" " $openblas_root / $build_bits /lib/${static_libname} "
109
+ cp -f " ${static_libname} .renamed" " $openblas_root / $build_bits /lib/${DLL_BASENAME} .a"
87
110
set +x
88
111
fi
89
- cd $OPENBLAS_ROOT
112
+ cd $openblas_root
90
113
# Copy library link file for custom name
91
- cd $BUILD_BITS /lib
114
+ cd $build_bits /lib
115
+ cp ${our_wd} /OpenBLAS/exports/${DLL_BASENAME} .def ${DLL_BASENAME} .def
92
116
# At least for the mingwpy wheel, we have to use the VC tools to build the
93
117
# export library. Maybe fixed in later binutils by patch referred to in
94
118
# https://sourceware.org/ml/binutils/2016-02/msg00002.html
95
- cp ${our_wd} /OpenBLAS/exports/${DLL_BASENAME} .def ${DLL_BASENAME} .def
96
- " lib.exe" /machine:${vc_arch} /def:${DLL_BASENAME} .def
119
+ # "lib.exe" /machine:${vc_arch} /def:${DLL_BASENAME}.def
120
+ # Maybe this will now work (after 2016 patch above).
121
+ dlltool --input-def ${DLL_BASENAME} .def \
122
+ --output-exp ${DLL_BASENAME} .exp \
123
+ --dllname ${DLL_BASENAME} .dll \
124
+ --output-lib ${DLL_BASENAME} .lib
125
+ # Replace the DLL name with the generated name.
126
+ sed -i " s/ -lopenblas$/ -l${DLL_BASENAME: 3} /g" pkgconfig/openblas.pc
97
127
cd ../..
98
128
# Build template site.cfg for using this build
99
- cat > ${BUILD_BITS } /site.cfg.template << EOF
129
+ cat > ${build_bits } /site.cfg.template << EOF
100
130
[openblas${SYMBOLSUFFIX} ]
101
131
libraries = $DLL_BASENAME
102
- library_dirs = {openblas_root}\\ ${BUILD_BITS } \\ lib
103
- include_dirs = {openblas_root}\\ ${BUILD_BITS } \\ include
132
+ library_dirs = {openblas_root}\\ ${build_bits } \\ lib
133
+ include_dirs = {openblas_root}\\ ${build_bits } \\ include
104
134
EOF
105
- ZIP_NAME =" openblas${SYMBOLSUFFIX} -${OPENBLAS_VERSION} -${plat_tag} -${GCC_TAG} .zip"
106
- zip -r $ZIP_NAME $BUILD_BITS
107
- cp $ZIP_NAME $our_wd /builds
135
+ zip_name =" openblas${SYMBOLSUFFIX} -${OPENBLAS_VERSION} -${plat_tag} -${GCC_TAG} .zip"
136
+ zip -r $zip_name $build_bits
137
+ cp $zip_name ${builds_dir}
0 commit comments