-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
84 lines (66 loc) · 2.36 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
CC = gcc
CXX = g++
CFLAGS=
CXXFLAGS=-Wall -Werror -pedantic -std=c++14
LIB_LINKS+=-lglfw3 -limgui
LIB_DIR+=-L./3rdparty/glfw/lib
3RDPARTY_GLFW_OPTIONS=
ifeq ($(OS),Windows_NT)
CURRENT_DIR += $(shell sh -c "pwd -W")
LIB_LINKS+=-lwinmm -lgdi32 -lkernel32
3RDPARTY_GLFW_OPTIONS+=-G "MinGW Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_MAKE_PROGRAM=make
LIB_DIR+=-L./3rdparty/imgui/lib/win32
else
CURRENT_DIR += $(shell pwd)
LIB_DIR+=-L./3rdparty/imgui/lib/linux/
endif
INCLUDES+=-I./$(SOURCE_DIR)
INCLUDES+=-I./3rdparty/glad/include
INCLUDES+=-I./3rdparty/stb
INCLUDES+=-I./3rdparty/glfw/include
INCLUDES+=-I./3rdparty/imgui/include
SOURCE_DIR = source
BUILD_DIR = build
BUILD_OBJ_DIR=$(BUILD_DIR)/obj
CSOURCES = $(wildcard $(SOURCE_DIR)/*.c)
CXXSOURCES = $(wildcard $(SOURCE_DIR)/*.cpp)
COBJECTS = $(patsubst $(SOURCE_DIR)/%.c,$(BUILD_OBJ_DIR)/%.o,$(CSOURCES))
CXXOBJECTS = $(patsubst $(SOURCE_DIR)/%.cpp,$(BUILD_OBJ_DIR)/%.o,$(CXXSOURCES))
EXECUTABLE = MGEngine
all: make_build_dir $(EXECUTABLE)
print_obj:
@echo $(COBJECTS) $(CXXOBJECTS)
$(EXECUTABLE): $(COBJECTS) $(CXXOBJECTS)
$(CXX) $(CXXFLAGS) $(COBJECTS) $(CXXOBJECTS) -o $(BUILD_DIR)/$@ $(LIB_DIR) $(LIB_LINKS)
$(BUILD_OBJ_DIR)/%.o: $(SOURCE_DIR)/%.c
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
$(BUILD_OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
.PHONY: 3rdparty
3rdparty:
cd 3rdparty/glfw/source && \
cmake -S . -B ../build -DCMAKE_INSTALL_PREFIX=../ $(3RDPARTY_GLFW_OPTIONS) && \
cd ../build && \
make && make install
test: make_build_dir $(COBJECTS) $(CXXOBJECTS)
$(CXX) $(INCLUDES) -c test.cpp -o $(BUILD_OBJ_DIR)/test.o
$(CXX) $(CXXFLAGS) $(COBJECTS) $(filter-out $(BUILD_OBJ_DIR)/main.o,$(CXXOBJECTS)) $(BUILD_OBJ_DIR)/test.o $(LIB_DIR) $(LIB_LINKS)
make_build_dir:
mkdir -p $(BUILD_OBJ_DIR)
cp -r ./assets $(BUILD_DIR)
cp -r ./shaders $(BUILD_DIR)
gen_clangd:
@rm -rf .clangd
@printf "CompileFlags:\n" >> .clangd
@printf "\tAdd:\n" >> .clangd
@printf " - $(CXXFLAGS)\n" >> .clangd
@printf " - -I$(CURRENT_DIR)/${SOURCE_DIR}\n" >> .clangd
@printf " - -I$(CURRENT_DIR)/3rdparty/glad/include\n" >> .clangd
@printf " - -I$(CURRENT_DIR)/3rdparty/glfw/include\n" >> .clangd
@printf " - -I$(CURRENT_DIR)/3rdparty/imgui/include\n" >> .clangd
@printf " - -I$(CURRENT_DIR)/3rdparty/stb\n" >> .clangd
.PHONY: clean
clean:
rm -rf *.o
rm -rf build/*
rm -rf 3rdparty/glfw/build