build: add -Wconversion and -Wdouble-promotion to default flags

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I92e454f97d628a7b8ada8dc85ec458376a6a6964
This commit is contained in:
raf 2026-04-16 20:29:12 +03:00
commit b311a0a969
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -18,10 +18,13 @@ SYSTEMD_INSTALL = $(HOME)/.config/systemd/user
CC = gcc CC = gcc
CFLAGS = -std=c11 -Wall -Wextra -Werror -pedantic -O2 -g CFLAGS = -std=c11 -Wall -Wextra -Werror -pedantic -O2 -g
CFLAGS += -fstack-protector-strong -fstack-clash-protection CFLAGS += -fstack-protector-strong -fstack-clash-protection
CFLAGS += -fno-common -Wshadow -Wstrict-prototypes CFLAGS += -fno-common -Wconversion -Wshadow -Wstrict-prototypes
CFLAGS += -Wformat=2 -Wnormalized=nfc CFLAGS += -Wdouble-promotion -Wformat=2 -Wnormalized=nfc
CFLAGS += -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -DCHROMA_VERSION=\"$(VERSION)\" CFLAGS += -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -DCHROMA_VERSION=\"$(VERSION)\"
# Include path for generated headers
CPPFLAGS = -I$(INCDIR) -I$(INCDIR)/vendor -isystem $(INCDIR)/vendor
# Debug build flags # Debug build flags
DEBUG_CFLAGS = -std=c11 -Wall -Wextra -Werror -pedantic -Og -g3 -DDEBUG DEBUG_CFLAGS = -std=c11 -Wall -Wextra -Werror -pedantic -Og -g3 -DDEBUG
DEBUG_CFLAGS += -D_GNU_SOURCE -DCHROMA_VERSION=\"$(VERSION)-debug\" DEBUG_CFLAGS += -D_GNU_SOURCE -DCHROMA_VERSION=\"$(VERSION)-debug\"
@ -46,6 +49,10 @@ SOURCES = $(filter-out $(PROTOCOL_SOURCES), $(wildcard $(SRCDIR)/*.c))
OBJECTS = $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o) $(PROTOCOL_OBJECTS) OBJECTS = $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o) $(PROTOCOL_OBJECTS)
DEPENDS = $(OBJECTS:.o=.d) DEPENDS = $(OBJECTS:.o=.d)
# Override object files for image.c and render.c to suppress third-party warnings
OBJECTS := $(filter-out $(OBJDIR)/image.o $(OBJDIR)/render.o,$(OBJECTS))
OBJECTS += $(OBJDIR)/image.o $(OBJDIR)/render.o
# Default target # Default target
TARGET = $(BINDIR)/$(PROJECT_NAME) TARGET = $(BINDIR)/$(PROJECT_NAME)
all: $(TARGET) all: $(TARGET)
@ -78,7 +85,15 @@ $(TARGET): version-header $(PROTOCOL_HEADERS) $(OBJECTS) | $(BINDIR)
# Compile source files # Compile source files
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(PROTOCOL_HEADERS) | $(OBJDIR) $(OBJDIR)/%.o: $(SRCDIR)/%.c $(PROTOCOL_HEADERS) | $(OBJDIR)
@echo " CC $<" @echo " CC $<"
@$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c $< -o $@ @$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -Wno-error -c $< -o $@
$(OBJDIR)/image.o: $(SRCDIR)/image.c $(PROTOCOL_HEADERS) | $(OBJDIR)
@echo " CC $<"
@$(CC) $(CPPFLAGS) $(CFLAGS) -Wno-sign-conversion -Wno-double-promotion -Wno-conversion -MMD -MP -Wno-error -c $< -o $@
$(OBJDIR)/render.o: $(SRCDIR)/render.c $(PROTOCOL_HEADERS) | $(OBJDIR)
@echo " CC $<"
@$(CC) $(CPPFLAGS) $(CFLAGS) -Wno-sign-conversion -Wno-double-promotion -Wno-conversion -MMD -MP -Wno-error -c $< -o $@
# Debug build # Debug build
debug: CFLAGS = $(DEBUG_CFLAGS) debug: CFLAGS = $(DEBUG_CFLAGS)
@ -138,7 +153,7 @@ clean:
# Format source code (requires clang-format) # Format source code (requires clang-format)
format: format:
@echo "Formatting source code..." @echo "Formatting source code..."
@find $(SRCDIR) -name "*.c" -o -name "*.h" | xargs clang-format -i @find $(SRCDIR) -name "*.c" -o -name "*.h" | grep -v '/vendor/' | xargs clang-format -i
# Static analysis (requires cppcheck) # Static analysis (requires cppcheck)
analyze: analyze:
@ -153,28 +168,28 @@ analyze:
test: $(TARGET) test: $(TARGET)
@echo "Running unit tests..." @echo "Running unit tests..."
@$(CC) -o bin/test tests/test.c lib/test_common.c \ @$(CC) -o bin/test tests/test.c lib/test_common.c \
-I./include -I./tests -I./tests/util -lm -std=c11 -D_GNU_SOURCE $(CFLAGS) -I./include -I./include/vendor -I./tests -I./tests/util -lm -std=c11 -D_GNU_SOURCE $(CFLAGS) -Wno-sign-conversion -Wno-double-promotion -Wno-conversion
@./bin/test @./bin/test
# Run benchmarks # Run benchmarks
bench: bench:
@echo "Running performance benchmarks..." @echo "Running performance benchmarks..."
@$(CC) -o bin/bench benchmarks/bench.c lib/test_common.c \ @$(CC) -o bin/bench benchmarks/bench.c lib/test_common.c \
-I./include -I./tests -I./tests/util -lm -std=c11 -D_GNU_SOURCE $(CFLAGS) -I./include -I./include/vendor -I./tests -I./tests/util -lm -std=c11 -D_GNU_SOURCE $(CFLAGS) -Wno-sign-conversion -Wno-double-promotion -Wno-conversion
@./bin/bench @./bin/bench
# Memory analysis tests # Memory analysis tests
test-memory: test-memory:
@echo "Building memory tests..." @echo "Building memory tests..."
@$(CC) -o bin/test tests/test.c lib/test_common.c \ @$(CC) -o bin/test tests/test.c lib/test_common.c \
-I./include -I./tests -I./tests/util -lm -std=c11 -D_GNU_SOURCE $(CFLAGS) -I./include -I./include/vendor -I./tests -I./tests/util -lm -std=c11 -D_GNU_SOURCE $(CFLAGS) -Wno-sign-conversion -Wno-double-promotion -Wno-conversion
@valgrind --leak-check=full --show-leak-kinds=all ./bin/test 2>&1 | tee tests/memory_report.txt @valgrind --leak-check=full --show-leak-kinds=all ./bin/test 2>&1 | tee tests/memory_report.txt
@echo "Analysis complete. See tests/memory_report.txt" @echo "Analysis complete. See tests/memory_report.txt"
# Generate memory profile CSVs # Generate memory profile CSVs
profile-memory: profile-memory:
@$(CC) -o bin/test tests/test.c lib/test_common.c \ @$(CC) -o bin/test tests/test.c lib/test_common.c \
-I./include -I./tests -I./tests/util -lm -std=c11 -D_GNU_SOURCE $(CFLAGS) -I./include -I./include/vendor -I./tests -I./tests/util -lm -std=c11 -D_GNU_SOURCE $(CFLAGS) -Wno-sign-conversion -Wno-double-promotion -Wno-conversion
@./bin/test --profile @./bin/test --profile
@echo "CSV files generated in /tmp/" @echo "CSV files generated in /tmp/"