[ion] Makefile linux: simplify build system by generating a header

This commit is contained in:
Émilie Feral
2020-09-18 16:19:02 +02:00
committed by EmilieNumworks
parent 4620aa8aa8
commit 8976ebfc41
3 changed files with 46 additions and 23 deletions

View File

@@ -29,14 +29,19 @@ LDFLAGS += -ljpeg
$(eval $(call rule_for, \
LINUX_ASSETS, \
ion/src/simulator/linux/assets.s ion/src/simulator/linux/images.h, \
ion/src/simulator/linux/assets.s, \
$(assets_paths), \
$$(PYTHON) ion/src/simulator/linux/assets.py --files $(assets) --header $$@ --implementation $$@, \
$$(PYTHON) ion/src/simulator/linux/assets.py --files $(assets) --implementation $$@, \
global \
))
assets_address_ranges_declaration = $(foreach i,$(assets),extern unsigned char _ion_simulator_$(basename $(i))_start;)
assets_address_ranges_declaration += $(foreach i,$(assets),extern unsigned char _ion_simulator_$(basename $(i))_end;)
assets_address_ranges_definition = $(foreach i,$(assets), {"$(i)", &_ion_simulator_$(basename $(i))_start, &_ion_simulator_$(basename $(i))_end},)
# The header is refered to as <ion/src/simulator/linux/images.h> so make sure it's findable this way
SFLAGS += -I$(BUILD_DIR)
$(call object_for,ion/src/simulator/linux/images.cpp): CXXFLAGS += -DASSETS_ADDRESS_RANGES_DECLARATION='$(assets_address_ranges_declaration)' -DASSETS_ADDRESS_RANGES_DEFINITION='$(assets_address_ranges_definition)'
$(eval $(call rule_for, \
LINUX_ASSETS, \
ion/src/simulator/linux/images.h, \
$(assets_paths), \
$$(PYTHON) ion/src/simulator/linux/assets.py --files $(assets) --header $$@, \
global \
))

View File

@@ -1,5 +1,6 @@
# This script generates a .s file representing assets in order to access
# them from C code
# This script generates:
# - .s file representing assets in order to access them from C code
# - .h representing the mapping between symbols and assets
import sys
import re
@@ -10,6 +11,7 @@ import os
parser = argparse.ArgumentParser(description="Process some asset files.")
parser.add_argument('--files', nargs='+', help='a list of file names')
parser.add_argument('--implementation', help='the .s file to generate')
parser.add_argument('--header', help='the .h file to generate')
args = parser.parse_args()
def print_asset(f, asset):
@@ -20,12 +22,39 @@ def print_asset(f, asset):
f.write(" .incbin \"ion/src/simulator/assets/" + asset + "\"\n")
f.write("_ion_simulator_" + asset_basename + "_end:\n\n")
def print(files, path):
def print_assembly(files, path):
f = open(path, "w")
for asset in files:
print_asset(f, asset)
identifier += 1
f.close()
print(args.files, args.implementation)
def print_declaration(f, asset):
asset_basename = os.path.splitext(asset)[0]
f.write("extern unsigned char _ion_simulator_" + asset_basename + "_start;\n")
f.write("extern unsigned char _ion_simulator_" + asset_basename + "_end;\n")
def print_mapping(f, asset):
f.write('"' + asset + '", &_ion_simulator_' + asset_basename +'_start, &_ion_simulator_' + asset_basename '_end},\n')
def print_header(files, path):
f = open(path, "w")
f.write("#ifndef ION_SIMULATOR_LINUX_IMAGES_H\n")
f.write("#define ION_SIMULATOR_LINUX_IMAGES_H\n\n")
f.write("// This file is auto-generated by assets.py\n\n")
for asset in files:
print_declaration(f, asset)
f.write("\nstatic struct { const char * identifier; unsigned char * start; unsigned char * end; } resources_addresses[] = {\n")
for asset in files:
print_mapping(f, asset)
f.write("};\n\n")
f.write("#endif\n")
f.close()
if (args.implementation):
print_assembly(args.files, args.implementation)
if (args.header):
print_header(args.files, args.implementation)

View File

@@ -5,18 +5,7 @@
#include <png.h>
#include <assert.h>
#ifndef ASSETS_ADDRESS_RANGES_DECLARATION
#error Missing assets adress range declarations
#endif
ASSETS_ADDRESS_RANGES_DECLARATION
static struct {
const char * identifier;
unsigned char * start;
unsigned char * end;
} resources_addresses[] = {
ASSETS_ADDRESS_RANGES_DEFINITION
};
#include <ion/src/simulator/linux/images.h>
enum class AssetFormat {
JPG,