# Standalone /net/aether 9P mock server (host build).
#
# Reuses the real firmware code (srv.c, srv_9p_adapter.c, dev_aether_net.c)
# over the 9p4z server core and aetherd's host TCP transport + Zephyr shims.
# The Æther PHY is a software loopback (main.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
AEPHYR  ?= $(WORKSPACE)/aephyr
AUNIX   ?= $(WORKSPACE)/aetherd/unix
FRST    ?= $(abspath $(CURDIR)/../../src)

# Include order matters: our slim shim first (overrides aephyr's heavy
# aether_mesh.h), then aetherd's host shims (zephyr/*, host 9p headers,
# tcp_transport.h), then 9p4z + aephyr (aether_reliable.h) + frst sources.
INCLUDES = -Ishim \
	-I$(AUNIX)/include \
	-I$(NINEP)/include \
	-I$(AEPHYR)/include \
	-I$(FRST)

# Host equivalents for the few Zephyr stack macros mem.h's (unused-here)
# mem_stack_alloc references.
HOST_DEFS = -DCONFIG_AETHER_MESH=1 \
	-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 \
	$(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)/dev_aether_net.c \
	$(FRST)/mem.c

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

clean:
	rm -f mock_aether

.PHONY: clean
