-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
30 lines (22 loc) · 1.06 KB
/
Makefile
File metadata and controls
30 lines (22 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
CC ?= clang
CFLAGS := -Wall -Wextra -pedantic -g -O2 -fstack-protector-strong
LDFLAGS := -lcap
TARGET := sandbox
SRC := sandbox.c
TEST_SH := tests/smoke.sh
.PHONY: all clean preflight test lint validate
all: $(TARGET)
test: $(TARGET)
./$(TEST_SH)
lint:
cppcheck --quiet --enable=warning,performance,portability --check-level=reduced --suppress=normalCheckLevelMaxBranches --inline-suppr --error-exitcode=1 sandbox.c
shellcheck tests/smoke.sh
validate: test lint
preflight:
@command -v $(CC) >/dev/null 2>&1 || { echo "Error: compiler '$(CC)' not found. Install it or set CC to an available compiler."; exit 1; }
@echo '#include <sys/capability.h>' | $(CC) -fsyntax-only -x c - 2>/dev/null || { echo "Error: <sys/capability.h> not found. Install libcap development headers (e.g. libcap-dev)."; exit 1; }
@echo 'int main(void){return 0;}' | $(CC) -x c - -lcap -o /dev/null 2>/dev/null || { echo "Error: cannot link with -lcap. Install libcap (e.g. libcap-dev)."; exit 1; }
$(TARGET): $(SRC) | preflight
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
clean:
rm -f $(TARGET)