@@ -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
5692ifeq ($(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
512557info :
0 commit comments