#
# 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
CC		= gcc
#CFLAGS		= -c -O
CFLAGS		= -c -g -O
.SUFFIXES:
.SUFFIXES:	.ft .c .o
.ft.o:
	$(FORTHC) $(FORTHFLAGS) $<
.c.o:
	$(CC) $(CFLAGS) $<

#
# 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 demos.  For demonstration purposes, we'll create static
# binaries where we can.  Most things, however, would be better as
# dynamically linked binaries.
#
all:	sleep printenv logname shell mv ln rm cat pi tricks

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

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

logname: logname.o $(LDEPS) $(ROOT)/compiler/forthc
	gcc -g -o logname logname.o $(LFLAGS) $(LIBS)

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

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

ln:	mv
	rm -f ln; /bin/ln mv ln

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

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

pi:	pi_c.o pi.o $(LDEPS) $(ROOT)/compiler/forthc
	gcc -g -o pi pi.o pi_c.o $(LFLAGS) $(LIBS)

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

#
# Run the demo programs
#
ADDLIB = LD_LIBRARY_PATH=$(ROOT)/runtime
verify:	sleep printenv logname shell mv ln rm cat pi tricks
	@echo "---> Sleep 1"
	./sleep 1
	@echo "---> Printenv PATH"
	./printenv PATH
	@echo "---> Logname"
	$(ADDLIB) ./logname
	@echo "---> Shell"
	/bin/echo -e "/bin/ls -l\n/bin/uname -a\nexit" | ./shell
	@echo "---> Mv foo bar"
	date >foo; ./mv foo bar
	@echo "---> Ln bar foo"
	./ln bar foo
	@echo "---> Cat bar foo"
	./cat bar foo
	@echo "---> Rm bar foo"
	./rm bar foo
	@echo "---> Pi"
	$(ADDLIB) ./pi
	@echo "---> tricks"
	./tricks

#
# Cleanup targets
#
clean:
	/bin/rm -f sleep printenv logname shell mv ln rm cat pi tricks
	/bin/rm -f foo bar
	/bin/rm -f core *.o *.s *.p

clobber: clean
