Files
cross-platform-compiling/Makefile-linux
junseopark-digipen 671d841861 Add weird codes
2026-09-14 14:30:06 +09:00

51 lines
1.3 KiB
Plaintext

# Specify our compiler
CXX := g++
# Specify where our source files are
SOURCE_DIR := src
# Specify where our object and program files should go
BUILD_DIR := build/linux
# Specify our program's name
BINARY := game
# Specify what flags to give to the compiler
CXX_FLAGS := -g -std=c++20 -Wall -Werror -Wextra -c
# Specify what flags to give to the linker
LINK_FLAGS := -lSDL2 -lGL -lGLEW -lGLU -lpthread
# Find all the source files
CXX_FILES := $(shell find $(SOURCE_DIR) -name *.cpp)
# Find all the source shaders
SHADER_FILES := $(shell find $(SOURCE_DIR) -name *.vert) $(shell find $(SOURCE_DIR) -name *.frag)
# Determine a list of object and dependency files from all the source files
OBJ_FILES := $(patsubst $(SOURCE_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(CXX_FILES))
DEP_FILES := $(patsubst %.o,%.d,$(OBJ_FILES))
COPIED_FILES := $(patsubst $(SOURCE_DIR)/%,$(BUILD_DIR)/%,$(SHADER_FILES))
.PHONY: program
program: $(BUILD_DIR)/$(BINARY) $(COPIED_FILES)
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
$(BUILD_DIR)/$(BINARY): $(OBJ_FILES) $(BUILD_DIR)
$(CXX) $(OBJ_FILES) $(LINK_FLAGS) -o "$@"
$(BUILD_DIR):
mkdir -p $@
-include $(DEP_FILES)
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.cpp
@mkdir -p "$(@D)"
$(CXX) $(CXX_FLAGS) -MMD -c "$<" -o "$@"
$(BUILD_DIR)/%.vert: $(SOURCE_DIR)/%.vert
cp $< $@
$(BUILD_DIR)/%.frag: $(SOURCE_DIR)/%.frag
cp $< $@