Files
SoilSimulator/MakeFile

46 lines
1.2 KiB
Plaintext

TARGET_EXEC := sim
BUILD_DIR := ./build
SRC_DIR := ./src
SHADER_DIR := ./shaders
# Find all the C and C++ files we want to compile
SRCS := $(shell find $(SRC_DIR) -name '*.cpp')
GLSLS := $(shell find $(SHADER_DIR) -name '*.glsl')
# Prepends BUILD_DIR and appends .o to every src file
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
SPIRVS := $(GLSLS:%.glsl=$(BUILD_DIR)/%.sphv)
# String substitution (suffix version without %).
DEPS := $(OBJS:.o=.d)
# Every folder in ./src will need to be passed to GCC so that it can find header files
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
# Add a prefix to INC_DIRS. So moduleA would become -ImoduleA. GCC understands this -I flag
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
# The -MMD and -MP flags together generate Makefiles for us!
CPPFLAGS := $(INC_FLAGS) -MMD -MP
# The final build step.
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
$(CXX) $(OBJS) -o $@ $(LDFLAGS)
# Build step for C++ source
$(BUILD_DIR)/%.cpp.o: %.cpp $(SPIRVS) .simdb
mkdir -p $(dir $@)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $i@
#build the shaders
$(SPIRVS): $(GLSL)
mkdir -p $(dir $@)
glslc $(shaders).glsl $(shaders).spv
run: $(BUILD_DIR)/$(TARGET_EXEC)
./$(BUILD_DIR)/$(TARGET_EXEC)