blob: 4780bf8edf0feb85fe96bd437f9cdfbe4e6b4e9e [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() {
54 GPIOMEM="/dev/gpiomem"
55
56 if [ -z $1 ] && [ "$(stat -c "%a %G" "$GPIOMEM")" != "660"*"odroid" ]; then
57 case "$(echo $hardware | tr [:upper:] [:lower:])" in
58 *xu4)
59 $sudo cp -f udev/rules.d/99-odroid-wiringpi-exynos.rules /etc/udev/rules.d/
60 ;;
Yang Deokgyu3ffc5832019-10-22 16:48:00 +090061 *c|*c1|*c2)
62 $sudo cp -f udev/rules.d/99-odroid-wiringpi-meson.rules /etc/udev/rules.d/
63 ;;
64 *n2)
Yang Deokgyu2ef868b2019-09-18 16:47:23 +090065 $sudo cp -f udev/rules.d/99-odroid-wiringpi-aml.rules /etc/udev/rules.d/
66 ;;
67 *)
68 echo "This system seems not ODROID"
69 ;;
70 esac
71
72 echo "Reload udev..."
73 [ -x "$(command -v udevadm)" ] \
74 && $sudo udevadm trigger \
75 || echo "udevadm not found. Please reboot to take effect"
76 elif [ "$1" = "uninstall" ]; then
77 $sudo rm -f /etc/udev/rules.d/99-odroid-wiringpi-*
78 else
79 echo "Not found $GPIOMEM"
80 echo "You will not be able to use WiringPi without root permission"
81 fi
82}
83
Yang Deokgyu868f2622019-12-24 10:36:18 +090084install() {
Gordon Hendersondb925ce2013-01-19 21:46:13 +000085 echo "wiringPi Build script"
86 echo "====================="
Gordon Hendersonc4335192012-08-18 20:07:42 +010087 echo
Gordon Hendersonc82fb872013-01-15 22:38:21 +000088
Gordon Hendersondb925ce2013-01-19 21:46:13 +000089 echo
Gordon Hendersonda384432013-05-13 19:43:26 +010090 echo "WiringPi Library"
Gordon Hendersonc4335192012-08-18 20:07:42 +010091 cd wiringPi
Yang Deokgyu57890f82019-09-18 17:47:26 +090092# $sudo $make uninstall
Gordon Henderson5e16e152013-07-28 10:54:32 +010093 if [ x$1 = "xstatic" ]; then
Yang Deokgyu57890f82019-09-18 17:47:26 +090094 $make static
Gordon Henderson5e16e152013-07-28 10:54:32 +010095 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +090096 $sudo $make install-static
Gordon Henderson5e16e152013-07-28 10:54:32 +010097 else
Yang Deokgyu57890f82019-09-18 17:47:26 +090098 $make
Gordon Henderson5e16e152013-07-28 10:54:32 +010099 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900100 $sudo $make install
Gordon Henderson5e16e152013-07-28 10:54:32 +0100101 fi
Gordon Henderson348bc732013-05-25 13:02:02 +0100102 check_make_ok
Gordon Hendersonda384432013-05-13 19:43:26 +0100103
104 echo
105 echo "WiringPi Devices Library"
106 cd ../devLib
Yang Deokgyu57890f82019-09-18 17:47:26 +0900107 $sudo $make uninstall
Gordon Henderson5e16e152013-07-28 10:54:32 +0100108 if [ x$1 = "xstatic" ]; then
Yang Deokgyu57890f82019-09-18 17:47:26 +0900109 $make static
Gordon Henderson5e16e152013-07-28 10:54:32 +0100110 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900111 $sudo $make install-static
Gordon Henderson5e16e152013-07-28 10:54:32 +0100112 else
Yang Deokgyu57890f82019-09-18 17:47:26 +0900113 $make
Gordon Henderson5e16e152013-07-28 10:54:32 +0100114 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900115 $sudo $make install
Gordon Henderson5e16e152013-07-28 10:54:32 +0100116 fi
Gordon Henderson348bc732013-05-25 13:02:02 +0100117 check_make_ok
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000118
Gordon Henderson183c5a62012-10-21 15:25:16 +0100119 echo
120 echo "GPIO Utility"
Gordon Hendersonc4335192012-08-18 20:07:42 +0100121 cd ../gpio
Yang Deokgyu57890f82019-09-18 17:47:26 +0900122 $make
Gordon Henderson348bc732013-05-25 13:02:02 +0100123 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900124 $sudo $make install
Gordon Henderson348bc732013-05-25 13:02:02 +0100125 check_make_ok
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000126
Yang Deokgyu2ef868b2019-09-18 16:47:23 +0900127 echo
128 echo "Configure /dev/gpiomem"
129 cd ..
130 configure_gpiomem
131
Yang Deokgyu868f2622019-12-24 10:36:18 +0900132 echo
133 echo All Done.
134 echo ""
135 echo "NOTE: To compile programs with wiringPi, you need to add:"
136 echo " -lwiringPi"
137 echo " to your compile line(s) To use the Gertboard, MaxDetect, etc."
138 echo " code (the devLib), you need to also add:"
139 echo " -lwiringPiDev"
140 echo " to your compile line(s)."
141 echo ""
142}
Gordon Henderson70fa99a2017-02-27 19:51:32 +0000143
Yang Deokgyu868f2622019-12-24 10:36:18 +0900144uninstall() {
145 cd wiringPi
146 echo -n "wiringPi: " ; $sudo $make uninstall
147 cd ../devLib
148 echo -n "DevLib: " ; $sudo $make uninstall
149 cd ../gpio
150 echo -n "gpio: " ; $sudo $make uninstall
151 cd ..
152 echo -n "Deconfigure /dev/gpiomem" ; configure_gpiomem uninstall
153 echo
154}
Gordon Hendersonc4335192012-08-18 20:07:42 +0100155
Yang Deokgyu868f2622019-12-24 10:36:18 +0900156clean() {
157 cd wiringPi
158 echo -n "wiringPi: " ; $make clean
159 cd ../devLib
160 echo -n "DevLib: " ; $make clean
161 cd ../gpio
162 echo -n "gpio: " ; $make clean
163 cd ../examples
164 echo -n "Examples: " ; $make clean
165 cd Gertboard
166 echo -n "Gertboard: " ; $make clean
167 cd ../PiFace
168 echo -n "PiFace: " ; $make clean
169 cd ../q2w
170 echo -n "Quick2Wire: " ; $make clean
171 cd ../PiGlow
172 echo -n "PiGlow: " ; $make clean
173 cd ../scrollPhat
174 echo -n "scrollPhat: " ; $make clean
175 cd ../..
176}
177
178if [ x$1 = "xclean" ]; then
179 clean
180 exit
181fi
182
183if [ x$1 = "xuninstall" ]; then
184 uninstall
185 exit
186fi
187
188# Only if you know what you're doing!
189if [ x$1 = "xdebian" ]; then
190 here=`pwd`
191 cd debian-template/wiringPi
192 rm -rf usr
193 cd $here/wiringPi
194 $make install-deb
195 cd $here/devLib
196 $make install-deb INCLUDE='-I. -I../wiringPi'
197 cd $here/gpio
198 $make install-deb INCLUDE='-I../wiringPi -I../devLib' LDFLAGS=-L../debian-template/wiringPi/usr/lib
199 cd $here/debian-template
200 fakeroot dpkg-deb --build wiringPi
201 mv wiringPi.deb odroid-wiringpi-`cat $here/VERSION`.deb
202 exit
203fi
204
205if [ x$1 != "x" ]; then
206 echo "Usage: $0 [clean | uninstall]"
207 exit 1
208fi
209
210uninstall; clean; install