# Makefile for the SAN Kit "examples-pascal" programs.
#
# These link the Free Pascal interface unit sankit.pas against the
# same ../SAN_SRC/libsan.a static library the C examples and demos
# use -- see sankit.pas's own header comment for how the interface
# itself was built, and README.md in this directory for the general
# picture.
#
# Usage:
#   cd ../SAN_SRC && make lib   (only needed once, or after editing the library)
#   cd ../examples-pascal && make
#   ./01_hello_board

SRC=	../SAN_SRC
LIB=	$(SRC)/libsan.a

FPC=	fpc
# -Fl tells fpc's linker where to find libsan.a for the {$linklib san}
# directive in sankit.pas; -O1 asks for basic optimization, matching
# the -O the C examples build with. fpc places its own intermediate
# .o/.ppu files alongside the sources; "make clean" removes them.
FPCFLAGS=	-Fl$(SRC) -O1

SOURCES=	$(wildcard [0-9]*.pas)
PROGRAMS=	$(SOURCES:.pas=)

all:	$(LIB) $(PROGRAMS)

$(LIB):
	$(MAKE) -C $(SRC) lib

%:	%.pas sankit.pas $(LIB)
	$(FPC) $(FPCFLAGS) $<

clean:
	rm -f $(PROGRAMS) *.o *.ppu

.PHONY:	all clean
