# Standalone /net/wifi 9P mock server (host build).
#
# Reuses the real firmware srv framework (srv.c, srv_9p_adapter.c) over the
# 9p4z server core + aetherd's host TCP transport + Zephyr shims, with a
# synthetic /net/wifi tree (dev_wifi_mock.c).  See main.c for usage.

CC      ?= cc
# Sibling checkouts in the west workspace by default; override as needed
# (e.g. make NINEP=/path/to/9p4z).
WORKSPACE ?= $(abspath $(CURDIR)/../../..)
NINEP   ?= $(WORKSPACE)/9p4z
AUNIX   ?= $(WORKSPACE)/aetherd/unix
FRST    ?= $(abspath $(CURDIR)/../../src)

# Our shim first, then aetherd's host shims (zephyr/*, host 9p, tcp_transport),
# then 9p4z + frst sources.
INCLUDES = -Ishim \
	-I. \
	-I$(AUNIX)/include \
	-I$(NINEP)/include \
	-I$(FRST)

# Host equivalents for the few Zephyr stack macros mem.c references.
HOST_DEFS = -DZ_KERNEL_STACK_OBJ_ALIGN=16 \
	-D'K_KERNEL_STACK_LEN(s)=(s)' \
	-D'k_aligned_alloc(a,s)=malloc(s)'

CFLAGS  = -Wall -Wextra -O2 -g $(HOST_DEFS) -include stdarg.h $(INCLUDES)
LDFLAGS = -lpthread

SRCS = main.c \
	$(FRST)/dev_wifi_sim.c \
	$(NINEP)/src/server.c \
	$(NINEP)/src/fid.c \
	$(NINEP)/src/message.c \
	$(NINEP)/src/proto.c \
	$(AUNIX)/src/tcp_transport.c \
	$(AUNIX)/src/log.c \
	$(FRST)/srv.c \
	$(FRST)/srv_9p_adapter.c \
	$(FRST)/mem.c

mock_wifi: $(SRCS)
	$(CC) $(CFLAGS) $(SRCS) -o $@ $(LDFLAGS)

clean:
	rm -f mock_wifi

.PHONY: clean
