# lispif_process_cmd must not leave the evaluator paused when a request
# that pauses it gives up. Builds the real lispBM/lispif.c and LispBM
# evaluator on the host against the stand-in headers of ../lispif_stats; see main.c.
#
# -m32 because lispif.c programs the const-heap image through a uint32_t
# address, and LispBM is built 32-bit as on the board. Needs gcc_multi, which
# the dev shell carries (check.sh skips on missing 32-bit headers).
TOP = ../..
LISPBM = $(TOP)/lispBM/lispBM

LBM_SRC = $(addprefix $(LISPBM)/src/, env.c fundamental.c heap.c lbm_memory.c \
          print.c stack.c symrepr.c tokpar.c extensions.c lispbm.c eval_cps.c \
          lbm_channel.c lbm_c_interop.c lbm_custom_type.c lbm_flat_value.c \
          lbm_prof.c lbm_defrag_mem.c lbm_image.c \
          extensions/array_extensions.c extensions/math_extensions.c \
          extensions/string_extensions.c extensions/mutex_extensions.c \
          extensions/lbm_dyn_lib.c) \
          $(LISPBM)/platform/linux/src/platform_mutex.c \
          $(LISPBM)/platform/linux/src/platform_timestamp.c

SOURCES = main.c $(TOP)/lispBM/lispif.c $(TOP)/util/buffer.c $(LBM_SRC) \
          $(TOP)/script/lbm_pkgs.c $(TOP)/script/pkg_table.c $(TOP)/script/script_pack.c
HEADERS = $(addprefix ../lispif_stats/, ch.h hal.h commands.h flash_helper.h main.h mempools.h \
          stm32f4xx_conf.h utils.h)

CC = gcc
# The firmware's LispBM options, from make/fw.mk.
LBM_OPT = -DLBM_USE_DYN_FUNS -DLBM_USE_DYN_MACROS -DLBM_USE_DYN_LOOPS \
          -DLBM_USE_TIME_QUOTA -DLBM_USE_ERROR_LINENO -DLBM_USE_MACRO_REST_ARGS
CFLAGS = -m32 -O1 -g -std=gnu99 -DNO_STM32 $(LBM_OPT) \
         -I. -I../lispif_stats -I$(TOP)/lispBM -I$(LISPBM) -I$(LISPBM)/include \
         -I$(LISPBM)/platform/linux/include -I$(TOP) -I$(TOP)/util -I$(TOP)/script
LIBS = -lm -lpthread

TARGET = test

.PHONY: default all clean run
default: $(TARGET)
all: default

$(TARGET): $(SOURCES) $(HEADERS)
	$(CC) $(CFLAGS) $(SOURCES) $(LIBS) -o $@

clean:
	rm -f $(TARGET)

run: $(TARGET)
	timeout 120 ./$(TARGET)
