-
Notifications
You must be signed in to change notification settings - Fork 2
/
configure
executable file
·221 lines (190 loc) · 6.39 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
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
#!/bin/bash
#
# A configure stub for people used to that syntax
# Do ./configure --help for usage instructions
#
usage()
{
tee -a $CONFIGLOG <<-EOF
Configure and prepare the source code for building.
Usage:
$0 [flags] [CMAKE_VAR1=VALUE [CMAKE_VAR2=VALUE2 [...]]]
Available flags:
--prefix=<prefix> # will install the code into <prefix>
--optimized # configure the 'Release' build
--debug # configure the 'Debug' build
--env=<VAR=VALUE> # set VAR=VALUE environment variable
# before running CMAKE
--with-gcc=<gcc_root> # use gcc from <gcc_root> directory
--with-cuda=<cuda_root> # use CUDA toolkit from <cuda_root>
--with-boost=<boost_root> # use boost from <boost_root> directory
--with-libpeyton=<lp_root> # use libpeyton from <lp_root> directory
--devemu # target CUDA code for device emulation
If ran from the top level source directory, it will configure the build
directory in build/optimized/debug (depending on whether --optimized or
--debug flags were present), as well as generate a simple Makefile to
allowing the user to build the code directly from the top-level directory.
Otherwise, it will configure the source in the current directory (assuming
it's meant to be the build directory).
This build system uses CMake. If your CMake executable is in
nonstandard location, you may specify it via the CMAKE environment
variable.
Written by Mario Juric <[email protected]>
EOF
}
xecho()
{
echo "== $@" | tee -a $CONFIGLOG
}
oecho()
{
echo "** $@" >> $CONFIGLOG
}
configlog()
{
CONFIGLOG_FINAL="$CONFIGLOG"
CONFIGLOG="$CONFIGLOG.tmp"
cat > $CONFIGLOG <<-EOF
This file contains any messages produced by CMake while
running configure, to aid debugging if configure makes a mistake.
It was created by configure, an Autoconf-like script for CMake
written by Mario Juric <[email protected]>. Invocation command line
was:
\$ $0 $@
## --------- ##
## Platform. ##
## --------- ##
hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
uname -m = `(uname -m) 2>/dev/null || echo unknown`
uname -r = `(uname -r) 2>/dev/null || echo unknown`
uname -s = `(uname -s) 2>/dev/null || echo unknown`
uname -v = `(uname -v) 2>/dev/null || echo unknown`
CMAKE = $CMAKE
which \$CMAKE = `(which "$CMAKE") 2>/dev/null || echo not found`
\$CMAKE --version = `("$CMAKE" --version) 2>/dev/null || echo not found`
## ------------------ ##
## Configuration log. ##
## ------------------ ##
EOF
# If CONFIGLOG_FINAL is defined, move $CONFIGLOG to $CONFIGLOG_FINAL (and delete $CONFIGLOG)
# In case you're wondering, CONFIGLOG_FINAL becomes undefined if --help was given on the command line
trap "{ test \"x\$CONFIGLOG_FINAL\" != x && mv '$CONFIGLOG' '$CONFIGLOG_FINAL'; rm -f '$CONFIGLOG'; }" EXIT
}
# Defaults
CMAKE=${CMAKE:-cmake}
ENV=${env}
# Store invocation information
CONFIGLOG="`pwd`/config.log"
configlog "$@"
# Quick check for CMake
which $CMAKE 2>&1 > /dev/null || {
CML=`dirname $0`"/CMakeLists.txt"
xecho "No usable CMake found (tried looking for executable \`$CMAKE')"
test -f "$CML" && {
CMV=`grep -i cmake_minimum_required "$CML" | perl -e '$_=<>; ($v) = /^cmake_minimum_required\s*\(\s*version\s+([0-9.]+)\s*\)/i; print $v'`;
test "x$CMV" != "x" && xecho "CMake $CMV or greater is needed to build this code.";
} || {
xecho "CMake is needed to build this code.";
}
xecho "If your CMake executable is in nonstandard location, you may specify"
xecho "it via the CMAKE environment variable."
exit -1;
}
BUILDDIR='build'
#
# Project-specific command-line argument parsing
#
TEMP=`getopt -o hp: -l help,prefix:,debug,optimized,devemu,env:,with-gcc:,with-cuda:,with-boost:,with-libpeyton: -- "$@"` || { xecho "Try $0 --help"; exit $?; }
eval set -- "$TEMP"
while true ; do
case "$1" in
-p|--prefix)
xecho "Setting install path to '$2'"
CMAKE="$CMAKE -DCMAKE_INSTALL_PREFIX='$2'"
shift 2 ;;
--env)
xecho "Setting environment variable '$2'"
ENV="$ENV '$2'"
shift 2 ;;
--devemu)
xecho "Targeting CUDA code for device emulation"
CMAKE="$CMAKE -DCUDA_BUILD_EMULATION=ON"
shift 1 ;;
--debug)
xecho "Setting build type to 'Debug'"
BUILDDIR='debug'
CMAKE="$CMAKE -DCMAKE_BUILD_TYPE='Debug'"
shift 1 ;;
--optimized)
xecho "Setting build type to 'Release'"
BUILDDIR='optimized'
CMAKE="$CMAKE -DCMAKE_BUILD_TYPE='Release'"
shift 1 ;;
--with-boost)
xecho "Using Boost from '$2'"
CMAKE="$CMAKE -DBOOST_ROOT='$2'"
shift 2 ;;
--with-cuda)
xecho "Using CUDA Toolkit from '$2'"
CMAKE="$CMAKE -DCUDA_TOOLKIT_ROOT_DIR='$2'"
shift 2 ;;
--with-gcc)
xecho "Using gcc suite from '$2'"
CMAKE="$CMAKE -DCMAKE_CXX_COMPILER='$2/bin/g++'"
CMAKE="$CMAKE -DCMAKE_C_COMPILER='$2/bin/gcc'"
CMAKE="$CMAKE -DGCC_ROOT='$2'"
ENV="$ENV LDFLAGS='-L$2/lib -L$2/lib64'"
shift 2 ;;
--with-libpeyton)
xecho "Using libpeyton from '$2'"
CMAKE="$CMAKE -Dlibpeyton_ROOT='$2'"
shift 2 ;;
-h|--help)
usage;
CONFIGLOG_FINAL=
exit 0 ;;
--) shift ; break ;;
*) xecho "Internal error!" ; exit 1 ;;
esac
done
# Figure out the build dir -- if we're in the same directory as the
# configure script, make a subdirectory based on the choice of BUILD_TYPE
test -x ./configure && {
mkdir -p "$BUILDDIR" && cd "$BUILDDIR" && SOURCEDIR=".." || {
xecho "Error creating build directory."; exit -1;
}
# A flag meaning we're configuring from in-source
BDSET=1
xecho "Build directory is '$BUILDDIR'"
} || {
BUILDDIR="."
SOURCEDIR=`dirname $0`
}
# Assume all extra arguments are CMAKE variable definitions
for arg do
CMAKE="$CMAKE '-D$arg'"
done
CMAKE="$CMAKE $SOURCEDIR"
# Delete old CMakeCache.txt if it exists
test -f CMakeCache.txt && rm -f CMakeCache.txt
# Run cmake
xecho "Invoking CMake to configure the source"
oecho "$ENV $CMAKE"
eval $ENV $CMAKE | tee -a $CONFIGLOG;
test "x${PIPESTATUS[0]}" == "x0" && {
if [ "$BDSET" == "1" ]; then
# Generate a stub makefile that will hand-off compilation to the real makefile
# This happens only when configure is run in-source
cat > ../Makefile <<EOT
all:
tidy:
@ rm -rf $BUILDDIR
%:
@ test -f $BUILDDIR/Makefile || { echo "$BUILDDIR directory not configured. Run configure first." && false; }
@ cd $BUILDDIR && \$(MAKE) \$@
EOT
fi;
xecho "Source configured in directory '$BUILDDIR'. Run \`make' to compile."
} || {
xecho "Error configuring source."
}