#
# Makefile for samuel
#
TOPDIR := ..
include $(TOPDIR)/make.common

CFILES	= samain.c lex.c parser.c functions.c
HFILES	= samuel.h tokens.h
OFILES	= $(CFILES:.c=.o)
PFILES	= $(CFILES:.c=.op)

all: samuel
profil: samuel_p

# Do you want the readline version of samuel?
# Select either "readline" (GNU readline), "editline" (a smaller clone)
# or "none" (no line editing -- this is not recommended).
READLINE := readline

RLLIB :=
ifeq ($(READLINE),editline)
CPPFLAGS += -DUSE_READLINE
RLLIB := -ledit -ltermcap
endif
ifeq ($(READLINE),readline)
CPPFLAGS += -DUSE_READLINE
RLLIB := -lreadline -lhistory -ltermcap
endif

samuel: $(OFILES) $(LIBDIR)/libsaml.a
	$(CC) $(LDFLAGS) -o $@~ $(OFILES) -lsaml $(RLLIB)
	mv $@~ $@

samuel_p: $(PFILES) $(LIBDIR)/libsaml_p.a
	$(CC) $(LDFLAGS) -pg -static -o $@~ $(PFILES) -lsaml_p $(RLLIB)
	mv $@~ $@

veryclean: clean
	rm -f *.s *.orig parser.c tokens.h samuel samuel_p

tokens.h: parser.c
parser.c: samuel.y
	$(YACC) -dv $<
	cmp -s y.tab.h tokens.h || mv y.tab.h tokens.h
	rm -f y.tab.h
	mv y.tab.c parser.c

include .depend
