2023-06-23 00:29:55 +02:00
|
|
|
CONFIG ?= Debug
|
|
|
|
LIB ?= 0
|
|
|
|
|
|
|
|
ifeq ($(CONFIG),Debug)
|
2023-10-23 21:03:05 +02:00
|
|
|
BUILD_DIR := build/Debug
|
2023-06-23 00:29:55 +02:00
|
|
|
FUNC_OPTFLAGS := -Og -g -fno-strict-aliasing
|
|
|
|
OPTFLAGS := -Og -g -fno-strict-aliasing
|
|
|
|
# Static C runtime linking
|
|
|
|
LIBS := -Wl,/nodefaultlib:libcmt -Wl,/nodefaultlib:ucrt -Wl,/nodefaultlib:libucrt -llibcmtd -llibvcruntimed -llibucrtd
|
|
|
|
# Dynamic
|
|
|
|
# LIBS := -Wl,/nodefaultlib:libcmt -Wl,/nodefaultlib:ucrt -Wl,/nodefaultlib:libucrt -lmsvcrtd -lvcruntimed -lucrtd
|
|
|
|
else ifeq ($(CONFIG),Release)
|
2023-10-23 21:03:05 +02:00
|
|
|
BUILD_DIR := build/Release
|
2023-06-23 00:29:55 +02:00
|
|
|
FUNC_OPTFLAGS := -O2 -g -fno-strict-aliasing
|
|
|
|
OPTFLAGS := -O2 -g -fno-strict-aliasing
|
2023-10-23 21:03:05 +02:00
|
|
|
else
|
|
|
|
$(error "Invalid build configuration: $(CONFIG)")
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(OS),Windows_NT)
|
|
|
|
DYN_EXT := .dll
|
|
|
|
LIB_EXT := .lib
|
|
|
|
EXE_EXT := .exe
|
|
|
|
AR := clang++
|
|
|
|
ARFLAGS := $(OPTFLAGS) -fuse-ld=llvm-lib -o
|
2023-06-23 00:29:55 +02:00
|
|
|
# Static C runtime linking
|
2023-10-23 21:03:05 +02:00
|
|
|
LIBS := -Wl,/nodefaultlib:libcmt -Wl,/nodefaultlib:ucrt -Wl,/nodefaultlib:libucrt -llibcmt -llibvcruntime -llibucrt
|
2023-06-23 00:29:55 +02:00
|
|
|
# Dynamic
|
2023-10-23 21:03:05 +02:00
|
|
|
# LIBS := -Wl,/nodefaultlib:libcmt -Wl,/nodefaultlib:ucrt -Wl,/nodefaultlib:libucrt -lmsvcrt -lvcruntime -lucrt
|
|
|
|
LIB_DIR ?= C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\lib\x64
|
|
|
|
UCRT_DIR ?= C:\Program Files (x86)\Windows Kits\10\lib\10.0.22000.0\ucrt\x64;
|
|
|
|
SDK_DIR ?= C:\Program Files (x86)\Windows Kits\10\lib\10.0.22000.0\um\x64
|
|
|
|
define mkdir
|
|
|
|
mkdir $(subst /,\\,$(1))
|
|
|
|
endef
|
|
|
|
define rmdir
|
|
|
|
rmdir /S /Q $(subst /,\\,$(1))
|
|
|
|
endef
|
2023-06-23 00:29:55 +02:00
|
|
|
else
|
2023-10-23 21:03:05 +02:00
|
|
|
DYN_EXT := .so
|
|
|
|
LIB_EXT := .a
|
|
|
|
EXE_EXT :=
|
|
|
|
LIB_PRE := lib
|
|
|
|
AR := ar
|
|
|
|
ARFLAGS := rcs
|
|
|
|
define mkdir
|
|
|
|
mkdir -p $(1)
|
|
|
|
endef
|
|
|
|
define rmdir
|
|
|
|
rm -rf $(1)
|
|
|
|
endef
|
2023-06-23 00:29:55 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
SRC_DIRS := portultra src rsp
|
|
|
|
|
2023-10-23 21:03:05 +02:00
|
|
|
# Add the main folder if not building a library
|
|
|
|
ifneq ($(LIB),1)
|
|
|
|
SRC_DIRS += src/main
|
|
|
|
endif
|
|
|
|
|
2023-06-23 00:29:55 +02:00
|
|
|
FUNCS_DIR := RecompiledFuncs
|
2023-10-23 21:03:05 +02:00
|
|
|
FUNCS_LIB := $(BUILD_DIR)/$(LIB_PRE)RecompiledFuncs$(LIB_EXT)
|
2023-06-23 00:29:55 +02:00
|
|
|
FUNCS_C_SRCS := $(wildcard $(FUNCS_DIR)/*.c)
|
|
|
|
FUNCS_CXX_SRCS := $(wildcard $(FUNCS_DIR)/*.cpp)
|
|
|
|
|
|
|
|
FUNC_BUILD_DIR := $(BUILD_DIR)/RecompiledFuncs
|
|
|
|
FUNCS_C_OBJS := $(addprefix $(BUILD_DIR)/,$(FUNCS_C_SRCS:.c=.o))
|
|
|
|
FUNCS_CXX_OBJS := $(addprefix $(BUILD_DIR)/,$(FUNCS_CXX_SRCS:.cpp=.o))
|
|
|
|
ALL_FUNC_OBJS := $(FUNCS_C_OBJS) $(FUNCS_CXX_OBJS)
|
|
|
|
|
|
|
|
BUILD_SRC_DIRS := $(addprefix $(BUILD_DIR)/,$(SRC_DIRS))
|
|
|
|
C_SRCS := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
|
|
|
|
CXX_SRCS := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
|
|
|
|
|
|
|
|
C_OBJS := $(addprefix $(BUILD_DIR)/,$(C_SRCS:.c=.o))
|
|
|
|
CXX_OBJS := $(addprefix $(BUILD_DIR)/,$(CXX_SRCS:.cpp=.o))
|
|
|
|
ALL_OBJS := $(C_OBJS) $(CXX_OBJS)
|
|
|
|
|
|
|
|
|
|
|
|
CC := clang
|
|
|
|
CXX := clang++
|
|
|
|
LD := clang++
|
|
|
|
|
|
|
|
FUNC_CFLAGS := $(FUNC_OPTFLAGS) -c -Wno-unused-but-set-variable
|
|
|
|
FUNC_CXXFLAGS := $(FUNC_OPTFLAGS) -std=c++20 -c
|
|
|
|
FUNC_CPPFLAGS := -Iinclude
|
|
|
|
|
|
|
|
WARNFLAGS := -Wall -Wextra -Wpedantic -Wno-gnu-anonymous-struct
|
2023-07-07 20:21:06 +02:00
|
|
|
CFLAGS := -ffunction-sections -fdata-sections -march=nehalem $(OPTFLAGS) $(WARNFLAGS) -c
|
|
|
|
CXXFLAGS := -ffunction-sections -fdata-sections -march=nehalem $(OPTFLAGS) $(WARNFLAGS) -std=c++20 -c
|
2023-06-23 00:29:55 +02:00
|
|
|
CPPFLAGS := -Iinclude -Ithirdparty
|
2023-10-23 21:03:05 +02:00
|
|
|
|
|
|
|
ifeq ($(OS),Windows_NT)
|
|
|
|
LDFLAGS := -v -Wl,/OPT:REF $(OPTFLAGS) $(LIBS) -L"$(LIB_DIR:;=)" -L"$(UCRT_DIR:;=)" -L"$(SDK_DIR:;=)" lib/RT64/$(CONFIG)/RT64.lib
|
|
|
|
else
|
|
|
|
LDFLAGS := $(OPTFLAGS) -L$(BUILD_DIR) -lRecompiledFuncs -L. -lrt64 -lSDL2 -lX11 -Wl,--gc-sections
|
|
|
|
FUNC_CFLAGS += -ffunction-sections -fdata-sections
|
|
|
|
FUNC_CXXFLAGS += -ffunction-sections -fdata-sections
|
|
|
|
EXTRA_DEPS := librt64.a
|
|
|
|
endif
|
2023-06-23 00:29:55 +02:00
|
|
|
|
|
|
|
ifeq ($(LIB),1)
|
2023-10-23 21:03:05 +02:00
|
|
|
TARGET := $(BUILD_DIR)/MMRecomp$(DYN_EXT)
|
2023-06-23 00:29:55 +02:00
|
|
|
LDFLAGS += -shared
|
|
|
|
else
|
2023-10-23 21:03:05 +02:00
|
|
|
TARGET := $(BUILD_DIR)/MMRecomp$(EXE_EXT)
|
2023-06-23 00:29:55 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
default: $(TARGET)
|
|
|
|
|
2023-10-23 21:03:05 +02:00
|
|
|
clean:
|
|
|
|
$(call rmdir,$(BUILD_DIR))
|
2023-06-23 00:29:55 +02:00
|
|
|
|
|
|
|
cleanfuncs:
|
|
|
|
|
|
|
|
|
|
|
|
$(FUNCS_CXX_OBJS) : $(BUILD_DIR)/%.o : %.cpp | $(FUNC_BUILD_DIR)
|
|
|
|
@$(CXX) $(FUNC_CXXFLAGS) $(FUNC_CPPFLAGS) $^ -o $@
|
|
|
|
|
|
|
|
$(FUNCS_C_OBJS) : $(BUILD_DIR)/%.o : %.c | $(FUNC_BUILD_DIR)
|
|
|
|
@$(CC) $(FUNC_CFLAGS) $(FUNC_CPPFLAGS) $^ -o $@
|
|
|
|
|
|
|
|
$(FUNCS_LIB): $(ALL_FUNC_OBJS) | $(BUILD_DIR)
|
2023-10-23 21:03:05 +02:00
|
|
|
$(AR) $(ARFLAGS) $@ $(FUNC_BUILD_DIR)/*.o
|
2023-06-23 00:29:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(CXX_OBJS) : $(BUILD_DIR)/%.o : %.cpp | $(BUILD_SRC_DIRS)
|
|
|
|
$(CXX) -MMD -MF $(@:.o=.d) $(CXXFLAGS) $(CPPFLAGS) $< -o $@
|
|
|
|
|
|
|
|
$(C_OBJS) : $(BUILD_DIR)/%.o : %.c | $(BUILD_SRC_DIRS)
|
|
|
|
$(CC) -MMD -MF $(@:.o=.d) $(CFLAGS) $(CPPFLAGS) $< -o $@
|
|
|
|
|
2023-10-23 21:03:05 +02:00
|
|
|
$(TARGET): $(FUNCS_LIB) $(ALL_OBJS) $(EXTRA_DEPS) | $(BUILD_SRC_DIRS)
|
|
|
|
$(LD) -o $@ $^ $(LDFLAGS)
|
2023-06-23 00:29:55 +02:00
|
|
|
|
|
|
|
$(BUILD_SRC_DIRS) $(FUNC_BUILD_DIR) $(BUILD_DIR):
|
2023-10-23 21:03:05 +02:00
|
|
|
$(call mkdir,$@)
|
2023-06-23 00:29:55 +02:00
|
|
|
|
|
|
|
-include $(ALL_OBJS:.o=.d)
|
|
|
|
|
|
|
|
MAKEFLAGS += --no-builtin-rules
|
|
|
|
.SUFFIXES:
|
|
|
|
.PHONY: default clean cleanfuncs
|
|
|
|
|
|
|
|
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true
|