@@ -6,6 +6,7 @@ TEST_DIR = tests/unit
66TEST_SRCS = $(TEST_DIR ) /test-runner.c \
77 $(TEST_DIR ) /test-fd-table.c \
88 $(TEST_DIR ) /test-path.c \
9+ $(TEST_DIR ) /test-cli.c \
910 $(TEST_DIR ) /test-identity.c \
1011 $(TEST_DIR ) /test-syscall-nr.c \
1112 $(TEST_DIR ) /test-elf.c \
2930# Unit tests link only the pure-computation sources (no LKL)
3031TEST_SUPPORT_SRCS = $(SRC_DIR ) /fd-table.c \
3132 $(SRC_DIR ) /path.c \
33+ $(SRC_DIR ) /cli.c \
3234 $(SRC_DIR ) /identity.c \
3335 $(SRC_DIR ) /syscall-nr.c \
3436 $(SRC_DIR ) /elf.c \
@@ -111,4 +113,45 @@ $(ROOTFS): scripts/mkrootfs.sh scripts/alpine-sha256.txt $(GUEST_BINS) $(STRESS_
111113 @echo " GEN $@ "
112114 $(Q ) ALPINE_ARCH=$(ARCH ) ./scripts/mkrootfs.sh
113115
114- .PHONY : check check-unit check-integration check-stress guest-bins stress-bins rootfs
116+ # ---- Syntax-only compilation check (used by pre-commit hook) ----
117+ # Usage: make check-syntax CHK_SOURCES="src/foo.c src/bar.c"
118+ # Uses the project's real CFLAGS with -fsyntax-only (no linking, no .o output).
119+ # Skips gracefully on non-Linux compilers.
120+
121+ CHK_CC_TARGET := $(shell $(CC ) -dumpmachine 2>/dev/null)
122+ check-syntax :
123+ ifeq ($(findstring linux,$(CHK_CC_TARGET ) ) ,)
124+ @echo " SKIP check-syntax (non-Linux compiler: $(CHK_CC_TARGET))"
125+ else
126+ ifdef CHK_SOURCES
127+ @echo " SYNTAX $(words $(CHK_SOURCES)) file(s)"
128+ $(Q)$(CC) $(CFLAGS) -DKBOX_UNIT_TEST -fsyntax-only \
129+ -Werror=implicit-function-declaration \
130+ -Werror=incompatible-pointer-types \
131+ -Werror=int-conversion \
132+ -Werror=return-type \
133+ -Werror=format=2 \
134+ -Werror=format-security \
135+ -Werror=strict-prototypes \
136+ -Werror=old-style-definition \
137+ -Werror=sizeof-pointer-memaccess \
138+ -Werror=vla \
139+ $(CHK_SOURCES)
140+ else
141+ @echo " SYNTAX all source files"
142+ $(Q)$(CC) $(CFLAGS) -DKBOX_UNIT_TEST -fsyntax-only \
143+ -Werror=implicit-function-declaration \
144+ -Werror=incompatible-pointer-types \
145+ -Werror=int-conversion \
146+ -Werror=return-type \
147+ -Werror=format=2 \
148+ -Werror=format-security \
149+ -Werror=strict-prototypes \
150+ -Werror=old-style-definition \
151+ -Werror=sizeof-pointer-memaccess \
152+ -Werror=vla \
153+ $(SRCS)
154+ endif
155+ endif
156+
157+ .PHONY : check check-unit check-integration check-stress guest-bins stress-bins rootfs check-syntax
0 commit comments