blob: e6d9d1815a799b3ff186c7c8cad1a17ad94d2862 [file] [log] [blame]
Ian Jackson95a29282015-09-09 23:30:16 +00001#!/bin/sh -e
Gordon Hendersonc4335192012-08-18 20:07:42 +01002
Gordon Hendersoneb1fc2c2015-01-30 18:14:49 +00003# build
4# Simple wiringPi build and install script
5#
6# Copyright (c) 2012-2015 Gordon Henderson
7#################################################################################
8# This file is part of wiringPi:
Gordon Hendersonb1dfc182016-12-12 14:19:55 +00009# A "wiring" library for the Raspberry Pi
Gordon Hendersoneb1fc2c2015-01-30 18:14:49 +000010#
11# wiringPi is free software: you can redistribute it and/or modify
12# it under the terms of the GNU Lesser General Public License as published by
13# the Free Software Foundation, either version 3 of the License, or
14# (at your option) any later version.
15#
16# wiringPi is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU Lesser General Public License for more details.
20#
21# You should have received a copy of the GNU Lesser General Public License
22# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
23#################################################################################
24#
25# wiringPi is designed to run on a Raspberry Pi only.
26# However if you're clever enough to actually look at this script to
27# see why it's not building for you, then good luck.
28#
29# To everyone else: Stop using cheap alternatives. Support the
30# Raspberry Pi Foundation as they're the only ones putting money
31# back into education!
32#################################################################################
33
Gordon Henderson348bc732013-05-25 13:02:02 +010034check_make_ok() {
Gordon Hendersonc82fb872013-01-15 22:38:21 +000035 if [ $? != 0 ]; then
36 echo ""
37 echo "Make Failed..."
38 echo "Please check the messages and fix any problems. If you're still stuck,"
39 echo "then please email all the output and as many details as you can to"
40 echo " projects@drogon.net"
41 echo ""
42 exit 1
43 fi
44}
45
Yang Deokgyu2ef868b2019-09-18 16:47:23 +090046configure_gpiomem() {
47 GPIOMEM="/dev/gpiomem"
48
49 if [ -z $1 ] && [ "$(stat -c "%a %G" "$GPIOMEM")" != "660"*"odroid" ]; then
50 case "$(echo $hardware | tr [:upper:] [:lower:])" in
51 *xu4)
52 $sudo cp -f udev/rules.d/99-odroid-wiringpi-exynos.rules /etc/udev/rules.d/
53 ;;
Yang Deokgyu639f1b42019-10-22 15:26:50 +090054 *c|*c1|*c2|*n2)
Yang Deokgyu2ef868b2019-09-18 16:47:23 +090055 $sudo cp -f udev/rules.d/99-odroid-wiringpi-aml.rules /etc/udev/rules.d/
56 ;;
57 *)
58 echo "This system seems not ODROID"
59 ;;
60 esac
61
62 echo "Reload udev..."
63 [ -x "$(command -v udevadm)" ] \
64 && $sudo udevadm trigger \
65 || echo "udevadm not found. Please reboot to take effect"
66 elif [ "$1" = "uninstall" ]; then
67 $sudo rm -f /etc/udev/rules.d/99-odroid-wiringpi-*
68 else
69 echo "Not found $GPIOMEM"
70 echo "You will not be able to use WiringPi without root permission"
71 fi
72}
73
Ian Jackson73aa8952015-09-12 16:41:38 +000074sudo=${WIRINGPI_SUDO-sudo}
Yang Deokgyu57890f82019-09-18 17:47:26 +090075make="make -j $(( $(nproc) + 1 ))"
Yang Deokgyud26507b2019-10-22 14:46:55 +090076hardware=$(fgrep -a Hardware /proc/cpuinfo | head -1 | awk '{ printf("%s %s %s\n", $3, $4, $5) }' | xargs)
Ian Jackson73aa8952015-09-12 16:41:38 +000077
Gordon Hendersonc4335192012-08-18 20:07:42 +010078if [ x$1 = "xclean" ]; then
Gordon Hendersonc4335192012-08-18 20:07:42 +010079 cd wiringPi
Yang Deokgyu57890f82019-09-18 17:47:26 +090080 echo -n "wiringPi: " ; $make clean
Gordon Hendersonda384432013-05-13 19:43:26 +010081 cd ../devLib
Yang Deokgyu57890f82019-09-18 17:47:26 +090082 echo -n "DevLib: " ; $make clean
Gordon Hendersonc4335192012-08-18 20:07:42 +010083 cd ../gpio
Yang Deokgyu57890f82019-09-18 17:47:26 +090084 echo -n "gpio: " ; $make clean
Gordon Hendersonc4335192012-08-18 20:07:42 +010085 cd ../examples
Yang Deokgyu57890f82019-09-18 17:47:26 +090086 echo -n "Examples: " ; $make clean
Gordon Hendersonda384432013-05-13 19:43:26 +010087 cd Gertboard
Yang Deokgyu57890f82019-09-18 17:47:26 +090088 echo -n "Gertboard: " ; $make clean
Gordon Hendersonda384432013-05-13 19:43:26 +010089 cd ../PiFace
Yang Deokgyu57890f82019-09-18 17:47:26 +090090 echo -n "PiFace: " ; $make clean
Gordon Hendersonbfaf2662013-05-20 21:13:44 +010091 cd ../q2w
Yang Deokgyu57890f82019-09-18 17:47:26 +090092 echo -n "Quick2Wire: " ; $make clean
Gordon Hendersone25cbc02013-07-24 15:14:09 +010093 cd ../PiGlow
Yang Deokgyu57890f82019-09-18 17:47:26 +090094 echo -n "PiGlow: " ; $make clean
Gordon Hendersonb0a60c32016-02-29 06:57:38 +000095 cd ../scrollPhat
Yang Deokgyu57890f82019-09-18 17:47:26 +090096 echo -n "scrollPhat: " ; $make clean
Gordon Hendersondb925ce2013-01-19 21:46:13 +000097 exit
98fi
99
100if [ x$1 = "xuninstall" ]; then
Gordon Henderson183c5a62012-10-21 15:25:16 +0100101 cd wiringPi
Yang Deokgyu57890f82019-09-18 17:47:26 +0900102 echo -n "wiringPi: " ; $sudo $make uninstall
Gordon Hendersonda384432013-05-13 19:43:26 +0100103 cd ../devLib
Yang Deokgyu57890f82019-09-18 17:47:26 +0900104 echo -n "DevLib: " ; $sudo $make uninstall
Gordon Henderson183c5a62012-10-21 15:25:16 +0100105 cd ../gpio
Yang Deokgyu57890f82019-09-18 17:47:26 +0900106 echo -n "gpio: " ; $sudo $make uninstall
Yang Deokgyu2ef868b2019-09-18 16:47:23 +0900107 cd ..
108 echo -n "Deconfigure /dev/gpiomem" ; configure_gpiomem uninstall
109 echo
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000110 exit
111fi
112
Gordon Henderson7cb81742015-01-31 16:43:08 +0000113# Only if you know what you're doing!
114
115if [ x$1 = "xdebian" ]; then
116 here=`pwd`
Ian Jacksonac0f0742015-09-12 17:25:39 +0000117 cd debian-template/wiringPi
Gordon Henderson7cb81742015-01-31 16:43:08 +0000118 rm -rf usr
119 cd $here/wiringPi
Yang Deokgyu57890f82019-09-18 17:47:26 +0900120 $make install-deb
Gordon Henderson7cb81742015-01-31 16:43:08 +0000121 cd $here/devLib
Yang Deokgyu57890f82019-09-18 17:47:26 +0900122 $make install-deb INCLUDE='-I. -I../wiringPi'
Gordon Henderson7cb81742015-01-31 16:43:08 +0000123 cd $here/gpio
Yang Deokgyu57890f82019-09-18 17:47:26 +0900124 $make install-deb INCLUDE='-I../wiringPi -I../devLib' LDFLAGS=-L../debian-template/wiringPi/usr/lib
Ian Jacksonac0f0742015-09-12 17:25:39 +0000125 cd $here/debian-template
Gordon Henderson7cb81742015-01-31 16:43:08 +0000126 fakeroot dpkg-deb --build wiringPi
Joshua Yang41a423e2019-07-16 18:08:16 +0900127 mv wiringPi.deb odroid-wiringpi-`cat $here/VERSION`.deb
Gordon Henderson7cb81742015-01-31 16:43:08 +0000128 exit
129fi
130
131if [ x$1 != "x" ]; then
132 echo "Usage: $0 [clean | uninstall]"
133 exit 1
134fi
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000135
136 echo "wiringPi Build script"
137 echo "====================="
Gordon Hendersonc4335192012-08-18 20:07:42 +0100138 echo
Gordon Hendersonc82fb872013-01-15 22:38:21 +0000139
Gordon Hendersoneb1fc2c2015-01-30 18:14:49 +0000140
Gordon Henderson72b2af22015-02-03 14:53:32 +0000141# if [ x$hardware != "xBCM2708" ]; then
142# echo ""
143# echo " +------------------------------------------------------------+"
144# echo " | wiringPi is designed to run on the Raspberry Pi only. |"
145# echo " | This processor does not appear to be a Raspberry Pi. |"
146# echo " +------------------------------------------------------------+"
147# echo " | In the unlikely event that you think it is a Raspberry Pi, |"
148# echo " | then please accept my apologies and email the contents of |"
149# echo " | /proc/cpuinfo to projects@drogon.net. |"
150# echo " | - Thanks, Gordon |"
151# echo " +------------------------------------------------------------+"
152# echo ""
153# exit 1
154# fi
Gordon Hendersoneb1fc2c2015-01-30 18:14:49 +0000155
156
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000157 echo
Gordon Hendersonda384432013-05-13 19:43:26 +0100158 echo "WiringPi Library"
Gordon Hendersonc4335192012-08-18 20:07:42 +0100159 cd wiringPi
Yang Deokgyu57890f82019-09-18 17:47:26 +0900160# $sudo $make uninstall
Gordon Henderson5e16e152013-07-28 10:54:32 +0100161 if [ x$1 = "xstatic" ]; then
Yang Deokgyu57890f82019-09-18 17:47:26 +0900162 $make static
Gordon Henderson5e16e152013-07-28 10:54:32 +0100163 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900164 $sudo $make install-static
Gordon Henderson5e16e152013-07-28 10:54:32 +0100165 else
Yang Deokgyu57890f82019-09-18 17:47:26 +0900166 $make
Gordon Henderson5e16e152013-07-28 10:54:32 +0100167 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900168 $sudo $make install
Gordon Henderson5e16e152013-07-28 10:54:32 +0100169 fi
Gordon Henderson348bc732013-05-25 13:02:02 +0100170 check_make_ok
Gordon Hendersonda384432013-05-13 19:43:26 +0100171
172 echo
173 echo "WiringPi Devices Library"
174 cd ../devLib
Yang Deokgyu57890f82019-09-18 17:47:26 +0900175 $sudo $make uninstall
Gordon Henderson5e16e152013-07-28 10:54:32 +0100176 if [ x$1 = "xstatic" ]; then
Yang Deokgyu57890f82019-09-18 17:47:26 +0900177 $make static
Gordon Henderson5e16e152013-07-28 10:54:32 +0100178 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900179 $sudo $make install-static
Gordon Henderson5e16e152013-07-28 10:54:32 +0100180 else
Yang Deokgyu57890f82019-09-18 17:47:26 +0900181 $make
Gordon Henderson5e16e152013-07-28 10:54:32 +0100182 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900183 $sudo $make install
Gordon Henderson5e16e152013-07-28 10:54:32 +0100184 fi
Gordon Henderson348bc732013-05-25 13:02:02 +0100185 check_make_ok
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000186
Gordon Henderson183c5a62012-10-21 15:25:16 +0100187 echo
188 echo "GPIO Utility"
Gordon Hendersonc4335192012-08-18 20:07:42 +0100189 cd ../gpio
Yang Deokgyu57890f82019-09-18 17:47:26 +0900190 $make
Gordon Henderson348bc732013-05-25 13:02:02 +0100191 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900192 $sudo $make install
Gordon Henderson348bc732013-05-25 13:02:02 +0100193 check_make_ok
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000194
Yang Deokgyu2ef868b2019-09-18 16:47:23 +0900195 echo
196 echo "Configure /dev/gpiomem"
197 cd ..
198 configure_gpiomem
199
Gordon Hendersone8da87f2017-03-01 11:55:19 +0000200# echo
201# echo "wiringPi Daemon"
202# cd ../wiringPiD
Yang Deokgyu57890f82019-09-18 17:47:26 +0900203# make
Gordon Hendersone8da87f2017-03-01 11:55:19 +0000204# check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900205# $sudo $make install
Gordon Hendersone8da87f2017-03-01 11:55:19 +0000206# check_make_ok
Gordon Henderson70fa99a2017-02-27 19:51:32 +0000207
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000208# echo
209# echo "Examples"
210# cd ../examples
211# make
212# cd ..
Gordon Hendersonc4335192012-08-18 20:07:42 +0100213
214echo
215echo All Done.
Gordon Hendersonbfaf2662013-05-20 21:13:44 +0100216echo ""
Gordon Hendersondf453882014-07-17 22:23:57 +0100217echo "NOTE: To compile programs with wiringPi, you need to add:"
218echo " -lwiringPi"
219echo " to your compile line(s) To use the Gertboard, MaxDetect, etc."
220echo " code (the devLib), you need to also add:"
221echo " -lwiringPiDev"
222echo " to your compile line(s)."
Gordon Hendersonbfaf2662013-05-20 21:13:44 +0100223echo ""