Compare commits

..

No commits in common. "52b3240549fa2a9ae918bcade65553653f71ba6e" and "124e30281ba0df26f9ca96e94ff0eca55d73024d" have entirely different histories.

23 changed files with 191 additions and 208 deletions

4
.vscode/launch.json vendored
View File

@ -8,8 +8,8 @@
"name": "Debug", "name": "Debug",
"type": "gdb", "type": "gdb",
"request": "launch", "request": "launch",
"target": "${workspaceFolder}/build/linux/2D_Engine", "target": "${workspaceFolder}/build/2D_Engine",
"cwd": "${workspaceFolder}/build/linux", "cwd": "${workspaceFolder}/build",
"valuesFormatting": "parseText", "valuesFormatting": "parseText",
"preLaunchTask": "Build" "preLaunchTask": "Build"
} }

28
.vscode/tasks.json vendored
View File

@ -1,23 +1,6 @@
{ {
"version": "2.0.0", "version": "2.0.0",
"tasks": [ "tasks": [
{
"label": "Configure",
"detail": "Configure project",
"type": "shell",
"command": "${workspaceFolder}/configure",
"args": [
],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "shared",
"showReuseMessage": true,
"clear": true
}
},
{ {
"label": "Build", "label": "Build",
"detail": "Build project", "detail": "Build project",
@ -73,13 +56,12 @@
} }
}, },
{ {
"label": "Run Debug", "label": "Run",
"detail": "Build project in debug mode and run", "detail": "Build project and run",
"type": "shell", "type": "shell",
"command": "make", "command": "make",
"args": [ "args": [
"-j$(nproc)", "-j$(nproc)",
"DEBUG=2",
"run" "run"
], ],
"group": "build", "group": "build",
@ -93,13 +75,13 @@
} }
}, },
{ {
"label": "Build Debug", "label": "Build Release",
"detail": "Build project in debug mode", "detail": "Build project in release mode",
"type": "shell", "type": "shell",
"command": "make", "command": "make",
"args": [ "args": [
"-j$(nproc)", "-j$(nproc)",
"DEBUG=2" "RELEASE=1"
], ],
"group": "build", "group": "build",
"presentation": { "presentation": {

View File

@ -1,34 +1,28 @@
export
SHELL = /usr/bin/env bash 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) ifneq ($(realpath $(ROOT)/config.mk), $(ROOT)/config.mk)
$(error ERROR: Please run the configure script before building) $(error ERROR: Please run the configure script before building.)
endif endif
include $(ROOT)/config.mk include $(ROOT)/config.mk
endif
# #
# User settings # User config
# #
BUILD_DIR = build BUILD_DIR_NAME = build
SOURCE_DIR = src SOURCE_DIR = src
CORE_DIR = core CORE_DIR = core
ASSETS_DIR = assets HOST_DIR = host
ASSET_BUILDER_DIR = asset_builder
OUTPUT = 2D_Engine OUTPUT = 2D_Engine
ASSET_OUTPUT = game.data ASSET_OUTPUT = game.data
ASSET_BUILDER_OUTPUT = asset_builder/asset_builder
ifneq ($(DEBUG),) ifneq ($(DEBUG),)
TARGET_HOST_CFLAGS += -O1 -g -DDEBUG=$(DEBUG) -Wextra -Wall --pedantic -Wno-missing-braces \ CFLAGS += -O1 -g -DDEBUG=$(DEBUG) -Wextra -Wall --pedantic -Wno-missing-braces \
-Wno-missing-field-initializers -Wformat=2 -Wswitch-default -Wswitch \ -Wno-missing-field-initializers -Wformat=2 -Wswitch-default -Wswitch \
-Wcast-align -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 \ -Wcast-align -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 \
-Wstrict-prototypes -Winline -Wundef -Wnested-externs -Wcast-qual \ -Wstrict-prototypes -Winline -Wundef -Wnested-externs -Wcast-qual \
@ -40,21 +34,11 @@ endif
# End # End
# #
# Relocate vars # Relocate build dir
BUILD_DIR := $(ROOT)/$(BUILD_DIR)/$(TARGET_HOST) BUILD_DIR := $(ROOT)/$(BUILD_DIR_NAME)/$(HOST)
SOURCE_DIR := $(ROOT)/$(SOURCE_DIR)
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)
ASSET_OUTPUT := $(BUILD_DIR)/$(ASSET_OUTPUT)
ASSET_BUILDER_OUTPUT := $(BUILD_DIR)/$(ASSET_BUILDER_OUTPUT)
# Verbosity # Verbosity
export Q := @ Q := @
ifeq ($(VERBOSE), 1) ifeq ($(VERBOSE), 1)
Q := Q :=
endif endif
@ -65,25 +49,21 @@ YELLOW := \033[33m
RESET := \033[m RESET := \033[m
# Default targets # Default targets
all: $(OUTPUT) $(ASSET_OUTPUT) all: setup $(BUILD_DIR)/$(OUTPUT)
$(OUTPUT): FORCE include $(ROOT)/$(SOURCE_DIR)/Makefile
$(Q)cd $(SOURCE_DIR) && $(MAKE) $@ include $(ROOT)/$(CORE_DIR)/Makefile
$(ASSET_OUTPUT): FORCE setup:
$(Q)cd $(ASSETS_DIR) && $(MAKE) $@ $(eval export TOTAL_BUILD_FILES := $(shell echo $$(($$(make -n $(OBJECTS) $(CORE_OBJECTS) 2>/dev/null | grep -c $(CC)) + 2))))
$(Q)mkdir -p $(dir $(OBJECTS) $(CORE_OBJECTS))
FORCE: .PHONY: clean run print-var-%
.PHONY: clean clean-all run print-var-%
clean: clean:
$(Q)rm -rf $(BUILD_DIR)
clean-all:
$(Q)rm -rf $(dir $(BUILD_DIR)) $(Q)rm -rf $(dir $(BUILD_DIR))
run: all run: all
$(Q)cd $(BUILD_DIR) && ./$(notdir $(OUTPUT)) $(Q)cd $(BUILD_DIR) && ./$(OUTPUT)
print-var-% : print-var-% :
@echo $($*) @echo $($*)

View File

@ -1,30 +0,0 @@
SOURCES := \
object.c \
image.c \
map.c \
utils.c \
main.c
INCLUDES += \
$(ASSET_BUILDER_DIR) \
$(SOURCE_DIR)/components
OBJECTS := $(SOURCES:%=$(BUILD_DIR)/$(notdir $(ASSET_BUILDER_DIR))/%.o)
ifeq ($(TOTAL_BUILD_FILES),)
TOTAL_BUILD_FILES := $(shell echo $$(($$($(MAKE) -n $(OBJECTS) TOTAL_BUILD_FILES=1 2>/dev/null | grep -c Building) + 1)))
endif
$(ASSET_BUILDER_OUTPUT): $(OBJECTS)
$(Q)mkdir -p $(dir $@)
@echo -e "[100%] $(YELLOW)Linking $(notdir $(ASSET_BUILDER_OUTPUT))$(RESET)"
$(Q)$(ASSET_BUILDER_CC) $(ASSET_BUILDER_CFLAGS) $(ASSET_BUILDER_LDFLAGS) $(OBJECTS) -o $@
$(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)))))
@echo -e "[$(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)

View File

@ -9,24 +9,37 @@ ASSETS := \
maps/dungeon_entry.map \ maps/dungeon_entry.map \
maps/dungeon_room_1.map maps/dungeon_room_1.map
OBJECTS := $(ASSETS:%=$(BUILD_DIR)/$(notdir $(ASSETS_DIR))/%.o) ASSETS := $(addprefix $(ASSETS_DIR)/,$(ASSETS))
ifeq ($(TOTAL_BUILD_FILES),) ASSETS_OBJECTS = $(ASSETS:%=$(BUILD_DIR)/%.o)
TOTAL_BUILD_FILES := $(shell echo $$(($$($(MAKE) -n $(OBJECTS) TOTAL_BUILD_FILES=1 2>/dev/null | grep -c Building) + 1)))
endif
$(ASSET_OUTPUT): $(OBJECTS) $(ASSET_BUILDER_OUTPUT) ASSET_BUILDER_DIR = $(ASSETS_DIR)/asset_builder/src
ASSET_BUILDER_OUTPUT = $(BUILD_DIR)/$(ASSETS_DIR)/asset_builder/asset_builder
include $(ASSET_BUILDER_DIR)/Makefile
build_assets: setup_asset build_asset_builder count_assets_build asset_end
# Current file nb to process
CURRENT_ASSET_FILE := 0
# Count nb of files to build
count_assets_build:
$(eval export TOTAL_ASSETS_FILES := $(shell echo $$(($$(make -n $(ASSETS_OBJECTS) 2>/dev/null | grep -c "Building") + 1))))
setup_asset:
@echo "Building $(notdir $(ASSET_OUTPUT))"
$(Q)mkdir -p $(dir $(ASSETS_OBJECTS))
$(ASSET_OUTPUT): $(ASSETS_OBJECTS) $(ASSET_BUILDER_OUTPUT)
@echo -e "[100%] $(YELLOW)Building $(notdir $(ASSET_OUTPUT))$(RESET)" @echo -e "[100%] $(YELLOW)Building $(notdir $(ASSET_OUTPUT))$(RESET)"
$(Q)$(ASSET_BUILDER_OUTPUT) $@ $(OBJECTS) $(Q)$(ASSET_BUILDER_OUTPUT) $@ $(ASSETS_OBJECTS)
$(BUILD_DIR)/$(notdir $(ASSETS_DIR))/%.o: $(ASSETS_DIR)/% $(ASSET_BUILDER_OUTPUT) # Build .o files
$(Q)mkdir -p $(dir $@) $(BUILD_DIR)/$(ASSETS_DIR)/%.o: $(ASSETS_DIR)/% $(ASSET_BUILDER_OUTPUT)
$(eval CURRENT_FILE := $(shell echo $$(($(CURRENT_FILE) + 1)))) $(eval CURRENT_ASSET_FILE := $(shell echo $$(($(CURRENT_ASSET_FILE)+1))))
$(eval PERCENTAGE := $(shell echo $$(($(CURRENT_FILE) * 100 / $(TOTAL_BUILD_FILES))))) $(eval PERCENTAGE := $(shell echo $$(($(CURRENT_ASSET_FILE)*100/$(TOTAL_ASSETS_FILES)))))
@echo -e "[$(PERCENTAGE)%] $(GREEN)Building ASSET object $@$(RESET)" @echo -e "[$(PERCENTAGE)%] $(GREEN)Building ASSET object $@$(RESET)"
$(Q)$(ASSET_BUILDER_OUTPUT) $@ -c $< $(Q)$(ASSET_BUILDER_OUTPUT) $@ -c $<
$(ASSET_BUILDER_OUTPUT): FORCE asset_end: $(ASSET_OUTPUT)
$(Q)cd $(ASSET_BUILDER_DIR) && $(MAKE) $@ @echo "Built target $(notdir $(ASSET_OUTPUT))"
FORCE:

View File

@ -0,0 +1,66 @@
# Source files
ASSET_BUILDER_SOURCES := \
object.c \
image.c \
map.c \
utils.c \
main.c
# Compiler and flags
ASSET_BUILDER_CC = gcc
ifeq ($(RELEASE), 1)
ASSET_BUILDER_CFLAGS = --std=c17 --pedantic -O3 $(shell pkg-config --cflags libpng json-c) # RELEASE
ASSET_BUILDER_LDFLAGS = -O3 $(shell pkg-config --libs libpng json-c)
else
ASSET_BUILDER_CFLAGS = --std=c17 --pedantic -O1 -DDEBUG=1 -g $(shell pkg-config --cflags libpng json-c) \
-Wall -Wno-missing-braces -Wextra -Wno-missing-field-initializers \
-Wformat=2 -Wswitch-default -Wswitch -Wcast-align \
-Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 \
-Wstrict-prototypes -Winline -Wundef -Wnested-externs \
-Wcast-qual -Wshadow -Wunreachable-code -Wlogical-op \
-Wfloat-equal -Wstrict-aliasing=2 -Wredundant-decls \
-Wold-style-definition # DEVELOPEMENT
ASSET_BUILDER_LDFLAGS = -O1 $(shell pkg-config --libs libpng json-c)
endif
ASSET_BUILDER_INCLUDE_DIRS = $(SOURCE_DIR)/components $(ASSET_BUILDER_DIR)
ASSET_BUILDER_INCLUDE_DIRS := $(addprefix -I, $(ASSET_BUILDER_INCLUDE_DIRS))
# Deduce objects
ASSET_BUILDER_OBJECTS = $(ASSET_BUILDER_SOURCES:%.c=$(BUILD_DIR)/$(ASSET_BUILDER_DIR)/%.o)
# Current file nb to process
CURRENT_ASSET_BUILDER_FILE := 0
# Build asset builder target
build_asset_builder: asset_builder_setup count_asset_builder_build asset_builder_end
# Source build directories
asset_builder_setup:
@echo "Building $(notdir $(ASSET_BUILDER_OUTPUT))"
$(Q)mkdir -p $(dir $(ASSET_BUILDER_OBJECTS))
# Count nb of files to build
count_asset_builder_build:
$(eval export TOTAL_ASSET_BUILDER_FILES := $(shell echo $$(($$(make -n $(ASSET_BUILDER_OBJECTS) 2>/dev/null | grep -c "Building") + 1))))
# Link asset builder target
$(ASSET_BUILDER_OUTPUT): $(ASSET_BUILDER_OBJECTS)
@echo -e "[100%] $(YELLOW)Linking $(notdir $(ASSET_BUILDER_OUTPUT))$(RESET)"
$(Q)$(SRC_CC) $(ASSET_BUILDER_OBJECTS) -o $@ $(ASSET_BUILDER_LDFLAGS)
# Build .o files
$(BUILD_DIR)/$(ASSET_BUILDER_DIR)/%.o: $(ASSET_BUILDER_DIR)/%.c
$(eval CURRENT_ASSET_BUILDER_FILE := $(shell echo $$(($(CURRENT_ASSET_BUILDER_FILE)+1))))
$(eval PERCENTAGE := $(shell echo $$(($(CURRENT_ASSET_BUILDER_FILE)*100/$(TOTAL_ASSET_BUILDER_FILES)))))
@echo -e "[$(PERCENTAGE)%] $(GREEN)Building C object $@$(RESET)"
$(Q)$(SRC_CC) $(ASSET_BUILDER_CFLAGS) $(ASSET_BUILDER_INCLUDE_DIRS) -MMD -MP -c $< -o $@
# Print ending message
asset_builder_end: $(ASSET_BUILDER_OUTPUT)
@echo "Built target $(notdir $(ASSET_BUILDER_OUTPUT))"
# Source files dependencies
-include $(ASSET_BUILDER_OBJECTS:.o=.d)

112
configure vendored
View File

@ -69,7 +69,7 @@ done
## Clean ## Clean
if [ -n "${CLEAN}" ]; then if [ -n "${CLEAN}" ]; then
make clean-all make clean
rm -rf ${CONFIG_FILE} rm -rf ${CONFIG_FILE}
fi fi
@ -93,84 +93,70 @@ case "${OSTYPE}" in
;; ;;
esac esac
echo "Configuring for current host: ${CURRENT_HOST}" echo "Detected current host: ${CURRENT_HOST}"
if [ "${TARGET_HOST}" = "guess" ]; then if [ "${TARGET_HOST}" = "guess" ]; then
TARGET_HOST=${CURRENT_HOST} TARGET_HOST=${CURRENT_HOST}
fi fi
case "${CURRENT_HOST}" in
linux)
ASSET_BUILDER_CC="gcc"
ASSET_BUILDER_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)"
;;
*)
print_error "Compiling from ${CURRENT_HOST} is not supported yet."
;;
esac
case "${TARGET_HOST}" in case "${TARGET_HOST}" in
linux) linux|fxcg50)
echo "Configuring for target: ${TARGET_HOST}" echo "Configuring for target: ${TARGET_HOST}"
case "${CURRENT_HOST}" in
linux)
;;
*)
print_error "Cross compiling from ${CURRENT_HOST} to ${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)"
TARGET_LDFLAGS="\$(shell pkg-config --libs sdl3) -lm"
TARGET_LIBCORE="libcore.a"
;;
fxcg50)
echo "Configuring for target: ${TARGET_HOST}"
case "${CURRENT_HOST}" in
linux)
;;
*)
print_error "Cross compiling from ${CURRENT_HOST} to ${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}" print_error "Unsupported target host: ${TARGET_HOST}"
;;
esac esac
echo
if [ "${CURRENT_HOST}" != "${TARGET_HOST}" ]; then
CROSS_COMPILE=TRUE
fi
if [ -n "${CROSS_COMPILE}" ]; then
case "${TARGET_HOST}" in
fxcg50)
case "${CURRENT_HOST}" in
linux)
;;
*)
print_error "Cross compiling from ${CURRENT_HOST} for ${TARGET_HOST} is not supported yet."
;;
esac
CC="sh-elf-gcc"
AR="sh-elf-ar"
LIBCORE="libcore.a"
;;
esac
else
case "${TARGET_HOST}" in
linux)
CC="gcc"
AR="ar"
CFLAGS="--std=c17 -Os -DASSET_FILE_NAME=\\\"\$(notdir \$(ASSET_OUTPUT))\\\" -D_GNU_SOURCE=1 \$(shell pkg-config --cflags sdl3)"
LDFLAGS="\$(shell pkg-config --libs sdl3) -lm"
LIBCORE="libcore.a"
;;
*)
;;
esac
fi
echo "Writing config file." echo "Writing config file."
echo echo
echo "${CONFIG_FILE}:" echo "${CONFIG_FILE}:"
echo "\`\`\`" echo "\`\`\`"
tee ${CONFIG_FILE} <<EOF echo "HOST = ${TARGET_HOST}" | tee ${CONFIG_FILE}
# This file was generated by the configure script. echo | tee -a ${CONFIG_FILE}
echo "CC = ${CC}" | tee -a ${CONFIG_FILE}
TARGET_HOST = ${TARGET_HOST} echo "AR = ${AR}" | tee -a ${CONFIG_FILE}
LIBCORE = ${TARGET_LIBCORE} echo "CFLAGS = ${CFLAGS}" | tee -a ${CONFIG_FILE}
echo "LDFLAGS = ${LDFLAGS}" | tee -a ${CONFIG_FILE}
TARGET_HOST_CC = ${TARGET_CC} echo | tee -a ${CONFIG_FILE}
TARGET_HOST_AR = ${TARGET_AR} echo "LIBCORE = ${LIBCORE}" | tee -a ${CONFIG_FILE}
TARGET_HOST_CFLAGS = ${TARGET_CFLAGS}
TARGET_HOST_LDFLAGS = ${TARGET_LDFLAGS}
ASSET_BUILDER_CC = ${ASSET_BUILDER_CC}
ASSET_BUILDER_AR = ${ASSET_BUILDER_AR}
ASSET_BUILDER_CFLAGS = ${ASSET_BUILDER_CFLAGS}
ASSET_BUILDER_LDFLAGS = ${ASSET_BUILDER_LDFLAGS}
EOF
echo "\`\`\`" echo "\`\`\`"
# #

View File

@ -1,4 +1,4 @@
SOURCES += \ CORE_SOURCES += \
main.c \ main.c \
camera.c \ camera.c \
linked_list.c \ linked_list.c \
@ -8,30 +8,24 @@ SOURCES += \
inputs.c \ inputs.c \
map.c map.c
INCLUDES += \ CORE_INCLUDES += \
$(CORE_DIR) \ $(CORE_DIR) \
$(CORE_DIR)/host/$(TARGET_HOST) \ $(CORE_DIR)/$(HOST_DIR)/$(HOST) \
$(SOURCE_DIR)/components $(SOURCE_DIR)/components
include $(CORE_DIR)/host/$(TARGET_HOST)/Makefile include $(ROOT)/$(CORE_DIR)/$(HOST_DIR)/$(HOST)/Makefile
CORE_OBJECTS := $(CORE_SOURCES:%=$(BUILD_DIR)/$(CORE_DIR)/%.o)
OBJECTS := $(SOURCES:%=$(BUILD_DIR)/$(notdir $(CORE_DIR))/%.o) $(BUILD_DIR)/$(LIBCORE): $(CORE_OBJECTS)
ifeq ($(TOTAL_BUILD_FILES),)
TOTAL_BUILD_FILES := $(shell echo $$(($$($(MAKE) -n $(OBJECTS) TOTAL_BUILD_FILES=1 2>/dev/null | grep -c Building) + 1)))
endif
$(LIBCORE): $(OBJECTS)
$(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)))))
@echo -e "[$(PERCENTAGE)%] $(YELLOW)Creating Static Lib $@$(RESET)" @echo -e "[$(PERCENTAGE)%] $(YELLOW)Creating Static Lib $@$(RESET)"
$(Q)$(TARGET_HOST_AR) rcs $@ $(OBJECTS) $(Q)$(AR) rcs $@ $(CORE_OBJECTS)
$(BUILD_DIR)/$(notdir $(CORE_DIR))/%.o: $(CORE_DIR)/% $(BUILD_DIR)/$(CORE_DIR)/%.c.o: $(ROOT)/$(CORE_DIR)/%.c
$(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)))))
@echo -e "[$(PERCENTAGE)%] $(GREEN)Building C object $@$(RESET)" @echo -e "[$(PERCENTAGE)%] $(GREEN)Building C object $@$(RESET)"
$(Q)$(TARGET_HOST_CC) $(TARGET_HOST_CFLAGS) $(INCLUDES:%=-I%) -MMD -MP -c $< -o $@ $(Q)$(CC) $(CFLAGS) $(CORE_INCLUDES:%=-I%) -MMD -MP -c $< -o $@
-include $(OBJECTS:.o=.d) -include $(CORE_OBJECTS:.o=.d)

View File

@ -1,5 +1,7 @@
SOURCES += $(addprefix host/$(TARGET_HOST)/, \ CORE_SOURCES += \
display.c \ $(HOST_DIR)/$(HOST)/display.c \
vector2d.c \ $(HOST_DIR)/$(HOST)/vector2d.c \
texture.c \ $(HOST_DIR)/$(HOST)/texture.c
)
CORE_INCLUDES += \
$(CORE_DIRE)

View File

@ -407,7 +407,7 @@ static inline int draw_tile(uint16_t tile_x, uint16_t tile_y, uint16_t tile_id)
rect_t src_frect = { rect_t src_frect = {
.x = tile_id * TILE_SIZE % get_width(game.map->tileset), .x = tile_id * TILE_SIZE % get_width(game.map->tileset),
.y = tile_id * TILE_SIZE / get_width(game.map->tileset) * TILE_SIZE, .y = tile_id * TILE_SIZE / get_height(game.map->tileset) * TILE_SIZE,
.w = TILE_SIZE, .w = TILE_SIZE,
.h = TILE_SIZE .h = TILE_SIZE
}; };

View File

@ -14,28 +14,18 @@ SOURCES += \
INCLUDES += \ INCLUDES += \
$(SOURCE_DIR)/components \ $(SOURCE_DIR)/components \
$(CORE_DIR) \ $(CORE_DIR) \
$(CORE_DIR)/host/$(TARGET_HOST) $(CORE_DIR)/$(HOST_DIR)/$(HOST)
OBJECTS := $(SOURCES:%=$(BUILD_DIR)/$(notdir $(SOURCE_DIR))/%.o) OBJECTS := $(SOURCES:%=$(BUILD_DIR)/$(SOURCE_DIR)/%.o)
ifeq ($(TOTAL_BUILD_FILES),) $(BUILD_DIR)/$(OUTPUT): $(BUILD_DIR)/$(LIBCORE) $(OBJECTS)
TOTAL_BUILD_FILES := $(shell echo $$(($$($(MAKE) -n $(OBJECTS) TOTAL_BUILD_FILES=1 2>/dev/null | grep -c Building) + 1))) @echo -e "[100%] $(YELLOW)Linking $(OUTPUT)$(RESET)"
endif $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(OBJECTS) $(BUILD_DIR)/$(LIBCORE) -o $@
$(OUTPUT): $(OBJECTS) $(LIBCORE) $(BUILD_DIR)/$(SOURCE_DIR)/%.c.o: $(ROOT)/$(SOURCE_DIR)/%.c
@echo -e "[100%] $(YELLOW)Linking $(notdir $(OUTPUT))$(RESET)"
$(Q)$(TARGET_HOST_CC) $(TARGET_HOST_CFLAGS) $(TARGET_HOST_LDFLAGS) $(OBJECTS) -L$(BUILD_DIR) -lcore -o $@
$(BUILD_DIR)/$(notdir $(SOURCE_DIR))/%.o: $(SOURCE_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)))))
@echo -e "[$(PERCENTAGE)%] $(GREEN)Building C object $@$(RESET)" @echo -e "[$(PERCENTAGE)%] $(GREEN)Building C object $@$(RESET)"
$(Q)$(TARGET_HOST_CC) $(TARGET_HOST_CFLAGS) $(INCLUDES:%=-I%) -MMD -MP -c $< -o $@ $(Q)$(CC) $(CFLAGS) $(INCLUDES:%=-I%) -MMD -MP -c $< -o $@
$(LIBCORE): FORCE
$(Q)cd $(CORE_DIR) && $(MAKE) $@
FORCE:
-include $(OBJECTS:.o=.d) -include $(OBJECTS:.o=.d)