updated Makefiles and configure script.

This commit is contained in:
Ulysse Cura 2026-09-24 22:27:35 +02:00
parent f599b85b67
commit 18c8e6b887
3 changed files with 62 additions and 51 deletions

View File

@ -4,14 +4,6 @@ SHELL = /usr/bin/env bash
ROOT := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) 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 # User settings
# #
@ -47,6 +39,15 @@ endif
# End # 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 # Relocate vars
BUILD_DIR := $(ROOT)/$(BUILD_DIR)/$(TARGET_HOST) BUILD_DIR := $(ROOT)/$(BUILD_DIR)/$(TARGET_HOST)

View File

@ -17,14 +17,14 @@ endif
$(ASSET_BUILDER_OUTPUT): $(OBJECTS) $(ASSET_BUILDER_OUTPUT): $(OBJECTS)
$(Q)mkdir -p $(dir $@) $(Q)mkdir -p $(dir $@)
$(Q)$(HOST_CC) $(ASSET_BUILDER_CFLAGS) $(OBJECTS) -o $@ $(ASSET_BUILDER_LDFLAGS)
@echo "[100%] $(YELLOW)Linking $(notdir $(ASSET_BUILDER_OUTPUT))$(RESET)" @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)/% $(BUILD_DIR)/$(notdir $(ASSET_BUILDER_DIR))/%.o: $(ASSET_BUILDER_DIR)/%
$(Q)mkdir -p $(dir $@) $(Q)mkdir -p $(dir $@)
$(eval CURRENT_FILE := $(shell echo $$(($(CURRENT_FILE)+1)))) $(eval CURRENT_FILE := $(shell echo $$(($(CURRENT_FILE)+1))))
$(eval PERCENTAGE := $(shell echo $$(($(CURRENT_FILE)*100/$(TOTAL_BUILD_FILES))))) $(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)" @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) -include $(ASSET_BUILDER_OBJECTS:.o=.d)

68
configure vendored
View File

@ -26,22 +26,27 @@ print_error()
} }
## Parse args ## Parse args
CURRENT_HOST="guess"
TARGET_HOST="guess" TARGET_HOST="guess"
for i in "$@"; do for i in "$@"; do
case $i in case $i in
--target-host=*) --target-host=*)
TARGET_HOST="${i#*=}" TARGET_HOST="${i#*=}"
shift # past argument=value shift
;;
--current-host=*)
CURRENT_HOST="${i#*=}"
shift
;; ;;
--clean) --clean)
CLEAN=1 CLEAN=1
EXIT_AFTER_CLEAN=1 EXIT_AFTER_CLEAN=1
shift # past argument=value shift
;; ;;
--reconfigure) --reconfigure)
CLEAN=1 CLEAN=1
shift # past argument=value shift
;; ;;
-h|--help) -h|--help)
echo "Usage : ./configure [OPTION]..." echo "Usage : ./configure [OPTION]..."
@ -51,6 +56,9 @@ for i in "$@"; do
echo -e "\033[1m --target-host=\033[mHOST" echo -e "\033[1m --target-host=\033[mHOST"
echo -e "\tselect target host platform, default is \"guess\" and" echo -e "\tselect target host platform, default is \"guess\" and"
echo -e "\twill try to configure for your current OS" 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 "\033[1m --clean\033[m"
echo -e "\tclean build, config, cache, etc, and exit" echo -e "\tclean build, config, cache, etc, and exit"
echo -e "\033[1m --reconfigure\033[m" echo -e "\033[1m --reconfigure\033[m"
@ -78,7 +86,8 @@ if [ -n "${EXIT_AFTER_CLEAN}" ]; then
fi fi
## Deduce current and target hosts ## Deduce current and target hosts
case "${OSTYPE}" in if [ "${CURRENT_HOST}" = "guess" ]; then
case "${OSTYPE}" in
linux*) linux*)
CURRENT_HOST="linux" CURRENT_HOST="linux"
;; ;;
@ -91,7 +100,8 @@ case "${OSTYPE}" in
*) *)
print_error "Current detected os is unsuppoted to build from: ${OSTYPE}\nUse --help for more informations." print_error "Current detected os is unsuppoted to build from: ${OSTYPE}\nUse --help for more informations."
;; ;;
esac esac
fi
echo "Configuring for current host: ${CURRENT_HOST}" echo "Configuring for current host: ${CURRENT_HOST}"
@ -101,8 +111,8 @@ fi
case "${CURRENT_HOST}" in case "${CURRENT_HOST}" in
linux) linux)
ASSET_BUILDER_CC="gcc" HOST_CC="gcc"
ASSET_BUILDER_AR="ar" HOST_AR="ar"
ASSET_BUILDER_CFLAGS="--std=c17 -O2 \$(shell pkg-config --cflags libpng json-c)" ASSET_BUILDER_CFLAGS="--std=c17 -O2 \$(shell pkg-config --cflags libpng json-c)"
ASSET_BUILDER_LDFLAGS="\$(shell pkg-config --libs 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 case "${CURRENT_HOST}" in
linux) 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 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) fxcg50)
@ -135,17 +144,16 @@ case "${TARGET_HOST}" in
case "${CURRENT_HOST}" in case "${CURRENT_HOST}" in
linux) 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 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}" print_error "Unsupported target host: ${TARGET_HOST}"
@ -155,22 +163,24 @@ echo "Writing config file."
echo echo
echo "${CONFIG_FILE}:" echo "${CONFIG_FILE}:"
echo "\`\`\`" echo "\`\`\`"
tee ${CONFIG_FILE} <<EOF
tee "${CONFIG_FILE}" <<EOF
# This file was generated by the configure script. # This file was generated by the configure script.
TARGET_HOST = ${TARGET_HOST} TARGET_HOST = ${TARGET_HOST}
LIBCORE = ${TARGET_LIBCORE} LIBCORE = ${TARGET_HOST_LIBCORE}
TARGET_HOST_CC = ${TARGET_CC} TARGET_HOST_CC = ${TARGET_HOST_CC}
TARGET_HOST_AR = ${TARGET_AR} TARGET_HOST_AR = ${TARGET_HOST_AR}
TARGET_HOST_CFLAGS = ${TARGET_CFLAGS} TARGET_HOST_CFLAGS = ${TARGET_HOST_CFLAGS}
TARGET_HOST_LDFLAGS = ${TARGET_LDFLAGS} TARGET_HOST_LDFLAGS = ${TARGET_HOST_LDFLAGS}
HOST_CC = ${HOST_CC}
ASSET_BUILDER_CC = ${ASSET_BUILDER_CC}
ASSET_BUILDER_AR = ${ASSET_BUILDER_AR}
ASSET_BUILDER_CFLAGS = ${ASSET_BUILDER_CFLAGS} ASSET_BUILDER_CFLAGS = ${ASSET_BUILDER_CFLAGS}
ASSET_BUILDER_LDFLAGS = ${ASSET_BUILDER_LDFLAGS} ASSET_BUILDER_LDFLAGS = ${ASSET_BUILDER_LDFLAGS}
EOF EOF
echo "\`\`\`" echo "\`\`\`"
# #