2024-03-23 18:41:26 -07:00
|
|
|
#!/usr/bin/python3
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import os.path as path
|
|
|
|
import shutil
|
2024-04-09 10:15:05 -07:00
|
|
|
from shutil import which
|
2024-03-23 18:41:26 -07:00
|
|
|
from glob import glob
|
|
|
|
olddir = os.curdir
|
|
|
|
print("Entering assets directory to begin asset conversion...")
|
|
|
|
os.chdir(path.realpath(path.dirname(__file__)))
|
|
|
|
ASSETS = []
|
2024-04-09 10:15:05 -07:00
|
|
|
WARNINGS: dict[str, bool] = {}
|
|
|
|
def warn(id: str, message: str, WARNINGS = WARNINGS) -> None:
|
|
|
|
warned_already: bool = False
|
|
|
|
try:
|
|
|
|
warned_already = WARNINGS[id]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
if not warned_already:
|
|
|
|
print("WARNING: %s" % message)
|
2024-03-23 18:41:26 -07:00
|
|
|
def run_btcc(args: list[str], outpath: str):
|
|
|
|
with open(outpath + ".h", "wt+") as f:
|
|
|
|
actual_args = ["./btcc"]
|
|
|
|
for arg in args:
|
|
|
|
actual_args += [arg]
|
|
|
|
actual_args += [outpath]
|
|
|
|
subprocess.call(actual_args, stdout=f)
|
|
|
|
def add_basic(input: str, output: str, ASSETS = ASSETS):
|
|
|
|
ASSETS += [output + ".h"]
|
|
|
|
run_btcc(["-nocompress", input], output)
|
|
|
|
def add_base85(input: str, output: str, ASSETS = ASSETS):
|
|
|
|
ASSETS += [output + ".h"]
|
|
|
|
run_btcc(["-base85", input], output)
|
|
|
|
def add_font(input: str, output: str|None = None):
|
|
|
|
if output == None:
|
|
|
|
FONT=path.basename(input).removesuffix(".ttf").lower().replace('-', '_')
|
|
|
|
else:
|
|
|
|
FONT=output
|
|
|
|
print("Adding font '%s' from file '%s'" % (FONT, path.abspath(input)))
|
|
|
|
add_base85(input, FONT)
|
|
|
|
def add_graphic(input: str):
|
|
|
|
GRAPHIC=path.basename(input).removesuffix(".png").lower().replace('-', '_')
|
|
|
|
print("Adding graphic '%s' from file '%s'" % (GRAPHIC, input))
|
|
|
|
add_base85(input, GRAPHIC)
|
|
|
|
def add_license(input: str, output: str):
|
|
|
|
LICENSE = output + "_license"
|
|
|
|
print("Adding license '%s' (C identifier: '%s') from file '%s'" % (output, LICENSE, input))
|
|
|
|
add_basic(input, LICENSE)
|
|
|
|
def compile_program(file: str, output: str):
|
|
|
|
print("Compiling file '%s' to '%s'" % (path.abspath(file), path.abspath(output)))
|
|
|
|
subprocess.call([os.environ.get("CXX", "c++"), file, "-o", output])
|
2024-03-26 18:39:02 -07:00
|
|
|
def add_css(file: str, output: str):
|
|
|
|
CSS_FILE = output + ".h"
|
|
|
|
print("Adding CSS file '%s' (C identifier '%s') from file '%s'" % (file, output, CSS_FILE))
|
|
|
|
add_basic(file, output)
|
2024-04-09 10:15:05 -07:00
|
|
|
def add_dbus(file: str, output_basename: str, adaptor: str|None = None, proxy: str|None = None, WARNINGS = WARNINGS):
|
|
|
|
if adaptor == None:
|
|
|
|
adaptor = output_basename + '_adaptor.hpp'
|
|
|
|
if proxy == None:
|
|
|
|
proxy = output_basename + '_proxy.hpp'
|
|
|
|
if which('sdbus-c++-xml2cpp') is not None:
|
|
|
|
subprocess.call(['sdbus-c++-xml2cpp', file, '--adaptor=' + adaptor, '--proxy=' + proxy])
|
|
|
|
else:
|
|
|
|
warn("Not generating DBus API stubs.")
|
2024-03-23 18:41:26 -07:00
|
|
|
compile_program("../backends/ui/imgui/imgui/misc/fonts/binary_to_compressed_c.cpp", "btcc")
|
|
|
|
for i in glob("Noto_Sans/*.ttf"):
|
|
|
|
add_font(i)
|
|
|
|
for i in glob("Noto_Sans_JP/*.ttf"):
|
|
|
|
add_font(i)
|
|
|
|
add_font("forkawesome-webfont.ttf", "forkawesome")
|
|
|
|
add_graphic("icon.png")
|
|
|
|
add_license("Noto_Sans/OFL.txt", "notosans")
|
|
|
|
add_license("Noto_Sans_JP/OFL.txt", "notosansjp")
|
2024-03-26 18:39:02 -07:00
|
|
|
add_license("../LICENSE.MIT", "looper_mit")
|
|
|
|
add_license("../LICENSE.GPL", "looper_gpl")
|
|
|
|
add_license("../COPYING.md", "looper")
|
2024-03-23 18:41:26 -07:00
|
|
|
add_license("../subprojects/jsoncpp/LICENSE", "jsoncpp")
|
|
|
|
|
|
|
|
add_license("../subprojects/SDL-Mixer-X/COPYING.txt", "sdl_mixer_x")
|
|
|
|
add_license("../backends/ui/imgui/imgui-filebrowser/LICENSE", "imgui_filebrowser")
|
|
|
|
add_license("../backends/ui/imgui/imgui/LICENSE.txt", "imgui")
|
2024-03-26 18:39:02 -07:00
|
|
|
add_license("licenses/lgpl-3.0.txt", "lgpl_3_0")
|
|
|
|
add_license("licenses/lgpl-2.1.txt", "lgpl_2_1")
|
|
|
|
add_license("licenses/lgpl-2.0.txt", "lgpl_2_0")
|
2024-03-23 18:41:26 -07:00
|
|
|
add_license("licenses/ForkAwesome.txt", "forkawesome")
|
|
|
|
add_license("licenses/cli11.txt", "cli11")
|
|
|
|
add_license("licenses/TomlPlusPlus.txt", "tomlplusplus")
|
|
|
|
add_license("../backends/ui/imgui/IconFontCppHeaders/licence.txt", "icnfntcpphdrs")
|
2024-03-26 18:39:02 -07:00
|
|
|
add_css("gtk-frontend.css", "gtk_frontend_css")
|
2024-04-09 10:15:05 -07:00
|
|
|
add_dbus('app.dbus.xml', 'dbus_stub')
|
|
|
|
add_dbus('mpris.dbus.xml', 'mpris_stub')
|
2024-03-23 18:41:26 -07:00
|
|
|
def finalize(output: str, ASSETS = ASSETS):
|
|
|
|
print("Writing a header including all previous asset headers and writing it to '%s'..." % output)
|
|
|
|
with open(output, "wt+") as f:
|
|
|
|
f.write("#pragma once\n")
|
|
|
|
for asset in ASSETS:
|
|
|
|
print("Adding include for '%s'..." % (asset))
|
|
|
|
f.write("#include \"%s\"\n" % asset)
|
|
|
|
ASSETS = []
|
|
|
|
finalize("assets.h")
|
|
|
|
os.remove("btcc")
|
|
|
|
print("Returning to previous directory, now that we're done!")
|
|
|
|
os.chdir(olddir)
|