From 0c52689ebeb28a5675fab1b58ac8c3485252b1ff Mon Sep 17 00:00:00 2001 From: Jaby Date: Sun, 21 Aug 2022 16:25:37 +0200 Subject: [PATCH] Setup build enviorment --- .gitignore | 1 + Makefile | 97 ++++++++++++++++++++++++++++++ build_all.bat | 13 ++++ src/Library/Library.code-workspace | 51 +++++++++++++++- src/Library/Makefile | 10 +++ src/Library/run_make.bat | 11 ++++ src/Library/src/test.cpp | 3 + src/Tools/build_all.bat | 2 +- src/Tools/run_cargo.bat | 1 + 9 files changed, 185 insertions(+), 4 deletions(-) create mode 100644 Makefile create mode 100644 build_all.bat create mode 100644 src/Library/Makefile create mode 100644 src/Library/run_make.bat create mode 100644 src/Library/src/test.cpp diff --git a/.gitignore b/.gitignore index 98b3d714..693c439e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ /iso *.dep +*.a *.o *.ii *.s diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..a3a3fdb5 --- /dev/null +++ b/Makefile @@ -0,0 +1,97 @@ +#Build architecture/variant string, possible values: x86, armv7le, etc... +PLATFORM ?= PSX + +#Build profile, possible values: release, debug, profile, coverage +BUILD_DIR ?= bin +BUILD_PROFILE ?= debug + +CONFIG_NAME ?= $(PLATFORM)-$(BUILD_PROFILE) +OUTPUT_DIR = $(BUILD_DIR)/$(CONFIG_NAME) +TARGET = $(OUTPUT_DIR)/$(ARTIFACT) + +#Compiler definitions +HAS_LINUX_MIPS_GCC = $(shell which mipsel-linux-gnu-gcc > /dev/null 2> /dev/null && echo true || echo false) +ifeq ($(HAS_LINUX_MIPS_GCC),true) +PREFIX ?= mipsel-linux-gnu +FORMAT ?= elf32-tradlittlemips +else +PREFIX ?= mipsel-none-elf +FORMAT ?= elf32-littlemips +endif + +CC ?= $(PREFIX)-gcc-10 +CXX ?= $(PREFIX)-g++-10 +LD ?= $(CXX) +AR ?= ar + +#architecture flags +ARCHFLAGS = -march=mips1 -mabi=32 -EL -fno-pic -mno-shared -mno-abicalls -mfp32 +ARCHFLAGS += -fno-stack-protector -nostdlib -ffreestanding + +#Compiler flags for build profiles +CCFLAGS_release += -O3 +CCFLAGS_debug += -O0 + +CXXFLAGS += -fno-exceptions -fno-rtti + +USE_FUNCTION_SECTIONS ?= true +ifeq ($(USE_FUNCTION_SECTIONS),true) +CCFLAGS_all += -ffunction-sections +endif +CCFLAGS_all += -mno-gpopt -fomit-frame-pointer +CCFLAGS_all += -fno-builtin -fno-strict-aliasing -Wno-attributes +CCFLAGS_all += $(ARCHFLAGS) + +CCFLAGS_all += $(CCFLAGS_$(BUILD_PROFILE)) + +#Linker flags +LDFLAGS_release += -Os + +LDFLAGS_all += -Wl,-Map=$(TARGET).map -nostdlib -T$(LDSCRIPT) -static -Wl,--gc-sections -Wl,--build-id=none +LDFLAGS_all += $(ARCHFLAGS) -Wl,--oformat=$(FORMAT) +LDFLAGS_all += $(LDFLAGS_$(BUILD_PROFILE)) + +LIBS_all += $(LIBS_$(BUILD_PROFILE)) + +DEPS = -Wp,-MMD,$(@:%.o=%.d),-MT,$@ + +#Macro to expand files recursively: parameters $1 - directory, $2 - extension, i.e. cpp +rwildcard = $(wildcard $(addprefix $1/*.,$2)) $(foreach d,$(wildcard $1/*),$(call rwildcard,$d,$2)) + +#Object files list +OBJS = $(addprefix $(OUTPUT_DIR)/,$(addsuffix .o, $(subst ..,!super,$(basename $(SRCS))))) + +#Compiling rule +$(OUTPUT_DIR)/%.o: %.c + @mkdir -p $(dir $@) + $(CC) -c $(DEPS) -o $@ $(CCFLAGS_all) $(CCFLAGS) $< + +$(OUTPUT_DIR)/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) -c $(DEPS) -o $@ $(CCFLAGS_all) $(CXXFLAGS) $< + +.SECONDEXPANSION: +$(OUTPUT_DIR)/%.o: $$(subst !super,..,%.s) + @mkdir -p $(dir $@) + $(CC) $(ARCHFLAGS) -I$(PCSX_REDUX) -g -c -o $@ $< + +#Linking rule +$(TARGET).a: $(OBJS) + @mkdir -p $(dir $@) + $(AR) rcs $(TARGET).a $(OBJS) + + +$(TARGET).elf: $(OBJS) + $(LD) -o $(TARGET).elf $(LDFLAGS_all) $(LDFLAGS) $(OBJS) $(LIBS_all) $(LIBS) + +#Strips the psexe +$(TARGET).psexe: $(TARGET).elf + $(PREFIX)-objcopy $(addprefix -R , $(OVERLAYSECTION)) -O binary $< $@ + +#Rules section for default compilation and linking +rebuild: + $(MAKE) clean + $(MAKE) all + +#Inclusion of dependencies (object files to source and includes) +-include $(OBJS:%.o=%.d) \ No newline at end of file diff --git a/build_all.bat b/build_all.bat new file mode 100644 index 00000000..0796f02b --- /dev/null +++ b/build_all.bat @@ -0,0 +1,13 @@ +@echo off +rem build_all [clean] + +set build_type=build + +IF NOT "%~1" == "" ( + set build_type=%~1 +) + +cd src\Library +call run_make.bat %build_type% release +cd ..\Tools\ +call build_all.bat %build_type% \ No newline at end of file diff --git a/src/Library/Library.code-workspace b/src/Library/Library.code-workspace index 2558d4cf..39a51c52 100644 --- a/src/Library/Library.code-workspace +++ b/src/Library/Library.code-workspace @@ -1,13 +1,58 @@ { "folders": [ + { + "name": "JabyEngine", + "path": ".", + }, { "name": "Include", "path": "..\\..\\include" }, { - "name": "JabyEngine", - "path": "." + "name": "Root", + "path": "..\\.." } ], - "settings": {} + "tasks": { + "version": "2.0.0", + "tasks": [ + { + "label": "make", + "type": "shell", + "command": "./run_make.bat ${input:target} ${input:build cfg}", + "group": { + "kind": "build" + } + }, + { + "label": "all", + "type": "shell", + "command": "./build_all.bat ${input:target}", + "group": { + "kind": "build" + }, + "options": { + "cwd": "../.." + } + }, + ], + "inputs": [ + { + "id": "build cfg", + "type": "pickString", + "options": ["debug", "release"], + "default": "release", + "description": "build configuration" + }, + { + "id": "target", + "type": "pickString", + "options": ["build", "clean", "rebuild"], + "default": "build", + "description": "build target", + } + ] + }, + "settings": {}, + } \ No newline at end of file diff --git a/src/Library/Makefile b/src/Library/Makefile new file mode 100644 index 00000000..d178c6fb --- /dev/null +++ b/src/Library/Makefile @@ -0,0 +1,10 @@ +ARTIFACT = libJabyEngine +BUILD_DIR = ../../lib + +include ../../Makefile + +#Rules section for default compilation and linking +all: $(TARGET).a + +clean: + rm -fr $(OUTPUT_DIR) \ No newline at end of file diff --git a/src/Library/run_make.bat b/src/Library/run_make.bat new file mode 100644 index 00000000..4453913e --- /dev/null +++ b/src/Library/run_make.bat @@ -0,0 +1,11 @@ +@echo off +rem run_make.bat build|clean|rebuild debug|release + +IF %1 == build ( + set make_target=all +) else ( + set make_target=%1 +) + +@echo make %make_target% BUILD_PROFILE=%2 +wsl make %make_target% BUILD_PROFILE=%2 diff --git a/src/Library/src/test.cpp b/src/Library/src/test.cpp new file mode 100644 index 00000000..52125bc2 --- /dev/null +++ b/src/Library/src/test.cpp @@ -0,0 +1,3 @@ +int wuff() { + return 0; +} \ No newline at end of file diff --git a/src/Tools/build_all.bat b/src/Tools/build_all.bat index b4cc906b..25e7bd22 100644 --- a/src/Tools/build_all.bat +++ b/src/Tools/build_all.bat @@ -18,6 +18,6 @@ IF NOT "%~1" == "" ( ) for %%a in (%projects%) do ( - call run_cargo %%a %build_type% release + call .\run_cargo %%a %build_type% release cd %cur_dir% ) diff --git a/src/Tools/run_cargo.bat b/src/Tools/run_cargo.bat index e90bdd5d..3f7fe2e2 100644 --- a/src/Tools/run_cargo.bat +++ b/src/Tools/run_cargo.bat @@ -24,6 +24,7 @@ IF %2 == check ( IF %2 == clean ( echo cargo clean %1 cargo clean + @del %org_dir%\..\..\bin\%1.exe exit /B %ERRORLEVEL% )