-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure
executable file
·113 lines (103 loc) · 2.52 KB
/
configure
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
#!/usr/bin/env bash
# A hach to restart the script with Bash
if [ -z "$BASH" ]; then exec bash "$0" "$@"; fi
set -eu
set -o pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd -L | sed 's://:/:g')"
WORKDIR="${SCRIPT_DIR}/third_party/build"
PREFIX="${SCRIPT_DIR}/third_party/lattice-symmetries"
get_num_procs() {
if [[ "$OSTYPE" == "darwin"* ]]; then
sysctl -n hw.logicalcpu
else
nproc
fi
}
download_lattice_symmetries() {
mkdir -vp "$WORKDIR"
pushd "$WORKDIR"
if [[ ! -d "lattice-symmetries" ]]; then
echo "Downloading lattice-symmetries..."
git clone --depth=1 https://github.com/twesterhout/lattice-symmetries.git
fi
pushd "lattice-symmetries"
git pull origin master
git submodule update --init --recursive
popd
popd
}
build_static_lib() {
pushd "${WORKDIR}/lattice-symmetries"
mkdir -vp build
pushd build
export CXXFLAGS="-fvisibility-inlines-hidden -march=nocona -mtune=haswell -fstack-protector-strong -fno-plt -ffunction-sections"
export CFLAGS="-march=nocona -mtune=haswell -fstack-protector-strong -fno-plt -ffunction-sections"
export LDFLAGS="-Wl,--as-needed -Wl,--gc-sections -Wl,-z,now -Wl,--disable-new-dtags"
cmake \
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DLatticeSymmetries_ENABLE_UNIT_TESTING=OFF \
..
cmake --build . -- -j$(get_num_procs)
cmake --build . --target install
popd
popd
}
generate_buildinfo() {
cat <<-EOF
include-dirs:
${PREFIX}/include
extra-lib-dirs:
${PREFIX}/lib64
${PREFIX}/lib
extra-libraries:
lattice_symmetries
gomp
stdc++
EOF
}
print_help() {
echo ""
echo "Usage: ./configure [--help] [--clean]"
echo ""
echo "This script builds LatticeSymmetries C library and generates"
echo "spin-ed.buildinfo echo file for Cabal."
echo ""
echo "Options:"
echo " --help Display this message."
echo " --clean Clean up build directory."
echo ""
}
main() {
CLEAN=0
while [ $# -gt 0 ]; do
key="$1"
case $key in
--clean)
CLEAN=1
shift
;;
--help)
print_help
exit 0
;;
*)
echo "Warning: argument '$1' ignored"
shift
;;
esac
done
if [ $CLEAN -eq 0 ]; then
echo "Running ./configure on $OSTYPE..."
download_lattice_symmetries
build_static_lib
generate_buildinfo >"spin-ed.buildinfo"
else
if [ -d "${WORKDIR}/lattice-symmetries" ]; then
cd "${WORKDIR}/lattice-symmetries"
rm -rf build
fi
fi
}
main "$@"