# SPDX-License-Identifier: GPL-3.0-or-later
# 入侵檢查／日誌／時間線／處置：核心的獨立編譯（不需要 libpomelo、顯示器）
#   make          編 test/pomelo-intr-tool（命令列外殼）
#   make test     編並跑單元測試
# 整合進主機醫生本體的方式見 README.md（patches/ 裡的補丁會把 INTR_SRC 加進 pomelo-doctor/Makefile）
CC ?= cc
CFLAGS ?= -O1 -g -pipe -Wall -Wextra -Wno-unused-parameter -Wno-format-truncation
override CFLAGS += -fstack-protector-strong -D_FORTIFY_SOURCE=2
DR = ..
DRCORE = $(DR)/store.c $(DR)/util.c $(DR)/logparse.c $(DR)/sec.c
INTR_SRC = intr-util.c intr-data.c intr-persist.c intr-procs.c intr-kmod.c intr-fs.c intr-integrity.c intrusion.c intr-admin.c utmp.c logclass.c logview.c logcli.c timeline.c crosstool.c evidence.c intr-cli.c
STUB = test/stub-sample.c

all: test/pomelo-intr-tool

test/pomelo-intr-tool: test/intr-tool.c $(INTR_SRC) $(DRCORE) $(STUB) intr.h
	$(CC) $(CFLAGS) -DDR_CORE_TEST -I. -o $@ test/intr-tool.c $(INTR_SRC) $(DRCORE) $(STUB) -lm

test/test-intr: test/test-intr.c $(INTR_SRC) $(DRCORE) $(STUB) intr.h
	$(CC) $(CFLAGS) -DDR_CORE_TEST -I. -o $@ test/test-intr.c $(INTR_SRC) $(DRCORE) $(STUB) -lm

test: test/test-intr
	TESTTMP=$${TESTTMP:-/tmp} TZ=Asia/Taipei test/test-intr test/fixtures

clean:
	rm -f test/pomelo-intr-tool test/test-intr

.PHONY: all test clean
