Skip to content

Commit 791f4d3

Browse files
committed
Update makefile of template
1 parent 77f005d commit 791f4d3

1 file changed

Lines changed: 96 additions & 65 deletions

File tree

templates/advanced/makefile

Lines changed: 96 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,12 @@
1515
# Default build type when running plain `make`
1616
.DEFAULT_GOAL := all
1717

18-
# 0 = Silent Mode; 1 = Color & Details Mode
19-
ifneq ($(filter -j%,$(MAKEFLAGS)),)
20-
VERBOSE := 0
21-
else
22-
VERBOSE := 1
23-
endif
24-
25-
ifeq ($(VERBOSE),1)
26-
NO_COLOR := \033[0m
27-
BOLD := \033[1m
28-
OK_COLOR := \033[32;01m
29-
WARN_COLOR := \033[33;01m
30-
ERROR_COLOR := \033[31;01m
31-
INFO_COLOR := \033[36;01m
32-
TITLE_COLOR := \033[35;01m
33-
HIGHLIGHT := \033[95;01m
34-
else
35-
NO_COLOR :=
36-
BOLD :=
37-
OK_COLOR :=
38-
WARN_COLOR :=
39-
ERROR_COLOR :=
40-
INFO_COLOR :=
41-
TITLE_COLOR :=
42-
HIGHLIGHT :=
43-
endif
44-
4518
# ──────────────────────────────────────────────────────────────────────────────
4619
# Main configuration – customize these variables
4720
# ──────────────────────────────────────────────────────────────────────────────
4821

4922
# Application name (without extension)
50-
APP_NAME ?= MyProject
23+
APP_NAME ?= ProjectName
5124

5225
# Source file extension
5326
SRC_EXT ?= cpp
@@ -102,10 +75,100 @@ else
10275
endif
10376

10477
# ──────────────────────────────────────────────────────────────────────────────
105-
# Platform detection & common settings
78+
# Verbose mode configuration
79+
# ──────────────────────────────────────────────────────────────────────────────
80+
81+
# 0 = Silent Mode; 1 = Color & Details Mode
82+
VERBOSE ?= 1
83+
84+
# Optional: if the user passes -s (--silent), force VERBOSE=0
85+
ifneq ($(findstring s,$(MAKEFLAGS)),)
86+
VERBOSE := 0
87+
else ifneq ($(filter -j%,$(MAKEFLAGS)),)
88+
VERBOSE := 0
89+
endif
90+
91+
ifeq ($(VERBOSE),1)
92+
NO_COLOR := \033[0m
93+
BOLD := \033[1m
94+
OK_COLOR := \033[32;01m
95+
WARN_COLOR := \033[33;01m
96+
ERROR_COLOR := \033[31;01m
97+
INFO_COLOR := \033[36;01m
98+
TITLE_COLOR := \033[35;01m
99+
HIGHLIGHT := \033[95;01m
100+
else
101+
NO_COLOR :=
102+
BOLD :=
103+
OK_COLOR :=
104+
WARN_COLOR :=
105+
ERROR_COLOR :=
106+
INFO_COLOR :=
107+
TITLE_COLOR :=
108+
HIGHLIGHT :=
109+
endif
110+
111+
# ──────────────────────────────────────────────────────────────────────────────
112+
# Platform detection
106113
# ──────────────────────────────────────────────────────────────────────────────
107114

108-
ifeq ($(OS),Windows_NT)
115+
UNAME_S := $(shell uname -s 2>/dev/null || echo Unknown)
116+
117+
ifeq ($(findstring Windows,$(OS)),Windows)
118+
IS_WINDOWS := yes
119+
else ifeq ($(UNAME_S),Darwin)
120+
IS_MACOS := yes
121+
else ifeq ($(UNAME_S),Linux)
122+
IS_LINUX := yes
123+
endif
124+
125+
# ──────────────────────────────────────────────────────────────────────────────
126+
# Libraries & linker flags – main customization area
127+
# ──────────────────────────────────────────────────────────────────────────────
128+
129+
# ── Library search paths (use -L) ──
130+
LDFLAGS ?= -L./lib/
131+
132+
# ── Libraries to link against (use -l) ──
133+
LIBS ?=
134+
135+
# === Platform-specific libraries ===
136+
ifeq ($(IS_WINDOWS),yes)
137+
# GLFW on Windows (dinamic linking)
138+
# LIBS += -lglfw3dll
139+
140+
# OpenGL on Windows
141+
LIBS += -lgdi32 -lopengl32
142+
143+
# If using GUI app (no console), link additional libraries
144+
#LIBS += -luser32 -lgdi32 -lkernel32
145+
146+
# Optional: link with Shell32 and Dwmapi for advanced Windows features
147+
# LIBS += -lshell32 -ldwmapi
148+
endif
149+
150+
ifeq ($(IS_LINUX),yes)
151+
# GLFW on Linux
152+
# LIBS += -lglfw
153+
154+
# OpenGL + X11 stack
155+
LIBS += -lGL -ldl -lpthread
156+
LIBS += -lXrandr -lXinerama -lXcursor -lXi
157+
endif
158+
159+
ifeq ($(IS_MACOS),yes)
160+
# macOS frameworks (use -framework instead of -l)
161+
LDFLAGS += -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo
162+
endif
163+
164+
# ── Final linker command ingredients ──
165+
LDFLAGS += $(LIBS) $(CONSOLEFLAGS)
166+
167+
# ──────────────────────────────────────────────────────────────────────────────
168+
# Platforms common configuration
169+
# ──────────────────────────────────────────────────────────────────────────────
170+
171+
ifeq ($(IS_WINDOWS),yes)
109172
OS_NAME := Windows
110173
ifeq ($(USE_CONSOLE),false)
111174
CONSOLEFLAGS := -mwindows
@@ -128,11 +191,10 @@ ifeq ($(OS),Windows_NT)
128191
HOST_ARCH := x86_64
129192
endif
130193
else
131-
UNAME_S := $(shell uname -s)
132-
ifeq ($(UNAME_S),Linux)
194+
ifeq ($(IS_LINUX),yes)
133195
OS_NAME := Linux
134196
endif
135-
ifeq ($(UNAME_S),Darwin)
197+
ifeq ($(IS_MACOS),yes)
136198
OS_NAME := macOS
137199
endif
138200
RM := rm -rf
@@ -144,37 +206,6 @@ endif
144206
TARGET_ARCH := $(if $(filter native,$(ARCH)),$(HOST_ARCH),$(ARCH))
145207
TARGET := $(APP_NAME)-$(TARGET_ARCH)$(if $(filter Windows,$(OS_NAME)),.exe,)
146208

147-
# ──────────────────────────────────────────────────────────────────────────────
148-
# Libraries & linker flags – main customization area
149-
# ──────────────────────────────────────────────────────────────────────────────
150-
151-
# ── Library search paths (use -L) ──
152-
LDFLAGS ?= -L./lib/
153-
154-
# ── Libraries to link against (use -l) ──
155-
LIBS ?=
156-
157-
# === Platform-specific libraries ===
158-
ifeq ($(OS),Windows_NT)
159-
# Windows / MinGW common
160-
LIBS += -lkernel32 -luser32 -lgdi32 -lshell32 -ldwmapi
161-
endif
162-
163-
ifeq ($(OS_NAME),Linux)
164-
# Typical Linux dependencies
165-
# threads (usually needed on Linux)
166-
# LIBS += -lXrandr -lXinerama -lXcursor -lXi
167-
LIBS += -lGL -ldl -lpthread
168-
endif
169-
170-
ifeq ($(OS_NAME),macOS)
171-
# macOS frameworks (use -framework instead of -l)
172-
LDFLAGS += -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo
173-
endif
174-
175-
# ── Final linker command ingredients ──
176-
LDFLAGS += $(LIBS) $(CONSOLEFLAGS)
177-
178209
# ──────────────────────────────────────────────────────────────────────────────
179210
# Automatic source & object discovery
180211
# ──────────────────────────────────────────────────────────────────────────────
@@ -258,7 +289,7 @@ $(DEP_DIR)/%.d: ;
258289

259290
.PHONY: clean-banner
260291
clean-banner:
261-
@clear 2>/dev/null || cls
292+
@if [ -t 1 ]; then clear; fi
262293
ifeq ($(VERBOSE),1)
263294
@printf "$(INFO_COLOR)─── Build: $(HIGHLIGHT)$(APP_NAME)$(NO_COLOR)\n"
264295
@printf " $(BOLD)> OS:$(NO_COLOR) %s\n" "$(OS_NAME)"

0 commit comments

Comments
 (0)