blob: bfe05dcbd675e2020bfe5825ebe2bb22dcd72ac8 [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 ;;
67 *n2)
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
Yang Deokgyu57890f82019-09-18 17:47:26 +090096# $sudo $make uninstall
Gordon Henderson5e16e152013-07-28 10:54:32 +010097 if [ x$1 = "xstatic" ]; then
Yang Deokgyu57890f82019-09-18 17:47:26 +090098 $make static
Gordon Henderson5e16e152013-07-28 10:54:32 +010099 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900100 $sudo $make install-static
Gordon Henderson5e16e152013-07-28 10:54:32 +0100101 else
Yang Deokgyu57890f82019-09-18 17:47:26 +0900102 $make
Gordon Henderson5e16e152013-07-28 10:54:32 +0100103 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900104 $sudo $make install
Gordon Henderson5e16e152013-07-28 10:54:32 +0100105 fi
Gordon Henderson348bc732013-05-25 13:02:02 +0100106 check_make_ok
Gordon Hendersonda384432013-05-13 19:43:26 +0100107
108 echo
109 echo "WiringPi Devices Library"
110 cd ../devLib
Yang Deokgyu57890f82019-09-18 17:47:26 +0900111 $sudo $make uninstall
Gordon Henderson5e16e152013-07-28 10:54:32 +0100112 if [ x$1 = "xstatic" ]; then
Yang Deokgyu57890f82019-09-18 17:47:26 +0900113 $make static
Gordon Henderson5e16e152013-07-28 10:54:32 +0100114 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900115 $sudo $make install-static
Gordon Henderson5e16e152013-07-28 10:54:32 +0100116 else
Yang Deokgyu57890f82019-09-18 17:47:26 +0900117 $make
Gordon Henderson5e16e152013-07-28 10:54:32 +0100118 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900119 $sudo $make install
Gordon Henderson5e16e152013-07-28 10:54:32 +0100120 fi
Gordon Henderson348bc732013-05-25 13:02:02 +0100121 check_make_ok
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000122
Gordon Henderson183c5a62012-10-21 15:25:16 +0100123 echo
124 echo "GPIO Utility"
Gordon Hendersonc4335192012-08-18 20:07:42 +0100125 cd ../gpio
Yang Deokgyu57890f82019-09-18 17:47:26 +0900126 $make
Gordon Henderson348bc732013-05-25 13:02:02 +0100127 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900128 $sudo $make install
Gordon Henderson348bc732013-05-25 13:02:02 +0100129 check_make_ok
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000130
Yang Deokgyu2ef868b2019-09-18 16:47:23 +0900131 echo
Yang Deokgyu2ef868b2019-09-18 16:47:23 +0900132 cd ..
133 configure_gpiomem
134
Yang Deokgyu868f2622019-12-24 10:36:18 +0900135 echo
136 echo All Done.
137 echo ""
138 echo "NOTE: To compile programs with wiringPi, you need to add:"
139 echo " -lwiringPi"
140 echo " to your compile line(s) To use the Gertboard, MaxDetect, etc."
141 echo " code (the devLib), you need to also add:"
142 echo " -lwiringPiDev"
143 echo " to your compile line(s)."
144 echo ""
145}
Gordon Henderson70fa99a2017-02-27 19:51:32 +0000146
Yang Deokgyu868f2622019-12-24 10:36:18 +0900147uninstall() {
148 cd wiringPi
149 echo -n "wiringPi: " ; $sudo $make uninstall
150 cd ../devLib
151 echo -n "DevLib: " ; $sudo $make uninstall
152 cd ../gpio
153 echo -n "gpio: " ; $sudo $make uninstall
154 cd ..
Yang Deokgyuae873a22020-02-13 18:40:51 +0900155 configure_gpiomem uninstall
Yang Deokgyu868f2622019-12-24 10:36:18 +0900156 echo
157}
Gordon Hendersonc4335192012-08-18 20:07:42 +0100158
Yang Deokgyu868f2622019-12-24 10:36:18 +0900159clean() {
160 cd wiringPi
161 echo -n "wiringPi: " ; $make clean
162 cd ../devLib
163 echo -n "DevLib: " ; $make clean
164 cd ../gpio
165 echo -n "gpio: " ; $make clean
166 cd ../examples
167 echo -n "Examples: " ; $make clean
168 cd Gertboard
169 echo -n "Gertboard: " ; $make clean
170 cd ../PiFace
171 echo -n "PiFace: " ; $make clean
172 cd ../q2w
173 echo -n "Quick2Wire: " ; $make clean
174 cd ../PiGlow
175 echo -n "PiGlow: " ; $make clean
176 cd ../scrollPhat
177 echo -n "scrollPhat: " ; $make clean
178 cd ../..
179}
180
181if [ x$1 = "xclean" ]; then
182 clean
183 exit
184fi
185
186if [ x$1 = "xuninstall" ]; then
187 uninstall
188 exit
189fi
190
191# Only if you know what you're doing!
192if [ x$1 = "xdebian" ]; then
193 here=`pwd`
194 cd debian-template/wiringPi
195 rm -rf usr
196 cd $here/wiringPi
197 $make install-deb
198 cd $here/devLib
199 $make install-deb INCLUDE='-I. -I../wiringPi'
200 cd $here/gpio
201 $make install-deb INCLUDE='-I../wiringPi -I../devLib' LDFLAGS=-L../debian-template/wiringPi/usr/lib
202 cd $here/debian-template
203 fakeroot dpkg-deb --build wiringPi
204 mv wiringPi.deb odroid-wiringpi-`cat $here/VERSION`.deb
205 exit
206fi
207
208if [ x$1 != "x" ]; then
209 echo "Usage: $0 [clean | uninstall]"
210 exit 1
211fi
212
213uninstall; clean; install