From 18c8e6b887be0ab037e00cd1f35a17831a045e6c Mon Sep 17 00:00:00 2001 From: Ulysse Cura Date: Thu, 24 Sep 2026 22:27:35 +0200 Subject: [PATCH] updated Makefiles and configure script. --- Makefile | 17 ++++---- asset_builder/Makefile | 4 +- configure | 92 +++++++++++++++++++++++------------------- 3 files changed, 62 insertions(+), 51 deletions(-) diff --git a/Makefile b/Makefile index 707b720..ad587ee 100644 --- a/Makefile +++ b/Makefile @@ -4,14 +4,6 @@ SHELL = /usr/bin/env bash ROOT := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) -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 # @@ -47,6 +39,15 @@ 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) diff --git a/asset_builder/Makefile b/asset_builder/Makefile index dd0ca7e..62beb15 100644 --- a/asset_builder/Makefile +++ b/asset_builder/Makefile @@ -17,14 +17,14 @@ endif $(ASSET_BUILDER_OUTPUT): $(OBJECTS) $(Q)mkdir -p $(dir $@) + $(Q)$(HOST_CC) $(ASSET_BUILDER_CFLAGS) $(OBJECTS) -o $@ $(ASSET_BUILDER_LDFLAGS) @echo "[100%] $(YELLOW)Linking $(notdir $(ASSET_BUILDER_OUTPUT))$(RESET)" - $(Q)$(ASSET_BUILDER_CC) $(ASSET_BUILDER_CFLAGS) $(OBJECTS) -o $@ $(ASSET_BUILDER_LDFLAGS) $(BUILD_DIR)/$(notdir $(ASSET_BUILDER_DIR))/%.o: $(ASSET_BUILDER_DIR)/% $(Q)mkdir -p $(dir $@) $(eval CURRENT_FILE := $(shell echo $$(($(CURRENT_FILE)+1)))) $(eval PERCENTAGE := $(shell echo $$(($(CURRENT_FILE)*100/$(TOTAL_BUILD_FILES))))) + $(Q)$(HOST_CC) $(ASSET_BUILDER_CFLAGS) $(INCLUDES:%=-I%) -MMD -MP -c $< -o $@ @echo "[$(PERCENTAGE)%] $(GREEN)Building C object $@$(RESET)" - $(Q)$(ASSET_BUILDER_CC) $(ASSET_BUILDER_CFLAGS) $(INCLUDES:%=-I%) -MMD -MP -c $< -o $@ -include $(ASSET_BUILDER_OBJECTS:.o=.d) diff --git a/configure b/configure index ed62454..752a40e 100755 --- a/configure +++ b/configure @@ -26,22 +26,27 @@ print_error() } ## Parse args +CURRENT_HOST="guess" TARGET_HOST="guess" for i in "$@"; do case $i in --target-host=*) TARGET_HOST="${i#*=}" - shift # past argument=value + shift + ;; + --current-host=*) + CURRENT_HOST="${i#*=}" + shift ;; --clean) CLEAN=1 EXIT_AFTER_CLEAN=1 - shift # past argument=value + shift ;; --reconfigure) CLEAN=1 - shift # past argument=value + shift ;; -h|--help) echo "Usage : ./configure [OPTION]..." @@ -51,6 +56,9 @@ for i in "$@"; do echo -e "\033[1m --target-host=\033[mHOST" echo -e "\tselect target host platform, default is \"guess\" and" echo -e "\twill try to configure for your current OS" + echo -e "\033[1m --current-host=\033[mHOST" + echo -e "\tselect current host platform, default is \"guess\" and" + echo -e "\twill try to detect your current OS" echo -e "\033[1m --clean\033[m" echo -e "\tclean build, config, cache, etc, and exit" echo -e "\033[1m --reconfigure\033[m" @@ -78,20 +86,22 @@ if [ -n "${EXIT_AFTER_CLEAN}" ]; then fi ## Deduce current and target hosts -case "${OSTYPE}" in - linux*) - CURRENT_HOST="linux" - ;; -# msys*|cygwin*) -# CURRENT_HOST="windows" -# ;; -# darwin*) -# CURRENT_HOST="macos" -# ;; - *) - print_error "Current detected os is unsuppoted to build from: ${OSTYPE}\nUse --help for more informations." - ;; -esac +if [ "${CURRENT_HOST}" = "guess" ]; then + case "${OSTYPE}" in + linux*) + CURRENT_HOST="linux" + ;; +# msys*|cygwin*) +# CURRENT_HOST="windows" +# ;; +# darwin*) +# CURRENT_HOST="macos" +# ;; + *) + print_error "Current detected os is unsuppoted to build from: ${OSTYPE}\nUse --help for more informations." + ;; + esac +fi echo "Configuring for current host: ${CURRENT_HOST}" @@ -101,8 +111,8 @@ fi case "${CURRENT_HOST}" in linux) - ASSET_BUILDER_CC="gcc" - ASSET_BUILDER_AR="ar" + 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)" ;; @@ -117,17 +127,16 @@ case "${TARGET_HOST}" in case "${CURRENT_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" ;; *) - print_error "Cross compiling from ${CURRENT_HOST} to ${TARGET_HOST} is not supported yet." + print_error "Cross compiling from ${CURRENT_HOST} for ${TARGET_HOST} is not supported yet." ;; esac - - TARGET_CC="gcc" - TARGET_AR="ar" - TARGET_CFLAGS="--std=c17 -Os -DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\" -D_GNU_SOURCE=1 \$(shell pkg-config --cflags sdl3 lua)" - TARGET_LDFLAGS="\$(shell pkg-config --libs sdl3 lua) -lm" - TARGET_LIBCORE="libcore.a" ;; fxcg50) @@ -135,17 +144,16 @@ case "${TARGET_HOST}" in case "${CURRENT_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_LIBCORE="libcore.a" ;; *) - print_error "Cross compiling from ${CURRENT_HOST} to ${TARGET_HOST} is not supported yet." + print_error "Cross compiling from ${CURRENT_HOST} for ${TARGET_HOST} is not supported yet." ;; esac - - TARGET_CC="sh-elf-gcc" - TARGET_AR="sh-elf-ar" - TARGET_CFLAGS="--std=c17 -O3" - TARGET_LDFLAGS="" - TARGET_LIBCORE="libcore.a" ;; *) print_error "Unsupported target host: ${TARGET_HOST}" @@ -155,22 +163,24 @@ echo "Writing config file." echo echo "${CONFIG_FILE}:" echo "\`\`\`" -tee ${CONFIG_FILE} <