forked from nRF24/RF24
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·479 lines (441 loc) · 13.3 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
#!/bin/bash
CROSS_CC=arm-linux-gnueabihf-gcc
CROSS_CXX=arm-linux-gnueabihf-g++
function help {
cat <<EOF
configure script for RF24 library.
Options:
Help:
-h, --help print this message
Driver options:
--driver=[wiringPi|SPIDEV|MRAA|RPi|LittleWire]
Driver for RF24 library. [configure autodetected]
Building options:
--os=[LINUX|DARWIN] Operating system. [configure autodetected]
--soc=[BCM2835|BCM2836|AM33XX|A10|A13|A20|H3]
SoC type to be used. [configure autodetected]
--cpu-flags=<CFLAGS> CPU defining/optimizing flags to be used. [configure autodetected]
--extra-cflags=<CFLAGS> Extra C flags passed to C/C++ compilation. []
--extra-ldflags=<LDFLAGS> Extra C flags passed to linking. []
--libname=<LIBNAME> Library name. [rf24]
--c_compiler=<CC> C compiler. [arm-linux-gnueabihf-gcc][gcc]
--cxx_compiler=<CXX> C++ compiler [arm-linux-gnueabihf-g++][g++]
--no-clean Don't clean previous build artifacts
Installation options:
--prefix=<PREFIX> Installation prefix path. [/usr/local]
--lib-dir=<DIR> Library target installation directory. [PREFIX/lib]
--header-dir=<DIR> Header files target installation directory. [PREFIX/include]
--examples-dir=<DIR> Example files installation directory. [PREFIX/bin]
--ldconfig=<LDCONFIG> Ldconfig binary. Can be set to '' to skip ldconfig step. [ldconfig]
Cross-compilation options:
--remote-host=<REMOTE_HOST> Remote hostname for installation.
--remote-user=<REMOTE_USER> Remote username for installation. [current user]
--remote-port=<REMOTE_PORT> Ssh port of remote machine. [22]
--remote=<USER@HOST> Remote ssh host identification for installation [REMOTE_USER@REMOTE_HOST]
--remote-prefix=<RPREFIX> Remote host installation prefix path. [/usr/local]
--remote-lib-dir=<DIR> Remote library target installation directory [RPREFIX/lib]
--remote-header-dir=<DIR> Remote header files target installation directory. [RPREFIX/include]
--remote-ldconfig=<RLDCON> Remote ldconfig binary filename. Can be set to '' to skip ldconfig call. [ldconfig]
--remote-examples-dir=<DIR> Example files remote installation directory. Default: [REMOTE_PREFIX/bin]
EOF
}
function execute_check {
if [ "${REMOTE}" ]; then
ssh -o 'PasswordAuthentication=no' -o 'PreferredAuthentications=publickey' -o 'ConnectTimeout=30' -o 'BatchMode=yes' -o 'StrictHostKeyChecking=no' -p ${REMOTE_PORT} ${REMOTE} $1
else
eval $1
fi
}
function die {
echo "[ERROR] $1"
exit $2
}
function detect_machine {
local cpu=$(execute_check "uname -m 2>/dev/null")
local machine=$(execute_check "cat -v /sys/firmware/devicetree/base/model 2>/dev/null")
local hardware=$(execute_check "grep sunxi_platform /sys/class/sunxi_info/sys_info 2>/dev/null | sed 's/^.*: \(.*\)$/\1/'")
if [ -z "$hardware" ]; then
local hardware=$(execute_check "grep Hardware /proc/cpuinfo 2>/dev/null | sed 's/^.*: \(.*\)$/\1/'")
fi
local soc="unknown"
local tp="unknown"
if [ -z "$cpu" ]; then
cpu="unknown"
fi
case $hardware in
BCM2708|BCM2835)
soc="BCM2835"
if [[ $machine == "Raspberry"* ]]; then
tp="RPi"
fi
;;
BCM2709)
soc="BCM2836"
if [[ $machine == "Raspberry"* ]]; then
tp="RPi2"
fi
;;
sun4i|Sun4iw1p1)
soc="A10"
;;
sun5i|Sun4iw2p1)
soc="A13"
;;
Sun4iw2p2)
soc="A12"
;;
Sun4iw2p3)
soc="A10s"
;;
sun6i|Sun8iw1p1)
soc="A31"
;;
Sun8iw1p2)
soc="A31s"
;;
sun7i|Sun8iw2p1)
soc="A20"
if [[ $machine == "Banana Pi"* ]]; then
tp="BananaPi"
elif [[ $machine == "Banana Pro"* ]]; then
tp="BananaPro"
fi
;;
sun8i|Sun8iw7p1)
soc="H3"
;;
Sun8iw3p1)
soc="A23"
;;
Sun8iw5p1)
soc="A33"
;;
Sun8iw6p1)
soc="A83t"
;;
sun9i|Sun9iw1p1)
soc="A80"
;;
Sun9iw1p2)
soc="A80t"
;;
sun50i|Sun50iw1p1)
soc="A64"
;;
'Generic AM33XX'*)
soc="AM33XX"
;;
*)
soc="unknown"
esac
echo "${soc} ${tp} ${cpu}"
}
function gcc_cpu_flags {
local soc=$1
case $soc in
BCM2835)
flags="-marm -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard"
;;
BCM2836)
flags="-march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard"
;;
AM33XX)
flags="-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=hard"
;;
A10)
flags="-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=hard"
;;
A13)
flags="-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=hard"
;;
A20)
flags="-march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard"
;;
H3)
flags="-march=armv8-a -mtune=cortex-a53 -mfpu=neon-vfpv4 -mfloat-abi=hard"
;;
*)
flags=""
esac
echo ${flags}
}
# no longer used. This should be removed when resolving
# https://github.com/nRF24/RF24/issues/971
function detect_driver {
if [[ $(execute_check "cat /proc/cpuinfo | grep Hardware | grep 'BCM2708\|BCM2709\|BCM2835'") ]]; then
result=RPi
elif [[ $(execute_check 'ls /dev/spidev* 2>/dev/null') ]]; then
result=SPIDEV
elif [[ $(execute_check "file /usr/lib/libwiringPi.so*") ]]; then
result=wiringPi
elif [[ $(execute_check "${REMOTE_LDCONFIG} -p | grep libmraa") ]]; then
result=MRAA
elif [[ $(execute_check "${REMOTE_LDCONFIG} -p | grep liblittlewire-spi") ]]; then
result=LittleWire
elif [[ -f "/usr/lib/libpigpio.so" || -f "/usr/local/lib/libpigpio.so" || -f "/usr/arm-linux-gnueabihf/lib/libpigpio.so" ]]; then
result=pigpio
else
result=""
fi
echo $result
}
function gen_symlink_names {
base_name="$1"
version="$2"
IFS='.' read -r -a ver <<< "$version"
versions=""
for index in "${!ver[@]}" ; do
verstr=""
for ind in `seq 0 $(expr $index - 1)` ; do
verstr="${verstr}.${ver[$ind]}"
done
versions="${base_name}${verstr} $versions"
done
echo ${versions}
}
params="OS SOC DRIVER CPUFLAGS CFLAGS PREFIX REMOTE_PREFIX LIB LIBNAME LIB_VERSION LIBSYMLINKS LIBDEPRECATE CC CXX LIB_DIR REMOTE_LIB_DIR HEADER_DIR REMOTE_HEADER_DIR DRIVER_DIR ARCH_DIR REMOTE REMOTE_HOST REMOTE_USER REMOTE_PORT SHARED_LINKER_FLAGS SHARED_LINKER_LIBS LDCONFIG REMOTE_LDCONFIG EXAMPLES_DIR REMOTE_EXAMPLES_DIR"
for opt do
if [ "$opt" = "-h" ] || [ "$opt" = "--help" ]; then
help
exit 0
fi
optarg="${opt#*=}"
case "$opt" in
--os=*)
OS="$optarg"
;;
--soc=*)
SOC="$optarg"
;;
--cpu-flags=*)
CPUFLAGS="$optarg"
;;
--extra-cflags=*)
CFLAGS="$optarg"
;;
--extra-ldflags=*)
LDFLAGS="$optarg"
;;
--libname=*)
LIB="$optarg"
;;
--c_compiler=*)
CC="$optarg"
;;
--cxx_compiler=*)
CXX="$optarg"
;;
--no-clean*)
NO_CLEAN="1"
;;
--prefix=*)
PREFIX="$optarg"
;;
--lib-dir=*)
LIB_DIR="$optarg"
;;
--header-dir=*)
HEADER_DIR="$optarg"
;;
--examples-dir=*)
EXAMPLES_DIR="$optarg"
;;
--ldconfig=*)
LDCONFIG="$optarg"
;;
--driver=*)
DRIVER="$optarg"
;;
--remote-host=*)
REMOTE_HOST="$optarg"
;;
--remote-user=*)
REMOTE_USER="$optarg"
;;
--remote-port=*)
REMOTE_PORT="$optarg"
;;
--remote=*)
REMOTE="$optarg"
;;
--remote-prefix=*)
REMOTE_PREFIX="$optarg"
;;
--remote-lib-dir=*)
REMOTE_LIB_DIR="$optarg"
;;
--remote-header-dir=*)
REMOTE_HEADER_DIR="$optarg"
;;
--remote-ldconfig=*)
REMOTE_LDCONFIG="$optarg"
;;
--remote-examples-dir=*)
REMOTE_EXAMPLES_DIR="$optarg"
;;
*)
echo "[WARNING] Unknown option detected:$opt, ignored"
;;
esac
done
#*******************************************
# remote machine verification
if [ "${REMOTE_HOST}" ]; then
if [ "${REMOTE_USER}" ]; then
REMOTE=${REMOTE_USER}@${REMOTE_HOST}
else
REMOTE=${REMOTE_HOST}
fi
fi
if [ "${REMOTE}" ]; then
echo "[SECTION] Checking remote host."
if [ -z "${REMOTE_HOST}" ]; then
REMOTE_HOST=${REMOTE/*@/}
fi
if [ -z "${REMOTE_PORT}" ]; then
REMOTE_PORT=22
fi
if [ "$(nmap ${REMOTE_HOST} -Pn --host-timeout 30s -p ${REMOTE_PORT} 2>/dev/null | grep open)" ]; then
echo " [OK] ssh daemon on ${REMOTE_HOST} port ${REMOTE_PORT} seems to be listening."
else
echo " [WARNING] ssh on ${REMOTE_HOST} port ${REMOTE_PORT} seems not to be listening or nmap not installed."
fi
if [[ "$(execute_check 'echo ok 2>/dev/null' 2>/dev/null)" ]]; then
echo " [OK] Remote machine ssh passwordless login configured fine."
else
die "Remote machine ssh and/or passwordless login check failed." 4
fi
if [[ $(execute_check "sudo echo ok 2>/dev/null") ]]; then
echo " [OK] Remote machine sudo configured fine."
else
die "Remote machine sudo test failed." 5
fi
fi
if [ -z "${CC}" ]; then
echo "[SECTION] Detecting arm compilation environment."
if [[ $(command -v ${CROSS_CC} 2>/dev/null) ]]; then
echo " [OK] ${CROSS_CC} detected."
CC=${CROSS_CC}
CROSS_SYSROOT="$(${CC} --print-sysroot)"
if [ "${CROSS_SYSROOT}" = "/" ]; then
CROSS_SYSROOT=""
fi
else
echo " [INFO] ${CROSS_CC} not found."
fi
if [[ $(command -v ${CROSS_CXX} 2>/dev/null) ]]; then
echo " [OK] ${CROSS_CXX} detected."
CXX=${CROSS_CXX}
else
echo " [INFO] ${CROSS_CXX} not found."
fi
fi
if [ "${CROSS_SYSROOT}" ]; then
PREFIX="${CROSS_SYSROOT}/usr/local"
fi
PREFIX=${PREFIX:-/usr/local}
REMOTE_PREFIX=${REMOTE_PREFIX:-/usr/local}
LIB_DIR=${LIB_DIR:-${PREFIX}/lib}
REMOTE_LIB_DIR=${REMOTE_LIB_DIR:-${REMOTE_PREFIX}/lib}
HEADER_DIR=${HEADER_DIR:-${PREFIX}/include/RF24}
REMOTE_HEADER_DIR=${REMOTE_HEADER_DIR:-${REMOTE_PREFIX}/include/RF24}
EXAMPLES_DIR=${EXAMPLES_DIR:-${PREFIX}/bin}
REMOTE_EXAMPLES_DIR=${REMOTE_EXAMPLES_DIR:-${REMOTE_PREFIX}/bin}
LDCONFIG=${LDCONFIG-ldconfig}
REMOTE_LDCONFIG=${REMOTE_LDCONFIG-/sbin/ldconfig}
LIB=${LIB:-rf24}
LIB_VERSION=${LIB_VERSION:-$(awk -F "=" '/version/ {print $2}' library.properties)}
LIB_DEPRECATE_NAME=${LIB_DEPRECATE_NAME:-"rf24-bcm"}
LIB_DEPRECATE_VERSION=${LIB_DEPRECATE_VERSION:-""}
CC=${CC:-gcc}
CXX=${CXX:-g++}
ARCH_DIR=${ARCH_DIR:-utility}
if [ -z "${SOC}" ]; then
echo "[SECTION] Detecting target machine."
info=($(detect_machine))
SOC=${info[0]}
TYPE=${info[1]}
CPU=${info[2]}
echo "[OK] machine detected: SoC=${SOC}, Type=${TYPE}, CPU=${CPU}."
fi
if [ -z "${CPUFLAGS}" ]; then
CPUFLAGS=$(gcc_cpu_flags $SOC)
fi
#*******************************************
# DRIVER detection
if [ -z "${DRIVER}" ]; then
echo "[SECTION] Detecting DRIVER"
# DRIVER=$(detect_driver)
DRIVER=SPIDEV
if [ -z "${DRIVER}" ]; then
die "No supported driver detected. Run configure with --driver=<driver> to set a driver explicitly." 1
fi
echo " [OK] DRIVER detected:${DRIVER}."
fi
case ${DRIVER} in
wiringPi)
SHARED_LINKER_LIBS+=" -lwiringPi"
CFLAGS+=" -lwiringPi"
;;
SPIDEV)
;;
RPi)
;;
MRAA)
SHARED_LINKER_LIBS+=" -lmraa"
;;
LittleWire)
SHARED_LINKER_LIBS+=" -llittlewire-spi"
;;
pigpio)
SHARED_LINKER_LIBS+=" -lpigpio"
;;
*)
die "Unsupported DRIVER: ${DRIVER}." 2
;;
esac
#*******************************************
# OS detection
if [ -z "${OS}" ]; then
echo "[SECTION] Detecting OS."
OS=$(execute_check "uname")
OS=${OS^^}
echo " [INFO] OS detected:${OS}."
fi
case ${OS} in
LINUX)
DYN_SUFFIX=so
SHARED_LINKER_FLAGS+=" -shared -Wl,-soname,lib${LIB}.${DYN_SUFFIX}.${LIB_VERSION%%.*}"
;;
DARWIN)
DYN_SUFFIX=dylib
SHARED_LINKER_FLAGS+=" -dynamiclib -install_name ${LIB_DIR}/lib${LIB}.${DYN_SUFFIX}.${LIB_VERSION%%.*}"
;;
*)
die "Unsupported OS: ${OS}." 3
;;
esac
LIBNAME=${LIBNAME:-lib${LIB}.${DYN_SUFFIX}.${LIB_VERSION}}
LIBSYMLINKS="${LIBSYMLINKS:-$(gen_symlink_names lib${LIB}.${DYN_SUFFIX} ${LIB_VERSION})}"
if [ "${LIB_DEPRECATE_NAME}" ]; then
LIBDEPRECATE="${LIBDEPRECATE:-lib${LIB_DEPRECATE_NAME}.${DYN_SUFFIX}}"
if [ "${LIB_DEPRECATE_VERSION}" ]; then
LIBDEPRECATE="${LIBDEPRECATE}.${LIB_DEPRECATE_VERSION}"
fi
fi
DRIVER_DIR=${DRIVER_DIR:-${ARCH_DIR}/${DRIVER}}
CFLAGS="$CPUFLAGS -Ofast -Wall -pthread $CFLAGS"
echo "[SECTION] Preparing configuration."
cp ${DRIVER_DIR}/includes.h ${ARCH_DIR}/includes.h
echo "[SECTION] Saving configuration."
echo -n "" > Makefile.inc
for param in ${params}; do
if [[ ${!param} ]]; then
echo "${param}=${!param}" >> Makefile.inc
fi
done
if [ -z "${NO_CLEAN}" ]; then
echo "[SECTION] Cleaning previous builds."
make clean >/dev/null
fi
echo "[OK] Finished."