blob: d74071e93367ae79dab5297a9662090c4a547296 [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
Yang Deokgyu868f2622019-12-24 10:36:18 +090034sudo=${WIRINGPI_SUDO-sudo}
35make="make -j $(( $(nproc) + 1 ))"
36hardware=$(fgrep -a Hardware /proc/cpuinfo | head -1 | awk '{ printf("%s %s %s\n", $3, $4, $5) }' | xargs)
37[ "$hardware",, != *"odroid"* ] \
38 && [ -f "/sys/firmware/devicetree/base/model" ] \
39 && hardware=$(cat /sys/firmware/devicetree/base/model)
40
Gordon Henderson348bc732013-05-25 13:02:02 +010041check_make_ok() {
Gordon Hendersonc82fb872013-01-15 22:38:21 +000042 if [ $? != 0 ]; then
43 echo ""
44 echo "Make Failed..."
45 echo "Please check the messages and fix any problems. If you're still stuck,"
46 echo "then please email all the output and as many details as you can to"
47 echo " projects@drogon.net"
48 echo ""
49 exit 1
50 fi
51}
52
Yang Deokgyu2ef868b2019-09-18 16:47:23 +090053configure_gpiomem() {
Yang Deokgyuae873a22020-02-13 18:40:51 +090054 [ $(env | grep DEB_BUILD | wc -l) -ne 0 ] && return
55
Yang Deokgyu2ef868b2019-09-18 16:47:23 +090056 GPIOMEM="/dev/gpiomem"
57
58 if [ -z $1 ] && [ "$(stat -c "%a %G" "$GPIOMEM")" != "660"*"odroid" ]; then
Yang Deokgyuae873a22020-02-13 18:40:51 +090059 echo "Configure /dev/gpiomem"
Yang Deokgyu2ef868b2019-09-18 16:47:23 +090060 case "$(echo $hardware | tr [:upper:] [:lower:])" in
61 *xu4)
62 $sudo cp -f udev/rules.d/99-odroid-wiringpi-exynos.rules /etc/udev/rules.d/
63 ;;
Yang Deokgyu3ffc5832019-10-22 16:48:00 +090064 *c|*c1|*c2)
65 $sudo cp -f udev/rules.d/99-odroid-wiringpi-meson.rules /etc/udev/rules.d/
66 ;;
Yang Deokgyuffeba7f2019-07-01 17:22:01 +090067 *n2|*c4)
Yang Deokgyu2ef868b2019-09-18 16:47:23 +090068 $sudo cp -f udev/rules.d/99-odroid-wiringpi-aml.rules /etc/udev/rules.d/
69 ;;
70 *)
71 echo "This system seems not ODROID"
72 ;;
73 esac
74
75 echo "Reload udev..."
76 [ -x "$(command -v udevadm)" ] \
77 && $sudo udevadm trigger \
78 || echo "udevadm not found. Please reboot to take effect"
79 elif [ "$1" = "uninstall" ]; then
Yang Deokgyuae873a22020-02-13 18:40:51 +090080 echo "Deconfigure /dev/gpiomem"
Yang Deokgyu2ef868b2019-09-18 16:47:23 +090081 $sudo rm -f /etc/udev/rules.d/99-odroid-wiringpi-*
82 else
83 echo "Not found $GPIOMEM"
84 echo "You will not be able to use WiringPi without root permission"
85 fi
86}
87
Yang Deokgyu868f2622019-12-24 10:36:18 +090088install() {
Gordon Hendersondb925ce2013-01-19 21:46:13 +000089 echo "wiringPi Build script"
90 echo "====================="
Gordon Hendersonc4335192012-08-18 20:07:42 +010091 echo
Gordon Hendersonc82fb872013-01-15 22:38:21 +000092
Gordon Hendersondb925ce2013-01-19 21:46:13 +000093 echo
Gordon Hendersonda384432013-05-13 19:43:26 +010094 echo "WiringPi Library"
Gordon Hendersonc4335192012-08-18 20:07:42 +010095 cd wiringPi
Gordon Henderson5e16e152013-07-28 10:54:32 +010096 if [ x$1 = "xstatic" ]; then
Yang Deokgyu57890f82019-09-18 17:47:26 +090097 $make static
Gordon Henderson5e16e152013-07-28 10:54:32 +010098 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +090099 $sudo $make install-static
Gordon Henderson5e16e152013-07-28 10:54:32 +0100100 else
Yang Deokgyu57890f82019-09-18 17:47:26 +0900101 $make
Gordon Henderson5e16e152013-07-28 10:54:32 +0100102 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900103 $sudo $make install
Gordon Henderson5e16e152013-07-28 10:54:32 +0100104 fi
Gordon Henderson348bc732013-05-25 13:02:02 +0100105 check_make_ok
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000106
Gordon Henderson183c5a62012-10-21 15:25:16 +0100107 echo
Deokgyu Yang3f787a12020-03-30 15:25:23 +0900108 echo "WiringPi Devices Library"
109 cd ../devLib
Deokgyu Yang2c7e86b2020-04-28 10:56:11 +0900110 $sudo $make uninstall
111 if [ x$1 = "xstatic" ]; then
112 $make static
113 check_make_ok
114 $sudo $make install-static
115 else
116 $make
117 check_make_ok
118 $sudo $make install
119 fi
120 check_make_ok
121
122 echo
123 echo "WiringPi Devices Library"
124 cd ../devLib
Deokgyu Yang3f787a12020-03-30 15:25:23 +0900125 if [ x$1 = "xstatic" ]; then
126 $make static
127 check_make_ok
128 $sudo $make install-static
129 else
130 $make
131 check_make_ok
132 $sudo $make install
133 fi
134 check_make_ok
135
136 echo
Gordon Henderson183c5a62012-10-21 15:25:16 +0100137 echo "GPIO Utility"
Gordon Hendersonc4335192012-08-18 20:07:42 +0100138 cd ../gpio
Yang Deokgyu57890f82019-09-18 17:47:26 +0900139 $make
Gordon Henderson348bc732013-05-25 13:02:02 +0100140 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900141 $sudo $make install
Gordon Henderson348bc732013-05-25 13:02:02 +0100142 check_make_ok
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000143
Yang Deokgyu2ef868b2019-09-18 16:47:23 +0900144 echo
Yang Deokgyu2ef868b2019-09-18 16:47:23 +0900145 cd ..
146 configure_gpiomem
147
Yang Deokgyu868f2622019-12-24 10:36:18 +0900148 echo
149 echo All Done.
150 echo ""
151 echo "NOTE: To compile programs with wiringPi, you need to add:"
Deokgyu Yang3f787a12020-03-30 15:25:23 +0900152 echo " -lwiringPi -wiringPiDev"
Deokgyu Yang2c7e86b2020-04-28 10:56:11 +0900153 echo " to your compile line(s) To use the Gertboard, MaxDetect, etc."
154 echo " code (the devLib), you need to also add:"
155 echo " -lwiringPiDev"
Yang Deokgyu868f2622019-12-24 10:36:18 +0900156 echo " to your compile line(s)."
157 echo ""
158}
Gordon Henderson70fa99a2017-02-27 19:51:32 +0000159
Yang Deokgyu868f2622019-12-24 10:36:18 +0900160uninstall() {
161 cd wiringPi
162 echo -n "wiringPi: " ; $sudo $make uninstall
Deokgyu Yang3f787a12020-03-30 15:25:23 +0900163 cd ../devLib
164 echo -n "DevLib: " ; $sudo $make uninstall
Yang Deokgyu868f2622019-12-24 10:36:18 +0900165 cd ../gpio
166 echo -n "gpio: " ; $sudo $make uninstall
167 cd ..
Yang Deokgyuae873a22020-02-13 18:40:51 +0900168 configure_gpiomem uninstall
Yang Deokgyu868f2622019-12-24 10:36:18 +0900169 echo
170}
Gordon Hendersonc4335192012-08-18 20:07:42 +0100171
Yang Deokgyu868f2622019-12-24 10:36:18 +0900172clean() {
173 cd wiringPi
174 echo -n "wiringPi: " ; $make clean
Deokgyu Yang3f787a12020-03-30 15:25:23 +0900175 cd ../devLib
176 echo -n "DevLib: " ; $make clean
Yang Deokgyu868f2622019-12-24 10:36:18 +0900177 cd ../gpio
178 echo -n "gpio: " ; $make clean
179 cd ../examples
Deokgyu Yang2c7e86b2020-04-28 10:56:11 +0900180 echo -n "Examples: " ; $make clean
181 cd Gertboard
182 echo -n "Gertboard: " ; $make clean
183 cd ../PiFace
184 echo -n "PiFace: " ; $make clean
185 cd ../q2w
186 echo -n "Quick2Wire: " ; $make clean
187 cd ../PiGlow
188 echo -n "PiGlow: " ; $make clean
189 cd ../scrollPhat
190 echo -n "scrollPhat: " ; $make clean
191 cd ../..
Yang Deokgyu868f2622019-12-24 10:36:18 +0900192}
193
194if [ x$1 = "xclean" ]; then
195 clean
196 exit
197fi
198
199if [ x$1 = "xuninstall" ]; then
200 uninstall
201 exit
202fi
203
Yang Deokgyu868f2622019-12-24 10:36:18 +0900204if [ x$1 != "x" ]; then
205 echo "Usage: $0 [clean | uninstall]"
206 exit 1
207fi
208
209uninstall; clean; install