#
# VNPForth - Compiled native Forth for IA32 Linux systems
# Copyright (C) 2000  Simon Baldwin (simonb@sco.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

ROOT		= ../..

#
# Define a standard method of compiling .ft files
#
FORTHC		= $(ROOT)/compiler/forthc
#FORTHFLAGS	= -g -O
FORTHFLAGS	= -g -O -P -S
.SUFFIXES:
.SUFFIXES:	.ft .o
.ft.o:
	$(FORTHC) $(FORTHFLAGS) $<

#
# Linker flags, and library dependencies
#
LFLAGS	= -L$(ROOT)/runtime
LIBS	= -lforth

LDEPS	= $(ROOT)/runtime/libforth.a
LDEPD	= $(ROOT)/runtime/libforth.so

default: all

#
# Build all tests and demos
#
all:	test01_s test01_d test02_s test02_d

test01_s: tester.o core.o $(LDEPS) $(ROOT)/compiler/forthc
	ld -static -g -o test01_s tester.o core.o \
				$(ROOT)/runtime/forthrt1.o $(LFLAGS) $(LIBS)

test01_d: tester.o core.o $(LDEPD) $(ROOT)/compiler/forthc
	gcc -g -o test01_d tester.o core.o $(LFLAGS) $(LIBS)

test02_s: environ.o $(LDEPS) $(ROOT)/compiler/forthc
	ld -static -g -o test02_s environ.o \
				$(ROOT)/runtime/forthrt1.o $(LFLAGS) $(LIBS)

test02_d: environ.o $(LDEPD) $(ROOT)/compiler/forthc
	gcc -g -o test02_d environ.o $(LFLAGS) $(LIBS)

#
# Run the test and demo programs
#
ADDLIB = LD_LIBRARY_PATH=$(ROOT)/runtime
verify:	test01_s test01_d test02_s test02_d
	@echo "---> Test01 static binary"
	@echo "Test01 stdin static" | $(ADDLIB) ./test01_s
	@echo "---> Test02 static binary"
	@$(ADDLIB) ./test02_s
	@echo "---> Test01 dynamic binary"
	@echo "Test01 stdin dynamic" | $(ADDLIB) ./test01_d
	@echo "---> Test02 dynamic binary"
	@$(ADDLIB) ./test02_d

#
# Cleanup targets
#
clean:
	rm -f test01_s test01_d test02_s test02_d
	rm -f core *.o *.s *.p

clobber: clean
