forked from arminbiere/cadical
/
configure
executable file
·250 lines (211 loc) · 6.31 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/bin/sh
#--------------------------------------------------------------------------#
# Run './configure' to produce a 'makefile' in the 'build' sub-directory or
# in any immediate sub-directory different from the 'src', 'scripts' and
# 'test' directories.
#--------------------------------------------------------------------------#
# Common default options.
debug=no
stats=no
logging=no
check=no
coverage=no
profile=no
realloc=yes
unlocked=yes
quiet=no
#--------------------------------------------------------------------------#
die () {
echo "*** cadical/configure: $*" 1>&2
exit 1
}
msg () {
echo "[cadical/configure] $*"
}
#--------------------------------------------------------------------------#
# Parse and handle command line options.
usage () {
cat << EOF
usage: configure [ <option> ... ]
where '<option>' is one of the following
-h|--help print this command line summary
-g|--debug compile with debugging information
-c|--check compile with assertion checking (default for '-g')
-l|--log include logging code (but disabled by default)
-s|--stats include and enable expensive statistics code
-a|--all short cut for all above, e.g., '-g -l -s' (thus also '-c')
-q|--quiet exclude message and profiling code (logging and stats too)
--coverage compile with '-ftest-coverage -fprofile-arcs' for 'gcov'
--profile compile with '-pg' to profile with 'gprof'
--no-realloc use C++ style allocators for all tables
--no-unlocked force compilation without unlocked IO
The environment variable CXX can be used to set a different C++
compiler than the default 'g++'. Similarly you can add additional
compilation options by setting CXXFLAGS. For instance
CXX=clang++ CXXFLAGS="-fPIC" ./configure
will enforce to use 'clang++' as C++ compiler and also produce
position independent code.
EOF
exit 0
}
while [ $# -gt 0 ]
do
case $1 in
-h|--help) usage;;
-g|--debug) debug=yes; check=yes;;
-c|--check) check=yes;;
-l|--logging) logging=yes;;
-s|--stats) stats=yes;;
-a|--all) debug=yes;check=yes;logging=yes;stats=yes;;
-q|--quiet) quiet=yes;;
--coverage) coverage=yes;;
--profile) profile=yes;;
--no-realloc) realloc=no;;
--no-unlocked) unlocked=no;;
*) die "invalid option '$1' (try '-h')";;
esac
shift
done
if [ $quiet = yes ]
then
logging=no
stats=no
fi
#--------------------------------------------------------------------------#
# Generate and enter 'build' directory if not already in sub-directory.
build_in_default_build_sub_directory () {
if [ -d build ]
then
msg "reusing default 'build' directory"
else
mkdir build 2>/dev/null || die "failed to generate 'build' directory"
msg "making default 'build' directory"
fi
cd build
msg "building in default '`pwd`'"
build=build
}
if [ -f configure -a -f makefile.in -a -f VERSION -a -d src ]
then
root="`pwd`"
build_in_default_build_sub_directory
elif [ -f ../configure -a -f ../makefile.in -a -f ../VERSION -a -d ../src ]
then
cwd="`pwd`"
build=`basename "$cwd"`
root=`dirname "$cwd"`
case x"$build" in
xsrc|xtest|xscripts)
cd ..
build_in_default_build_sub_directory
;;
*)
msg "building in '$build' sub-directory"
;;
esac
else
die "call 'configure' from root of CaDiCaL source or a sub-directory"
fi
msg "root directory '$root'"
#--------------------------------------------------------------------------#
# Prepare '@CXX@' and '@CXXFLAGS@' parameters for 'makefile.in'
[ x"$CXX" = x ] && CXX=g++
[ x"$CXXFLAGS" = x ] || CXXFLAGS="$CXXFLAGS "
case x"$CXX" in
xg++*|xclang++*) CXXFLAGS="${CXXFLAGS}-Wall";;
*) CXXFLAGS="${CXXFLAGS}-W";;
esac
if [ $debug = yes ]
then
CXXFLAGS="$CXXFLAGS -g"
else
case x"$CXX" in
xg++*|xclang++*) CXXFLAGS="$CXXFLAGS -O3";;
*) CXXFLAGS="$CXXFLAGS -O";;
esac
fi
[ $check = no ] && CXXFLAGS="$CXXFLAGS -DNDEBUG"
[ $logging = yes ] && CXXFLAGS="$CXXFLAGS -DLOGGING"
[ $stats = yes ] && CXXFLAGS="$CXXFLAGS -DSTATS"
[ $quiet = yes ] && CXXFLAGS="$CXXFLAGS -DQUIET"
[ $realloc = no ] && CXXFLAGS="$CXXFLAGS -DNREALLOC"
[ $profile = yes ] && CXXFLAGS="$CXXFLAGS -pg"
[ $coverage = yes ] && CXXFLAGS="$CXXFLAGS -ftest-coverage -fprofile-arcs"
#--------------------------------------------------------------------------#
if [ $unlocked = yes ]
then
check=/tmp/cadical-have-unlocked-io-$$
trap "rm -f $check*" 2
cat <<EOF > $check.cpp
#include <cstdio>
int main () {
const char * path = "$check.log";
FILE * file = fopen (path, "w");
if (!file) return 1;
if (putc_unlocked (42, file) != 42) return 1;
if (fclose (file)) return 1;
file = fopen (path, "r");
if (!file) return 1;
if (getc_unlocked (file) != 42) return 1;
if (fclose (file)) return 1;
return 0;
}
EOF
if $CXX $CXXFLAGS -o $check.exe $check.cpp
then
$check.exe
res=$?
if [ $res ]
then
msg "unlocked IO with '{putc,getc}_unlocked' seems to work"
else
msg "not using unlocked IO (running '$check.exe' failed)"
unlocked=no
fi
else
msg "not using unlocked IO (failed to compile '$check.cpp')"
unlocked=no
fi
rm -f $check*
else
msg "not using unlocked IO (since '--no-unlocked' specified)"
fi
[ $unlocked = no ] && CXXFLAGS="$CXXFLAGS -DNUNLOCKED"
#--------------------------------------------------------------------------#
# Instantiate '../makefile.in' template to produce 'makefile' in 'build'.
msg "compiling with '$CXX $CXXFLAGS'"
rm -f makefile
sed \
-e "1c\\
# This 'makefile' is generated from '../makefile.in'." \
-e "s,@CXX@,$CXX," \
-e "s,@CXXFLAGS@,$CXXFLAGS," \
../makefile.in > makefile
msg "generated '$build/makefile' from '../makefile.in'"
#--------------------------------------------------------------------------#
build=`pwd`
cat <<EOF > ../makefile
CADICALROOT=$root
CADICALBUILD=$build
all:
make -C "\$(CADICALBUILD)"
clean:
@if [ -d "\$(CADICALBUILD)" ]; \\
then \\
if [ -f "\$(CADICALBUILD)"/makefile ]; \\
then \\
touch "\$(CADICALBUILD)"/config.hpp; \\
touch "\$(CADICALBUILD)"/dependencies; \\
make -C "\$(CADICALBUILD)" clean; \\
fi; \\
rm -rf "\$(CADICALBUILD)"; \\
fi
rm -f "\$(CADICALROOT)/makefile"
test:
make -C "\$(CADICALBUILD)" test
.PHONY: all clean test
EOF
msg "generated '../makefile' as proxy to ..."
msg "... '$build/makefile'"
msg "now run 'make' to compile CaDiCaL"
msg "optionally test it with 'make test'"