include ../../config.mk

INCLUDE+=-I.. -I.

PROGS=test test_pci

TEST_NGMP=
TEST_LEON3=
ifeq ($(strip $(CPU)),ngmp)
	TEST_NGMP+=-DTEST_NGMP
	PROGS+=test_pci_rtr
endif

ifeq ($(strip $(CPU)),ngmp_smp)
	TEST_NGMP+=-DTEST_NGMP
	PROGS+=test_pci_rtr
endif

override CONFIG_DEPS=config*.c

all: $(PROGS)

clean:
	rm -f *.o core test test_pci test_pci_rtr > /dev/null

mmu_setup.o: mmu_setup.c
	$(CC) $(CFLAGS) -c $< -o $@

grspw_router_lib.o: ../grspw_router_lib.c ../grspw_router_lib.h
	$(CC) $(CFLAGS) -c $< -o $@

spwrouter_custom_config.o: spwrouter_custom_config.c
	$(CC) $(CFLAGS) -c $< -o $@

grspw_pkt_lib.o: ../grspw_pkt_lib.c ../grspw_pkt_lib.h
	$(CC) $(CFLAGS) -c $< -o $@

spwlib.o: spwlib.c spwlib.h
	$(CC) $(CFLAGS) -c $< -o $@

# GR740/LEON4-N2X router with 8 SpW ports and 4 AMBA ports. 4 AMBA ports used.
test_rtr: test.c test_rtems.c spwlib.o spwrouter_custom_config.o grspw_router_lib.o $(if $(TEST_NGMP),mmu_setup.o) grspw_pkt_lib.o $(CONFIG_DEPS)
	$(CC) $(CFLAGS) $(TEST_NGMP) $< -o $@ spwlib.o spwrouter_custom_config.o grspw_router_lib.o $(if $(TEST_NGMP),mmu_setup.o) grspw_pkt_lib.o

# Loopback between two SpW connectors without SpW router. Compatible with GR712RC/UT699E/UT700/etc.
test_dual: test.c test_rtems.c spwlib.o spwrouter_custom_config.o grspw_router_lib.o $(if $(TEST_NGMP),mmu_setup.o) grspw_pkt_lib.o $(CONFIG_DEPS)
	$(CC) $(CFLAGS) $(TEST_LEON3) -DDUAL_LOOPBACK $< -o $@ spwlib.o spwrouter_custom_config.o grspw_router_lib.o $(if $(TEST_NGMP),mmu_setup.o) grspw_pkt_lib.o

test_pci: test_pci.c spwlib.o spwrouter_custom_config.o grspw_router_lib.o $(if $(TEST_NGMP),mmu_setup.o) grspw_pkt_lib.o $(CONFIG_DEPS)
	$(CC) $(CFLAGS) $(TEST_NGMP) $< -o $@ spwlib.o spwrouter_custom_config.o grspw_router_lib.o $(if $(TEST_NGMP),mmu_setup.o) grspw_pkt_lib.o

test_pci_rtr: test_pci_rtr.c spwlib.o spwrouter_custom_config.o grspw_router_lib.o $(if $(TEST_NGMP),mmu_setup.o) grspw_pkt_lib.o $(CONFIG_DEPS)
	$(CC) $(CFLAGS) $(TEST_NGMP) $< -o $@ spwlib.o spwrouter_custom_config.o grspw_router_lib.o $(if $(TEST_NGMP),mmu_setup.o) grspw_pkt_lib.o

