mirror of
https://github.com/fscotto/fsnap.git
synced 2026-11-26 03:09:51 +00:00
Without optimisation GCC skips the flow analysis most of these warnings are derived from, so -O2 is what makes the existing -W flags do their job. The new flags found three real defects: -Wstrict-prototypes/-Wold-style-definition: init_crc32_table() and RecordObjectNew() were declared with (), which in C11 means "no prototype", not "no arguments". RecordObjectNew even contradicted its own header, which declares (void). -Wwrite-strings: walk's blacklist held string literals in a non-const char *[], so they were writable through the array. Also make ignore_file size its loop with sizeof(blacklist[0]) instead of repeating the element type, and drop the order-only build/ prerequisite on the link rule, which the %.o rule's mkdir -p already covers. The tree builds clean under all twelve flags. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
49 lines
960 B
Makefile
49 lines
960 B
Makefile
CC := cc
|
|
|
|
CPPFLAGS := -Iinclude -MMD -MP
|
|
|
|
# -O2 is not only about speed: without optimisation GCC skips the flow
|
|
# analysis that most of these warnings are derived from.
|
|
WARNINGS := -Wall -Wextra -Wpedantic -Wconversion -Wshadow -Wvla \
|
|
-Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition \
|
|
-Wcast-qual -Wwrite-strings -Wdouble-promotion
|
|
CFLAGS := -std=c11 $(WARNINGS) -O2 -ggdb
|
|
LDFLAGS :=
|
|
LDLIBS :=
|
|
|
|
BUILD_DIR := build
|
|
TARGET := $(BUILD_DIR)/fsnap
|
|
|
|
SOURCES := \
|
|
src/main.c \
|
|
src/utility.c \
|
|
src/types.c \
|
|
src/hash.c \
|
|
src/walk.c \
|
|
src/scan.c \
|
|
src/create.c \
|
|
src/list.c \
|
|
src/diff.c
|
|
|
|
OBJECTS := $(SOURCES:%.c=$(BUILD_DIR)/%.o)
|
|
DEPENDENCIES := $(OBJECTS:.o=.d)
|
|
|
|
.PHONY: all clean run
|
|
|
|
all: $(TARGET)
|
|
|
|
$(TARGET): $(OBJECTS)
|
|
$(CC) $(LDFLAGS) $(OBJECTS) $(LDLIBS) -o $@
|
|
|
|
$(BUILD_DIR)/%.o: %.c
|
|
@mkdir -p $(dir $@)
|
|
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
|
|
|
run: $(TARGET)
|
|
./$(TARGET)
|
|
|
|
clean:
|
|
rm -rf $(BUILD_DIR)
|
|
|
|
-include $(DEPENDENCIES)
|