-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·255 lines (214 loc) · 6.64 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
251
252
253
254
255
#!/bin/sh
# Determine the directory in which the user is running configure,
# and the source directory where it lives
WORKING_DIR=$(pwd)
cd $(dirname $0)
SOURCE_DIR=$(pwd)
cd "${WORKING_DIR}"
find_libcurl(){
PKG=libcurl
echo "Looking for $PKG..."
VAR_PREFIX=`echo $PKG | tr [:lower:] [:upper:]`
TMP_FOUND=`eval echo "$"${VAR_PREFIX}_FOUND`
if [ "$TMP_FOUND" ]; then return; fi
which "$CURL_CONFIG" 2>&1 > /dev/null
if [ "$?" -ne 0 ]; then
echo "$CURL_CONFIG not found; unable to locate $PKG" >&2
return;
fi
LIBCURL_CFLAGS=`"$CURL_CONFIG" --cflags`" -I"`curl-config --prefix`"/include"
LIBCURL_LDFLAGS=`"$CURL_CONFIG" --libs`
LIBCURL_FOUND=1
echo " Found $PKG"
}
find_libxml2(){
PKG=libxml2
echo "Looking for $PKG..."
VAR_PREFIX=`echo $PKG | tr [:lower:] [:upper:]`
TMP_FOUND=`eval echo "$"${VAR_PREFIX}_FOUND`
if [ "$TMP_FOUND" ]; then return; fi
which "$XML2_CONFIG" 2>&1 > /dev/null
if [ "$?" -ne 0 ]; then
echo "$XML2_CONFIG not found; unable to locate $PKG" >&2
return;
fi
LIBXML2_CFLAGS=`"$XML2_CONFIG" --cflags`
LIBXML2_LDFLAGS=`"$XML2_CONFIG" --libs`
LIBXML2_FOUND=1
echo " Found $PKG"
}
find_cryptopp(){
# We have no actual way to do this. Try compiling a trivial program to see if
# it works.
echo "Checking for cryptopp..."
TEST_FLAGS="$CXXFLAGS $CRYPTOPP_CFLAGS $LDFLAGS $CRYPTOPP_LDFLAGS"
$CXX "${SOURCE_DIR}/src/cryptopp_test.cpp" $TEST_FLAGS -o "${WORKING_DIR}/bin/cryptopp_test" >/dev/null 2>&1
RESULT=$?
if [ "$RESULT" -ne 0 ];
then
echo "Unable to compile a basic program using the Crypto++ library" >&2
echo "There is either a problem with the compiler or the flags " >&2
echo " associated with cryptopp. Please specify --with-cryptopp=..." >&2
echo " as necessary. " >&2
return
fi
rm -f bin/cryptopp_test
CRYPTOPP_FOUND=1
echo " cryptopp available"
}
PREFIX=/usr/local
VERSION_NUM=000100
VERSION=`echo $VERSION_NUM | awk '{
major = int($1/100000);
minor = ($1/100)%1000;
patch = $1%100;
print major"."minor"."patch;
}'`
OS_NAME=`uname -s`
GUESS_CXX=g++
GUESS_AR=ar
GUESS_LD=ld
if [ "$OS_NAME" = Darwin ]; then
GUESS_CXX=clang++
GUESS_LD=clang++
DYN_SUFFIX=.dylib
DYN_OPT='-dynamiclib -compatibility_version $(VERSION) -current_version $(VERSION)'
elif [ "$OS_NAME" = FreeBSD ]; then
DYN_SUFFIX=.so
DYN_OPT='-shared'
else
DYN_SUFFIX=.so
DYN_OPT='-shared -Wl,-soname,$(shell basename $(DYN_PRODUCT))'
fi
CXX=${CXX-$GUESS_CXX}
AR=${AR-$GUESS_AR}
LD=${LD-$GUESS_LD}
CURL_CONFIG="curl-config"
XML2_CONFIG="xml2-config"
CRYPTOPP_CFLAGS=${CRYPTOPP_CFLAGS-""}
CRYPTOPP_LDFLAGS=${CRYPTOPP_LDFLAGS-"-lcryptopp"}
CXXFLAGS="$CXXFLAGS -std=c++11 -O2 -I${SOURCE_DIR}/include"
if [ ! -d ./bin/ ]; then
mkdir bin;
fi
if [ ! -d ./lib/ ]; then
mkdir lib;
fi
# define help
HELP="Usage: ./config.sh [OPTION]...
Installation directories:
--prefix=PREFIX install files in PREFIX
[$PREFIX]
By default, \`make install' will install all the files in
\`$PREFIX/bin', \`$PREFIX/lib' etc. You can specify
an installation prefix other than \`$PREFIX' using \`--prefix',
for instance \`--prefix=\$HOME'.
The following options can be used to maunally specify the
locations of dependencies:
--with-cryptopp=DIR use the copy of Crypto++ in DIR
assuming headers are in DIR/include
and libraries in DIR/lib
--with-cryptopp-incdir=DIR use the Crypto++ headers in DIR
--with-cryptopp-libdir=DIR use the Crypto++ library in DIR
--with-curl-config=PROG use PROG as curl-config to obtain
suitable libcurl flags
--with-xml2-config=PROG use PROG as xml2-config to obtain
suitable libxml2 flags
Some influential environment variables:
CXX C++ compiler command
AR Static linker command
LD Dynamic linker command
CXXFLAGS C++ compiler flags
LDFLAGS Linker flags
" #`
# parse arguments
for var in "$@"
do
if [ "$var" = "--help" -o "$var" = "-h" ]; then
echo "$HELP"
exit 0
fi
TMP=`echo "$var" | sed -n 's/^--prefix=\(.*\)$/\1/p'`
if [ "$TMP" ]; then PREFIX="$TMP"; continue; fi
TMP=`echo "$var" | sed -n 's/^--with-cryptopp=\(.*\)$/\1/p'`
if [ "$TMP" ]; then
CRYPTOPP_INCDIR="${TMP}/include";
CRYPTOPP_LIBDIR="${TMP}/lib";
continue; fi
TMP=`echo "$var" | sed -n 's/^--with-cryptopp-incdir=\(.*\)$/\1/p'`
if [ "$TMP" ]; then CRYPTOPP_INCDIR="$TMP"; continue; fi
TMP=`echo "$var" | sed -n 's/^--with-cryptopp-libdir=\(.*\)$/\1/p'`
if [ "$TMP" ]; then CRYPTOPP_LIBDIR="$TMP"; continue; fi
TMP=`echo "$var" | sed -n 's/^--with-curl-config=\(.*\)$/\1/p'`
if [ "$TMP" ]; then CURL_CONFIG="${TMP}"; continue; fi
TMP=`echo "$var" | sed -n 's/^--with-xml2-config=\(.*\)$/\1/p'`
if [ "$TMP" ]; then XML2_CONFIG="${TMP}"; continue; fi
echo "config.sh: Unknown or malformed option '$var'" 1>&2
exit 1
done
find_libcurl
find_libxml2
if [ "$CRYPTOPP_INCDIR" -o "$CRYPTOPP_LIBDIR" ]; then
echo "Checking manually specified cryptopp..."
if [ -d "$CRYPTOPP_INCDIR/cryptopp" \
-a -e "$CRYPTOPP_INCDIR/cryptopp/sha.h" \
-a -d "$CRYPTOPP_LIBDIR" \
-a -e "$CRYPTOPP_LIBDIR/libcryptopp.a" ]; then
CRYPTOPP_FOUND=1
CRYPTOPP_CFLAGS="-I$CRYPTOPP_INCDIR"
CRYPTOPP_LDFLAGS="-L$CRYPTOPP_LIBDIR -lcryptopp"
else
echo "Warning: manually specifed crypto++ not found"
fi
fi
find_cryptopp
if [ ! "$LIBCURL_FOUND" -o ! "$LIBXML2_FOUND" -o ! "$CRYPTOPP_FOUND" ]; then
echo >&2
if [ ! "$LIBCURL_FOUND" ]; then
echo "configure: Error: libcurl not found" >&2
fi
if [ ! "$LIBXML2_FOUND" ]; then
echo "configure: Error: libxml2 not found" >&2
fi
if [ ! "$CRYPTOPP_FOUND" ]; then
echo "configure: Error: cryptopp not found" >&2
fi
exit 1
fi
# git and git-like things are too dumb to know about directories, so any
# directories which are initially empty need to be re-created on demand.
mkdir -p bin
mkdir -p build
mkdir -p lib
if [ ! -e "${WORKING_DIR}/makefile" -o "${SOURCE_DIR}/makefile" -nt "${WORKING_DIR}/makefile" ]; then
echo "Copying makefile"
cp "${SOURCE_DIR}/makefile" "${WORKING_DIR}/makefile"
fi
CRYPTOPP_SRC_URL="https://cryptopp.com/cryptopp870.zip"
echo "Generating settings.mk"
echo "
# Directories
SOURCE_DIR:=$SOURCE_DIR
WORKING_DIR:=$WORKING_DIR
# Compiler
CXX:=$CXX
AR:=$AR
LD:=$LD
# Dependencies
LIBCURL_CFLAGS=$LIBCURL_CFLAGS
LIBCURL_LDFLAGS=$LIBCURL_LDFLAGS
LIBXML2_CFLAGS=$LIBXML2_CFLAGS
LIBXML2_LDFLAGS=$LIBXML2_LDFLAGS
CRYPTOPP_CFLAGS=$CRYPTOPP_CFLAGS
CRYPTOPP_LDFLAGS=$CRYPTOPP_LDFLAGS
# Installation
PREFIX:=$PREFIX
# Other
VERSION:=$VERSION
CXXFLAGS:=$CXXFLAGS
LDFLAGS:=$LDFLAGS
CRYPTOPP_SRC_URL:=$CRYPTOPP_SRC_URL
DYN_SUFFIX:=$DYN_SUFFIX
DYN_OPT=$DYN_OPT
"> settings.mk
echo "Generation done. Now ready to run 'make'."