|
1 |
| -# **************************************************************************** # |
2 |
| -# # |
3 |
| -# ::: :::::::: # |
4 |
| -# Makefile :+: :+: :+: # |
5 |
| -# +:+ +:+ +:+ # |
6 |
| -# By: kiroussa <oss@xtrm.me> +#+ +:+ +#+ # |
7 |
| -# +#+#+#+#+#+ +#+ # |
8 |
| -# Created: 2022/10/04 16:43:41 by maldavid #+# #+# # |
9 |
| -# Updated: 2024/04/24 14:59:23 by kiroussa ### ########.fr # |
10 |
| -# # |
11 |
| -# **************************************************************************** # |
12 |
| - |
13 |
| -NAME = libmlx.so |
14 |
| -MAKE = make --no-print-directory |
15 |
| - |
16 |
| -OS ?= $(shell uname -s) |
17 |
| -DEBUG ?= false |
18 |
| -TOOLCHAIN ?= clang |
19 |
| -IMAGES_OPTIMIZED ?= true |
20 |
| -FORCE_INTEGRATED_GPU ?= false |
21 |
| -GRAPHICS_MEMORY_DUMP ?= false |
22 |
| -PROFILER ?= false |
23 |
| -_ENABLEDFLAGS = |
24 |
| - |
25 |
| -SRCS = $(wildcard $(addsuffix /*.cpp, src/core)) |
26 |
| -SRCS += $(wildcard $(addsuffix /*.cpp, src/platform)) |
27 |
| -SRCS += $(wildcard $(addsuffix /*.cpp, src/renderer)) |
28 |
| -SRCS += $(wildcard $(addsuffix /*.cpp, src/renderer/**)) |
29 |
| - |
30 |
| -OBJ_DIR = objs/make/$(shell echo $(OS) | tr '[:upper:]' '[:lower:]') |
31 |
| -OBJS := $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o)) |
32 |
| - |
33 |
| -CXX = clang++ |
34 |
| -CXXFLAGS = -std=c++17 -O3 -fPIC -Wall -Wextra -Werror -DSDL_MAIN_HANDLED |
35 |
| -INCLUDES = -I./includes -I./src -I./third_party |
| 1 | +NAME = libmlx.so |
| 2 | +MAKE = make --no-print-directory |
| 3 | + |
| 4 | +OS ?= $(shell uname -s) |
| 5 | +DEBUG ?= false |
| 6 | +TOOLCHAIN ?= clang |
| 7 | +IMAGES_OPTIMIZED ?= true |
| 8 | +FORCE_INTEGRATED_GPU ?= false |
| 9 | +GRAPHICS_MEMORY_DUMP ?= false |
| 10 | +PROFILER ?= false |
| 11 | +FORCE_WAYLAND ?= false |
| 12 | +DISABLE_ALL_SAFETIES ?= false |
| 13 | +_ENABLEDFLAGS = |
| 14 | + |
| 15 | +SRCS = $(wildcard $(addsuffix /*.cpp, runtime/Sources/Core)) |
| 16 | +SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Graphics)) |
| 17 | +SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Platform)) |
| 18 | +SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Renderer)) |
| 19 | +SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Renderer/Vulkan)) |
| 20 | +SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Renderer/Pipelines)) |
| 21 | +SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Renderer/RenderPasses)) |
| 22 | + |
| 23 | +OBJ_DIR = objs/make/$(shell echo $(OS) | tr '[:upper:]' '[:lower:]') |
| 24 | +OBJS := $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o)) |
| 25 | + |
| 26 | +SHADERS_DIR = runtime/Includes/Embedded |
| 27 | +SHADERS_SRCS = $(wildcard $(addsuffix /*.nzsl, $(SHADERS_DIR))) |
| 28 | +SPVS = $(SHADERS_SRCS:.nzsl=.spv.h) |
| 29 | + |
| 30 | +CXX = clang++ |
| 31 | +CXXFLAGS = -std=c++20 -fPIC -Wall -Wextra -DSDL_MAIN_HANDLED |
| 32 | +INCLUDES = -I./includes -I./runtime/Includes -I./runtime/Sources -I./third_party |
| 33 | + |
| 34 | +CXXPCHFLAGS = -xc++-header -std=c++20 -Wall -Wextra |
| 35 | + |
| 36 | +PCH_SOURCE = runtime/Includes/PreCompiled.h |
| 37 | +GCH = runtime/Includes/PreCompiled.h.gch |
| 38 | +CCH = runtime/Includes/PreCompiled.h.pch |
| 39 | +PCH = |
| 40 | + |
| 41 | +NZSLC ?= nzslc |
36 | 42 |
|
37 | 43 | ifeq ($(TOOLCHAIN), gcc)
|
38 |
| -CXX = g++ |
39 |
| -CXXFLAGS += -Wno-error=cpp |
| 44 | + CXX = g++ |
| 45 | + PCH = $(GCH) |
| 46 | + CXXFLAGS += -Wno-error=cpp |
40 | 47 | else
|
41 |
| -CXXFLAGS += -Wno-error=#warning |
| 48 | + PCH = $(CCH) |
| 49 | + CXXFLAGS += -Wno-error=#warning -include-pch $(PCH) |
42 | 50 | endif
|
43 | 51 |
|
44 | 52 | ifeq ($(OS), Darwin)
|
45 |
| -LDFLAGS += -L /opt/homebrew/lib -lSDL2 |
46 |
| -CXXFLAGS += -I /opt/homebrew/include |
47 |
| -NAME = libmlx.dylib |
| 53 | + LDFLAGS += -L /opt/homebrew/Cellar/lib -L /usr/local/Cellar -L /opt/homebrew/lib -lSDL2 |
| 54 | + INCLUDES += -I /opt/homebrew/Cellar/include -I /usr/local/Cellar/include -I /opt/homebrew/include |
| 55 | + NAME = libmlx.dylib |
48 | 56 | endif
|
49 | 57 |
|
50 | 58 | ifeq ($(DEBUG), true)
|
51 |
| -CXXFLAGS += -g3 -D DEBUG |
52 |
| -LDFLAGS += -rdynamic |
| 59 | + CXXFLAGS += -g3 -O0 -D DEBUG |
| 60 | + LDFLAGS += -rdynamic |
| 61 | +else |
| 62 | + CXXFLAGS += -O3 |
53 | 63 | endif
|
54 | 64 |
|
55 | 65 | ifeq ($(FORCE_INTEGRATED_GPU), true)
|
56 |
| -_ENABLEDFLAGS += FORCE_INTEGRATED_GPU |
| 66 | + _ENABLEDFLAGS += FORCE_INTEGRATED_GPU |
57 | 67 | endif
|
58 | 68 |
|
59 | 69 | ifeq ($(IMAGES_OPTIMIZED), true)
|
60 |
| -_ENABLEDFLAGS += IMAGE_OPTIMIZED |
| 70 | + _ENABLEDFLAGS += IMAGE_OPTIMIZED |
61 | 71 | endif
|
62 | 72 |
|
63 | 73 | ifeq ($(GRAPHICS_MEMORY_DUMP), true)
|
64 |
| -_ENABLEDFLAGS += GRAPHICS_MEMORY_DUMP |
| 74 | + _ENABLEDFLAGS += GRAPHICS_MEMORY_DUMP |
65 | 75 | endif
|
66 | 76 |
|
67 | 77 | ifeq ($(PROFILER), true)
|
68 |
| -_ENABLEDFLAGS += PROFILER |
| 78 | + _ENABLEDFLAGS += PROFILER |
| 79 | +endif |
| 80 | + |
| 81 | +ifeq ($(FORCE_WAYLAND), true) |
| 82 | + _ENABLEDFLAGS += FORCE_WAYLAND |
69 | 83 | endif
|
70 | 84 |
|
71 |
| -CXXFLAGS += $(addprefix -D, $(_ENABLEDFLAGS)) |
| 85 | +ifeq ($(DISABLE_ALL_SAFETIES), true) |
| 86 | + _ENABLEDFLAGS += DISABLE_ALL_SAFETIES |
| 87 | +endif |
| 88 | + |
| 89 | +CXXFLAGS += $(addprefix -D, $(_ENABLEDFLAGS)) |
72 | 90 |
|
73 | 91 | RM = rm -rf
|
74 | 92 |
|
75 |
| -TPUT = tput -T xterm-256color |
76 |
| -_RESET := $(shell $(TPUT) sgr0) |
77 |
| -_BOLD := $(shell $(TPUT) bold) |
78 |
| -_ITALIC := $(shell $(TPUT) sitm) |
79 |
| -_UNDER := $(shell $(TPUT) smul) |
80 |
| -_GREEN := $(shell $(TPUT) setaf 2) |
81 |
| -_YELLOW := $(shell $(TPUT) setaf 3) |
82 |
| -_RED := $(shell $(TPUT) setaf 1) |
83 |
| -_GRAY := $(shell $(TPUT) setaf 8) |
84 |
| -_PURPLE := $(shell $(TPUT) setaf 5) |
| 93 | +TPUT = tput -T xterm-256color |
| 94 | +_RESET := $(shell $(TPUT) sgr0) |
| 95 | +_BOLD := $(shell $(TPUT) bold) |
| 96 | +_ITALIC := $(shell $(TPUT) sitm) |
| 97 | +_UNDER := $(shell $(TPUT) smul) |
| 98 | +_GREEN := $(shell $(TPUT) setaf 2) |
| 99 | +_YELLOW := $(shell $(TPUT) setaf 3) |
| 100 | +_RED := $(shell $(TPUT) setaf 1) |
| 101 | +_GRAY := $(shell $(TPUT) setaf 8) |
| 102 | +_PURPLE := $(shell $(TPUT) setaf 5) |
85 | 103 |
|
86 | 104 | ifeq ($(DEBUG), true)
|
87 |
| -MODE := $(_RESET)$(_PURPLE)$(_BOLD)Debug$(_RESET)$(_PURPLE) |
88 |
| -COLOR := $(_PURPLE) |
| 105 | + MODE := $(_RESET)$(_PURPLE)$(_BOLD)Debug$(_RESET)$(_PURPLE) |
| 106 | + COLOR := $(_PURPLE) |
89 | 107 | else
|
90 |
| -MODE := $(_RESET)$(_GREEN)$(_BOLD)Release$(_RESET)$(_GREEN) |
91 |
| -COLOR := $(_GREEN) |
| 108 | + MODE := $(_RESET)$(_GREEN)$(_BOLD)Release$(_RESET)$(_GREEN) |
| 109 | + COLOR := $(_GREEN) |
92 | 110 | endif
|
93 | 111 |
|
94 |
| -OBJS_TOTAL = $(words $(OBJS)) |
95 |
| -N_OBJS := $(shell find $(OBJ_DIR) -type f -name '*.o' 2>/dev/null | wc -l) |
96 |
| -OBJS_TOTAL := $(shell echo $$(( $(OBJS_TOTAL) - $(N_OBJS) ))) |
97 |
| -CURR_OBJ = 0 |
| 112 | +OBJS_TOTAL = $(words $(OBJS)) |
| 113 | +N_OBJS := $(shell find $(OBJ_DIR) -type f -name '*.o' 2>/dev/null | wc -l) |
| 114 | +OBJS_TOTAL := $(shell echo $$(( $(OBJS_TOTAL) - $(N_OBJS) ))) |
| 115 | +ifeq ($(OBJS_TOTAL), 0) # To avoid division per 0 |
| 116 | + OBJS_TOTAL := 1 |
| 117 | +endif |
| 118 | +CURR_OBJ = 0 |
98 | 119 |
|
99 |
| -$(OBJ_DIR)/%.o: %.cpp |
| 120 | +$(OBJ_DIR)/%.o: %.cpp $(PCH) |
100 | 121 | @mkdir -p $(dir $@)
|
101 | 122 | @$(eval CURR_OBJ=$(shell echo $$(( $(CURR_OBJ) + 1 ))))
|
102 | 123 | @$(eval PERCENT=$(shell echo $$(( $(CURR_OBJ) * 100 / $(OBJS_TOTAL) ))))
|
103 | 124 | @printf "$(COLOR)($(_BOLD)%3s%%$(_RESET)$(COLOR)) $(_RESET)Compiling $(_BOLD)$<$(_RESET)\n" "$(PERCENT)"
|
104 | 125 | @$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
|
105 | 126 |
|
106 |
| -all: _printbuildinfos |
| 127 | +SPVS_TOTAL = $(words $(SPVS)) |
| 128 | +N_SPVS := $(shell find $(SHADERS_DIR) -type f -name '*.spv.h' 2>/dev/null | wc -l) |
| 129 | +SPVS_TOTAL := $(shell echo $$(( $(SPVS_TOTAL) - $(N_SPVS) ))) |
| 130 | +ifeq ($(SPVS_TOTAL), 0) # Same |
| 131 | + SPVS_TOTAL := 1 |
| 132 | +endif |
| 133 | +CURR_SPV = 0 |
| 134 | + |
| 135 | +%.spv.h: %.nzsl |
| 136 | + @$(eval CURR_SPV=$(shell echo $$(( $(CURR_SPV) + 1 )))) |
| 137 | + @$(eval PERCENT=$(shell echo $$(( $(CURR_SPV) * 100 / $(SPVS_TOTAL) )))) |
| 138 | + @printf "$(COLOR)($(_BOLD)%3s%%$(_RESET)$(COLOR)) $(_RESET)Compiling $(_BOLD)$<$(_RESET)\n" "$(PERCENT)" |
| 139 | + @$(NZSLC) --compile=spv-header $< -o $(SHADERS_DIR) --optimize |
| 140 | + |
| 141 | +all: _printbuildinfos |
107 | 142 | @$(MAKE) $(NAME)
|
108 | 143 |
|
109 |
| -$(NAME): $(OBJS) |
| 144 | +$(PCH): |
| 145 | + @printf "$(COLOR)($(_BOLD)%3s%%$(_RESET)$(COLOR)) $(_RESET)Compiling $(_BOLD)PreCompiled header$(_RESET)\n" "0" |
| 146 | + @$(CXX) $(CXXPCHFLAGS) $(INCLUDES) $(PCH_SOURCE) -o $(PCH) |
| 147 | + |
| 148 | +$(NAME): $(OBJS) |
110 | 149 | @printf "Linking $(_BOLD)$(NAME)$(_RESET)\n"
|
111 | 150 | @$(CXX) -shared -o $(NAME) $(OBJS) $(LDFLAGS)
|
112 | 151 | @printf "$(_BOLD)$(NAME)$(_RESET) compiled $(COLOR)$(_BOLD)successfully$(_RESET)\n"
|
113 | 152 |
|
114 | 153 | _printbuildinfos:
|
115 |
| - @printf "$(_PURPLE)$(_BOLD)MacroLibX $(_RESET)Compiling in $(_BOLD)$(MODE)$(_RESET) mode on $(_BOLD)$(OS)$(_RESET) | Using $(_BOLD)$(CXX)$(_RESET), flags: $(_BOLD)$(_ENABLEDFLAGS)$(_RESET)\n" |
| 154 | + @printf "$(_PURPLE)$(_BOLD)MacroLibX $(_RESET)Compiling in $(_BOLD)$(MODE)$(_RESET) mode on $(_BOLD)$(OS)$(_RESET) | Using $(_BOLD)$(CXX) ($(shell $(CXX) --version | head -n 1))$(_RESET), flags: $(_BOLD)$(_ENABLEDFLAGS)$(_RESET)\n" |
116 | 155 |
|
117 | 156 | debug:
|
118 | 157 | @$(MAKE) all DEBUG=true -j$(shell nproc)
|
119 | 158 |
|
| 159 | +clean-shaders: |
| 160 | + @$(RM) $(SPVS) |
| 161 | + |
| 162 | +shaders: clean-shaders $(SPVS) |
| 163 | + |
120 | 164 | clean:
|
121 | 165 | @$(RM) $(OBJ_DIR)
|
122 | 166 | @printf "Cleaned $(_BOLD)$(OBJ_DIR)$(_RESET)\n"
|
| 167 | + @$(RM) $(GCH) |
| 168 | + @$(RM) $(CCH) |
| 169 | + @printf "Cleaned pre compiled header\n" |
123 | 170 |
|
124 |
| -fclean: clean |
| 171 | +fclean: clean |
125 | 172 | @$(RM) $(NAME)
|
126 | 173 | @printf "Cleaned $(_BOLD)$(NAME)$(_RESET)\n"
|
127 | 174 |
|
128 |
| -re: fclean _printbuildinfos |
| 175 | +re: fclean _printbuildinfos |
129 | 176 | @$(MAKE) $(NAME)
|
130 | 177 |
|
131 |
| -.PHONY: all clean debug fclean re |
| 178 | +.PHONY: all clean debug shaders clean-shaders fclean re |
0 commit comments