From 4a00e9f6d40975b49fb5fae246e0263f13fd06ba Mon Sep 17 00:00:00 2001 From: Ulysse Cura Date: Thu, 24 Sep 2026 23:21:55 +0200 Subject: [PATCH 1/5] almost bulding for fxcg50. --- .vscode/c_cpp_properties.json | 7 +++++-- configure | 4 ++-- core/Makefile | 1 - core/host/fxcg50/Makefile | 5 +++++ core/host/fxcg50/display.h | 23 +++++++++++++++++++++++ core/host/fxcg50/inputs.c | 16 ++++++++++++++++ core/{ => host/fxcg50}/inputs.h | 7 +------ core/host/fxcg50/keycodes.h | 15 +++++++++++++++ core/host/fxcg50/memory_alloc.h | 6 ++++++ core/host/fxcg50/texture.h | 16 ++++++++++++++++ core/host/fxcg50/update_time.c | 13 +++++++++++++ core/host/fxcg50/update_time.h | 6 ++++++ core/host/fxcg50/vector2d.h | 2 +- core/host/generic/display.h | 3 --- core/host/generic/inputs.h | 19 +++++++++++++++++++ core/host/generic/keycodes.h | 17 +++++++++++++++++ core/host/generic/update_time.h | 6 ++++++ core/host/linux/Makefile | 2 ++ core/{ => host/linux}/inputs.c | 0 core/host/linux/inputs.h | 17 +++++++++++++++++ core/{ => host/linux}/keycodes.h | 4 ++++ core/host/linux/update_time.c | 13 +++++++++++++ core/host/linux/update_time.h | 6 ++++++ core/main.c | 11 +---------- src/Makefile | 2 +- src/components/components.def | 4 ++-- src/components/components.h | 2 +- 27 files changed, 198 insertions(+), 29 deletions(-) create mode 100644 core/host/fxcg50/Makefile create mode 100644 core/host/fxcg50/display.h create mode 100644 core/host/fxcg50/inputs.c rename core/{ => host/fxcg50}/inputs.h (58%) create mode 100644 core/host/fxcg50/keycodes.h create mode 100644 core/host/fxcg50/memory_alloc.h create mode 100644 core/host/fxcg50/texture.h create mode 100644 core/host/fxcg50/update_time.c create mode 100644 core/host/fxcg50/update_time.h create mode 100644 core/host/generic/inputs.h create mode 100644 core/host/generic/keycodes.h create mode 100644 core/host/generic/update_time.h rename core/{ => host/linux}/inputs.c (100%) create mode 100644 core/host/linux/inputs.h rename core/{ => host/linux}/keycodes.h (71%) create mode 100644 core/host/linux/update_time.c create mode 100644 core/host/linux/update_time.h diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index d22e7be..bfc7dfd 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -13,11 +13,14 @@ "/usr/include/spa-0.2", "/usr/include/libdrm", "/usr/include/libdecor-0", - "/usr/include/x86_64-linux-gnu" + "/usr/include/x86_64-linux-gnu", + "${env:HOME}/.local/share/fxsdk/sysroot/sh3eb-elf/include" ], "compilerPath": "/usr/bin/gcc", "defines": [ - "-D_REENTRANT" + "_REENTRANT", + "FXCG50", + "TARGET_FXCG50" ], "cStandard": "c17", "browse": { diff --git a/configure b/configure index 752a40e..a9ef698 100755 --- a/configure +++ b/configure @@ -146,8 +146,8 @@ case "${TARGET_HOST}" in linux) TARGET_HOST_CC="sh-elf-gcc" TARGET_HOST_AR="sh-elf-ar" - TARGET_HOST_CFLAGS="--std=c17 -Os" - TARGET_HOST_LDFLAGS="" + TARGET_HOST_CFLAGS="--std=c17 -Os -DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\" -mb -ffreestanding -nostdlib -fstrict-volatile-bitfields -DFXCG50 -DTARGET_FXCG50 -m4-nofpu" + TARGET_HOST_LDFLAGS="-T fxcg50.ld -lgint-cg -lgcc" TARGET_HOST_LIBCORE="libcore.a" ;; *) diff --git a/core/Makefile b/core/Makefile index a8ff7cd..19753d0 100644 --- a/core/Makefile +++ b/core/Makefile @@ -5,7 +5,6 @@ SOURCES += \ event_bus.c \ ecs.c \ asset_manager.c \ - inputs.c \ map.c INCLUDES += \ diff --git a/core/host/fxcg50/Makefile b/core/host/fxcg50/Makefile new file mode 100644 index 0000000..6613fbb --- /dev/null +++ b/core/host/fxcg50/Makefile @@ -0,0 +1,5 @@ +SOURCES += $(addprefix host/$(TARGET_HOST)/, \ + vector2d.c \ + inputs.c \ + update_time.c \ +) diff --git a/core/host/fxcg50/display.h b/core/host/fxcg50/display.h new file mode 100644 index 0000000..8f3e0e4 --- /dev/null +++ b/core/host/fxcg50/display.h @@ -0,0 +1,23 @@ +#ifndef DISPLAY_H +#define DISPLAY_H + +#include +#include "texture.h" +#include "vector2d.h" + +#define DISPLAY_WIDTH DWIDTH +#define DISPLAY_HEIGHT DHEIGHT + +typedef struct display_t { +} display_t; + +int display_init(void); +void display_exit(void); + +int display_clear(void); +int display_update(void); + +int display_draw_texture(texture_t *texture, const rect_t *src_rect, const rect_t *dst_rect, bool flip); +int display_draw_frect(const frect_t *frect, unsigned int r, unsigned int g, unsigned int b, unsigned int a); + +#endif // DISPLAY_H \ No newline at end of file diff --git a/core/host/fxcg50/inputs.c b/core/host/fxcg50/inputs.c new file mode 100644 index 0000000..5caf27b --- /dev/null +++ b/core/host/fxcg50/inputs.c @@ -0,0 +1,16 @@ +#include "inputs.h" + +#include + +inline int poll_event(input_event_t *event) +{ + key_event_t gint_event = pollevent(); + + if(gint_event.type = KEYEV_NONE) + return 0; + + event->type = gint_event.type; + event->key = gint_event.key; + + return 1; +} diff --git a/core/inputs.h b/core/host/fxcg50/inputs.h similarity index 58% rename from core/inputs.h rename to core/host/fxcg50/inputs.h index ef2c7c7..92d1b67 100644 --- a/core/inputs.h +++ b/core/host/fxcg50/inputs.h @@ -1,16 +1,11 @@ #ifndef KEYBOARD_H #define KEYBOARD_H -#include #include "keycodes.h" -#define INPUT_EVENT_KEY_UP SDL_EVENT_KEY_UP -#define INPUT_EVENT_KEY_DOWN SDL_EVENT_KEY_DOWN -#define INPUT_EVENT_QUIT SDL_EVENT_QUIT - typedef struct input_event_t { uint32_t type; - SDL_Scancode key; + int key; } input_event_t; int poll_event(input_event_t *event); diff --git a/core/host/fxcg50/keycodes.h b/core/host/fxcg50/keycodes.h new file mode 100644 index 0000000..113e16a --- /dev/null +++ b/core/host/fxcg50/keycodes.h @@ -0,0 +1,15 @@ +#ifndef KEYCODES_H +#define KEYCODES_H + +#include + +#define MAX_KEYCODES 0xB0 + +#define KEY_MOD KEY_SHIFT +#define KEY_INTERACT KEY_ALPHA + +#define INPUT_EVENT_KEY_UP KEYEV_UP +#define INPUT_EVENT_KEY_DOWN KEYEV_DOWN +#define INPUT_EVENT_QUIT 0xFF + +#endif // KEYCODES_H \ No newline at end of file diff --git a/core/host/fxcg50/memory_alloc.h b/core/host/fxcg50/memory_alloc.h new file mode 100644 index 0000000..ef8e8b6 --- /dev/null +++ b/core/host/fxcg50/memory_alloc.h @@ -0,0 +1,6 @@ +#ifndef MEMORY_ALLOC_H +#define MEMORY_ALLOC_H + +#include + +#endif // MEMORY_ALLOC_H \ No newline at end of file diff --git a/core/host/fxcg50/texture.h b/core/host/fxcg50/texture.h new file mode 100644 index 0000000..ffa870a --- /dev/null +++ b/core/host/fxcg50/texture.h @@ -0,0 +1,16 @@ +#ifndef TEXTURE_H +#define TEXTURE_H + +#include + +#define TEXTURE_TRANSPARENT_COLOR 0x0001 + +typedef bopti_image_t texture_t; + +#define get_width(T) T->width +#define get_height(T) T->height + +texture_t *load_texture(void); +void destroy_texture(texture_t *texture); + +#endif // TEXTURE_H \ No newline at end of file diff --git a/core/host/fxcg50/update_time.c b/core/host/fxcg50/update_time.c new file mode 100644 index 0000000..c4ad525 --- /dev/null +++ b/core/host/fxcg50/update_time.c @@ -0,0 +1,13 @@ +#include "update_time.h" + +#include +#include "game.h" + +inline void update_time(void) +{ + static clock_t last_clock_state = 0; + clock_t start_clock = clock(); + game.delta_time_ms = (float)(start_clock - last_clock_state) / (float)CLOCKS_PER_SEC; + if(game.delta_time_ms > 100.0f) game.delta_time_ms = 100.0f; + last_clock_state = start_clock; +} diff --git a/core/host/fxcg50/update_time.h b/core/host/fxcg50/update_time.h new file mode 100644 index 0000000..0b22fb9 --- /dev/null +++ b/core/host/fxcg50/update_time.h @@ -0,0 +1,6 @@ +#ifndef TIME_H +#define TIME_H + +void update_time(void); + +#endif // TIME_H \ No newline at end of file diff --git a/core/host/fxcg50/vector2d.h b/core/host/fxcg50/vector2d.h index 81a5c2d..5370552 100644 --- a/core/host/fxcg50/vector2d.h +++ b/core/host/fxcg50/vector2d.h @@ -1,7 +1,7 @@ #ifndef VECTOR2D_H #define VECTOR2D_H -#include +#include #include /** diff --git a/core/host/generic/display.h b/core/host/generic/display.h index 6ab412f..a155b51 100644 --- a/core/host/generic/display.h +++ b/core/host/generic/display.h @@ -13,9 +13,6 @@ #define DISPLAY_WIDTH 720 #define DISPLAY_HEIGHT 480 -//#define DRIVERS NULL -#define DRIVERS "vulkan,gpu,software" - typedef struct display_t { } display_t; diff --git a/core/host/generic/inputs.h b/core/host/generic/inputs.h new file mode 100644 index 0000000..ac0c8d0 --- /dev/null +++ b/core/host/generic/inputs.h @@ -0,0 +1,19 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +#include +#include +#include "keycodes.h" + +typedef struct input_event_t { + uint32_t type; + int key; +} input_event_t; + +int poll_event(input_event_t *event); + +typedef struct inputs_t { + bool keys[MAX_KEYCODES]; +} inputs_t; + +#endif // KEYBOARD_H \ No newline at end of file diff --git a/core/host/generic/keycodes.h b/core/host/generic/keycodes.h new file mode 100644 index 0000000..2cbf8c2 --- /dev/null +++ b/core/host/generic/keycodes.h @@ -0,0 +1,17 @@ +#ifndef KEYCODES_H +#define KEYCODES_H + +#define MAX_KEYCODES 0xFF + +#define KEY_UP 0x01 +#define KEY_DOWN 0x02 +#define KEY_LEFT 0x03 +#define KEY_RIGHT 0x04 +#define KEY_MOD 0x05 +#define KEY_INTERACT 0x06 + +#define INPUT_EVENT_KEY_UP 0x01 +#define INPUT_EVENT_KEY_DOWN 0x02 +#define INPUT_EVENT_QUIT 0xFF + +#endif // KEYCODES_H \ No newline at end of file diff --git a/core/host/generic/update_time.h b/core/host/generic/update_time.h new file mode 100644 index 0000000..0b22fb9 --- /dev/null +++ b/core/host/generic/update_time.h @@ -0,0 +1,6 @@ +#ifndef TIME_H +#define TIME_H + +void update_time(void); + +#endif // TIME_H \ No newline at end of file diff --git a/core/host/linux/Makefile b/core/host/linux/Makefile index 7b7c188..7961d48 100644 --- a/core/host/linux/Makefile +++ b/core/host/linux/Makefile @@ -2,4 +2,6 @@ SOURCES += $(addprefix host/$(TARGET_HOST)/, \ display.c \ vector2d.c \ texture.c \ + inputs.c \ + update_time.c \ ) diff --git a/core/inputs.c b/core/host/linux/inputs.c similarity index 100% rename from core/inputs.c rename to core/host/linux/inputs.c diff --git a/core/host/linux/inputs.h b/core/host/linux/inputs.h new file mode 100644 index 0000000..92d1b67 --- /dev/null +++ b/core/host/linux/inputs.h @@ -0,0 +1,17 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +#include "keycodes.h" + +typedef struct input_event_t { + uint32_t type; + int key; +} input_event_t; + +int poll_event(input_event_t *event); + +typedef struct inputs_t { + bool keys[MAX_KEYCODES]; +} inputs_t; + +#endif // KEYBOARD_H \ No newline at end of file diff --git a/core/keycodes.h b/core/host/linux/keycodes.h similarity index 71% rename from core/keycodes.h rename to core/host/linux/keycodes.h index 9783ac5..7ac90de 100644 --- a/core/keycodes.h +++ b/core/host/linux/keycodes.h @@ -12,4 +12,8 @@ #define KEY_MOD SDL_SCANCODE_LCTRL #define KEY_INTERACT SDL_SCANCODE_E +#define INPUT_EVENT_KEY_UP SDL_EVENT_KEY_UP +#define INPUT_EVENT_KEY_DOWN SDL_EVENT_KEY_DOWN +#define INPUT_EVENT_QUIT SDL_EVENT_QUIT + #endif // KEYCODES_H \ No newline at end of file diff --git a/core/host/linux/update_time.c b/core/host/linux/update_time.c new file mode 100644 index 0000000..0d74c0c --- /dev/null +++ b/core/host/linux/update_time.c @@ -0,0 +1,13 @@ +#include "update_time.h" + +#include +#include "game.h" + +inline void update_time(void) +{ + static uint32_t last_clock_state = 0; + uint64_t start_clock = SDL_GetTicksNS(); + game.delta_time_ms = SDL_NS_TO_MS((float)(start_clock - last_clock_state)); + if(game.delta_time_ms > 100.0f) game.delta_time_ms = 100.0f; + last_clock_state = start_clock; +} diff --git a/core/host/linux/update_time.h b/core/host/linux/update_time.h new file mode 100644 index 0000000..0b22fb9 --- /dev/null +++ b/core/host/linux/update_time.h @@ -0,0 +1,6 @@ +#ifndef TIME_H +#define TIME_H + +void update_time(void); + +#endif // TIME_H \ No newline at end of file diff --git a/core/main.c b/core/main.c index 09cb5b6..5020ddb 100644 --- a/core/main.c +++ b/core/main.c @@ -1,20 +1,11 @@ #include "game.h" -#include #include +#include "update_time.h" #include "errors.h" game_t game; -static inline void update_time(void) -{ - static uint64_t last_clock_state = 0; - uint64_t start_clock = SDL_GetTicksNS(); - game.delta_time_ms = SDL_NS_TO_MS((float)(start_clock - last_clock_state)); - if(game.delta_time_ms > 100.0f) game.delta_time_ms = 100.0f; - last_clock_state = start_clock; -} - int main(void) { if(game_init()) goto_failure; diff --git a/src/Makefile b/src/Makefile index 4ff26f5..9753616 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,7 +8,7 @@ SOURCES += \ components/animation_system.c \ components/player_system.c \ components/lever_component.c \ - components/door_component.c \ + components/door_component.c# \ components/lua_component.c INCLUDES += \ diff --git a/src/components/components.def b/src/components/components.def index a00f213..9c63831 100644 --- a/src/components/components.def +++ b/src/components/components.def @@ -6,12 +6,12 @@ COMPONENT(TRANSFORM_COMPONENT, transform_component, DRAW) COMPONENT(HITBOX_COMPONENT, hitbox_component, DRAW) COMPONENT(INTERACT_COMPONENT, interact_component, DRAW) -COMPONENT(LUA_COMPONENT, lua_component, DRAW) +//COMPONENT(LUA_COMPONENT, lua_component, DRAW) #else COMPONENT(TRANSFORM_COMPONENT, transform_component, NO_DRAW) COMPONENT(HITBOX_COMPONENT, hitbox_component, NO_DRAW) COMPONENT(INTERACT_COMPONENT, interact_component, NO_DRAW) -COMPONENT(LUA_COMPONENT, lua_component, NO_DRAW) +//COMPONENT(LUA_COMPONENT, lua_component, NO_DRAW) #endif // DEBUG >= 2 COMPONENT(PHYSICS_SYSTEM, physics_system, NO_DRAW) diff --git a/src/components/components.h b/src/components/components.h index 0082d1c..e15df97 100644 --- a/src/components/components.h +++ b/src/components/components.h @@ -10,7 +10,7 @@ #include "player_system.h" #include "lever_component.h" #include "door_component.h" -#include "lua_component.h" +//#include "lua_component.h" // Add new components header file here #endif // COMPONENTS_H \ No newline at end of file From c8c6620ba7578a49557434e1c17c1f33e064ffb6 Mon Sep 17 00:00:00 2001 From: Ulysse Cura Date: Thu, 24 Sep 2026 23:30:03 +0200 Subject: [PATCH 2/5] Fixed config importation in Makefile. --- Makefile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index ad587ee..d5fc73c 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,15 @@ SHELL = /usr/bin/env bash ROOT := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) +# Import config +ifeq ($(filter clean-all,$(MAKECMDGOALS)),) +ifneq ($(realpath $(ROOT)/config.mk), $(ROOT)/config.mk) +$(error ERROR: Please run the configure script before building) +endif + +include $(ROOT)/config.mk +endif + # # User settings # @@ -39,15 +48,6 @@ endif # End # -# Import config -ifeq ($(filter clean-all,$(MAKECMDGOALS)),) -ifneq ($(realpath $(ROOT)/config.mk), $(ROOT)/config.mk) -$(error ERROR: Please run the configure script before building) -endif - -include $(ROOT)/config.mk -endif - # Relocate vars BUILD_DIR := $(ROOT)/$(BUILD_DIR)/$(TARGET_HOST) From 699ac6c7cd2326e1573173b6acb28c1466ec4f2d Mon Sep 17 00:00:00 2001 From: Ulysse Cura Date: Thu, 24 Sep 2026 23:30:17 +0200 Subject: [PATCH 3/5] Fixed update time implementation. --- core/host/linux/update_time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/host/linux/update_time.c b/core/host/linux/update_time.c index 0d74c0c..3778b80 100644 --- a/core/host/linux/update_time.c +++ b/core/host/linux/update_time.c @@ -5,7 +5,7 @@ inline void update_time(void) { - static uint32_t last_clock_state = 0; + static uint64_t last_clock_state = 0; uint64_t start_clock = SDL_GetTicksNS(); game.delta_time_ms = SDL_NS_TO_MS((float)(start_clock - last_clock_state)); if(game.delta_time_ms > 100.0f) game.delta_time_ms = 100.0f; From 70e9691cf5cd800fbe1623012f34c1b5c2a318f7 Mon Sep 17 00:00:00 2001 From: Ulysse Cura Date: Thu, 24 Sep 2026 23:30:51 +0200 Subject: [PATCH 4/5] Load dungeon_room_1. --- src/game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game.c b/src/game.c index fe12cb7..ed9e800 100644 --- a/src/game.c +++ b/src/game.c @@ -21,7 +21,7 @@ int game_init(void) entity_manager_init(); if(asset_manager_init()) return_failure_int; - asset_t *map_asset = asset_manager_load_asset("dungeon_entry", ASSET_MAP); + asset_t *map_asset = asset_manager_load_asset("dungeon_room_1", ASSET_MAP); if(!map_asset) return_failure_int; game.map = map_asset->data; From 6e1ed2079d2234d2238db33ec503b385455d1fd7 Mon Sep 17 00:00:00 2001 From: Ulysse Cura Date: Fri, 25 Sep 2026 21:29:43 +0200 Subject: [PATCH 5/5] Added checks for compilers archiver and libs. --- Makefile | 7 +- configure | 250 ++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 188 insertions(+), 69 deletions(-) diff --git a/Makefile b/Makefile index d5fc73c..b458077 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,6 @@ ASSET_BUILDER_DIR = asset_builder OUTPUT = 2D_Engine ASSET_OUTPUT = game.data -ASSET_BUILDER_OUTPUT = asset_builder/asset_builder ifneq ($(DEBUG),) TARGET_HOST_CFLAGS += -O1 -g -DDEBUG=$(DEBUG) -Wextra -Wall --pedantic -Wno-missing-braces \ @@ -56,10 +55,10 @@ CORE_DIR := $(ROOT)/$(CORE_DIR) ASSETS_DIR := $(ROOT)/$(ASSETS_DIR) ASSET_BUILDER_DIR := $(ROOT)/$(ASSET_BUILDER_DIR) -OUTPUT := $(BUILD_DIR)/$(OUTPUT) -LIBCORE := $(BUILD_DIR)/$(LIBCORE) +OUTPUT := $(BUILD_DIR)/$(OUTPUT)$(OUTPUT_EXT) +LIBCORE := $(BUILD_DIR)/libcore$(LIB_OUTPUT_EXT) ASSET_OUTPUT := $(BUILD_DIR)/$(ASSET_OUTPUT) -ASSET_BUILDER_OUTPUT := $(BUILD_DIR)/$(ASSET_BUILDER_OUTPUT) +ASSET_BUILDER_OUTPUT := $(BUILD_DIR)/asset_builder/asset_builder$(OUTPUT_EXT) # Verbosity export Q := @ diff --git a/configure b/configure index a9ef698..866222b 100755 --- a/configure +++ b/configure @@ -11,22 +11,23 @@ # CONFIG_FILE="config.mk" - -#LUA_VERSION="5.5.1" -#LUA_CHECKSUM="1c4b4068d67061f2a2231ad2b5422e77acea1487ea9890f6320af614f4373dce" +CACHE_DIR="cache" +LIB_DIR="lib" # # Main # -print_error() +set -e + +exit_error_message() { echo -e "\033[31merror\033[m: $1" exit 0 } ## Parse args -CURRENT_HOST="guess" +HOST="guess" TARGET_HOST="guess" for i in "$@"; do @@ -36,7 +37,7 @@ for i in "$@"; do shift ;; --current-host=*) - CURRENT_HOST="${i#*=}" + HOST="${i#*=}" shift ;; --clean) @@ -68,7 +69,7 @@ for i in "$@"; do exit 0 ;; -*) - print_error "Unknown option $i" + exit_error_message "Unknown option $i" ;; *) ;; @@ -78,7 +79,7 @@ done ## Clean if [ -n "${CLEAN}" ]; then make clean-all - rm -rf ${CONFIG_FILE} + rm -rf ${CONFIG_FILE} ${CACHE_DIR} ${LIB_DIR} fi if [ -n "${EXIT_AFTER_CLEAN}" ]; then @@ -86,10 +87,10 @@ if [ -n "${EXIT_AFTER_CLEAN}" ]; then fi ## Deduce current and target hosts -if [ "${CURRENT_HOST}" = "guess" ]; then +if [ "${HOST}" = "guess" ]; then case "${OSTYPE}" in linux*) - CURRENT_HOST="linux" + HOST="linux" ;; # msys*|cygwin*) # CURRENT_HOST="windows" @@ -98,67 +99,212 @@ if [ "${CURRENT_HOST}" = "guess" ]; then # CURRENT_HOST="macos" # ;; *) - print_error "Current detected os is unsuppoted to build from: ${OSTYPE}\nUse --help for more informations." + exit_error_message "Current detected os is unsuppoted to build from: ${OSTYPE}\nUse --help for more informations." ;; esac fi -echo "Configuring for current host: ${CURRENT_HOST}" +echo "Configuring for current host: ${HOST}" +# If target host is guess then configure for host if [ "${TARGET_HOST}" = "guess" ]; then - TARGET_HOST=${CURRENT_HOST} + TARGET_HOST=${HOST} fi -case "${CURRENT_HOST}" in +# Set host compiler and asset builder flags +case "${HOST}" in linux) - HOST_CC="gcc" - HOST_AR="ar" - ASSET_BUILDER_CFLAGS="--std=c17 -O2 \$(shell pkg-config --cflags libpng json-c)" - ASSET_BUILDER_LDFLAGS="\$(shell pkg-config --libs libpng json-c)" + HOST_CC=gcc + ASSET_BUILDER_CFLAGS=( + "--std=c17" + "-O2" + ) + ASSET_BUILDER_LDFLAGS=() + ASSET_BUILDER_LIBS=( + "libpng|1.6.48" + "json-c|0.18" + ) ;; *) - print_error "Compiling from ${CURRENT_HOST} is not supported yet." + exit_error_message "Compiling from ${HOST} is not supported yet." ;; esac +# Set target host compiler, outputs extensions and flags case "${TARGET_HOST}" in linux) echo "Configuring for target: ${TARGET_HOST}" - case "${CURRENT_HOST}" in + case "${HOST}" in linux) - TARGET_HOST_CC="gcc" - TARGET_HOST_AR="ar" - TARGET_HOST_CFLAGS="--std=c17 -Os -DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\" -D_GNU_SOURCE=1 \$(shell pkg-config --cflags sdl3 lua)" - TARGET_HOST_LDFLAGS="\$(shell pkg-config --libs sdl3 lua) -lm" - TARGET_HOST_LIBCORE="libcore.a" + TARGET_HOST_CC=gcc + TARGET_HOST_AR=ar + TARGET_HOST_CFLAGS=( + "--std=c17" "-Os" + "-DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\"" "-D_GNU_SOURCE=1" + ) + TARGET_HOST_LDFLAGS=() + OUTPUT_EXT="" + LIB_OUTPUT_EXT=".a" ;; *) - print_error "Cross compiling from ${CURRENT_HOST} for ${TARGET_HOST} is not supported yet." + exit_error_message "Cross compiling from ${HOST} for ${TARGET_HOST} is not supported yet." ;; esac + + TARGET_HOST_LIBS=( + "sdl3|3.2.10" + "lua|5.4.7" + ) ;; fxcg50) echo "Configuring for target: ${TARGET_HOST}" - case "${CURRENT_HOST}" in + case "${HOST}" in linux) - TARGET_HOST_CC="sh-elf-gcc" - TARGET_HOST_AR="sh-elf-ar" - TARGET_HOST_CFLAGS="--std=c17 -Os -DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\" -mb -ffreestanding -nostdlib -fstrict-volatile-bitfields -DFXCG50 -DTARGET_FXCG50 -m4-nofpu" - TARGET_HOST_LDFLAGS="-T fxcg50.ld -lgint-cg -lgcc" - TARGET_HOST_LIBCORE="libcore.a" + TARGET_HOST_CC=sh-elf-gcc + TARGET_HOST_AR=sh-elf-ar + TARGET_HOST_CFLAGS=( + "--std=c17" "-Os" + "-DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\"" "-DFXCG50" "-DTARGET_FXCG50" + "-mb" "-m4-nofpu" + "-ffreestanding" "-nostdlib" "-fstrict-volatile-bitfields" + ) + TARGET_HOST_LDFLAGS="-T fxcg50.ld" + OUTPUT_EXT="" + LIB_OUTPUT_EXT=".a" ;; *) - print_error "Cross compiling from ${CURRENT_HOST} for ${TARGET_HOST} is not supported yet." + exit_error_message "Cross compiling from ${HOST} for ${TARGET_HOST} is not supported yet." ;; esac ;; *) - print_error "Unsupported target host: ${TARGET_HOST}" + exit_error_message "Unsupported target host: ${TARGET_HOST}" esac +# +# Checks +# + +echo + +echo "Checking host compiler \"${HOST_CC}\"." +if ${HOST_CC} --version &> /dev/null; then + echo " ${HOST_CC} OK." +else + exit_error_message "Compiler not working." +fi + +echo "Checking asset builder libs." +for LIB in ${ASSET_BUILDER_LIBS[@]}; do + LIB_NAME="$(echo ${LIB} | cut -d "|" -f 1)" + LIB_MIN_VERSION="$(echo ${LIB} | cut -d "|" -f 2)" + + if pkg-config --atleast-version "${LIB_MIN_VERSION}" "${LIB_NAME}"; then + echo " ${LIB_NAME} OK." + else + LIB_URL=$(echo $LIB | cut -d "|" -f 3) + + if [ "${LIB_URL}" = "" ]; then + exit_error_message "Library ${LIB_NAME} version >= ${LIB_MIN_VERSION} was not found and no precompiled binaries are available." + else + LIB_DOWNLOAD_CHECKSUM=$(echo $LIB | cut -d "|" -f 4) + LIB_DOWNLOAD_FILENAME="$(echo ${LIB_URL} | rev | cut -d "/" -f 1 | rev)" + LIB_DOWNLOAD_PATH="${CACHE_DIR}/${TARGET_HOST}/${LIB_DOWNLOAD_FILENAME}" + + case "${LIB_DOWNLOAD_FILENAME}" in + *.txz) + LIB_FOLDER_NAME="${LIB_DOWNLOAD_FILENAME%.txz}" + ;; + *) + exit_error_message "File ${LIB_DOWNLOAD_FILENAME} extension substitution is not supported." + esac + LIB_PATH="${LIB_DIR}/${TARGET_HOST}/${LIB_FOLDER_NAME}" + + echo " ${LIB_NAME} version >= ${LIB_MIN_VERSION} was not found but precompiled binaries are available." + + if [ ! -f "${LIB_DOWNLOAD_PATH}" ]; then + echo " downloading from ${LIB_URL}." + mkdir -p "$(dirname "${LIB_DOWNLOAD_PATH}")" + wget -q -O"${LIB_DOWNLOAD_PATH}" "${LIB_URL}" + fi + + if echo "${LIB_DOWNLOAD_CHECKSUM} ${LIB_DOWNLOAD_PATH}" | md5sum --check &> /dev/null; then + echo " ${LIB_DOWNLOAD_PATH} OK." + else + rm -rf "${LIB_DOWNLOAD_PATH}" + exit_error_message "Failed to verify checksum of ${LIB_DOWNLOAD_PATH}." + fi + + mkdir -p "${LIB_PATH}" + tar -xf "${LIB_DOWNLOAD_PATH}" -C "${LIB_PATH}" + fi + fi +done + +echo "Checking target host compiler \"${TARGET_HOST_CC}\"." +if ${TARGET_HOST_CC} --version &> /dev/null; then + echo " ${TARGET_HOST_CC} OK." +else + exit_error_message "Compiler not working." +fi + +echo "Checking target host archiver \"${TARGET_HOST_AR}\"." +if ${TARGET_HOST_AR} --version &> /dev/null; then + echo " ${TARGET_HOST_AR} OK." +else + exit_error_message "Compiler not working." +fi + +echo "Checking target host libs." +for LIB in ${TARGET_HOST_LIBS[@]}; do + LIB_NAME="$(echo ${LIB} | cut -d "|" -f 1)" + LIB_MIN_VERSION="$(echo ${LIB} | cut -d "|" -f 2)" + + if pkg-config --atleast-version "${LIB_MIN_VERSION}" "${LIB_NAME}"; then + echo " ${LIB_NAME} OK." + else + LIB_URL=$(echo $LIB | cut -d "|" -f 3) + + if [ "${LIB_URL}" = "" ]; then + exit_error_message "Library ${LIB_NAME} version >= ${LIB_MIN_VERSION} was not found and no precompiled binaries are available." + else + LIB_DOWNLOAD_CHECKSUM=$(echo $LIB | cut -d "|" -f 4) + LIB_DOWNLOAD_FILENAME="$(echo ${LIB_URL} | rev | cut -d "/" -f 1 | rev)" + LIB_DOWNLOAD_PATH="${CACHE_DIR}/${TARGET_HOST}/${LIB_DOWNLOAD_FILENAME}" + + case "${LIB_DOWNLOAD_FILENAME}" in + *.txz) + LIB_FOLDER_NAME="${LIB_DOWNLOAD_FILENAME%.txz}" + ;; + *) + exit_error_message "File ${LIB_DOWNLOAD_FILENAME} extension substitution is not supported." + esac + LIB_PATH="${LIB_DIR}/${TARGET_HOST}/${LIB_FOLDER_NAME}" + + echo " ${LIB_NAME} version >= ${LIB_MIN_VERSION} was not found but precompiled binaries are available." + + if [ ! -f "${LIB_DOWNLOAD_PATH}" ]; then + echo " downloading from ${LIB_URL}." + mkdir -p "$(dirname "${LIB_DOWNLOAD_PATH}")" + wget -q -O"${LIB_DOWNLOAD_PATH}" "${LIB_URL}" + fi + + if echo "${LIB_DOWNLOAD_CHECKSUM} ${LIB_DOWNLOAD_PATH}" | md5sum --check &> /dev/null; then + echo " ${LIB_DOWNLOAD_PATH} OK." + else + rm -rf "${LIB_DOWNLOAD_PATH}" + exit_error_message "Failed to verify checksum of ${LIB_DOWNLOAD_PATH}." + fi + + mkdir -p "${LIB_PATH}" + tar -xf "${LIB_DOWNLOAD_PATH}" -C "${LIB_PATH}" + fi + fi +done + echo "Writing config file." echo echo "${CONFIG_FILE}:" @@ -168,43 +314,17 @@ tee "${CONFIG_FILE}" <