This repository has been archived by the owner on Nov 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
190 lines (135 loc) · 5.5 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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
CXX = clang++
CC = clang
INCLUDE = -Ikgfx/include -Ikgfx/vendor/include
DEFINES = -DKGFX_DEBUG
CXXFLAGS = -std=c++14 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-variable -Wno-unused-private-field -Wno-unused-function $(INCLUDE) $(DEFINES)
CCFLAGS = -std=c99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-variable -Wno-unused-private-field -Wno-unused-function $(INCLUDE) $(DEFINES)
MMFLAGS = -fobjc-arc
KGFX_SRC_DIR = kgfx/src/kgfx
KGFX_VENDOR = kgfx/vendor
KGFX_SRC_METAL = $(KGFX_SRC_DIR)/kgfx_metal.mm
KGFX_SRC_D3D12 = $(KGFX_SRC_DIR)/kgfx_d3d12.cpp
KGFX_SRC_VULKAN = $(KGFX_SRC_DIR)/kgfx_vulkan.cpp
KGFX_SRC_DUMMY = $(KGFX_SRC_DIR)/kgfx_dummy.c
OBJ_DIR = obj
BUILD_DIR = build
KGFX_OBJ_METAL = $(OBJ_DIR)/$(subst .mm,.o,$(KGFX_SRC_METAL))
KGFX_OBJ_D3D12 = $(OBJ_DIR)/$(subst .cpp,.o,$(KGFX_SRC_D3D12))
KGFX_OBJ_VULKAN = $(OBJ_DIR)/$(subst .cpp,.o,$(KGFX_SRC_VULKAN))
KGFX_OBJ_DUMMY = $(OBJ_DIR)/$(subst .c,.o,$(KGFX_SRC_DUMMY))
OS = $(shell uname)
STATIC_LIB_EXT = a
DYNAMIC_LIB_EXT = dylib
DYNAMIC_LINK_FLAG = -dynamiclib
STATIC_LINK_FLAGS_METAL = -framework Metal -framework Cocoa -framework QuartzCore
DYNAMIC_LINK_FLAGS_METAL = -lobjc -framework Metal -framework Cocoa -framework QuartzCore
STATIC_LINK_FLAGS_VULKAN = -lvulkan
DYNAMIC_LINK_FLAGS_VULKAN = -lvulkan
KGFXGH_LINK_FLAGS = -lglfw3
KGFXGH_SRC_DIR = kgfx/src/kgfx_gh
KGFXGH_OBJ =
ifeq ($(OS),Windows_NT)
STATIC_LIB_EXT = lib
DYNAMIC_LIB_EXT = dll
KGFXGH_LINK_FLAGS = -lglfw3
KGFXGH_OBJ = $(OBJ_DIR)/$(KGFXGH_SRC_DIR)/kgfx_gh_win32.o
else ifeq ($(OS),Darwin)
STATIC_LIB_EXT = a
DYNAMIC_LIB_EXT = dylib
STATIC_LINK_FLAGS_VULKAN = -L$(KGFX_VENDOR)/mac -lMoltenVK
DYNAMIC_LINK_FLAGS_VULKAN = -L$(KGFX_VENDOR)/mac -lMoltenVK
DYNAMIC_LINK_FLAG = -shared -undefined dynamic_lookup
KGFXGH_LINK_FLAGS = -L$(KGFX_VENDOR)/mac -lglfw3 -framework Cocoa -framework IOKit
KGFXGH_OBJ = $(OBJ_DIR)/$(KGFXGH_SRC_DIR)/kgfx_gh_cocoa.o
else
STATIC_LIB_EXT = a
DYNAMIC_LIB_EXT = so
STATIC_LINK_FLAGS_VULKAN = -lvulkan
DYNAMIC_LINK_FLAGS_VULKAN = -lvulkan
DYNAMIC_LINK_FLAG = -shared -fPIC
KGFXGH_LINK_FLAGS = -lglfw
KGFXGH_OBJ = $(OBJ_DIR)/$(KGFXGH_SRC_DIR)/kgfx_gh_xlib.o
endif
.PHONY: clean-obj clean-build obj-gh build-gh-static link-gh-static build-gh-dynamic link-gh-dynamic obj-metal build-metal-static link-metal-static build-metal-dylib link-metal-dylib obj-dummy build-dummy-static link-dummy-static build-dummy-dynamic link-dummy-dynamic obj-vulkan build-vulkan-static link-vulkan-static build-vulkan-dynamic link-vulkan-dynamic clean make-vars
make-vars:
@echo "Makefile variables debug:"
@echo "CXX: " $(CXX)
@echo "CC: " $(CC)
@echo "CXXFLAGS: " $(CXXFLAGS)
@echo "CCFLAGS: " $(CCFLAGS)
@echo "MMFLAGS: " $(MMFLAGS)
@echo "KGFX_SRC_METAL: " $(KGFX_SRC_METAL)
@echo "KGFX_SRC_D3D12: " $(KGFX_SRC_D3D12)
@echo "KGFX_SRC_VULKAN: " $(KGFX_SRC_VULKAN)
@echo "KGFX_SRC_DUMMY: " $(KGFX_SRC_DUMMY)
@echo "OBJ_DIR: " $(OBJ_DIR)
@echo "BUILD_DIR: " $(BUILD_DIR)
@echo "KGFX_OBJ_METAL: " $(KGFX_OBJ_METAL)
@echo "KGFX_OBJ_D3D12: " $(KGFX_OBJ_D3D12)
@echo "KGFX_OBJ_VULKAN: " $(KGFX_OBJ_VULKAN)
@echo "KGFX_OBJ_DUMMY: " $(KGFX_OBJ_DUMMY)
clean: clean-obj clean-build
clean-obj:
rm -rf $(OBJ_DIR)
clean-build:
rm -rf $(BUILD_DIR)
obj-gh: $(KGFXGH_OBJ)
build-gh-static: obj-gh link-gh-static
link-gh-static:
@echo "| Linking static lib: libkgfx_gh.$(STATIC_LIB_EXT)"
@mkdir -p $(BUILD_DIR)
ar rcs $(BUILD_DIR)/libkgfx_gh.$(STATIC_LIB_EXT) $(KGFXGH_OBJ)
build-gh-dynamic: obj-gh link-gh-dynamic
link-gh-dynamic:
@echo "| Linking libkgfx_gh dynamic lib:.$(DYNAMIC_LIB_EXT)"
@mkdir -p $(BUILD_DIR)
$(CXX) $(DYNAMIC_LINK_FLAG) -o $(BUILD_DIR)/libkgfx_gh.$(DYNAMIC_LIB_EXT) $(KGFXGH_OBJ) $(KGFXGH_LINK_FLAGS)
build-metal-static: obj-metal link-metal-static
link-metal-static:
@echo "| Linking static lib: libkgfx.a"
@mkdir -p $(BUILD_DIR)
ar rcs $(BUILD_DIR)/libkgfx.a $(KGFX_OBJ_METAL)
build-metal-dylib: obj-metal link-metal-dylib
obj-metal: $(KGFX_OBJ_METAL)
link-metal-dylib:
@echo "| Linking libkgfx_metal.dylib"
@mkdir -p $(BUILD_DIR)
$(CXX) -dynamiclib -o $(BUILD_DIR)/libkgfx.dylib $(KGFX_OBJ_METAL) -lobjc -framework Metal -framework Cocoa -framework QuartzCore
obj-dummy: $(KGFX_OBJ_DUMMY)
build-dummy-static: obj-dummy link-dummy-static
link-dummy-static:
@echo "| Linking static lib: libkgfx.a"
@mkdir -p $(BUILD_DIR)
ar rcs $(BUILD_DIR)/libkgfx.a $(KGFX_OBJ_DUMMY)
build-dummy-dynamic: obj-dummy link-dummy-dynamic
link-dummy-dynamic:
@echo "| Linking dynamic lib: libkgfx.dylib"
@mkdir -p $(BUILD_DIR)
$(CC) $(DYNAMIC_LINK_FLAG) -o $(BUILD_DIR)/libkgfx.dylib $(KGFX_OBJ_DUMMY)
obj-vulkan: $(KGFX_OBJ_VULKAN)
build-vulkan-static: obj-vulkan link-vulkan-static
link-vulkan-static:
@echo "| Linking static lib: libkgfx.$(STATIC_LIB_EXT)"
@mkdir -p $(BUILD_DIR)
ar rcs $(BUILD_DIR)/libkgfx.$(STATIC_LIB_EXT) $(KGFX_OBJ_VULKAN)
build-vulkan-dynamic: obj-vulkan link-vulkan-dynamic
link-vulkan-dynamic:
@echo "| Linking dynamic lib: libkgfx.$(DYNAMIC_LIB_EXT)"
@mkdir -p $(BUILD_DIR)
$(CXX) $(DYNAMIC_LINK_FLAG) -o $(BUILD_DIR)/libkgfx.$(DYNAMIC_LIB_EXT) $(KGFX_OBJ_VULKAN) $(DYNAMIC_LINK_FLAGS_VULKAN)
$(OBJ_DIR)/%.o: %.cpp
@echo "|-> Compiling $< to $@"
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: %.mm
@echo "|-> Compiling $< to $@"
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(MMFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: %.c
@echo "|-> Compiling $< to $@"
@mkdir -p $(dir $@)
$(CC) $(CCFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: %.m
@echo "|-> Compiling $< to $@"
@mkdir -p $(dir $@)
$(CC) $(CCFLAGS) $(MMFLAGS) -c $< -o $@