#!/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-2026 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}/mingw64.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 "^mkwin64: revision identifier: "
mkIgnoreMismatch "^ *Creating library "
mkIgnoreMismatch "^Successfully compiled: "

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="win64[${usbPackage}]"
   mkOldLogName="Windows64-${usbPackage}"
   mkNewLogName="${programName}-${usbPackage}"
   mkBuild "${windowsDirectory}/mkwin64" -P "${pythonLocation}" -u "${usbPackage}" -- "${sourceRoot}"
done

exit 0
