Debian Codegraph @

Windows/mkwin32

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 set -e
21 umask 022
22 export MAKEFLAGS=
23
24 copyProperties() {
25 local from="${1}"
26 local to="${2}"
27 shift 2
28
29 for suffix in ${*}
30 do
31 setVariable "${to}${suffix}" "$(getVariable "${from}${suffix}")"
32 done
33 }
34
35 installFile() {
36 local source="${1}"
37 local target="${2}"
38
39 [ "${target%/}" = "${target}" ] || target="${target}${source##*/}"
40
41 if [ -e "${source}" ]
42 then
43 local path="${installRoot}/${target}"
44 mkdir -p "${path%/*}"
45 cp "${source}" "${path}"
46 else
47 logWarning "file not installed: ${target}"
48 fi
49 }
50
51 installFiles() {
52 local target="${1}"
53 shift 1
54 local source
55
56 for source
57 do
58 installFile "${source}" "${target}"
59 done
60 }
61
62 installPackages() {
63 while [ "${#}" -gt 0 ]
64 do
65 local package="${1}"
66 shift 1
67
68 local name="$(getVariable "${package}Name")"
69 logTask "installing package files: ${name}"
70 "installPackage_${package}"
71 done
72 }
73
74 installPackage_libusb0() {
75 if [ -n "${libusb0Root}" ]
76 then
77 cd "${libusb0Root}/bin"
78 installFile "x86/libusb0.sys" "bin/libusb0.sys"
79 installFile "x86/libusb0_x86.dll" "bin/libusb0.dll"
80 installFile "amd64/libusb0.sys" "bin/libusb0_x64.sys"
81 installFile "amd64/libusb0.dll" "bin/libusb0_x64.dll"
82 else
83 logWarning "${libusb0Name} not installable"
84 fi
85 }
86
87 installPackage_libusb1() {
88 if [ -n "${libusb1Root}" ]
89 then
90 cd "${libusb1Root}"
91 installFile "MinGW32/dll/libusb-1.0.dll" "bin/"
92 else
93 logWarning "${libusb1Name} not installable"
94 fi
95 }
96
97 installPackage_winusb() {
98 if [ -n "${winusbRoot}" ]
99 then
100 cd "${winusbRoot}"
101 installFile "x86/winusbcoinstaller2.dll" "bin/x86/"
102 installFile "amd64/winusbcoinstaller2.dll" "bin/amd64/"
103 installFile "x86/WdfCoInstaller01009.dll" "bin/x86/"
104 installFile "amd64/WdfCoInstaller01009.dll" "bin/amd64/"
105 else
106 logWarning "${winusbName} not installable"
107 fi
108 }
109
110 . "`dirname "${0}"`/../brltty-prologue.sh"
111 . "${programDirectory}/mingw32.sh"
112
113 defaultUsbPackage="libusb"
114 defaultTemporaryDirectory="${TMPDIR:-/tmp}/brltty-${programName}"
115
116 addProgramOption u string.package usbPackage "which USB package to use" "${defaultUsbPackage}"
117 addProgramOption s flag invokeShell "invoke interactive shell to inspect/modify result"
118 addProgramOption t string.directory temporaryDirectory "the temporary directory to use for the build" "${defaultTemporaryDirectory}"
119 addProgramOption k flag keepBuild "keep (do not remove) the temporary directory"
120 addWindowsPackageOption M msvc
121 addWindowsPackageOption A ahk
122 addWindowsPackageOption N nsis
123 addWindowsPackageOption U libusb0
124 addWindowsPackageOption X libusb1
125 addWindowsPackageOption W winusb
126 addWindowsPackageOption P python
127 addWindowsPackageOption I icu
128 addProgramOption C string.directory cygwinRoot "the root directory of a Cygwin installation"
129 addProgramParameter source sourceRoot "the top-level directory of the source tree"
130 optionalProgramParameters
131 addProgramParameter revision buildRevision "the revision of the build"
132 parseProgramArguments "${@}"
133
134 sourceRoot="$(cd "${sourceRoot}" && pwd -W)"
135 [ -f "${sourceRoot}/configure" ] || semanticError "not a source tree: ${sourceRoot}"
136
137 revisionIdentifier="$("${sourceRoot}/getrevid" "${sourceRoot}")"
138 logTask "revision identifier: ${revisionIdentifier}"
139
140 [ -n "${buildRevision}" ] || {
141 buildRevision="${revisionIdentifier%-g*}-"
142 buildRevision="${buildRevision#*-}"
143 buildRevision="${buildRevision#*-}"
144
145 if [ -n "${buildRevision}" ]
146 then
147 buildRevision="${buildRevision%-}"
148 else
149 buildRevision="0"
150 fi
151 }
152
153 [ -n "${cygwinRoot}" ] || {
154 directory=/cygwin
155 [ -e "${directory}" ] && cygwinRoot="${directory}"
156 }
157
158 [ -n "${cygwinRoot}" ] && {
159 if [ -f "${cygwinRoot}/cygwin.ico" ]
160 then
161 export PATH="${PATH}:${cygwinRoot}/bin"
162 export nodosfilewarning=1
163 else
164 logWarning "not a Cygwin root directory: ${cygwinRoot}"
165 fi
166 }
167
168 [ -n "${usbPackage}" ] || usbPackage="${defaultUsbPackage}"
169
170 case "${usbPackage}"
171 in
172 winusb) usbWindowsPackages=();;
173 libusb) usbWindowsPackages=("libusb0");;
174 libusb-1.0) usbWindowsPackages=("libusb1" "winusb");;
175 *) syntaxError "unrecognized USB package: ${usbPackage}"
176 esac
177
178 winusbFilter=""
179
180 libusb0Filter="\
181 select "USB:", and install the ${libusb0Name} filter by doing one of the
182 following:
183 + run Install ${libusb0Name} Filter from the Start Menu
184 + answer yes to the setup prompt for installing the ${libusb0Name} filter
185 + install it by hand, from ${libusb0Download}"
186
187 libusb1Filter="\
188 you will need to use ${libusb0Name} instead because
189 ${libusb1Name} does not support this requirement."
190
191 set -- "${usbWindowsPackages[@]}"
192 copyProperties "${1}" usb Name Location Download Version Pattern Filter
193
194 [ -z "${msvcRoot}" ] || {
195 if verifyWindowsPackage msvc
196 then
197 export PATH="${msvcRoot}:${PATH}"
198 fi
199 }
200
201 getPythonLocation pythonRoot && {
202 if verifyWindowsPackage python
203 then
204 export PATH="${pythonRoot}:${pythonRoot}/Scripts:${PATH}"
205 export PYTHON="${pythonRoot}/python"
206 fi
207 }
208
209 verifyWindowsPackages ahk nsis icu "${usbWindowsPackages[@]}" || :
210 verifyWindowsCommands lib python cython || :
211 verifyMingwPackages pthreads curses || :
212 verifyMingwCommands zip unix2dos linuxdoc doxygen groff || :
213
214 if [ -z "${temporaryDirectory}" ]
215 then
216 temporaryDirectory="${defaultTemporaryDirectory}"
217 rm -f -r "${temporaryDirectory}"
218 elif [ -e "${temporaryDirectory}" ]
219 then
220 semanticError "directory already exists: ${temporaryDirectory}"
221 fi
222
223 mkdir -p "${temporaryDirectory}"
224 cd "${temporaryDirectory}"
225 temporaryDirectory="$(pwd -W)"
226
227 logTask "copying source tree"
228 resolveDirectory "${sourceRoot}" rsyncSource
229 newSourceRoot="${temporaryDirectory}/source"
230 mkdir "${newSourceRoot}"
231 resolveDirectory "${newSourceRoot}" rsyncTarget
232 rsyncOptions=(--recursive --perms --times)
233 rsyncOptions+=(--exclude "/Android/Gradle/??l")
234 rsync "${rsyncOptions[@]}" -- "${rsyncSource}/" "${rsyncTarget}/"
235 cd "${newSourceRoot}"
236 sourceRoot="${newSourceRoot}"
237
238 logTask "applying patches"
239 for patch in affinity
240 do
241 patch -p0 <"Windows/${patch}.patch"
242 done
243
244 infFile="${usbPackage}.inf"
245 infPath="Windows/${infFile}"
246 Tools/updusbdevs -q "c:Programs/usb_devices.c" "inf:${infPath}"
247 Tools/updcsvs -q
248
249 buildRoot="${temporaryDirectory}/build"
250 mkdir -p "${buildRoot}"
251 cd "${buildRoot}"
252
253 logTask "configuring build"
254 "../source/cfg-windows" \
255 --prefix=/ \
256 --enable-relocatable-install \
257 --with-usb-package="${usbPackage}" \
258 --quiet
259
260 . ./brltty-config.sh
261 buildVersion="${BRLTTY_VERSION}-${buildRevision}"
262 buildName="${BRLTTY_TARNAME}-win32-${buildVersion}-${usbPackage}"
263
264 logTask "building programs"
265 make -s
266 make -s -C Drivers/BrlAPI/WindowEyes we-dynamic-library-windows
267
268 logTask "building documents"
269 make -s -C Documents
270
271 logTask "installing files"
272 installRoot="${temporaryDirectory}/install/${buildName}"
273 make -s install install-messages \
274 JAVA_JAR_DIR=/lib JAVA_JNI_DIR=/lib \
275 PYTHON_PREFIX="Python" \
276 INSTALL_ROOT="${installRoot}"
277
278 logTask "updating files"
279 documentDirectory="doc"
280
281 readmeHeader="\
282 This build of ${BRLTTY_NAME} ${BRLTTY_VERSION} includes Windows-specific patches.
283
284 You should probably read doc/BRLTTY.txt and doc/Windows.txt for information
285 about BRLTTY.
286
287 Here are some notes on how to get started:
288
289 - BRLTTY only gives access to text consoles. For the rest of the Windows
290 environment, you need to also install and run NVDA.
291 - Either use the BRLTTY configurator (brlttycnf.exe) or manually uncomment the
292 appropriate lines in etc/brltty.conf.
293 - For Python support (e.g. for NVDA), install Brlapi-${BRLAPI_RELEASE}-<PythonVersion>-win32.whl using pip.
294 - For sighted users, use the xw braille driver to get a virtual braille box.
295 "
296
297 readmeFooter="\
298
299 If you are having problems, please run debug-brltty.bat and send us the
300 debug.log and brltty.conf files.
301
302 Documentation can be found in the doc/ subdirectory.
303
304 ==============================
305 Technical notes on this build:
306
307 - Source Revision: ${revisionIdentifier}
308 - BRLTTY Version: ${BRLTTY_VERSION}
309 - BrlAPI Version: ${BRLAPI_RELEASE}
310 - Some MinGW-specific path and file name changes have been made.
311 - To make life easier for Windows users, the BrlAPI server was modified to:
312 * not use authentication by default (BRLAPI_DEFAUTH set to none)
313 * only use local sockets (:0+127.0.0.1:0 changed to :0)
314 - *${usbPattern}* files come from ${usbName} ${usbVersion}, which can be found at:
315 ${usbDownload}
316 - Python bindings are provided by: Brlapi-${BRLAPI_RELEASE}-<PythonVersion>-win32.whl
317 - C bindings are provided in: include/, and lib/
318 A .lib file is provided for linking in (for example) Visual C. Then you can
319 just ship bin/brlapi${BRLAPI_RELEASE%.*}.dll alongside your .exe application.
320 "
321
322 cd "${buildRoot}"
323 installFile "Documents/brltty.conf" "etc/"
324 installFile "Drivers/BrlAPI/WindowEyes/webrloem109.dll" "WindowEyes/"
325
326 installFiles "Debug/" config.h config.mk config.log
327 installFiles "Debug/" Programs/*.exe Programs/*.dll
328
329 set -- Bindings/Python/dist/Brlapi-${BRLAPI_RELEASE}-*.whl
330 if [ "${#}" -gt 0 ]
331 then
332 for file
333 do
334 installFile "${file}" "Python/"
335 done
336 else
337 logWarning "Python bindings installer not found"
338 fi
339
340 cd "${sourceRoot}"
341 installFile "LICENSE-LGPL" "LICENSE-LGPL.txt"
342 installFile "README" "${documentDirectory}/BRLTTY.txt"
343 installFile "Drivers/Braille/XWindow/UBraille.ttf" "Fonts/"
344 installFile "Drivers/BrlAPI/WindowEyes/README" "${documentDirectory}/WindowEyes.txt"
345 installFile "${infPath}" "bin/brltty-${infFile}"
346 installFiles "etc/" Documents/*.csv
347
348 for document in ChangeLog HISTORY TODO
349 do
350 installFile "Documents/${document}" "${documentDirectory}/${document}.txt"
351 done
352
353 for document in Windows BrailleDots TextTables ContractionTables AttributesTables KeyTables
354 do
355 installFile "Documents/README.${document}" "${documentDirectory}/${document}.txt"
356 done
357
358 for root in "${sourceRoot}" "${buildRoot}"
359 do
360 cd "${root}/Documents"
361
362 for manual in Manual-BRLTTY Manual-BrlAPI BrlAPIref
363 do
364 [ -d "${manual}" ] || continue
365
366 for file in $(find "${manual}" -type f -print)
367 do
368 name="${file##*/}"
369 extension="${name##*.}"
370
371 case "${extension}"
372 in
373 txt | html | htm | doc | pdf)
374 installFile "${file}" "${documentDirectory}/${file}"
375 ;;
376
377 *);;
378 esac
379 done
380 done
381 done
382
383 cd "${sourceRoot}/Drivers"
384 for document in $(find Braille Speech -type f -name "README*" -print)
385 do
386 installFile "${document}" "${documentDirectory}/Drivers/${document}.txt"
387 done
388
389 cd "${programDirectory}"
390 installFiles "bin/" *.dll *.cat
391 installFiles "/" *.bat
392
393 logTask "USB package: ${usbPackage}"
394 installPackages "${usbWindowsPackages[@]}"
395
396 cd /mingw/bin
397 for file in libgcc_s_dw2-1.dll libiconv-2.dll libpdcurses*.dll libintl-8.dll
398 do
399 installFile "${file}" "bin/"
400 done
401
402 cd "${installRoot}"
403 rm -f "bin/brltty-config"
404 rm -f "etc/brlapi.key"
405
406 echo "${revisionIdentifier}" >"REVISION.txt"
407
408 for source in $(find "share/man" -type f -name "*.[1-9]" -print)
409 do
410 [ -z "${groffPath}" ] || {
411 target="${source%.*}.txt"
412
413 "${groffPath}" -T ascii -mandoc 2>/dev/null <"${source}" |
414 sed -e 's/'$'\033''\[[0-9]*m//g' >"${target}"
415
416 [ -s "${target}" ] || rm -f "${target}"
417 }
418
419 rm -f "${source}"
420 done
421
422 cat >"README.txt" <<END-OF-README
423 ${readmeHeader}
424 - To register BRLTTY as a service so that it will get started automatically at
425 boot, run enable-brlapi.bat. To unregister it, run disable-brlapi.bat.
426 - If your braille device uses a USB connection:
427 * If you either cannot, or would prefer not to, install its
428 manufacturer's driver, then you can select "USB:", and install
429 the ${usbName} driver by doing one of the following:
430 + right-clicking on bin/brltty-${usbPackage}.inf and selecting install
431 + answering yes to the setup prompt for installing the ${usbName} driver
432 * If you have installed its manufacturer's driver, and if that driver defines
433 a virtual COM port, then select that virtual COM port.
434 * If you need to install its manufacturer's driver, but
435 that driver does not define a virtual COM port, then
436 ${usbFilter}
437 - If your braille device uses a serial connection, or if it is connected via a
438 serial to USB converter, then select the correct COM port. Make sure to
439 select the correct braille driver as well, because serial autodetection may
440 brick some devices.
441 - If your braille device uses a Bluetooth connection, you can either use the
442 Windows Bluetooth facilities to create a virtual COM port which you can then
443 select, or manually configure the braille-device line in brltty.conf.
444 ${readmeFooter}
445 END-OF-README
446
447 if [ -n "${libPath}" ]
448 then
449 cd "${installRoot}/lib"
450 "${libPath}" //nologo /def:brlapi.def /name:brlapi-${BRLAPI_VERSION}.dll /out:brlapi.lib /machine:x86
451 else
452 logWarning "import library not creatable"
453 fi
454
455 cd "${installRoot}/.."
456 cat >"README.txt" <<END-OF-README
457 ${readmeHeader}
458 ${readmeFooter}
459 END-OF-README
460
461 # for the installer but before text file conversion
462 nsisScript="${usbPackage}.nsi"
463 nsisStrings="nsistrings.txt"
464
465 for file in "${nsisScript}" "brltty.nsi" "${nsisStrings}"
466 do
467 path="${programDirectory}/${file}"
468
469 if [ -f "${path}" ]
470 then
471 cp "${path}" .
472 else
473 logWarning "installer source file not found: ${file}"
474 nsisRoot=""
475 fi
476 done
477
478 if [ -n "${ahkRoot}" ]
479 then
480 logTask "creating configurator"
481 cd "${installRoot}"
482 cp "${programDirectory}/brlttycnf.ahk" .
483 "${ahkRoot}/Compiler/Ahk2Exe.exe" //in brlttycnf.ahk //out brlttycnf.exe
484 rm brlttycnf.ahk
485 else
486 logWarning "configurator not creatable"
487 fi
488
489 if [ -n "${unix2dosPath}" ]
490 then
491 logTask "converting text files"
492 cd "${installRoot}/.."
493
494 find . -print |
495 while read path
496 do
497 handle="${path#.}"
498 [ -n "${handle}" ] || continue
499 handle="${handle#/}"
500
501 name="${path##*/}"
502 extension="${name##*.}"
503
504 if [ -f "${path}" ]
505 then
506 if [ "${extension}" != "${name}" ]
507 then
508 case "${extension}"
509 in
510 bash | bat | cat | conf | csv | h | htm | html | inf | log | lua | mk | nsi | pc | policy | sh | tcl | txt | xml | [tcak]t[bi])
511 "${unix2dosPath}" -q -o "${path}"
512 ;;
513
514 a | def | dll | doc | egg-info | exe | exp | lib | mo | pdf | pyd | sys | ttf | whl);;
515 *) logWarning "unexpected file extension: ${handle}";;
516 esac
517 fi
518 elif [ ! -d "${path}" ]
519 then
520 logWarning "unsupported special file: ${handle}"
521 fi
522 done
523 else
524 logWarning "text files not convertible"
525 fi
526
527 if "${invokeShell}"
528 then
529 logTask "invoking shell"
530 cd "${installRoot}"
531 "${SHELL:-/bin/sh}" || :
532 fi
533
534 if [ -n "${zipPath}" ]
535 then
536 logTask "creating archive"
537 archiveFile="${initialDirectory}/${buildName}.zip"
538 rm -f "${archiveFile}"
539 cd "${installRoot}/.."
540 "${zipPath}" -q -A -r "${archiveFile}" "${buildName}"
541 else
542 logWarning "archive not creatable"
543 fi
544
545 if [ -n "${nsisRoot}" ]
546 then
547 logTask "creating installer"
548 cd "${installRoot}/.."
549 mv "${nsisStrings}" "${buildName}"
550 installerFile="${buildName}.exe"
551
552 "${nsisRoot}/makensis" -V2 \
553 -DVERSION="${buildVersion}" \
554 -DDISTDIR="${buildName}" \
555 -DOUTFILE="${installerFile}" \
556 "${nsisScript}"
557
558 rm -f "${initialDirectory}/${installerFile}"
559 cp "${installerFile}" "${initialDirectory}/${installerFile}"
560 else
561 logWarning "installer not creatable"
562 fi
563
564 "${keepBuild}" || {
565 logTask "cleaning up"
566 cd "${initialDirectory}"
567 rm -f -r "${temporaryDirectory}"
568 }
569
570 logTask "done"
571 exit 0