build 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #!/bin/bash -e
  2. # build
  3. # Simple wiringPi build and install script
  4. #
  5. # Copyright (c) 2012-2015 Gordon Henderson
  6. #################################################################################
  7. # This file is part of wiringPi:
  8. # A "wiring" library for the Raspberry Pi
  9. #
  10. # wiringPi is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU Lesser General Public License as published by
  12. # the Free Software Foundation, either version 3 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # wiringPi is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU Lesser General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Lesser General Public License
  21. # along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
  22. #################################################################################
  23. #
  24. # wiringPi is designed to run on a Raspberry Pi only.
  25. # However if you're clever enough to actually look at this script to
  26. # see why it's not building for you, then good luck.
  27. #
  28. # To everyone else: Stop using cheap alternatives. Support the
  29. # Raspberry Pi Foundation as they're the only ones putting money
  30. # back into education!
  31. #################################################################################
  32. check_make_ok() {
  33. if [ $? != 0 ]; then
  34. echo ""
  35. echo "Make Failed..."
  36. echo "Please check the messages and fix any problems. If you're still stuck,"
  37. echo "then please email all the output and as many details as you can to"
  38. echo " projects@drogon.net"
  39. echo ""
  40. exit 1
  41. fi
  42. }
  43. select_boards()
  44. {
  45. local cnt=0
  46. local choice
  47. local call=${1}
  48. boards=("clockworkpi-a04" "clockworkpi-a06" )
  49. if [[ -f /etc/armbian-release ]]; then
  50. source /etc/armbian-release
  51. else
  52. printf "All available boards:\n"
  53. for var in ${boards[@]} ; do
  54. printf "%4d. %s\n" $cnt ${boards[$cnt]}
  55. ((cnt+=1))
  56. done
  57. while true ; do
  58. read -p "Choice: " choice
  59. if [ -z "${choice}" ] ; then
  60. continue
  61. fi
  62. if [ -z "${choice//[0-9]/}" ] ; then
  63. if [ $choice -ge 0 -a $choice -lt $cnt ] ; then
  64. export BOARD="${boards[$choice]}"
  65. break
  66. fi
  67. fi
  68. printf "Invalid input ...\n"
  69. done
  70. fi
  71. [[ $BOARD == clockworkpi-a04 ]] && BOARD=clockworkpi-a04-h6
  72. [[ $BOARD == clockworkpi-a06 ]] && BOARD=clockworkpi-a06-rk3399
  73. export BOARD="${BOARD}"
  74. }
  75. sudo=${WIRINGPI_SUDO-sudo}
  76. if [ x$1 = "xclean" ]; then
  77. cd wiringPi
  78. echo -n "wiringPi: " ; make clean
  79. cd ../devLib
  80. echo -n "DevLib: " ; make clean
  81. cd ../gpio
  82. echo -n "gpio: " ; make clean
  83. cd ../examples
  84. echo -n "Examples: " ; make clean
  85. cd Gertboard
  86. echo -n "Gertboard: " ; make clean
  87. cd ../PiFace
  88. echo -n "PiFace: " ; make clean
  89. cd ../q2w
  90. echo -n "Quick2Wire: " ; make clean
  91. cd ../PiGlow
  92. echo -n "PiGlow: " ; make clean
  93. cd ../scrollPhat
  94. echo -n "scrollPhat: " ; make clean
  95. cd ../..
  96. echo -n "Deb: " ; rm -f debian-template/wiringpi*.deb
  97. echo
  98. exit
  99. fi
  100. if [ x$1 = "xuninstall" ]; then
  101. cd wiringPi
  102. echo -n "wiringPi: " ; $sudo make uninstall
  103. cd ../devLib
  104. echo -n "DevLib: " ; $sudo make uninstall
  105. cd ../gpio
  106. echo -n "gpio: " ; $sudo make uninstall
  107. exit
  108. fi
  109. # Only if you know what you're doing!
  110. if [ x$1 = "xdebian" ]; then
  111. here=`pwd`
  112. cd debian-template/wiringPi
  113. rm -rf usr
  114. cd $here/wiringPi
  115. make install-deb
  116. cd $here/devLib
  117. make install-deb INCLUDE='-I. -I../wiringPi'
  118. cd $here/gpio
  119. make install-deb INCLUDE='-I../wiringPi -I../devLib' LDFLAGS=-L../debian-template/wiringPi/usr/lib
  120. cd $here/debian-template
  121. fakeroot dpkg-deb --build wiringPi
  122. mv wiringPi.deb wiringpi-`cat $here/VERSION`-1.deb
  123. exit
  124. fi
  125. if [ x$1 != "x" ]; then
  126. echo "Usage: $0 [clean | uninstall]"
  127. exit 1
  128. fi
  129. select_boards
  130. echo "wiringPi Build script"
  131. echo "====================="
  132. echo
  133. hardware=`fgrep Hardware /proc/cpuinfo | head -1 | awk '{ print $3 }'`
  134. # if [ x$hardware != "xBCM2708" ]; then
  135. # echo ""
  136. # echo " +------------------------------------------------------------+"
  137. # echo " | wiringPi is designed to run on the Raspberry Pi only. |"
  138. # echo " | This processor does not appear to be a Raspberry Pi. |"
  139. # echo " +------------------------------------------------------------+"
  140. # echo " | In the unlikely event that you think it is a Raspberry Pi, |"
  141. # echo " | then please accept my apologies and email the contents of |"
  142. # echo " | /proc/cpuinfo to projects@drogon.net. |"
  143. # echo " | - Thanks, Gordon |"
  144. # echo " +------------------------------------------------------------+"
  145. # echo ""
  146. # exit 1
  147. # fi
  148. echo
  149. echo "WiringPi Library"
  150. cd wiringPi
  151. $sudo make uninstall
  152. if [ x$1 = "xstatic" ]; then
  153. make -j5 static
  154. check_make_ok
  155. $sudo make install-static
  156. else
  157. make -j5
  158. check_make_ok
  159. $sudo make install
  160. fi
  161. check_make_ok
  162. echo
  163. echo "WiringPi Devices Library"
  164. cd ../devLib
  165. $sudo make uninstall
  166. if [ x$1 = "xstatic" ]; then
  167. make -j5 static
  168. check_make_ok
  169. $sudo make install-static
  170. else
  171. make -j5
  172. check_make_ok
  173. $sudo make install
  174. fi
  175. check_make_ok
  176. echo
  177. echo "GPIO Utility"
  178. cd ../gpio
  179. make -j5
  180. check_make_ok
  181. $sudo make install
  182. check_make_ok
  183. # echo
  184. # echo "wiringPi Daemon"
  185. # cd ../wiringPiD
  186. # make -j5
  187. # check_make_ok
  188. # $sudo make install
  189. # check_make_ok
  190. # echo
  191. # echo "Examples"
  192. # cd ../examples
  193. # make
  194. # cd ..
  195. echo
  196. echo All Done.
  197. echo ""
  198. echo "NOTE: To compile programs with wiringPi, you need to add:"
  199. echo " -lwiringPi"
  200. echo " to your compile line(s) To use the Gertboard, MaxDetect, etc."
  201. echo " code (the devLib), you need to also add:"
  202. echo " -lwiringPiDev"
  203. echo " to your compile line(s)."
  204. echo ""