Files
fsnap/Makefile
Fabio Scotto di Santolo e19378308d Declare feature test macros once in the build, not per source file
Nine files had drifted into four different combinations: _GNU_SOURCE in
walk.c, _XOPEN_SOURCE 700 in utility.c, _DEFAULT_SOURCE in scan.c,
_POSIX_C_SOURCE 200809L in list.c and diff.c, and all three at once in
create.c and types.c, where _XOPEN_SOURCE 700 already implies POSIX 2008.

_GNU_SOURCE was also wider than anything the code asks for: walk needs
dirent.d_type, which _DEFAULT_SOURCE provides. Closing that gap is what
SPEC.md section 19 asks for and what the README flags as the one thing
keeping the tree from being POSIX-only.

CPPFLAGS now carries -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE, and the
sources declare nothing. Confirmed DT_UNKNOWN is still visible under that
pair, so the d_type fast path stays active rather than silently falling
back to lstat.

Verified against the previous build: byte-identical scan output over
/usr/include, /usr/share/doc and /etc (17820 entries), and byte-identical
snapshots from create.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
2026-08-26 15:32:35 +02:00

56 lines
1.4 KiB
Makefile

CC := cc
# Feature test macros belong to the build, not to individual files: declaring
# them per-source drifted into four different combinations across nine files.
# _POSIX_C_SOURCE covers getline and realpath(path, NULL); _DEFAULT_SOURCE adds
# dirent.d_type, which walk uses as a fast path. SPEC.md section 19 targets
# POSIX, so nothing here asks for _GNU_SOURCE.
FEATURES := -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE
CPPFLAGS := -Iinclude -MMD -MP $(FEATURES)
# -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)