-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_rpi_ws281x.sh
executable file
·103 lines (80 loc) · 3.67 KB
/
build_rpi_ws281x.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
# ---------------------------------------------------------------------------------------------------------------------
# Compiles shared libraries required for interfacing with Raspberry Pi GPIO hardware from Java, using JNI.
# ---------------------------------------------------------------------------------------------------------------------
# Author(s): limpygnome <[email protected]>, mbelling <[email protected]>
# ---------------------------------------------------------------------------------------------------------------------
# *********************************************************************************************************************
# Configuration
# *********************************************************************************************************************
# Relative dir names for input/output
BASE_DIR="$(dirname "$0")/"
OUTPUT="${BASE_DIR}/build"
NATIVE_SRC="${OUTPUT}/ws281x"
NATIVE_OUT="${NATIVE_SRC}/output"
NATIVE_LIB_NAME="ws281x.so"
LIB_BASE_NAME="libws281x"
WRAPPER_LIB_NAME="${LIB_BASE_NAME}.so"
# *********************************************************************************************************************
# Functions
# *********************************************************************************************************************
function compileSrc
{
SRC="${1}"
OUT="${2}"
gcc -shared -fPIC -w -o "${OUT}" -c "${SRC}" -I./
}
function programInstalled
(
CMD="${1}"
EXPECTED="${2}"
ERROR="${3}"
SUCCESS="${4}"
OUTPUT=$(eval ${CMD} || echo "fail")
if [[ "${OUTPUT}" != *"${EXPECTED}"* ]]; then
echo "${ERROR}"
exit 1
else
echo "${SUCCESS}"
fi
)
# *********************************************************************************************************************
# Main
# *********************************************************************************************************************
echo "NeoPixel ws281x Library Compiler"
echo "****************************************************"
# Check dependencies installed
set -e
programInstalled "gcc --version" "free software" "Error - GCC is not installed, cannot continue!" "Check - GCC installed..."
programInstalled "git --version" "git version" "Error - git is not installed, cannot continue!" "Check - git installed..."
set +e
# Clean workspace
echo "Deleting build directory to start clean..."
rm -rf build
# Retrieve rpi_ws281x repository
echo "Cloning rpi_ws281x repository..."
git clone https://github.com/jgarff/rpi_ws281x.git ${NATIVE_SRC}
# # At the time of this writing this repository does not tag versions, so checking out at a specific commit so we build a consistent library
# echo "Checking out specific revision..."
# pushd ${NATIVE_SRC}
# git checkout master
# popd
# Create all the required dirs
echo "Creating required dirs..."
mkdir -p "${NATIVE_OUT}"
mkdir -p "${OUTPUT}/nativeLib"
# Compile library objects
echo "Compiling ws281x library objects..."
compileSrc "${NATIVE_SRC}/ws2811.c" "${NATIVE_OUT}/ws2811.o"
compileSrc "${NATIVE_SRC}/pwm.c" "${NATIVE_OUT}/pwm.o"
compileSrc "${NATIVE_SRC}/pcm.c" "${NATIVE_OUT}/pcm.o"
compileSrc "${NATIVE_SRC}/dma.c" "${NATIVE_OUT}/dma.o"
compileSrc "${NATIVE_SRC}/rpihw.c" "${NATIVE_OUT}/rpihw.o"
compileSrc "${NATIVE_SRC}/mailbox.c" "${NATIVE_OUT}/mailbox.o"
# Compile library
echo "Compiling ws281x library..."
gcc -shared -o "${OUTPUT}/${NATIVE_LIB_NAME}" "${NATIVE_OUT}/ws2811.o" "${NATIVE_OUT}/pwm.o" "${NATIVE_OUT}/pcm.o" "${NATIVE_OUT}/dma.o" "${NATIVE_OUT}/rpihw.o" "${NATIVE_OUT}/mailbox.o"
cp "Makefile.template" "${NATIVE_SRC}/Makefile"
cd $NATIVE_SRC && make
sudo make install
echo "Done!"