Debian Codegraph @

Windows/winsetup32

raw
1 #!/bin/bash
2 ###############################################################################
3 # BRLTTY - A background process providing access to the console screen (when in
4 # text mode) for a blind person using a refreshable braille display.
5 #
6 # Copyright (C) 1995-2026 by The BRLTTY Developers.
7 #
8 # BRLTTY comes with ABSOLUTELY NO WARRANTY.
9 #
10 # This is free software, placed under the terms of the
11 # GNU Lesser General Public License, as published by the Free Software
12 # Foundation; either version 2.1 of the License, or (at your option) any
13 # later version. Please see the file LICENSE-LGPL for details.
14 #
15 # Web Page: http://brltty.app/
16 #
17 # This software is maintained by Dave Mielke <[email protected]>.
18 ###############################################################################
19
20 . "`dirname "${0}"`/../brltty-prologue.sh"
21 . "${programDirectory}/mingw32.sh"
22
23 set -e
24 umask 022
25
26 readonly defaultArchiveRoot="http://brltty.app/archive/Windows"
27 readonly defaultTemporaryDirectory="${TMPDIR:-/tmp}/brltty-${programName}"
28
29 havePath() {
30 local path="${1}"
31
32 [ -n "${path}" ] || return 1
33 [ -e "${path}" ] || return 2
34 return 0
35 }
36
37 verifyDirectory() {
38 local path="${1}"
39
40 [ -e "${path}" ] || semanticError "directory not found: ${path}"
41 [ -d "${path}" ] || semanticError "not a directory: ${path}"
42 [ -w "${path}" ] || semanticError "directory not writable: ${path}"
43 [ -r "${path}" ] || semanticError "directory not readable: ${path}"
44 [ -x "${path}" ] || semanticError "directory not searchable: ${path}"
45 }
46
47 findCommand() {
48 local variable="${1}"
49 shift 1
50
51 local name
52 for name
53 do
54 local path="$(command -v "${name}")"
55 [ -n "${path}" ] && {
56 setVariable "${variable}" "${path}"
57 return 0
58 }
59 done
60
61 return 1
62 }
63
64 executeCommand() {
65 logDetail "executing command: ${*}"
66
67 exitStatus=0
68 "${@}" || exitStatus="${?}"
69
70 [ "${exitStatus}" -eq 0 ] || logWarning "command failed: ${1}: exit status ${exitStatus}"
71 return "${exitStatus}"
72 }
73
74 downloadFile() {
75 local source="${1}"
76 local target="${2}"
77
78 logNote "downloading file: ${source}"
79 [ -z "${target}" ] && target="${source##*/}"
80 executeCommand wget -nv -O "${target}" "${archiveRoot}/${source}"
81 }
82
83 unpackArchive() {
84 local path="${1}"
85
86 case "${path}"
87 in
88 *.zip) set -- unzip -q;;
89 *.tar.gz) set -- tar xfz;;
90 *) semanticError "unsupported archive: ${path}";;
91 esac
92
93 executeCommand "${@}" "${path}"
94 }
95
96 applyPatch() {
97 local patch="${1}"
98 local directory="${2}"
99 local file="${3}"
100 local pattern="${4}"
101
102 local path="${directory}/${file}"
103
104 if [ -f "${path}" ]
105 then
106 grep -q "${pattern}" "${path}" || {
107 local name="${patch##*/}"
108 logTask "applying patch: ${name}"
109
110 "${dryRun}" || {
111 downloadFile "${patch}"
112 executeCommand patch -N -i "${temporaryDirectory}/${name}" -d "${directory}" "${file}"
113 }
114 }
115 else
116 logWarning "file not found: ${path}"
117 fi
118 }
119
120 installFile() {
121 local file="${1}"
122 local directory="${2}"
123
124 local source="${file##*/}"
125 local target="${directory}/${source}"
126
127 [ -e "${target}" ] || {
128 logTask "installing file: ${target}"
129
130 "${dryRun}" || {
131 downloadFile "${file}"
132 [ -d "${directory}" ] || executeCommand mkdir -p "${directory}"
133 executeCommand cp "${source}" "${target}"
134 }
135 }
136 }
137
138 installLink() {
139 local to="${1}"
140 local directory="${2}"
141 local name="${3}"
142
143 [ -n "${name}" ] || name="${to##*/}"
144 local from="${directory}/${name}"
145
146 havePath "${from}" || {
147 logTask "installing link: ${from} -> ${to}"
148 [ -e "${to}" ] || semanticError "link target not found: ${to}"
149 "${dryRun}" || executeCommand ln -s "${to}" "${from}"
150 }
151 }
152
153 installWindowsArchive() {
154 local archive="${1}"
155 local path="${2}"
156
157 havePath "${path}" || {
158 logTask "installing Windows archive: ${archive}"
159
160 "${dryRun}" || {
161 downloadFile "${archive}"
162
163 local directory="content-${archive}"
164 executeCommand mkdir "${directory}"
165 executeCommand cd "${directory}"
166
167 unpackArchive "../${archive}"
168 set -- *
169
170 if [ "${#}" -eq 1 -a -d "${1}" ]
171 then
172 executeCommand mv "${1}" "${path}"
173 executeCommand cd ..
174 executeCommand rmdir "${directory}"
175 else
176 executeCommand cd ..
177 executeCommand mv "${directory}" "${path}"
178 fi
179 }
180 }
181 }
182
183 installMingwArchive() {
184 local archive="${1}"
185 local path="${2}"
186
187 havePath "${mingwDirectory}/${path}" || {
188 logTask "installing MinGW archive: ${archive}"
189
190 "${dryRun}" || {
191 downloadFile "MinGW/${archive}"
192 executeCommand cd "${mingwDirectory}"
193 unpackArchive "${temporaryDirectory}/${archive}"
194 executeCommand cd "${temporaryDirectory}"
195 }
196 }
197 }
198
199 installMingwPackage() {
200 local package="${1}"
201 local path="${2}"
202
203 havePath "${path}" || {
204 logTask "installing MinGW package: ${package}"
205 "${dryRun}" || executeCommand mingw-get --verbose=0 install "${package}"
206 }
207 }
208
209 installMicrosoftVisualCTools() {
210 local file
211
212 for file in lib.exe link.exe mspdb100.dll msvcr100.dll
213 do
214 installFile "MSVC/${file}" "/usr/local/bin"
215 done
216 }
217
218 installPackageConfigurationFiles() {
219 local package
220
221 for package in libusb libusb-1.0
222 do
223 installFile "pkgconfig/${package}.pc" "${librariesDirectory}/pkgconfig"
224 done
225 }
226
227 installBluetoothHeaders() {
228 local name
229
230 for name in ws2bth bthdef bthsdpdef
231 do
232 installFile "Bluetooth/${name}.h" "${headersDirectory}"
233 done
234 }
235
236 installLibUSB0() {
237 local directory="${windowsDirectory}/LibUSB-Win32"
238 installWindowsArchive libusb-win32-bin-1.2.6.0.zip "${directory}"
239 installLink "${directory}/include/lusb0_usb.h" "${headersDirectory}" usb.h
240 installLink "${directory}/lib/gcc/libusb.a" "${librariesDirectory}"
241 installLink "${directory}/bin/x86/libusb0_x86.dll" "${commandsDirectory}" libusb0.dll
242 }
243
244 installLibUSB1() {
245 local directory="${windowsDirectory}/LibUSB-1.0"
246 installWindowsArchive libusbx-1.0.18-win.tar.gz "${directory}"
247 installLink "${directory}/include/libusbx-1.0" "${headersDirectory}" libusb-1.0
248 installLink "${directory}/MinGW32/dll/libusb-1.0.dll.a" "${librariesDirectory}"
249 installLink "${directory}/MinGW32/dll/libusb-1.0.dll" "${commandsDirectory}"
250 installWindowsArchive winusb.zip "${windowsDirectory}/WinUSB"
251 }
252
253 installPythonDependencies() {
254 local python
255
256 if findCommand python python py
257 then
258 export PYTHONIOENCODING="utf-8"
259 local directory="${python%/*}"
260
261 findCommand cython cython || {
262 logTask "installing Cython"
263 "${dryRun}" || executeCommand pip -q install cython
264 }
265
266 # Keep these in case any of them is still needed.
267 # installFile Cython/vcruntime140.dll "${directory}/libs"
268 # installFile Cython/distutils.cfg "${directory}/lib/distutils"
269 # applyPatch "Cython/PythonCygwinCCompiler.patch" "${directory}/lib/distutils" "cygwinccompiler.py" "vcruntime140"
270
271 findCommand wheel wheel || {
272 logTask "installing Wheel"
273 "${dryRun}" || executeCommand pip -q install wheel
274 }
275
276 logTask "ensuring Setuptools is up to date"
277 "${dryRun}" || executeCommand pip -q install --upgrade setuptools
278 else
279 logWarning "Python not found"
280 fi
281 }
282
283 addProgramOption a string.URL archiveRoot "the URL for BRLTTY's Windows archive" "${defaultArchiveRoot}"
284 addProgramOption d flag dryRun "dry run - don't actually install anything"
285 addProgramOption k flag keepFiles "keep (do not remove) the temporary directory"
286 addProgramOption p string.directory pythonRoot "the directory where Python has been installed"
287 addProgramOption t string.directory temporaryDirectory "the temporary directory to use" "${defaultTemporaryDirectory}"
288 parseProgramArguments "${@}"
289
290 [ -n "${archiveRoot}" ] || archiveRoot="${defaultArchiveRoot}"
291
292 getPythonLocation pythonRoot && {
293 [ -d "${pythonRoot}" ] || semanticError "Python directory not found: ${pythonRoot}"
294 export PATH="${pythonRoot}:${pythonRoot}/scripts:${PATH}"
295 }
296
297 readonly windowsDirectory="/c"
298 verifyDirectory "${windowsDirectory}"
299
300 readonly mingwDirectory="/mingw"
301 verifyDirectory "${mingwDirectory}"
302
303 readonly commandsDirectory="${mingwDirectory}/bin"
304 verifyDirectory "${commandsDirectory}"
305
306 readonly librariesDirectory="${mingwDirectory}/lib"
307 verifyDirectory "${librariesDirectory}"
308
309 readonly headersDirectory="${mingwDirectory}/include"
310 verifyDirectory "${headersDirectory}"
311
312 if [ -z "${temporaryDirectory}" ]
313 then
314 temporaryDirectory="${defaultTemporaryDirectory}"
315 rm -f -r "${temporaryDirectory}"
316 elif [ -e "${temporaryDirectory}" ]
317 then
318 semanticError "directory already exists: ${temporaryDirectory}"
319 fi
320
321 mkdir -p "${temporaryDirectory}"
322 cd "${temporaryDirectory}"
323 temporaryDirectory="$(pwd -W)"
324
325 installMingwPackage msys-bison /bin/bison
326 installMingwPackage msys-dos2unix /bin/dos2unix
327 installMingwPackage msys-groff /bin/groff
328 installMingwPackage msys-m4 /bin/m4
329 installMingwPackage msys-tar /bin/tar
330 installMingwPackage msys-unzip /bin/unzip
331 installMingwPackage msys-wget /bin/wget
332 installMingwPackage msys-zip /bin/zip
333
334 installMingwPackage mingw32-libpdcurses /mingw/include/curses.h
335 installMingwPackage mingw32-pthreads-w32 /mingw/include/pthread.h
336 installMingwPackage mingw32-tcl /mingw/bin/tclsh
337
338 installMicrosoftVisualCTools
339 installPackageConfigurationFiles
340 installBluetoothHeaders
341
342 installMingwArchive pkg-config_0.28-1_win32.zip "bin/pkg-config.exe"
343 installMingwArchive glib_2.34.3-1_win32.zip "bin/libgobject-2.0-0.dll"
344
345 installWindowsArchive AutoHotkey104805.tar.gz "${ahkLocation}"
346 installWindowsArchive nsis-3.0b0.tar.gz "${nsisLocation}"
347 installWindowsArchive icu4c-53_1-Win32-msvc10.zip "${icuLocation}"
348
349 installLibUSB0
350 installLibUSB1
351 installPythonDependencies
352
353 "${keepFiles}" || {
354 logTask "cleaning up"
355 cd "${initialDirectory}"
356 rm -f -r "${temporaryDirectory}"
357 }
358
359 logTask "done"
360 exit 0