-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfigure
executable file
·196 lines (179 loc) · 4.46 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
#!/bin/sh
# Library versions
LIB_VER="190"
TLS_VER="daca7a3"
# Initialise
PKG_CFLAGS=""
PKG_LIBS="-lnng -lmbedtls -lmbedx509 -lmbedcrypto"
NNG_CFLAGS=""
NNG_LIBS=""
# Find compiler and export flags
CC=`"${R_HOME}/bin/R" CMD config CC`
export CC
if [ -z "$MACOSX_DEPLOYMENT_TARGET" ]; then
export MACOSX_DEPLOYMENT_TARGET=`echo $CC | sed -En 's/.*-version-min=([0-9][0-9.]*).*/\1/p'`
fi
# Detect -latomic linker flag for ARM architectures (Raspberry Pi etc.)
echo "#include <stdint.h>
uint64_t v;
int main() {
return (int)__atomic_load_n(&v, __ATOMIC_ACQUIRE);
}" | ${CC} -xc - -o /dev/null > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "Adding -latomic linker flag ..."
PKG_LIBS="$PKG_LIBS -latomic"
fi
# Force build bundled libs
if [ -z "$NANONEXT_LIBS" ]; then
# Find MbedTLS and compile if necessary
if [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]
then
PKG_CFLAGS="-I$INCLUDE_DIR $PKG_CFLAGS"
PKG_LIBS="-L$LIB_DIR $PKG_LIBS"
echo "Found INCLUDE_DIR $INCLUDE_DIR"
echo "Found LIB_DIR $LIB_DIR"
elif [ -d "/usr/local/include/mbedtls" ]
then
PKG_CFLAGS="-I/usr/local/include $PKG_CFLAGS"
PKG_LIBS="-L/usr/local/lib $PKG_LIBS"
echo "Found 'libmbedtls' $PKG_CFLAGS"
elif [ -d "/usr/include/mbedtls" ]
then
PKG_CFLAGS="-I/usr/include $PKG_CFLAGS"
PKG_LIBS="-L/usr/lib $PKG_LIBS"
echo "Found 'libmbedtls' $PKG_CFLAGS"
elif [ -d "/usr/local/opt/mbedtls" ]
then
PKG_CFLAGS="-I/usr/local/opt/mbedtls/include $PKG_CFLAGS"
PKG_LIBS="-L/usr/local/opt/mbedtls/lib $PKG_LIBS"
echo "Found 'libmbedtls' $PKG_CFLAGS"
fi
echo "#include <mbedtls/version.h>
int main() {
#if MBEDTLS_VERSION_MAJOR < 2 || MBEDTLS_VERSION_MAJOR == 2 && MBEDTLS_VERSION_MINOR < 5
*(void *) 0 = 0;
#endif
}" | ${CC} ${PKG_CFLAGS} -xc - -o /dev/null > /dev/null 2>&1
else
echo "NANONEXT_LIBS is set... skipping detection"
false
fi
if [ $? -ne 0 ]
then
echo "No existing 'libmbedtls' >= 2.5 found"
echo "Detecting 'cmake'..."
which cmake
if [ $? -ne 0 ]
then
export PATH=$PATH:/Applications/CMake.app/Contents/bin
which cmake
if [ $? -ne 0 ]
then
echo "Required 'cmake' not found"
exit 1
fi
fi
echo "Detecting 'xz'..."
which xz
if [ $? -ne 0 ]
then
tar -xf src/mbedtls-$TLS_VER.tar.xz
if [ $? -ne 0 ]
then
echo "No 'xz' command found"
exit 1
fi
else
xz -dc src/mbedtls-$TLS_VER.tar.xz | tar -xf -
fi
cd mbedtls-$TLS_VER
echo "Compiling 'libmbedtls' from source ..."
cmake -DCMAKE_INSTALL_PREFIX=../install .
cmake --build . --target install
cd ..
rm -rf mbedtls-$TLS_VER
fi
# Force build bundled libs
if [ -z "$NANONEXT_LIBS" ]; then
# Find NNG and compile if necessary
if [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]
then
NNG_CFLAGS="-I$INCLUDE_DIR"
NNG_LIBS="-L$LIB_DIR"
elif [ -d "/usr/local/include/nng" ]
then
NNG_CFLAGS="-I/usr/local/include"
NNG_LIBS="-L/usr/local/lib"
elif [ -d "/usr/include/nng" ]
then
NNG_CFLAGS="-I/usr/include"
NNG_LIBS="-L/usr/lib"
elif [ -d "/usr/local/opt/nng" ]
then
NNG_CFLAGS="-I/usr/local/opt/nng/include"
NNG_LIBS="-L/usr/local/opt/nng/lib"
fi
echo "#include <nng/nng.h>
int main() {
#if NNG_MAJOR_VERSION < 1 || NNG_MAJOR_VERSION == 1 && NNG_MINOR_VERSION < 6
*(void *) 0 = 0;
#endif
}" | ${CC} ${NNG_CFLAGS} -xc - -o /dev/null > /dev/null 2>&1
else
echo "NANONEXT_LIBS is set... skipping detection"
false
fi
if [ $? -ne 0 ]
then
echo "No existing 'libnng' >= 1.6 found"
echo "Detecting 'cmake'..."
which cmake
if [ $? -ne 0 ]
then
export PATH=$PATH:/Applications/CMake.app/Contents/bin
which cmake
if [ $? -ne 0 ]
then
echo "Required 'cmake' not found"
exit 1
fi
fi
echo "Detecting 'xz'..."
which xz
if [ $? -ne 0 ]
then
tar -xf src/nng-$LIB_VER.tar.xz
if [ $? -ne 0 ]
then
echo "No 'xz' command found"
exit 1
fi
else
xz -dc src/nng-$LIB_VER.tar.xz | tar -xf -
fi
cd nng-$LIB_VER
echo "Compiling 'libnng' from source ..."
cmake -DCMAKE_INSTALL_PREFIX=../install .
cmake --build . --target install
cd ..
rm -rf nng-$LIB_VER
else
echo "Found 'libnng' $NNG_CFLAGS"
PKG_CFLAGS="$NNG_CFLAGS $PKG_CFLAGS"
PKG_LIBS="$NNG_LIBS $PKG_LIBS"
fi
if [ -d "install/lib64" ]
then
PKG_CFLAGS="-I../install/include $PKG_CFLAGS"
PKG_LIBS="-L../install/lib64 $PKG_LIBS"
fi
if [ -d "install/lib" ]
then
PKG_CFLAGS="-I../install/include $PKG_CFLAGS"
PKG_LIBS="-L../install/lib $PKG_LIBS"
fi
# Write to Makevars
sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars
# Success
exit 0