Skip to content

Commit 02241ab

Browse files
committed
feat: Added WARN_LEVELS for compilation
1 parent 562bc7d commit 02241ab

4 files changed

Lines changed: 198 additions & 33 deletions

File tree

examples/ImGui/makefile

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,47 @@ DOC_BUILD := $(BUILD_BASE)/docs
4747

4848
# ─── Compiler Configuration ───────────────────────────────────────────────────
4949

50-
# Error handling and warnings
51-
# -Werror: The compiler when throw error message stop the compilation.
52-
ERRORFLAGS := -Wall -Wextra -pedantic-errors -Wconversion -Wsign-conversion \
53-
-Wdouble-promotion -Wduplicated-cond -Wduplicated-branches \
54-
-Wlogical-op -Wrestrict -Wnull-dereference -Wformat=2
50+
# Warning Level Configuration
51+
# Options: minimal, normal, strict (default: strict)
52+
# - minimal: Only -Wall -Wextra -pedantic-errors
53+
# - normal: + type conversion and format checks
54+
# - strict: + logic, safety, and quality warnings
55+
WARN_LEVEL ?= strict
56+
57+
# Base warnings (always applied)
58+
ERROFFLAGS := -Wall -Wextra -pedantic-errors
59+
60+
# Type conversion warnings
61+
WARN_CONVERSION := -Wconversion -Wsign-conversion -Wdouble-promotion
62+
63+
# Logic and correctness warnings
64+
WARN_LOGIC := -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict
65+
66+
# Safety warnings
67+
WARN_SAFETY := -Wnull-dereference -Wformat=2 -Wunreachable-code
68+
69+
# Code quality warnings
70+
WARN_QUALITY := -Wshadow -Wunused -Wunused-parameter
71+
72+
# Apply warning level based on WARN_LEVEL setting
73+
ifeq ($(WARN_LEVEL),strict)
74+
ERROFFLAGS += $(WARN_CONVERSION) $(WARN_LOGIC) $(WARN_SAFETY) $(WARN_QUALITY)
75+
else ifeq ($(WARN_LEVEL),normal)
76+
ERROFFLAGS += $(WARN_CONVERSION) $(WARN_LOGIC) $(WARN_SAFETY)
77+
else ifeq ($(WARN_LEVEL),minimal)
78+
# Only base flags
79+
else
80+
$(warning WARNING: Unknown WARN_LEVEL='$(WARN_LEVEL)', using 'strict')
81+
WARN_LEVEL := strict
82+
ERROFFLAGS += $(WARN_CONVERSION) $(WARN_LOGIC) $(WARN_SAFETY) $(WARN_QUALITY)
83+
endif
84+
85+
# Convert warnings to errors in release mode
86+
ifeq ($(BUILD_TYPE),debug)
87+
# Debug: keep warnings as warnings for easier development
88+
else
89+
ERRORFLAGS += -Werror
90+
endif
5591

5692
ifeq ($(CXX),cl)
5793
# MSVC
@@ -501,12 +537,21 @@ help:
501537
@printf " $(OK_COLOR)clean-all$(NO_COLOR) - Remove all build artifacts\n"
502538
@printf " $(OK_COLOR)clean-bench$(NO_COLOR) - Remove benchmark builds\n\n"
503539

540+
@printf "$(BOLD)Configuration Options:$(NO_COLOR)\n"
541+
@printf " WARN_LEVEL=<level> - Warning strictness (minimal, normal, strict)\n"
542+
@printf " BUILD_TYPE=<type> - Build variant (release, debug, relwithdebinfo)\n"
543+
@printf " ARCH=<arch> - Target architecture (native, skylake, znver4, etc)\n"
544+
@printf " LANGUAGE=<std> - C++ standard (c++20, c++23, etc)\n"
545+
@printf " CXX=<compiler> - Compiler command (g++, clang++, cl, etc)\n"
546+
@printf " VERBOSE=<0|1> - Output verbosity (1=detailed, 0=quiet)\n\n"
547+
504548
@printf "$(BOLD)Examples:$(NO_COLOR)\n"
505-
@printf " make APP_NAME=myapp # Custom app name\n"
506-
@printf " make debug # Debug with sanitizers\n"
507-
@printf " make ARCH=native # Optimize for native CPU\n"
508-
@printf " make ARCH=znver4 CXX=clang++ # AMD Zen4 with Clang\n"
509-
@printf " make LANGUAGE=c++20 # Use C++20 standard\n"
549+
@printf " make APP_NAME=myapp # Custom app name\n"
550+
@printf " make debug # Debug with sanitizers\n"
551+
@printf " make WARN_LEVEL=minimal # Minimal warnings\n"
552+
@printf " make WARN_LEVEL=normal ARCH=native # Balanced warnings + optimization\n"
553+
@printf " make ARCH=znver4 CXX=clang++ # AMD Zen4 with Clang\n"
554+
@printf " make debug WARN_LEVEL=strict VERBOSE=1 # Full debug with detailed output\n"
510555
@printf "$(LINES_COLOR)────────────────────────────────────────────$(NO_COLOR)\n\n"
511556

512557
info:

examples/donut-basic/makefile

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,45 @@ DEP_DIR := $(BUILD_BASE)/dep
3333

3434
CXXFLAGS_BASE := -std=$(LANGUAGE) -fdiagnostics-color=always
3535

36-
# Set flags that control and show compiler errors
37-
ERRORFLAGS := -Wall -Wextra -pedantic-errors
36+
# Warning Level Configuration
37+
# Options: minimal, normal, strict (default: strict)
38+
# - minimal: Only -Wall -Wextra -pedantic-errors
39+
# - normal: + type conversion and format checks
40+
# - strict: + logic, safety, and quality warnings
41+
WARN_LEVEL ?= strict
42+
43+
# Base warnings (always applied)
44+
ERRORFLAGS := -Wall -Wextra -pedantic-errors
45+
46+
# Type conversion warnings
47+
WARN_CONVERSION := -Wconversion -Wsign-conversion -Wdouble-promotion
48+
49+
# Logic and correctness warnings
50+
WARN_LOGIC := -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict
51+
52+
# Safety warnings
53+
WARN_SAFETY := -Wnull-dereference -Wformat=2 -Wunreachable-code
54+
55+
# Code quality warnings
56+
WARN_QUALITY := -Wshadow -Wunused -Wunused-parameter
57+
58+
# Apply warning level based on WARN_LEVEL setting
59+
ifeq ($(WARN_LEVEL),strict)
60+
ERRORFLAGS += $(WARN_CONVERSION) $(WARN_LOGIC) $(WARN_SAFETY) $(WARN_QUALITY)
61+
else ifeq ($(WARN_LEVEL),normal)
62+
ERRORFLAGS += $(WARN_CONVERSION) $(WARN_LOGIC) $(WARN_SAFETY)
63+
else ifeq ($(WARN_LEVEL),minimal)
64+
# Only base flags
65+
else
66+
$(warning WARNING: Unknown WARN_LEVEL='$(WARN_LEVEL)', using 'strict')
67+
WARN_LEVEL := strict
68+
ERRORFLAGS += $(WARN_CONVERSION) $(WARN_LOGIC) $(WARN_SAFETY) $(WARN_QUALITY)
69+
endif
70+
71+
# Convert warnings to errors in release mode (optional)
72+
ifeq (release,$(findstring release,$(MAKECMDGOALS)))
73+
ERRORFLAGS += -Werror
74+
endif
3875

3976
CXXFLAGS := $(CXXFLAGS_BASE) $(ERRORFLAGS)
4077
LDFLAGS ?= -L./lib
@@ -178,10 +215,15 @@ help:
178215
@printf " full-clean Delete entire build/\n"
179216
@printf " info Show configuration\n"
180217
@printf " help This message\n\n"
181-
@printf "Variables (example: make APP_NAME=MyApp):\n"
182-
@printf " APP_NAME App name (default: $(APP_NAME))\n"
183-
@printf " CXX Compiler (default: $(CXX))\n"
184-
@printf " LANGUAGE C++ standard (default: $(LANGUAGE))\n\n"
218+
@printf "Configuration Variables:\n"
219+
@printf " APP_NAME App name (default: $(APP_NAME))\n"
220+
@printf " CXX Compiler (default: $(CXX))\n"
221+
@printf " LANGUAGE C++ standard (default: $(LANGUAGE))\n"
222+
@printf " WARN_LEVEL Warning level: minimal, normal, strict (default: strict)\n\n"
223+
@printf "Examples:\n"
224+
@printf " make debug # Debug with all warnings\n"
225+
@printf " make WARN_LEVEL=minimal # Minimal warnings\n"
226+
@printf " make WARN_LEVEL=normal CXX=clang++ # Balanced + clang\n"
185227

186228
info:
187229
@printf "\n═══════ Project Info ═══════\n"

templates/advanced/makefile

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,47 @@ DOC_BUILD := $(BUILD_BASE)/docs
4747

4848
# ─── Compiler Configuration ───────────────────────────────────────────────────
4949

50-
# Error handling and warnings
51-
# -Werror: The compiler when throw error message stop the compilation.
52-
ERRORFLAGS := -Wall -Wextra -pedantic-errors -Wconversion -Wsign-conversion \
53-
-Wdouble-promotion -Wduplicated-cond -Wduplicated-branches \
54-
-Wlogical-op -Wrestrict -Wnull-dereference -Wformat=2
50+
# Warning Level Configuration
51+
# Options: minimal, normal, strict (default: strict)
52+
# - minimal: Only -Wall -Wextra -pedantic-errors
53+
# - normal: + type conversion and format checks
54+
# - strict: + logic, safety, and quality warnings
55+
WARN_LEVEL ?= strict
56+
57+
# Base warnings (always applied)
58+
ERRORFLAGS := -Wall -Wextra -pedantic-errors
59+
60+
# Type conversion warnings
61+
WARN_CONVERSION := -Wconversion -Wsign-conversion -Wdouble-promotion
62+
63+
# Logic and correctness warnings
64+
WARN_LOGIC := -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict
65+
66+
# Safety warnings
67+
WARN_SAFETY := -Wnull-dereference -Wformat=2 -Wunreachable-code
68+
69+
# Code quality warnings
70+
WARN_QUALITY := -Wshadow -Wunused -Wunused-parameter
71+
72+
# Apply warning level based on WARN_LEVEL setting
73+
ifeq ($(WARN_LEVEL),strict)
74+
ERRORFLAGS += $(WARN_CONVERSION) $(WARN_LOGIC) $(WARN_SAFETY) $(WARN_QUALITY)
75+
else ifeq ($(WARN_LEVEL),normal)
76+
ERRORFLAGS += $(WARN_CONVERSION) $(WARN_LOGIC) $(WARN_SAFETY)
77+
else ifeq ($(WARN_LEVEL),minimal)
78+
# Only base flags
79+
else
80+
$(warning WARNING: Unknown WARN_LEVEL='$(WARN_LEVEL)', using 'strict')
81+
WARN_LEVEL := strict
82+
ERRORFLAGS += $(WARN_CONVERSION) $(WARN_LOGIC) $(WARN_SAFETY) $(WARN_QUALITY)
83+
endif
84+
85+
# Convert warnings to errors in release mode
86+
ifeq ($(BUILD_TYPE),debug)
87+
# Debug: keep warnings as warnings for easier development
88+
else
89+
ERRORFLAGS += -Werror
90+
endif
5591

5692
ifeq ($(CXX),cl)
5793
# MSVC
@@ -495,11 +531,12 @@ help:
495531
@printf " $(OK_COLOR)clean-bench$(NO_COLOR) - Remove benchmark builds\n\n"
496532

497533
@printf "$(BOLD)Examples:$(NO_COLOR)\n"
498-
@printf " make APP_NAME=myapp # Custom app name\n"
499-
@printf " make debug # Debug with sanitizers\n"
500-
@printf " make ARCH=native # Optimize for native CPU\n"
501-
@printf " make ARCH=znver4 CXX=clang++ # AMD Zen4 with Clang\n"
502-
@printf " make LANGUAGE=c++20 # Use C++20 standard\n"
534+
@printf " make APP_NAME=myapp # Custom app name\n"
535+
@printf " make debug # Debug with sanitizers\n"
536+
@printf " make WARN_LEVEL=minimal # Minimal warnings\n"
537+
@printf " make WARN_LEVEL=normal ARCH=native # Balanced warnings + optimization\n"
538+
@printf " make ARCH=znver4 CXX=clang++ # AMD Zen4 with Clang\n"
539+
@printf " make debug WARN_LEVEL=strict VERBOSE=1 # Full debug with detailed output\n"
503540
@printf "$(LINES_COLOR)────────────────────────────────────────────$(NO_COLOR)\n\n"
504541

505542
info:

templates/basic/makefile

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,45 @@ DEP_DIR := $(BUILD_BASE)/dep
3333

3434
CXXFLAGS_BASE := -std=$(LANGUAGE) -fdiagnostics-color=always
3535

36-
# Set flags that control and show compiler errors
37-
# Use -Werror to stop compilation on warnings
38-
ERRORFLAGS := -Wall -Wextra -pedantic-errors
36+
# Warning Level Configuration
37+
# Options: minimal, normal, strict (default: strict)
38+
# - minimal: Only -Wall -Wextra -pedantic-errors
39+
# - normal: + type conversion and format checks
40+
# - strict: + logic, safety, and quality warnings
41+
WARN_LEVEL ?= strict
42+
43+
# Base warnings (always applied)
44+
ERROFFLAGS := -Wall -Wextra -pedantic-errors
45+
46+
# Type conversion warnings
47+
WARN_CONVERSION := -Wconversion -Wsign-conversion -Wdouble-promotion
48+
49+
# Logic and correctness warnings
50+
WARN_LOGIC := -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict
51+
52+
# Safety warnings
53+
WARN_SAFETY := -Wnull-dereference -Wformat=2 -Wunreachable-code
54+
55+
# Code quality warnings
56+
WARN_QUALITY := -Wshadow -Wunused -Wunused-parameter
57+
58+
# Apply warning level based on WARN_LEVEL setting
59+
ifeq ($(WARN_LEVEL),strict)
60+
ERROFFLAGS += $(WARN_CONVERSION) $(WARN_LOGIC) $(WARN_SAFETY) $(WARN_QUALITY)
61+
else ifeq ($(WARN_LEVEL),normal)
62+
ERROFFLAGS += $(WARN_CONVERSION) $(WARN_LOGIC) $(WARN_SAFETY)
63+
else ifeq ($(WARN_LEVEL),minimal)
64+
# Only base flags
65+
else
66+
$(warning WARNING: Unknown WARN_LEVEL='$(WARN_LEVEL)', using 'strict')
67+
WARN_LEVEL := strict
68+
ERROFFLAGS += $(WARN_CONVERSION) $(WARN_LOGIC) $(WARN_SAFETY) $(WARN_QUALITY)
69+
endif
70+
71+
# Convert warnings to errors in release mode
72+
ifeq (release,$(findstring release,$(BUILD_TYPE)))
73+
ERROFFLAGS += -Werror
74+
endif
3975

4076
CXXFLAGS := $(CXXFLAGS_BASE) $(ERRORFLAGS)
4177
LDFLAGS ?= -L./lib
@@ -179,10 +215,15 @@ help:
179215
@printf " full-clean Delete entire build/\n"
180216
@printf " info Show configuration\n"
181217
@printf " help This message\n\n"
182-
@printf "Variables (example: make APP_NAME=MyApp):\n"
183-
@printf " APP_NAME App name (default: $(APP_NAME))\n"
184-
@printf " CXX Compiler (default: $(CXX))\n"
185-
@printf " LANGUAGE C++ standard (default: $(LANGUAGE))\n\n"
218+
@printf "Configuration Variables:\n"
219+
@printf " APP_NAME App name (default: $(APP_NAME))\n"
220+
@printf " CXX Compiler (default: $(CXX))\n"
221+
@printf " LANGUAGE C++ standard (default: $(LANGUAGE))\n"
222+
@printf " WARN_LEVEL Warning level: minimal, normal, strict (default: strict)\n\n"
223+
@printf "Examples:\n"
224+
@printf " make debug # Debug with all warnings\n"
225+
@printf " make WARN_LEVEL=minimal # Minimal warnings\n"
226+
@printf " make WARN_LEVEL=normal CXX=clang++ # Balanced + clang\n"
186227

187228
info:
188229
@printf "\n═══════ Project Info ═══════\n"

0 commit comments

Comments
 (0)