-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
149 lines (126 loc) · 3.24 KB
/
Makefile
File metadata and controls
149 lines (126 loc) · 3.24 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
.SILENT:
# Compiler and flags
CXX = ccache clang++#g++
# SANFLAGS = -fsanitize=undefined
SANFLAGS = -fsanitize=address
CXXFLAGS = \
-MMD -MP \
-std=c++23 \
-I./src \
-g \
-march=native \
$(SANFLAGS) \
-fsafe-buffer-usage-suggestions \
-Wall \
-Wextra \
-Wpedantic \
-Wshadow \
-Wno-switch \
-Wno-sign-conversion \
-Wno-unused-parameter \
-Wno-implicit-float-conversion \
-Wno-implicit-int-float-conversion \
-Wno-shorten-64-to-32 \
-Wno-gnu-zero-variadic-macro-arguments \
-Wno-float-conversion \
-Wno-c++11-narrowing
#-fsanitize=memory -fsanitize-memory-track-origins=2
LDFLAGS = \
$(SANFLAGS) \
-lraylib \
-lGL \
-lX11 \
-lpthread \
-lm \
-lrt \
-lbacktrace \
-lstdc++exp
# Directories
SRC_DIR = src
BUILD_DIR = build
BIN_DIR =.
# Executable name
TARGET = main
EXEC_PATH =$(patsubst ./%,%,$(BIN_DIR)/$(TARGET))
EXEC_FULL_PATH =$(CURDIR)/$(patsubst ./%,%,$(BIN_DIR)/$(TARGET))
DESKTOP_FILE_NAME = claire.desktop
DESKTOP_DIR = $(HOME)/.local/share/applications
DESKTOP_PATH = $(DESKTOP_DIR)/$(DESKTOP_FILE_NAME)
SOURCES := $(shell find $(SRC_DIR) -name '*.cpp')
OBJECTS := $(SOURCES:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.o)
DEPS := $(OBJECTS:.o=.d)
NPROC ?= $(shell nproc || echo 1)
MAKEFLAGS += -j$(NPROC)
.DEFAULT_GOAL := $(EXEC_PATH)
all: $(EXEC_PATH)
# Link object files into the final executable
$(EXEC_PATH): $(OBJECTS)
@echo "LD :: $@"
$(CXX) $^ -o $@ $(LDFLAGS)
+$(MAKE) $(DESKTOP_PATH)
# Compile source files into object files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(@D)
@echo "CXX :: $@"
$(CXX) $(CXXFLAGS) -c $< -o $@
$(DESKTOP_DIR)/$(DESKTOP_FILE_NAME):
mkdir -p $(DESKTOP_DIR)
echo "[Desktop Entry]" > $@
echo "Version=1.0" >> $@
echo "Name=Claire's Editor" >> $@
# echo "Comment=My development build of the application" >> $@
echo "Exec=$(EXEC_FULL_PATH)" >> $@
echo "Icon=$(CURDIR)/claire_head.png" >> $@
echo "Terminal=false" >> $@
echo "Type=Application" >> $@
echo "Categories=Development;" >> $@
update-desktop-database $(DESKTOP_DIR) || true
# Clean target to remove build files and the executable
clean:
rm -rf $(BUILD_DIR) $(EXEC_PATH) $(DESKTOP_PATH) $(BUILD_DIR_WIN) $(TARGET_WIN)
run: $(EXEC_PATH)
@echo "RUN :: $(EXEC_FULL_PATH)"
$(EXEC_FULL_PATH)
# Windows
CXX_WIN = x86_64-w64-mingw32-g++
BUILD_DIR_WIN = build-win
TARGET_WIN = claire.exe
SOURCES_WIN := $(shell find $(SRC_DIR) -name '*.cpp')
OBJECTS_WIN := $(SOURCES:$(SRC_DIR)/%.cpp=$(BUILD_DIR_WIN)/%.o)
CXXFLAGS_WIN = \
-MMD -MP \
-std=c++23 \
-I./src \
-g \
-march=native \
-Wall \
-Wextra \
-Wpedantic \
-Wno-switch \
-Wno-narrowing \
-Wno-sign-conversion \
-Wno-unused-parameter \
-Wno-float-conversion \
LDFLAGS_WIN = \
-Llib \
-lraylib \
-lopengl32 \
-lgdi32 \
-lwinmm \
-static-libgcc \
-static-libstdc++
windows: $(TARGET_WIN)
$(TARGET_WIN): $(OBJECTS_WIN)
@echo "LD-WIN :: $@"
$(CXX_WIN) $^ -o $@ $(LDFLAGS_WIN)
# Rule to compile source files into Windows object files
$(BUILD_DIR_WIN)/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(@D)
@echo "CXX-WIN :: $@"
$(CXX_WIN) $(CXXFLAGS_WIN) -c $< -o $@
# Update the existing run-win rule to depend on the new windows target
run-win: windows
@echo "RUN-WIN :: Running $(TARGET_WIN) via Windows Explorer"
/mnt/c/Windows/explorer.exe $(TARGET_WIN)
.PHONY: all clean run
-include $(DEPS)