#! /usr/bin/env python3

#
#  Copyright 2016 - 2023 gary@drinkingtea.net
#
#  This Source Code Form is subject to the terms of the Mozilla Public
#  License, v. 2.0. If a copy of the MPL was not distributed with this
#  file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

import platform
import shutil
import subprocess
import sys

os = platform.system().lower()
arch = platform.machine()
host_env = f'{os}-{arch}'

# get current build type
with open(".current_build","r") as f:
    current_build = f.readlines()[0]

bin = f'./build/{host_env}-{current_build}/bin/'
nostalgia_bin = 'build/gba-release/bin/nostalgia.bin'
nostalgia_project = sys.argv[1]
nostalgia_gba = 'nostalgia.gba'

shutil.copyfile(nostalgia_bin, nostalgia_gba)
subprocess.run([
    f'{bin}/nost-pack', '-src', nostalgia_project, '-rom-bin', nostalgia_gba])
subprocess.run(['gbafix', nostalgia_gba])