[ion] Windows Makefile: build .rc from the list of assets

This commit is contained in:
Émilie Feral
2020-09-18 15:43:32 +02:00
committed by EmilieNumworks
parent 40392fff9c
commit c96efa76b9
7 changed files with 78 additions and 55 deletions

View File

@@ -56,7 +56,7 @@ $(eval $(call rule_for, \
$(eval $(call rule_for, \
WINDRES, %.o, %.rc, \
$$(WINDRES) $$< -O coff -o $$@, \
$$(WINDRES) $$< -Ioutput/release/simulator/windows -O coff -o $$@, \
global \
))

View File

@@ -29,9 +29,9 @@ LDFLAGS += -ljpeg
$(eval $(call rule_for, \
LINUX_ASSETS, \
ion/src/simulator/linux/assets.s, \
ion/src/simulator/linux/assets.s ion/src/simulator/linux/images.h, \
$(assets_paths), \
$$(PYTHON) ion/src/simulator/linux/assets.py --files $(assets) --implementation $$@, \
$$(PYTHON) ion/src/simulator/linux/assets.py --files $(assets) --header $$@ --implementation $$@, \
global \
))

View File

@@ -22,12 +22,22 @@ LDFLAGS += -lgdiplus
SFLAGS += -I$(BUILD_DIR)
$(eval $(call rule_for, \
WINDOWS_RESOURCES, \
WINDOWS_ASSETS, \
ion/src/simulator/windows/resources.h, \
ion/src/simulator/windows/resources.rc, \
$$(PYTHON) ion/src/simulator/windows/resources.py --resource $$^ --header $$@, \
$(assets_paths), \
$$(PYTHON) ion/src/simulator/windows/assets.py --files $$^ --header-resource-rc $$@, \
global \
))
$(BUILD_DIR)/ion/src/simulator/windows/images.o: $(BUILD_DIR)/ion/src/simulator/windows/resources.h
$(eval $(call rule_for, \
WINDOWS_ASSETS, \
ion/src/simulator/windows/resource_mapping.h, \
$(assets_paths), \
$$(PYTHON) ion/src/simulator/windows/assets.py --files $$^ --header-resource-mapping $$@, \
global \
))
$(BUILD_DIR)/ion/src/simulator/windows/images.o: $(BUILD_DIR)/ion/src/simulator/windows/resource_mapping.h
$(BUILD_DIR)/ion/src/simulator/windows/resources.o: $(BUILD_DIR)/ion/src/simulator/windows/resources.h

View File

@@ -0,0 +1,59 @@
# This script generates two headers:
# - the list of the resources to be included in resources.rc
# - the mapping of the resource names and identifiers
import sys
import re
import argparse
import io
parser = argparse.ArgumentParser(description="Process some windows resources.")
parser.add_argument('--files', nargs='+', help='a list of file names')
parser.add_argument('--header-resource-rc', help='the .h file to generate to be included in .rc')
parser.add_argument('--header-resource-mapping', help='the .h file to generate mapping resource names and identifiers')
args = parser.parse_args()
def process_line(f, line):
rc_re = re.compile('^(\d{1,4}) RCDATA "\.\./assets/(.*)"')
rc_match = rc_re.match(line)
if rc_match:
f.write('{"' + rc_match.groups()[1] + '", ' + rc_match.groups()[0] + '},\n')
return True
return False
identifier = 300
def print_declaration(f, asset, identifier):
f.write(str(identifier) + " RCDATA " + "../assets/" + asset + "\n")
def print_mapping(f, asset, identifier):
f.write('{"' + asset + '", ' + str(identifier) + '},\n')
def print_mapping_header(f):
f.write("#ifndef ION_SIMULATOR_WINDOWS_RESOURCES_H\n")
f.write("#define ION_SIMULATOR_WINDOWS_RESOURCES_H\n\n")
f.write("// This file is auto-generated by assets.py\n\n")
f.write("constexpr struct {const char * identifier; int id; } resourcesIdentifiers[] = {\n")
def print_mapping_footer(f):
f.write("};\n\n")
f.write("#endif\n")
def print(files, path, print_header, print_footer, process_asset):
f = open(path, "w")
print_header(f)
identifier = 300
for asset in files:
process_asset(f, asset, identifier)
identifier += 1
print_footer(f)
f.close()
if (args.header_resource_rc):
print(args.files, args.header_resource_rc, lambda f: None, lambda f: None, print_declaration)
if (args.header_resource_mapping):
print(args.files, args.header_resource_mapping, print_mapping_header, print_mapping_footer, print_mapping)

View File

@@ -1,5 +1,5 @@
#include "../shared/platform.h"
#include <ion/src/simulator/windows/resources.h>
#include <ion/src/simulator/windows/resource_mapping.h>
#include <SDL.h>
#include <windows.h>

View File

@@ -1,41 +0,0 @@
# This script generates a .h file representing available resources to access
# them from C code
import sys
import re
import argparse
import io
parser = argparse.ArgumentParser(description="Process some jpg files.")
parser.add_argument('--resource', help='the resources.rc file')
parser.add_argument('--header', help='the .h file to generate')
args = parser.parse_args()
def process_line(f, line):
rc_re = re.compile('^(\d{1,4}) RCDATA "\.\./assets/(.*)"')
rc_match = rc_re.match(line)
if rc_match:
f.write('{"' + rc_match.groups()[1] + '", ' + rc_match.groups()[0] + '},\n')
return True
return False
def process_resource(resource, path):
rc = open(resource, "r")
f = open(path, "w")
f.write("#ifndef ION_SIMULATOR_WINDOWS_RESOURCES_H\n")
f.write("#define ION_SIMULATOR_WINDOWS_RESOURCES_H\n\n")
f.write("// This file is auto-generated by resources.py\n\n")
f.write("constexpr struct {const char * identifier; int id; } resourcesIdentifiers[] = {\n")
while (process_line(f, rc.readline())):
pass
f.write("};\n\n")
f.write("#endif\n")
rc.close()
f.close()
process_resource(args.resource, args.header)

View File

@@ -1,9 +1,4 @@
300 RCDATA "../assets/background.jpg"
301 RCDATA "../assets/horizontal_arrow.png"
302 RCDATA "../assets/large_squircle.png"
303 RCDATA "../assets/round.png"
304 RCDATA "../assets/small_squircle.png"
305 RCDATA "../assets/vertical_arrow.png"
#include <ion/src/simulator/windows/resources.h>
1 VERSIONINFO
FILEVERSION 1,0,0,0