#!/bin/bash
###############################################################################
# BRLTTY - A background process providing access to the console screen (when in
#          text mode) for a blind person using a refreshable braille display.
#
# Copyright (C) 1995-2025 by The BRLTTY Developers.
#
# BRLTTY comes with ABSOLUTELY NO WARRANTY.
#
# This is free software, placed under the terms of the
# GNU Lesser General Public License, as published by the Free Software
# Foundation; either version 2.1 of the License, or (at your option) any
# later version. Please see the file LICENSE-LGPL for details.
#
# Web Page: http://brltty.app/
#
# This software is maintained by Dave Mielke <dave@mielke.cc>.
###############################################################################

. "`dirname "${0}"`/mk-prologue.sh"
windowsDirectory="${sourceRoot}/Windows"
. "${windowsDirectory}/mingw32.sh"

readonly defaultUsbPackageNames=( libusb libusb-1.0 )

showProgramUsageNotes() {
cat <<END_OF_PROGRAM_USAGE_NOTES
The positional parameters are the names of USB packages. If none are
specified, the default is: ${defaultUsbPackageNames[*]}
END_OF_PROGRAM_USAGE_NOTES
}

processExtraProgramParameters() {
   [ "${#}" -gt 0 ] || set -- "${defaultUsbPackageNames[@]}"
   usbPackageNames=( "${@}" )
}

optionalProgramParameters
parseProgramArguments "${@}"

mkIgnoreMismatch "^mkwin32: revision identifier: "
mkIgnoreMismatch "^ *Creating library "
mkIgnoreMismatch "^Successfully compiled: "

mkIgnoreMismatch "^declare: usage: "
mkIgnoreMismatch "^.*: declare: -[nA]: "

read <"${windowsDirectory}/python-location" pythonLocation || exit "${?}"
[ -e "${pythonLocation}" ] || logError "Python not found: ${pythonLocation}"
[ -d "${pythonLocation}" ] || logError "not a directory: ${pythonLocation}"

for usbPackage in "${usbPackageNames[@]}"
do
   mkPlatformName="win32[${usbPackage}]"
   mkOldLogName="Windows32-${usbPackage}"
   mkNewLogName="${programName}-${usbPackage}"
   mkBuild "${windowsDirectory}/mkwin32" -P "${pythonLocation}" -u "${usbPackage}" -- "${sourceRoot}"
done

exit 0
