Ein Roboter mit bürstenlosem Antrieb, differenzial und NRF24L01 Funk. Großflächig gebaut um ein großes Solarpanel aufzunehmen. https://gitlab.informatik.hs-fulda.de/fdai5253/roboter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

473 lines
13 KiB

  1. #!/bin/bash
  2. CROSS_CC=arm-linux-gnueabihf-gcc
  3. CROSS_CXX=arm-linux-gnueabihf-g++
  4. function help {
  5. cat <<EOF
  6. configure script for RF24 library.
  7. Options:
  8. Help:
  9. -h, --help print this message
  10. Driver options:
  11. --driver=[wiringPi|SPIDEV|MRAA|RPi|LittleWire]
  12. Driver for RF24 library. [configure autodetected]
  13. Building options:
  14. --os=[LINUX|DARWIN] Operating system. [configure autodetected]
  15. --soc=[BCM2835|BCM2836|AM33XX|A10|A13|A20|H3]
  16. SoC type to be used. [configure autodetected]
  17. --cpu-flags=<CFLAGS> CPU defining/optimizing flags to be used. [configure autodetected]
  18. --extra-cflags=<CFLAGS> Extra C flags passed to C/C++ compilation. []
  19. --extra-ldflags=<LDFLAGS> Extra C flags passed to linking. []
  20. --libname=<LIBNAME> Library name. [rf24]
  21. --c_compiler=<CC> C compiler. [arm-linux-gnueabihf-gcc][gcc]
  22. --cxx_compiler=<CXX> C++ compiler [arm-linux-gnueabihf-g++][g++]
  23. --no-clean Don't clean previous build artifacts
  24. Installation options:
  25. --prefix=<PREFIX> Installation prefix path. [/usr/local]
  26. --lib-dir=<DIR> Library target installation directory. [PREFIX/lib]
  27. --header-dir=<DIR> Header files target installation directory. [PREFIX/include]
  28. --examples-dir=<DIR> Example files installation directory. [PREFIX/bin]
  29. --ldconfig=<LDCONFIG> Ldconfig binary. Can be set to '' to skip ldconfig step. [ldconfig]
  30. Cross-compilation options:
  31. --remote-host=<REMOTE_HOST> Remote hostname for installation.
  32. --remote-user=<REMOTE_USER> Remote username for installation. [current user]
  33. --remote-port=<REMOTE_PORT> Ssh port of remote machine. [22]
  34. --remote=<USER@HOST> Remote ssh host identification for installation [REMOTE_USER@REMOTE_HOST]
  35. --remote-prefix=<RPREFIX> Remote host installation prefix path. [/usr/local]
  36. --remote-lib-dir=<DIR> Remote library target installation directory [RPREFIX/lib]
  37. --remote-header-dir=<DIR> Remote header files target installation directory. [RPREFIX/include]
  38. --remote-ldconfig=<RLDCON> Remote ldconfig binary filename. Can be set to '' to skip ldconfig call. [ldconfig]
  39. --remote-examples-dir=<DIR> Example files remote installation directory. Default: [REMOTE_PREFIX/bin]
  40. EOF
  41. }
  42. function execute_check {
  43. if [ "${REMOTE}" ]; then
  44. ssh -o 'PasswordAuthentication=no' -o 'PreferredAuthentications=publickey' -o 'ConnectTimeout=30' -o 'BatchMode=yes' -o 'StrictHostKeyChecking=no' -p ${REMOTE_PORT} ${REMOTE} $1
  45. else
  46. eval $1
  47. fi
  48. }
  49. function die {
  50. echo "[ERROR] $1"
  51. exit $2
  52. }
  53. function detect_machine {
  54. local cpu=$(execute_check "uname -m 2>/dev/null")
  55. local machine=$(execute_check "cat /sys/firmware/devicetree/base/model 2>/dev/null")
  56. local hardware=$(execute_check "grep sunxi_platform /sys/class/sunxi_info/sys_info 2>/dev/null | sed 's/^.*: \(.*\)$/\1/'")
  57. if [ -z "$hardware" ]; then
  58. local hardware=$(execute_check "grep Hardware /proc/cpuinfo 2>/dev/null | sed 's/^.*: \(.*\)$/\1/'")
  59. fi
  60. local soc="unknown"
  61. local tp="unknown"
  62. if [ -z "$cpu" ]; then
  63. cpu="unknown"
  64. fi
  65. case $hardware in
  66. BCM2708|BCM2835)
  67. soc="BCM2835"
  68. if [[ $machine == "Raspberry"* ]]; then
  69. tp="RPi"
  70. fi
  71. ;;
  72. BCM2709)
  73. soc="BCM2836"
  74. if [[ $machine == "Raspberry"* ]]; then
  75. tp="RPi2"
  76. fi
  77. ;;
  78. sun4i|Sun4iw1p1)
  79. soc="A10"
  80. ;;
  81. sun5i|Sun4iw2p1)
  82. soc="A13"
  83. ;;
  84. Sun4iw2p2)
  85. soc="A12"
  86. ;;
  87. Sun4iw2p3)
  88. soc="A10s"
  89. ;;
  90. sun6i|Sun8iw1p1)
  91. soc="A31"
  92. ;;
  93. Sun8iw1p2)
  94. soc="A31s"
  95. ;;
  96. sun7i|Sun8iw2p1)
  97. soc="A20"
  98. if [[ $machine == "Banana Pi"* ]]; then
  99. tp="BananaPi"
  100. elif [[ $machine == "Banana Pro"* ]]; then
  101. tp="BananaPro"
  102. fi
  103. ;;
  104. sun8i|Sun8iw7p1)
  105. soc="H3"
  106. ;;
  107. Sun8iw3p1)
  108. soc="A23"
  109. ;;
  110. Sun8iw5p1)
  111. soc="A33"
  112. ;;
  113. Sun8iw6p1)
  114. soc="A83t"
  115. ;;
  116. sun9i|Sun9iw1p1)
  117. soc="A80"
  118. ;;
  119. Sun9iw1p2)
  120. soc="A80t"
  121. ;;
  122. sun50i|Sun50iw1p1)
  123. soc="A64"
  124. ;;
  125. 'Generic AM33XX'*)
  126. soc="AM33XX"
  127. ;;
  128. *)
  129. soc="unknown"
  130. esac
  131. echo "${soc} ${tp} ${cpu}"
  132. }
  133. function gcc_cpu_flags {
  134. local soc=$1
  135. case $soc in
  136. BCM2835)
  137. flags="-march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard"
  138. ;;
  139. BCM2836)
  140. flags="-march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard"
  141. ;;
  142. AM33XX)
  143. flags="-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=hard"
  144. ;;
  145. A10)
  146. flags="-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=hard"
  147. ;;
  148. A13)
  149. flags="-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=hard"
  150. ;;
  151. A20)
  152. flags="-march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard"
  153. ;;
  154. H3)
  155. flags="-march=armv8-a -mtune=cortex-a53 -mfpu=neon-vfpv4 -mfloat-abi=hard"
  156. ;;
  157. *)
  158. flags=""
  159. esac
  160. echo ${flags}
  161. }
  162. function detect_driver {
  163. if [[ $(execute_check "cat /proc/cpuinfo | grep Hardware | grep 'BCM2708\|BCM2709\|BCM2835'") ]]; then
  164. result=RPi
  165. elif [[ $(execute_check 'ls /dev/spidev* 2>/dev/null') ]]; then
  166. result=SPIDEV
  167. elif [[ $(execute_check "file /usr/lib/libwiringPi.so*") ]]; then
  168. result=wiringPi
  169. elif [[ $(execute_check "${REMOTE_LDCONFIG} -p | grep libmraa") ]]; then
  170. result=MRAA
  171. elif [[ $(execute_check "${REMOTE_LDCONFIG} -p | grep liblittlewire-spi") ]]; then
  172. result=LittleWire
  173. else
  174. result=""
  175. fi
  176. echo $result
  177. }
  178. function gen_symlink_names {
  179. base_name="$1"
  180. version="$2"
  181. IFS='.' read -r -a ver <<< "$version"
  182. versions=""
  183. for index in "${!ver[@]}" ; do
  184. verstr=""
  185. for ind in `seq 0 $(expr $index - 1)` ; do
  186. verstr="${verstr}.${ver[$ind]}"
  187. done
  188. versions="${base_name}${verstr} $versions"
  189. done
  190. echo ${versions}
  191. }
  192. 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"
  193. for opt do
  194. if [ "$opt" = "-h" ] || [ "$opt" = "--help" ]; then
  195. help
  196. exit 0
  197. fi
  198. optarg="${opt#*=}"
  199. case "$opt" in
  200. --os=*)
  201. OS="$optarg"
  202. ;;
  203. --soc=*)
  204. SOC="$optarg"
  205. ;;
  206. --cpu-flags=*)
  207. CPUFLAGS="$optarg"
  208. ;;
  209. --extra-cflags=*)
  210. CFLAGS="$optarg"
  211. ;;
  212. --extra-ldflags=*)
  213. LDFLAGS="$optarg"
  214. ;;
  215. --libname=*)
  216. LIB="$optarg"
  217. ;;
  218. --c_compiler=*)
  219. CC="$optarg"
  220. ;;
  221. --cxx_compiler=*)
  222. CXX="$optarg"
  223. ;;
  224. --no-clean*)
  225. NO_CLEAN="1"
  226. ;;
  227. --prefix=*)
  228. PREFIX="$optarg"
  229. ;;
  230. --lib-dir=*)
  231. LIB_DIR="$optarg"
  232. ;;
  233. --header-dir=*)
  234. HEADER_DIR="$optarg"
  235. ;;
  236. --examples-dir=*)
  237. EXAMPLES_DIR="$optarg"
  238. ;;
  239. --ldconfig=*)
  240. LDCONFIG="$optarg"
  241. ;;
  242. --driver=*)
  243. DRIVER="$optarg"
  244. ;;
  245. --remote-host=*)
  246. REMOTE_HOST="$optarg"
  247. ;;
  248. --remote-user=*)
  249. REMOTE_USER="$optarg"
  250. ;;
  251. --remote-port=*)
  252. REMOTE_PORT="$optarg"
  253. ;;
  254. --remote=*)
  255. REMOTE="$optarg"
  256. ;;
  257. --remote-prefix=*)
  258. REMOTE_PREFIX="$optarg"
  259. ;;
  260. --remote-lib-dir=*)
  261. REMOTE_LIB_DIR="$optarg"
  262. ;;
  263. --remote-header-dir=*)
  264. REMOTE_HEADER_DIR="$optarg"
  265. ;;
  266. --remote-ldconfig=*)
  267. REMOTE_LDCONFIG="$optarg"
  268. ;;
  269. --remote-examples-dir=*)
  270. REMOTE_EXAMPLES_DIR="$optarg"
  271. ;;
  272. *)
  273. echo "[WARNING] Unknown option detected:$opt, ignored"
  274. ;;
  275. esac
  276. done
  277. #*******************************************
  278. # remote machine verification
  279. if [ "${REMOTE_HOST}" ]; then
  280. if [ "${REMOTE_USER}" ]; then
  281. REMOTE=${REMOTE_USER}@${REMOTE_HOST}
  282. else
  283. REMOTE=${REMOTE_HOST}
  284. fi
  285. fi
  286. if [ "${REMOTE}" ]; then
  287. echo "[SECTION] Checking remote host."
  288. if [ -z "${REMOTE_HOST}" ]; then
  289. REMOTE_HOST=${REMOTE/*@/}
  290. fi
  291. if [ -z "${REMOTE_PORT}" ]; then
  292. REMOTE_PORT=22
  293. fi
  294. if [ "$(nmap ${REMOTE_HOST} -Pn --host-timeout 30s -p ${REMOTE_PORT} 2>/dev/null | grep open)" ]; then
  295. echo " [OK] ssh daemon on ${REMOTE_HOST} port ${REMOTE_PORT} seems to be listening."
  296. else
  297. echo " [WARNING] ssh on ${REMOTE_HOST} port ${REMOTE_PORT} seems not to be listening or nmap not installed."
  298. fi
  299. if [[ "$(execute_check 'echo ok 2>/dev/null' 2>/dev/null)" ]]; then
  300. echo " [OK] Remote machine ssh passwordless login configured fine."
  301. else
  302. die "Remote machine ssh and/or passwordless login check failed." 4
  303. fi
  304. if [[ $(execute_check "sudo echo ok 2>/dev/null") ]]; then
  305. echo " [OK] Remote machine sudo configured fine."
  306. else
  307. die "Remote machine sudo test failed." 5
  308. fi
  309. fi
  310. if [ -z "${CC}" ]; then
  311. echo "[SECTION] Detecting arm compilation environment."
  312. if [[ $(command -v ${CROSS_CC} 2>/dev/null) ]]; then
  313. echo " [OK] ${CROSS_CC} detected."
  314. CC=${CROSS_CC}
  315. CROSS_SYSROOT="$(${CC} --print-sysroot)"
  316. if [ "${CROSS_SYSROOT}" = "/" ]; then
  317. CROSS_SYSROOT=""
  318. fi
  319. else
  320. echo " [INFO] ${CROSS_CC} not found."
  321. fi
  322. if [[ $(command -v ${CROSS_CXX} 2>/dev/null) ]]; then
  323. echo " [OK] ${CROSS_CXX} detected."
  324. CXX=${CROSS_CXX}
  325. else
  326. echo " [INFO] ${CROSS_CXX} not found."
  327. fi
  328. fi
  329. if [ "${CROSS_SYSROOT}" ]; then
  330. PREFIX="${CROSS_SYSROOT}/usr/local"
  331. fi
  332. PREFIX=${PREFIX:-/usr/local}
  333. REMOTE_PREFIX=${REMOTE_PREFIX:-/usr/local}
  334. LIB_DIR=${LIB_DIR:-${PREFIX}/lib}
  335. REMOTE_LIB_DIR=${REMOTE_LIB_DIR:-${REMOTE_PREFIX}/lib}
  336. HEADER_DIR=${HEADER_DIR:-${PREFIX}/include/RF24}
  337. REMOTE_HEADER_DIR=${REMOTE_HEADER_DIR:-${REMOTE_PREFIX}/include/RF24}
  338. EXAMPLES_DIR=${EXAMPLES_DIR:-${PREFIX}/bin}
  339. REMOTE_EXAMPLES_DIR=${REMOTE_EXAMPLES_DIR:-${REMOTE_PREFIX}/bin}
  340. LDCONFIG=${LDCONFIG-ldconfig}
  341. REMOTE_LDCONFIG=${REMOTE_LDCONFIG-/sbin/ldconfig}
  342. LIB=${LIB:-rf24}
  343. LIB_VERSION=${LIB_VERSION:-$(awk -F "=" '/version/ {print $2}' library.properties)}
  344. LIB_DEPRECATE_NAME=${LIB_DEPRECATE_NAME:-"rf24-bcm"}
  345. LIB_DEPRECATE_VERSION=${LIB_DEPRECATE_VERSION:-""}
  346. CC=${CC:-gcc}
  347. CXX=${CXX:-g++}
  348. ARCH_DIR=${ARCH_DIR:-utility}
  349. if [ -z "${SOC}" ]; then
  350. echo "[SECTION] Detecting target machine."
  351. info=($(detect_machine))
  352. SOC=${info[0]}
  353. TYPE=${info[1]}
  354. CPU=${info[2]}
  355. echo "[OK] machine detected: SoC=${SOC}, Type=${TYPE}, CPU=${CPU}."
  356. fi
  357. if [ -z "${CPUFLAGS}" ]; then
  358. CPUFLAGS=$(gcc_cpu_flags $SOC)
  359. fi
  360. #*******************************************
  361. # DRIVER detection
  362. if [ -z "${DRIVER}" ]; then
  363. echo "[SECTION] Detecting DRIVER"
  364. DRIVER=$(detect_driver)
  365. if [ -z "${DRIVER}" ]; then
  366. die "No supported driver detected. Run configure with --driver=<driver> to set a driver explicitly." 1
  367. fi
  368. echo " [OK] DRIVER detected:${DRIVER}."
  369. fi
  370. case ${DRIVER} in
  371. wiringPi)
  372. SHARED_LINKER_LIBS+=" -pthread -lwiringPi"
  373. CFLAGS+=" -lwiringPi"
  374. ;;
  375. SPIDEV)
  376. SHARED_LINKER_LIBS+=" -pthread"
  377. ;;
  378. RPi)
  379. SHARED_LINKER_LIBS+=" -pthread"
  380. ;;
  381. MRAA)
  382. SHARED_LINKER_LIBS+=" -lmraa"
  383. ;;
  384. LittleWire)
  385. SHARED_LINKER_LIBS+=" -llittlewire-spi"
  386. ;;
  387. *)
  388. die "Unsupported DRIVER: ${DRIVER}." 2
  389. ;;
  390. esac
  391. #*******************************************
  392. # OS detection
  393. if [ -z "${OS}" ]; then
  394. echo "[SECTION] Detecting OS."
  395. OS=$(execute_check "uname")
  396. OS=${OS^^}
  397. echo " [INFO] OS detected:${OS}."
  398. fi
  399. case ${OS} in
  400. LINUX)
  401. DYN_SUFFIX=so
  402. SHARED_LINKER_FLAGS+=" -shared -Wl,-soname,lib${LIB}.${DYN_SUFFIX}.${LIB_VERSION%%.*}"
  403. ;;
  404. DARWIN)
  405. DYN_SUFFIX=dylib
  406. SHARED_LINKER_FLAGS+=" -dynamiclib -install_name ${LIB_DIR}/lib${LIB}.${DYN_SUFFIX}.${LIB_VERSION%%.*}"
  407. ;;
  408. *)
  409. die "Unsupported OS: ${OS}." 3
  410. ;;
  411. esac
  412. LIBNAME=${LIBNAME:-lib${LIB}.${DYN_SUFFIX}.${LIB_VERSION}}
  413. LIBSYMLINKS="${LIBSYMLINKS:-$(gen_symlink_names lib${LIB}.${DYN_SUFFIX} ${LIB_VERSION})}"
  414. if [ "${LIB_DEPRECATE_NAME}" ]; then
  415. LIBDEPRECATE="${LIBDEPRECATE:-lib${LIB_DEPRECATE_NAME}.${DYN_SUFFIX}}"
  416. if [ "${LIB_DEPRECATE_VERSION}" ]; then
  417. LIBDEPRECATE="${LIBDEPRECATE}.${LIB_DEPRECATE_VERSION}"
  418. fi
  419. fi
  420. DRIVER_DIR=${DRIVER_DIR:-${ARCH_DIR}/${DRIVER}}
  421. CFLAGS="$CPUFLAGS -Ofast -Wall -pthread $CFLAGS"
  422. echo "[SECTION] Preparing configuration."
  423. cp ${DRIVER_DIR}/includes.h ${ARCH_DIR}/includes.h
  424. echo "[SECTION] Saving configuration."
  425. echo -n "" > Makefile.inc
  426. for param in ${params}; do
  427. if [[ ${!param} ]]; then
  428. echo "${param}=${!param}" >> Makefile.inc
  429. fi
  430. done
  431. if [ -z "${NO_CLEAN}" ]; then
  432. echo "[SECTION] Cleaning previous builds."
  433. make clean >/dev/null
  434. fi
  435. echo "[OK] Finished."