#!/usr/bin/env bash

set -euo pipefail

REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$REPO_ROOT"
source "$REPO_ROOT/scripts/version-common.sh"

APP_VERSION="$(smplayer_current_version macos)"
echo "[build-macos] App version: $APP_VERSION (windows/pc line)"

BUILD_ARGS=(build macos --release)
if [[ $# -gt 0 ]]; then
  BUILD_ARGS+=("$@")
fi
if ! smplayer_has_flutter_option --build-name "${BUILD_ARGS[@]}"; then
  BUILD_ARGS+=(--build-name "$APP_VERSION")
fi
if ! smplayer_has_dart_define SMPLAYER_VERSION "${BUILD_ARGS[@]}"; then
  BUILD_ARGS+=("--dart-define=SMPLAYER_VERSION=$APP_VERSION")
fi

echo "[build-macos] flutter ${BUILD_ARGS[*]}"
exec flutter "${BUILD_ARGS[@]}"
