jabyengine/Makefile

146 lines
3.6 KiB
Makefile

ARTIFACT = JabyEngine
#Build architecture/variant string, possible values: x86, armv7le, etc...
PLATFORM ?= x86_64
#Build profile, possible values: release, debug, profile, coverage
BUILD_PROFILE ?= debug
CONFIG_NAME ?= $(PLATFORM)-$(BUILD_PROFILE)
OUTPUT_DIR = build/$(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
ROOTDIR = ../../../GIT/pcsx-redux/src/mips
LDSCRIPT ?= $(ROOTDIR)/ps-exe.ld
LDSCRIPT := $(addprefix $(ROOTDIR)/default.ld , -T$(LDSCRIPT))
CC = $(PREFIX)-gcc-10
CXX = $(PREFIX)-g++-10
LD = $(CXX)
LIB_DEPS_NAMES = Qt_Obj
LIB_DEPS_PATHES = ../QtXTObj/build/$(CONFIG_NAME)-Qt_Obj
#LIBS += -lsocket
#LIBS += -liconv
#Compiler flags for build profiles
CCFLAGS_release += -O3
CCFLAGS_debug += -O0 -fno-builtin
CXXFLAGS += -fno-exceptions -fno-rtti
#Generic compiler flags (which include build type flags)
ARCHFLAGS = -march=mips1 -mabi=32 -EL -fno-pic -mno-shared -mno-abicalls -mfp32
ARCHFLAGS += -fno-stack-protector -nostdlib -ffreestanding
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))
################################################################
PSYQ_PATH ?= ../../../PSYQ/Converted
CCFLAGS_all += -I$(PSYQ_PATH)/Include
LIBS += -L$(PSYQ_PATH)/Lib
LIBS += -Wl,--start-group
LIBS += -lapi
LIBS += -lc
LIBS += -lc2
LIBS += -lcard
LIBS += -lcomb
LIBS += -lds
LIBS += -letc
LIBS += -lgpu
LIBS += -lgs
LIBS += -lgte
LIBS += -lgun
LIBS += -lhmd
LIBS += -lmath
LIBS += -lmcrd
LIBS += -lmcx
LIBS += -lpad
LIBS += -lpress
LIBS += -lsio
LIBS += -lsnd
LIBS += -lspu
LIBS += -ltap
LIBS += -lcd
LIBS += -Wl,--end-group
################################################################
#Linker flags
LDFLAGS_release += -Os
LDFLAGS_all += -Wl,-Map=$(BINDIR)$(TARGET).map -nostdlib -T$(LDSCRIPT) -static -Wl,--gc-sections
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))
#Source list
SRCS += $(ROOTDIR)/common/crt0/crt0.s
SRCS += $(call rwildcard, src, c cpp)
#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$(ROOTDIR) -g -c -o $@ $<
$(info at is $@)
$(info dollar is $<)
#Linking rule
$(TARGET).elf: $(OBJS)
$(LD) -o $(TARGET).elf $(LDFLAGS_all) $(LDFLAGS) $(OBJS) $(LIBS_all) $(LIBS)
#
$(TARGET).psexe: $(TARGET).elf
$(PREFIX)-objcopy $(addprefix -R , $(OVERLAYSECTION)) -O binary $< $@
#Rules section for default compilation and linking
all: $(TARGET).psexe
clean:
rm -fr $(OUTPUT_DIR)
rebuild:
$(MAKE) clean
$(MAKE) all
#Inclusion of dependencies (object files to source and includes)
-include $(OBJS:%.o=%.d)