Debian Codegraph @

DOS/mkdosarc

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 shopt -s nullglob
22
23 defaultArchiveName="brltty-dos"
24 defaultInstallDirectory="BRLTTY"
25
26 . "`dirname "${0}"`/../prologue.sh"
27 addProgramOption a string.name archiveName "specify archive name" "${defaultArchiveName}"
28 addProgramOption i string.directory installDirectory "specify installation directory on target system" "${defaultInstallDirectory}"
29 addProgramOption o flag overwriteArchive "overwrite existing archive"
30 addProgramOption s flag invokeShell "invoke interactive shell to inspect/modify result"
31 addProgramOption T string.directory toolsRoot "specify tool chain root directory"
32 addProgramParameter source sourceDirectory "top-level directory of source tree"
33 parseProgramArguments "${@}"
34
35 [ -n "${archiveName}" ] || archiveName="${defaultArchiveName}"
36 [ -n "${installDirectory}" ] || installDirectory="${defaultInstallDirectory}"
37 [ -n "${toolsRoot}" ] && export DOS_TOOLS_ROOT="${toolsRoot}"
38
39 [ -n "${sourceDirectory}" ] || sourceDirectory="."
40 verifyInputDirectory "${sourceDirectory}" || semanticError
41 sourceDirectory="$(resolveDirectory "${sourceDirectory}")"
42
43 archivePath="${initialDirectory}/${archiveName}.zip"
44 [ ! -e "${archivePath}" ] || {
45 "${overwriteArchive}" ] || semanticError "archive already exists: ${archivePath}"
46 rm -f -r "${archivePath}"
47 }
48
49 function convertTextFile {
50 local file="${1}"
51
52 unix2dos -q -o "${file}"
53 }
54
55 function installFile {
56 local sourceFile="${1}"
57 local targetFile="${2}"
58
59 targetFile="${installDirectory}/${targetFile}"
60 local targetDirectory="${targetFile%/*}"
61 mkdir -p "${targetDirectory}"
62 cp "${sourceFile}" "${targetFile}"
63 }
64
65 function installCSV {
66 local oldName="${1}"
67 local newName="${2}"
68
69 local extension="csv"
70 installFile "${sourceDirectory}/${documentsSubdirectory}/${oldName}.${extension}" "${documentSubdirectory}/${newName}.${extension}"
71 }
72
73 function installManualFiles {
74 local directory="${1}"
75
76 cd "${directory}/Documents/Manual-BRLTTY"
77
78 local oldFile
79 for oldFile in $(find . -type f)
80 do
81 local newFile="${oldFile}"
82
83 local subdirectory="${oldFile%/*}"
84 local name="${oldFile##*/}"
85
86 local extension="${name##*.}"
87 name="${name%.*}"
88
89 case "${extension}"
90 in
91 html)
92 sed -r -e 's/"([[:alpha:]]+)(-([[:digit:]]+))?\.html(["#])/"\1\3.htm\4/g' -i "${oldFile}"
93 newFile="${subdirectory}/${name/-/}.${extension:0:3}"
94 ;;
95
96 txt | htm | doc | pdf);;
97 *) continue;;
98 esac
99
100 installFile "${oldFile}" "${manualSubdirectory}/${newFile}"
101 done
102 }
103
104 needTemporaryDirectory
105
106 buildDirectory="${temporaryDirectory}/build"
107 mkdir -p "${buildDirectory}"
108
109 installDirectory="${temporaryDirectory}/install/${installDirectory}"
110 mkdir -p "${installDirectory}"
111 documentSubdirectory="doc"
112 manualSubdirectory="${documentSubdirectory}/Manual"
113
114 cd "${buildDirectory}"
115 logTask "configuring build"
116 "${sourceDirectory}/cfg-dos" --prefix="${installDirectory}"
117
118 logTask "building programs"
119 make -s -C Programs all-commands
120
121 logTask "building documentation"
122 make -s -C Documents all
123
124 logTask "installing files"
125 make -s -C Programs install-commands install-tables
126
127 logTask "updating files"
128
129 cd "${installDirectory}/bin"
130 mv brltty-cmdref.exe brllscmd.exe
131 mv brltty-trtxt.exe brltrtxt.exe
132 mv brltty-ttb.exe brlttb.exe
133 mv brltty-ctb.exe brlctb.exe
134 mv brltty-atb.exe brlatb.exe
135 mv brltty-ktb.exe brlktb.exe
136 mv brltty-tune.exe brltune.exe
137 mv brltty-morse.exe brlmorse.exe
138
139 cd "${sourceDirectory}/DOS"
140 installFile cwsdpmi.exe "bin/cwsdpmi.exe"
141
142 cd "${sourceDirectory}/Drivers"
143 name=README
144 for driverType in Braille Speech
145 do
146 cd "${driverType}"
147
148 for driverName in *
149 do
150 cd "${driverName}"
151 typeset -u driverCode="$(sed -n -e '/^ *DRIVER_CODE *= */s/^.*= *//p' "Makefile.in")"
152
153 for file in "${name}"*
154 do
155 document="${file/#${name}/${driverCode}}"
156 document="${document//./-}"
157 installFile "${file}" "${documentSubdirectory}/Drivers/${driverType}/${document}.txt"
158 done
159
160 cd ..
161 done
162
163 cd ..
164 done
165
166 cd "${sourceDirectory}"
167 installFile "LICENSE-LGPL" "LIC-LGPL.txt"
168 installFile "README" "README.txt"
169
170 cd "${documentsSubdirectory}"
171 installFile "ChangeLog" "${documentSubdirectory}/CHG-LOG.txt"
172
173 for file in DOS
174 do
175 installFile "README.${file}" "${documentSubdirectory}/${file}.txt"
176 done
177
178 for file in BUGS CONTRIBUTORS HISTORY TODO
179 do
180 installFile "${file}" "${documentSubdirectory}/${file}.txt"
181 done
182
183 installCSV braille-driver BRL-DRV
184 installCSV speech-driver SPK-DRV
185 installCSV screen-driver SCR-DRV
186
187 installCSV text-table TEXT-TBL
188 installCSV contraction-table CONT-TBL
189 installCSV attributes-table ATTR-TBL
190 installCSV keyboard-table KBD-TBL
191
192 installManualFiles "${sourceDirectory}"
193 installManualFiles "${buildDirectory}"
194
195 cd "${buildDirectory}"
196 installFile "Documents/brltty.conf" "etc/brltty.cfg"
197 installFile "Programs/revision_identifier.auto.h" "REVISION.txt"
198 sed -e 's/"//g' -i "${installDirectory}/REVISION.txt"
199
200 logTask "converting text files"
201 cd "${installDirectory}"
202 find . -print |
203 while read path
204 do
205 handle="${path#.}"
206 [ -n "${handle}" ] || continue
207
208 name="${path##*/}"
209 extension="${name##*.}"
210
211 if [ "${name#*.*.}" != "${name}" ]
212 then
213 logWarning "name contains more than one dot: ${handle}"
214 elif [ "${name#.}" != "${name}" ]
215 then
216 logWarning "null name: ${handle}"
217 elif [ "${name%.}" != "${name}" ]
218 then
219 logWarning "null extension: ${handle}"
220 elif [ -f "${path}" ]
221 then
222 if [ "${extension}" = "${name}" ]
223 then
224 logWarning "file without an extension: ${handle}"
225 else
226 case "${extension}"
227 in
228 txt | html | htm | csv | cfg | [tcak]t[bi] | h) convertTextFile "${path}";;
229 exe | pdf | doc);;
230 *) logWarning "unexpected file extension: ${handle}";;
231 esac
232 fi
233 elif [ -d "${path}" ]
234 then
235 if [ "${extension}" != "${name}" ]
236 then
237 logWarning "directory with an extension: ${handle}"
238 fi
239 else
240 logWarning "unsupported special file: ${handle}"
241 fi
242 done
243
244 logTask "checking for name collisions"
245 cd "${installDirectory}"
246 find . -type d -print |
247 while read directory
248 do
249 declare -A shortNames=()
250
251 for longName in $(ls -1 --quote-name --quoting-style=shell "${directory}")
252 do
253 delimiter="."
254 prefix="${longName%${delimiter}*}"
255
256 if [ "${prefix}" = "${longName}" ]
257 then
258 suffix=""
259 delimiter=""
260 else
261 suffix="${longName:${#prefix}+${#delimiter}}"
262 fi
263
264 prefix="${prefix:0:8}"
265 suffix="${suffix:0:3}"
266 declare -u shortName="${prefix}${delimiter}${suffix}"
267
268 if [ "${#shortNames["${shortName}"]}" -eq 0 ]
269 then
270 shortNames["${shortName}"]="${longName}"
271 else
272 logWarning "name collision: ${directory#.}: ${shortNames["${shortName}"]} & ${longName}"
273 fi
274 done
275 done
276
277 ! "${invokeShell}" || {
278 logTask "invoking shell"
279 cd "${installDirectory}"
280 "${SHELL:-/bin/sh}" || :
281 }
282
283 logTask "creating archive"
284 cd "${installDirectory}/.."
285 zip -q -r "${archivePath}" "${installDirectory##*/}"
286
287 logTask "done"
288 exit 0