-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
136 lines (111 loc) · 4.38 KB
/
Copy pathMakefile
File metadata and controls
136 lines (111 loc) · 4.38 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Kube : An OpenGL based game engine.
# Copyright (C) 2021 Kendal Harland GPL-3.0-only
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# To install dependencies:
# * libglfw: https://www.glfw.org/
# * libGLEW: https://glew.sourceforge.net/
# * libGL: https://dri.freedesktop.org/wiki/libGL/
ifndef config
config = release
endif
SOURCE_ROOT := $(realpath ./)
LIBRARY_PATH := $(SOURCE_ROOT)/src/lib/
BIN_PATH := $(SOURCE_ROOT)/bin
CXX := clang++
CXXFLAGS += -std=c++20 -Wall
INC := -I./src/include -I./third_party/assimp/include -I./third_party/wren/src/include
ifeq ($(config),debug)
CXXFLAGS += -g -O0
else
CXXFLAGS += -O2
endif
# Detect OS (Darwin = macOS, otherwise assume Linux/Unix-like)
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SHLIB_EXT := dylib
LINKSHARED := -dynamiclib
CXXFLAGS += -I/opt/homebrew/include -I/opt/homebrew/opt/llvm/include
LDFLAGS += -L/opt/homebrew/lib -L$(SOURCE_ROOT)/third_party/assimp/bin \
-L$(SOURCE_ROOT)/third_party/wren/bin \
-L$(LIBRARY_PATH) -Wl,-rpath,@executable_path/../src/lib
LIBS := -lglfw -lGLEW -lassimp -lwren -lm -framework OpenGL -framework AppKit
PLATFORM_OBJ := $(LIBRARY_PATH)platform_macos.o
else
SHLIB_EXT := so
LINKSHARED := -shared
LDFLAGS += -L$(LIBRARY_PATH)
LIBS := -lglfw -lGLEW -lGL -lm -lassimp -lwren
endif
TARGET_OBJ := $(LIBRARY_PATH)libkube.o
TARGET_LIB := $(LIBRARY_PATH)libkube.$(SHLIB_EXT)
.PHONY: default pull-submodules clean help format build build3p assimp kube demo-ships clean-build
default: kube
format:
@echo "=== Formatting code ==="
# find src -type f -exec clang-format -style=file -i {} \;
assimp:
@echo "=== Building third_party/assimp ==="
cd third_party/assimp; cmake CMakeLists.txt -DASSIMP_BUILD_TESTS=OFF -DASSIMP_BUILD_ASSIMP_TOOLS=OFF; make -j4
@mkdir -p $(LIBRARY_PATH)
# Copy the real dylib and its symlinks
cp -av third_party/assimp/bin/libassimp*.dylib $(LIBRARY_PATH)
wren:
@echo "=== Building third_party/wren ==="
cd third_party/wren/projects/make.mac; make -j4
@mkdir -p $(LIBRARY_PATH)
# Copy the real dylib and its symlinks
cp -av third_party/wren/lib/libwren*.dylib $(LIBRARY_PATH)
# Copy wren sources
cp -av third_party/wren/src/optional/wren_opt_random.wren src/wren/random.wren
build3p: assimp wren
@echo "=="
clean:
@echo "=== Removing temporary files ==="
rm -f $(TARGET_OBJ) $(TARGET_LIB) $(PLATFORM_OBJ)
rm -f $(BIN_PATH)/*
$(TARGET_OBJ): src/kube.cpp
@mkdir -p $(LIBRARY_PATH)
@echo "=== Compiling libkube object ($(config)) ==="
$(CXX) -c -o $@ $< $(CXXFLAGS) $(INC) -fPIC
$(PLATFORM_OBJ): src/kube/platform_macos.mm
@echo "=== Compiling platform_macos ($(config)) ==="
$(CXX) -c -o $@ $< $(CXXFLAGS) $(INC) -fPIC
$(TARGET_LIB): $(TARGET_OBJ) $(PLATFORM_OBJ)
@echo "=== Linking $(TARGET_LIB) ($(config)) ==="
$(CXX) $(LINKSHARED) -o $@ $^ $(LDFLAGS) $(LIBS)
build: build3p format $(TARGET_LIB)
@echo "=== Build complete: $(TARGET_LIB) ==="
clean-build: clean build
@echo "=== Performing a clean build ==="
pull-submodules:
@echo "=== Fetching submodules ==="
git submodule update --init --recursive
kube: build
@mkdir -p $(BIN_PATH)
@echo "=== Building demos ($(config)) ==="
# Ensure the linker finds libkube in src/lib
$(CXX) cmd/main.cpp -o $(BIN_PATH)/kube $(CXXFLAGS) $(INC) -L$(LIBRARY_PATH) -lkube $(LDFLAGS) $(LIBS)
demo-ships: kube
./bin/wren demos/main-ships.wren
help:
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@echo " demo (default) Builds all demos and places them in bin/"
@echo " clean Deletes temporary files from the project directory"
@echo " format Runs clang-format on all source files"
@echo " build Builds libkube shared library"
@echo " clean-build Cleans and then builds"
@echo " pull-submodules Initializes/updates git submodules"