forked from gary-rowe/hid4java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-hidapi.sh
executable file
·340 lines (288 loc) · 14.1 KB
/
build-hidapi.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!/usr/bin/env bash
# Convenience script to build hidapi locally
# Directory structure is
# ~/Workspaces
# + Cpp
# + hidapi
# + Docker
# + dockcross
# + Java
# + Personal
# + hid4java
#
# Supported command line arguments are:
#
# all - build all variants (except linux-arm which is built on an RPi at present)
# windows - build all Windows variants
# linux - build all Linux variants
# osx - build all OS X variants
# darwin - OS X 64-bit
# linux-aarch64 - Linux ARMv8 64-bit
# linux-amd64 - Linux AMD 64-bit
# linux-arm - Linux ARMv7 hard float 32-bit
# linux-armel - Linux ARMv6 EABI 32-bit
# linux-x86-64 - Linux x86 64-bit
# linux-x86 - Linux x86 32-bit
# win32-x86 - Windows 32-bit
# win32-x86-64 - Windows 64-bit
#
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
echo -e "\033[33mTarget build for HIDAPI is $1\033[0m"
# Dockcross latest release
echo -e "\033[32mConfiguring Dockcross\033[0m"
cd ~/Workspaces/Docker/dockcross/
git checkout master
git pull
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
# Ensure Docker is running
echo -e "\033[32mConfiguring Docker\033[0m"
if docker_result=$(docker-machine env default); then
eval "$docker_result"
echo -e "\033[32mOK\033[0m"
else
echo -e "\033[31mFailed\033[0m - Docker not running. Use 'docker-machine start default'"
exit
fi
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
# Windows cross compilers
# 64-bit
echo -e "\033[32mConfiguring Windows 64-bit\033[0m"
docker run --rm dockcross/windows-shared-x64 > ./dockcross-windows-shared-x64
chmod +x ./dockcross-windows-shared-x64
mv ./dockcross-windows-shared-x64 /usr/local/bin
# 32-bit
echo -e "\033[32mConfiguring Windows 32-bit\033[0m"
docker run --rm dockcross/windows-shared-x86 > ./dockcross-windows-shared-x86
chmod +x ./dockcross-windows-shared-x86
mv ./dockcross-windows-shared-x86 /usr/local/bin
echo -e "\033[32mConfiguring Linux environments\033[0m"
# Linux cross compilers
# 64 bit
echo -e "\033[32mConfiguring Linux 64-bit\033[0m"
docker run --rm dockcross/linux-x64 > ./dockcross-linux-x64
chmod +x ./dockcross-linux-x64
mv ./dockcross-linux-x64 /usr/local/bin
# 32 bit
echo -e "\033[32mConfiguring Linux 32-bit\033[0m"
docker run --rm dockcross/linux-x86 > ./dockcross-linux-x86
chmod +x ./dockcross-linux-x86
mv ./dockcross-linux-x86 /usr/local/bin
# ARM cross compilers
# 32-bit ARMv6 EABI
echo -e "\033[32mConfiguring ARMv6 EABI 32-bit\033[0m"
docker run --rm dockcross/linux-armv6 > ./dockcross-linux-armv6
chmod +x ./dockcross-linux-armv6
mv ./dockcross-linux-armv6 /usr/local/bin
# 32-bit ARMv7 hard float
echo -e "\033[32mConfiguring ARMv7 32-bit\033[0m"
docker run --rm dockcross/linux-armv7 > ./dockcross-linux-armv7
chmod +x ./dockcross-linux-armv7
mv ./dockcross-linux-armv7 /usr/local/bin
# 64-bit (arm64, aarch64)
echo -e "\033[32mConfiguring ARM 64-bit\033[0m"
docker run --rm dockcross/linux-arm64 > ./dockcross-linux-arm64
chmod +x ./dockcross-linux-arm64
mv ./dockcross-linux-arm64 /usr/local/bin
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
# HIDAPI latest release
echo -e "\033[32mConfiguring HIDAPI\033[0m"
cd ~/Workspaces/Cpp/hidapi/
git checkout master
git pull
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
# Windows environments
# 64-bit
if [[ "$1" == "all" ]] || [[ "$1" == "windows" ]] || [[ "$1" == "win32-x86-64" ]]
then
echo -e "\033[32mBuilding Windows 64-bit\033[0m"
dockcross-windows-shared-x64 bash -c 'sudo apt-get update && sudo apt-get --yes install libudev-dev libusb-1.0-0-dev && sudo make clean && sudo ./bootstrap && sudo ./configure --host=x86_64-w64-mingw32 && sudo make'
if [[ "$?" -ne 0 ]]
then
echo -e "\033[31mFailed\033[0m - Removing damaged targets"
rm ../../Java/Personal/hid4java/src/main/resources/win32-x86-64/hidapi.dll
exit
else
echo -e "\033[32mOK\033[0m"
cp windows/.libs/libhidapi-0.dll ../../Java/Personal/hid4java/src/main/resources/win32-x86-64/hidapi.dll
fi
else
echo -e "\033[33mSkipping win32-x86-64\033[0m"
fi
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
# 32-bit
if [[ "$1" == "all" ]] || [[ "$1" == "windows" ]] || [[ "$1" == "win32-x86" ]]
then
echo -e "\033[32mBuilding Windows 32-bit\033[0m"
dockcross-windows-shared-x86 bash -c 'sudo make clean && sudo ./bootstrap && sudo ./configure --host=i686-w64-mingw32 && sudo make'
if [[ "$?" -ne 0 ]]
then
echo -e "\033[31mFailed\033[0m - Removing damaged targets"
rm ../../Java/Personal/hid4java/src/main/resources/win32-x86/hidapi.dll
else
echo -e "\033[32mOK\033[0m"
cp windows/.libs/libhidapi-0.dll ../../Java/Personal/hid4java/src/main/resources/win32-x86/hidapi.dll
fi
else
echo -e "\033[33mSkipping win32-x86\033[0m"
fi
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
# Linux environments
# 64-bit
if [[ "$1" == "all" ]] || [[ "$1" == "linux" ]] || [[ "$1" == "linux-x86-64" ]]
then
echo -e "\033[32mBuilding Linux 64-bit\033[0m"
# Note the use of a double sudo apt-get update here
dockcross-linux-x64 bash -c 'sudo apt-get update || sudo apt-get update && sudo apt-get --yes install libudev-dev libusb-1.0-0-dev && sudo make clean && sudo ./bootstrap && sudo ./configure && sudo make'
if [[ "$?" -ne 0 ]]
then
echo -e "\033[31mFailed\033[0m - Removing damaged targets"
rm ../../Java/Personal/hid4java/src/main/resources/linux-x86-64/libhidapi.so
rm ../../Java/Personal/hid4java/src/main/resources/linux-amd64/libhidapi.so
rm ../../Java/Personal/hid4java/src/main/resources/linux-x86-64/libhidapi-libusb.so
rm ../../Java/Personal/hid4java/src/main/resources/linux-amd64/libhidapi-libusb.so
else
echo -e "\033[32mOK\033[0m"
cp linux/.libs/libhidapi-hidraw.so ../../Java/Personal/hid4java/src/main/resources/linux-x86-64/libhidapi.so
cp linux/.libs/libhidapi-hidraw.so ../../Java/Personal/hid4java/src/main/resources/linux-amd64/libhidapi.so
cp libusb/.libs/libhidapi-libusb.so ../../Java/Personal/hid4java/src/main/resources/linux-x86-64/libhidapi-libusb.so
cp libusb/.libs/libhidapi-libusb.so ../../Java/Personal/hid4java/src/main/resources/linux-amd64/libhidapi-libusb.so
fi
else
echo -e "\033[33mSkipping linux-x86-64\033[0m"
fi
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
# 32-bit
if [[ "$1" == "all" ]] || [[ "$1" == "linux" ]] || [[ "$1" == "linux-x86" ]]
then
echo -e "\033[32mBuilding Linux 32-bit\033[0m"
dockcross-linux-x86 bash -c 'sudo dpkg --add-architecture i386 && sudo apt-get update && sudo apt-get --yes install libudev-dev libusb-1.0-0-dev libudev-dev:i386 libusb-1.0-0-dev:i386 && sudo make clean && sudo ./bootstrap && sudo ./configure && sudo make'
if [[ "$?" -ne 0 ]]
then
echo -e "\033[31mFailed\033[0m - Removing damaged targets"
rm ../../Java/Personal/hid4java/src/main/resources/linux-x86/libhidapi.so
rm ../../Java/Personal/hid4java/src/main/resources/linux-x86/libhidapi-libusb.so
else
echo -e "\033[32mOK\033[0m"
cp linux/.libs/libhidapi-hidraw.so ../../Java/Personal/hid4java/src/main/resources/linux-x86/libhidapi.so
cp libusb/.libs/libhidapi-libusb.so ../../Java/Personal/hid4java/src/main/resources/linux-x86/libhidapi-libusb.so
fi
else
echo -e "\033[33mSkipping linux-x86\033[0m"
fi
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
# ARM environments
# 64-bit (arm64/aarch64)
if [[ "$1" == "all" ]] || [[ "$1" == "linux" ]] || [[ "$1" == "linux-aarch64" ]]
then
echo -e "\033[32mBuilding ARM64/aarch64 (ARMv8)\033[0m"
dockcross-linux-arm64 bash -c 'sudo dpkg --add-architecture arm64 && sudo apt-get update && sudo apt-get --yes install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libudev-dev:arm64 libusb-1.0-0-dev:arm64 && sudo make clean && sudo ./bootstrap && sudo ./configure --host=aarch64-linux-gnu CC=aarch64-linux-gnu-gcc && sudo make'
if [[ "$?" -ne 0 ]]
then
echo -e "\033[31mFailed\033[0m - Removing damaged targets"
rm ../../Java/Personal/hid4java/src/main/resources/linux-aarch64/libhidapi.so
rm ../../Java/Personal/hid4java/src/main/resources/linux-aarch64/libhidapi-libusb.so
else
echo -e "\033[32mOK\033[0m"
cp linux/.libs/libhidapi-hidraw.so ../../Java/Personal/hid4java/src/main/resources/linux-aarch64/libhidapi.so
cp libusb/.libs/libhidapi-libusb.so ../../Java/Personal/hid4java/src/main/resources/linux-aarch64/libhidapi-libusb.so
fi
else
echo -e "\033[33mSkipping linux-aarch64\033[0m"
fi
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
# 32-bit ARMv6 EABI (linux-armel)
if [[ "$1" == "all" ]] || [[ "$1" == "linux" ]] || [[ "$1" == "linux-armel" ]]
then
echo -e "\033[32mBuilding ARMv6 EABI\033[0m"
dockcross-linux-armv6 bash -c 'sudo dpkg --add-architecture armhf && sudo apt-get update && sudo apt-get --yes install gcc-arm-linux-gnueabihf libudev-dev:armhf libusb-1.0-0-dev:armhf && sudo make clean && sudo ./bootstrap && sudo ./configure --host=arm-linux-gnueabihf && sudo make'
if [[ "$?" -ne 0 ]]
then
echo -e "\033[31mFailed\033[0m - Removing damaged targets"
rm ../../Java/Personal/hid4java/src/main/resources/linux-armel/libhidapi.so
rm ../../Java/Personal/hid4java/src/main/resources/linux-armel/libhidapi-libusb.so
else
echo -e "\033[32mOK\033[0m"
cp linux/.libs/libhidapi-hidraw.so ../../Java/Personal/hid4java/src/main/resources/linux-armel/libhidapi.so
cp libusb/.libs/libhidapi-libusb.so ../../Java/Personal/hid4java/src/main/resources/linux-armel/libhidapi-libusb.so
fi
else
echo -e "\033[33mSkipping linux-armel\033[0m"
fi
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
if [[ "$1" == "all" ]] || [[ "$1" == "linux" ]] || [[ "$1" == "linux-arm" ]]
then
echo -e "\033[32mBuilding ARMv7 hard float\033[0m"
dockcross-linux-armv7 bash -c 'sudo dpkg --add-architecture armhf && sudo apt-get update && sudo apt-get --yes install libudev-dev:armhf libusb-1.0-0-dev:armhf && sudo make clean && sudo ./bootstrap && sudo ./configure --host=arm-linux-gnueabihf && sudo make'
if [[ "$?" -ne 0 ]]
then
echo -e "\033[31mFailed\033[0m - Removing damaged targets"
rm ../../Java/Personal/hid4java/src/main/resources/linux-arm/libhidapi.so
else
echo -e "\033[32mOK\033[0m"
cp linux/.libs/libhidapi-hidraw.so ../../Java/Personal/hid4java/src/main/resources/linux-arm/libhidapi.so
cp libusb/.libs/libhidapi-libusb.so ../../Java/Personal/hid4java/src/main/resources/linux-arm/libhidapi-libusb.so
fi
else
echo -e "\033[33mSkipping linux-arm\033[0m"
fi
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
# OS X environments
# Darwin
if [[ "$1" == "all" ]] || [[ "$1" == "osx" ]] || [[ "$1" == "darwin" ]]
then
echo -e "\033[32mBuilding OS X Darwin\033[0m"
make clean
./bootstrap
./configure
make
if [[ "$?" -ne 0 ]]
then
echo -e "\033[31mFailed\033[0m - Removing damaged targets"
rm ../../Java/Personal/hid4java/src/main/resources/darwin/libhidapi.dylib
else
echo -e "\033[32mOK\033[0m"
cp mac/.libs/libhidapi.0.dylib ../../Java/Personal/hid4java/src/main/resources/darwin/libhidapi.dylib
fi
else
echo -e "\033[33mSkipping darwin\033[0m"
fi
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
# List all file info
echo -e "\033[32mResulting build files placed in hid4java:\033[0m"
# Windows environments
echo -e "\033[32mWindows\033[0m"
echo -e "\033[32mwin32-x86-64\033[0m"
file -b ../../Java/Personal/hid4java/src/main/resources/win32-x86-64/hidapi.dll
echo -e "\033[32mwin32-x86\033[0m"
file -b ../../Java/Personal/hid4java/src/main/resources/win32-x86/hidapi.dll
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
# Linux environments
echo -e "\033[32mLinux\033[0m"
echo -e "\033[32mlinux-x86-64\033[0m"
file -b ../../Java/Personal/hid4java/src/main/resources/linux-x86-64/libhidapi.so
file -b ../../Java/Personal/hid4java/src/main/resources/linux-x86-64/libhidapi-libusb.so
echo -e "\033[32mlinux-amd64\033[0m"
file -b ../../Java/Personal/hid4java/src/main/resources/linux-amd64/libhidapi.so
file -b ../../Java/Personal/hid4java/src/main/resources/linux-amd64/libhidapi-libusb.so
echo -e "\033[32mlinux-x86\033[0m"
file -b ../../Java/Personal/hid4java/src/main/resources/linux-x86/libhidapi.so
file -b ../../Java/Personal/hid4java/src/main/resources/linux-x86/libhidapi-libusb.so
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
# ARM
echo -e "\033[32mARM\033[0m"
echo -e "\033[32mlinux-arm\033[0m"
file -b ../../Java/Personal/hid4java/src/main/resources/linux-arm/libhidapi.so
file -b ../../Java/Personal/hid4java/src/main/resources/linux-arm/libhidapi-libusb.so
echo -e "\033[32mlinux-armel\033[0m"
file -b ../../Java/Personal/hid4java/src/main/resources/linux-armel/libhidapi.so
file -b ../../Java/Personal/hid4java/src/main/resources/linux-armel/libhidapi-libusb.so
echo -e "\033[32mlinux-aarch64\033[0m"
file -b ../../Java/Personal/hid4java/src/main/resources/linux-aarch64/libhidapi.so
file -b ../../Java/Personal/hid4java/src/main/resources/linux-aarch64/libhidapi-libusb.so
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
# OS X
echo -e "\033[32mOS X\033[0m"
echo -e "\033[32mdarwin\033[0m"
file -b ../../Java/Personal/hid4java/src/main/resources/darwin/libhidapi.dylib
echo -e "\033[32m------------------------------------------------------------------------\033[0m"
echo -e "\033[32mDone - Check all OK in summary above.\033[0m"