blob: 890ebc357df968f64f77521826c2cde56b654d18 [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 Deokgyu3ffc5832019-10-22 16:48:00 +090054 *c|*c1|*c2)
55 $sudo cp -f udev/rules.d/99-odroid-wiringpi-meson.rules /etc/udev/rules.d/
56 ;;
57 *n2)
Yang Deokgyu2ef868b2019-09-18 16:47:23 +090058 $sudo cp -f udev/rules.d/99-odroid-wiringpi-aml.rules /etc/udev/rules.d/
59 ;;
60 *)
61 echo "This system seems not ODROID"
62 ;;
63 esac
64
65 echo "Reload udev..."
66 [ -x "$(command -v udevadm)" ] \
67 && $sudo udevadm trigger \
68 || echo "udevadm not found. Please reboot to take effect"
69 elif [ "$1" = "uninstall" ]; then
70 $sudo rm -f /etc/udev/rules.d/99-odroid-wiringpi-*
71 else
72 echo "Not found $GPIOMEM"
73 echo "You will not be able to use WiringPi without root permission"
74 fi
75}
76
Ian Jackson73aa8952015-09-12 16:41:38 +000077sudo=${WIRINGPI_SUDO-sudo}
Yang Deokgyu57890f82019-09-18 17:47:26 +090078make="make -j $(( $(nproc) + 1 ))"
Yang Deokgyud26507b2019-10-22 14:46:55 +090079hardware=$(fgrep -a Hardware /proc/cpuinfo | head -1 | awk '{ printf("%s %s %s\n", $3, $4, $5) }' | xargs)
Ian Jackson73aa8952015-09-12 16:41:38 +000080
Gordon Hendersonc4335192012-08-18 20:07:42 +010081if [ x$1 = "xclean" ]; then
Gordon Hendersonc4335192012-08-18 20:07:42 +010082 cd wiringPi
Yang Deokgyu57890f82019-09-18 17:47:26 +090083 echo -n "wiringPi: " ; $make clean
Gordon Hendersonda384432013-05-13 19:43:26 +010084 cd ../devLib
Yang Deokgyu57890f82019-09-18 17:47:26 +090085 echo -n "DevLib: " ; $make clean
Gordon Hendersonc4335192012-08-18 20:07:42 +010086 cd ../gpio
Yang Deokgyu57890f82019-09-18 17:47:26 +090087 echo -n "gpio: " ; $make clean
Gordon Hendersonc4335192012-08-18 20:07:42 +010088 cd ../examples
Yang Deokgyu57890f82019-09-18 17:47:26 +090089 echo -n "Examples: " ; $make clean
Gordon Hendersonda384432013-05-13 19:43:26 +010090 cd Gertboard
Yang Deokgyu57890f82019-09-18 17:47:26 +090091 echo -n "Gertboard: " ; $make clean
Gordon Hendersonda384432013-05-13 19:43:26 +010092 cd ../PiFace
Yang Deokgyu57890f82019-09-18 17:47:26 +090093 echo -n "PiFace: " ; $make clean
Gordon Hendersonbfaf2662013-05-20 21:13:44 +010094 cd ../q2w
Yang Deokgyu57890f82019-09-18 17:47:26 +090095 echo -n "Quick2Wire: " ; $make clean
Gordon Hendersone25cbc02013-07-24 15:14:09 +010096 cd ../PiGlow
Yang Deokgyu57890f82019-09-18 17:47:26 +090097 echo -n "PiGlow: " ; $make clean
Gordon Hendersonb0a60c32016-02-29 06:57:38 +000098 cd ../scrollPhat
Yang Deokgyu57890f82019-09-18 17:47:26 +090099 echo -n "scrollPhat: " ; $make clean
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000100 exit
101fi
102
103if [ x$1 = "xuninstall" ]; then
Gordon Henderson183c5a62012-10-21 15:25:16 +0100104 cd wiringPi
Yang Deokgyu57890f82019-09-18 17:47:26 +0900105 echo -n "wiringPi: " ; $sudo $make uninstall
Gordon Hendersonda384432013-05-13 19:43:26 +0100106 cd ../devLib
Yang Deokgyu57890f82019-09-18 17:47:26 +0900107 echo -n "DevLib: " ; $sudo $make uninstall
Gordon Henderson183c5a62012-10-21 15:25:16 +0100108 cd ../gpio
Yang Deokgyu57890f82019-09-18 17:47:26 +0900109 echo -n "gpio: " ; $sudo $make uninstall
Yang Deokgyu2ef868b2019-09-18 16:47:23 +0900110 cd ..
111 echo -n "Deconfigure /dev/gpiomem" ; configure_gpiomem uninstall
112 echo
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000113 exit
114fi
115
Gordon Henderson7cb81742015-01-31 16:43:08 +0000116# Only if you know what you're doing!
117
118if [ x$1 = "xdebian" ]; then
119 here=`pwd`
Ian Jacksonac0f0742015-09-12 17:25:39 +0000120 cd debian-template/wiringPi
Gordon Henderson7cb81742015-01-31 16:43:08 +0000121 rm -rf usr
122 cd $here/wiringPi
Yang Deokgyu57890f82019-09-18 17:47:26 +0900123 $make install-deb
Gordon Henderson7cb81742015-01-31 16:43:08 +0000124 cd $here/devLib
Yang Deokgyu57890f82019-09-18 17:47:26 +0900125 $make install-deb INCLUDE='-I. -I../wiringPi'
Gordon Henderson7cb81742015-01-31 16:43:08 +0000126 cd $here/gpio
Yang Deokgyu57890f82019-09-18 17:47:26 +0900127 $make install-deb INCLUDE='-I../wiringPi -I../devLib' LDFLAGS=-L../debian-template/wiringPi/usr/lib
Ian Jacksonac0f0742015-09-12 17:25:39 +0000128 cd $here/debian-template
Gordon Henderson7cb81742015-01-31 16:43:08 +0000129 fakeroot dpkg-deb --build wiringPi
Joshua Yang41a423e2019-07-16 18:08:16 +0900130 mv wiringPi.deb odroid-wiringpi-`cat $here/VERSION`.deb
Gordon Henderson7cb81742015-01-31 16:43:08 +0000131 exit
132fi
133
134if [ x$1 != "x" ]; then
135 echo "Usage: $0 [clean | uninstall]"
136 exit 1
137fi
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000138
139 echo "wiringPi Build script"
140 echo "====================="
Gordon Hendersonc4335192012-08-18 20:07:42 +0100141 echo
Gordon Hendersonc82fb872013-01-15 22:38:21 +0000142
Gordon Hendersoneb1fc2c2015-01-30 18:14:49 +0000143
Gordon Henderson72b2af22015-02-03 14:53:32 +0000144# if [ x$hardware != "xBCM2708" ]; then
145# echo ""
146# echo " +------------------------------------------------------------+"
147# echo " | wiringPi is designed to run on the Raspberry Pi only. |"
148# echo " | This processor does not appear to be a Raspberry Pi. |"
149# echo " +------------------------------------------------------------+"
150# echo " | In the unlikely event that you think it is a Raspberry Pi, |"
151# echo " | then please accept my apologies and email the contents of |"
152# echo " | /proc/cpuinfo to projects@drogon.net. |"
153# echo " | - Thanks, Gordon |"
154# echo " +------------------------------------------------------------+"
155# echo ""
156# exit 1
157# fi
Gordon Hendersoneb1fc2c2015-01-30 18:14:49 +0000158
159
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000160 echo
Gordon Hendersonda384432013-05-13 19:43:26 +0100161 echo "WiringPi Library"
Gordon Hendersonc4335192012-08-18 20:07:42 +0100162 cd wiringPi
Yang Deokgyu57890f82019-09-18 17:47:26 +0900163# $sudo $make uninstall
Gordon Henderson5e16e152013-07-28 10:54:32 +0100164 if [ x$1 = "xstatic" ]; then
Yang Deokgyu57890f82019-09-18 17:47:26 +0900165 $make static
Gordon Henderson5e16e152013-07-28 10:54:32 +0100166 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900167 $sudo $make install-static
Gordon Henderson5e16e152013-07-28 10:54:32 +0100168 else
Yang Deokgyu57890f82019-09-18 17:47:26 +0900169 $make
Gordon Henderson5e16e152013-07-28 10:54:32 +0100170 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900171 $sudo $make install
Gordon Henderson5e16e152013-07-28 10:54:32 +0100172 fi
Gordon Henderson348bc732013-05-25 13:02:02 +0100173 check_make_ok
Gordon Hendersonda384432013-05-13 19:43:26 +0100174
175 echo
176 echo "WiringPi Devices Library"
177 cd ../devLib
Yang Deokgyu57890f82019-09-18 17:47:26 +0900178 $sudo $make uninstall
Gordon Henderson5e16e152013-07-28 10:54:32 +0100179 if [ x$1 = "xstatic" ]; then
Yang Deokgyu57890f82019-09-18 17:47:26 +0900180 $make static
Gordon Henderson5e16e152013-07-28 10:54:32 +0100181 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900182 $sudo $make install-static
Gordon Henderson5e16e152013-07-28 10:54:32 +0100183 else
Yang Deokgyu57890f82019-09-18 17:47:26 +0900184 $make
Gordon Henderson5e16e152013-07-28 10:54:32 +0100185 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900186 $sudo $make install
Gordon Henderson5e16e152013-07-28 10:54:32 +0100187 fi
Gordon Henderson348bc732013-05-25 13:02:02 +0100188 check_make_ok
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000189
Gordon Henderson183c5a62012-10-21 15:25:16 +0100190 echo
191 echo "GPIO Utility"
Gordon Hendersonc4335192012-08-18 20:07:42 +0100192 cd ../gpio
Yang Deokgyu57890f82019-09-18 17:47:26 +0900193 $make
Gordon Henderson348bc732013-05-25 13:02:02 +0100194 check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900195 $sudo $make install
Gordon Henderson348bc732013-05-25 13:02:02 +0100196 check_make_ok
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000197
Yang Deokgyu2ef868b2019-09-18 16:47:23 +0900198 echo
199 echo "Configure /dev/gpiomem"
200 cd ..
201 configure_gpiomem
202
Gordon Hendersone8da87f2017-03-01 11:55:19 +0000203# echo
204# echo "wiringPi Daemon"
205# cd ../wiringPiD
Yang Deokgyu57890f82019-09-18 17:47:26 +0900206# make
Gordon Hendersone8da87f2017-03-01 11:55:19 +0000207# check_make_ok
Yang Deokgyu57890f82019-09-18 17:47:26 +0900208# $sudo $make install
Gordon Hendersone8da87f2017-03-01 11:55:19 +0000209# check_make_ok
Gordon Henderson70fa99a2017-02-27 19:51:32 +0000210
Gordon Hendersondb925ce2013-01-19 21:46:13 +0000211# echo
212# echo "Examples"
213# cd ../examples
214# make
215# cd ..
Gordon Hendersonc4335192012-08-18 20:07:42 +0100216
217echo
218echo All Done.
Gordon Hendersonbfaf2662013-05-20 21:13:44 +0100219echo ""
Gordon Hendersondf453882014-07-17 22:23:57 +0100220echo "NOTE: To compile programs with wiringPi, you need to add:"
221echo " -lwiringPi"
222echo " to your compile line(s) To use the Gertboard, MaxDetect, etc."
223echo " code (the devLib), you need to also add:"
224echo " -lwiringPiDev"
225echo " to your compile line(s)."
Gordon Hendersonbfaf2662013-05-20 21:13:44 +0100226echo ""