# vi: set ts=8 shiftwidth=8 noexpandtab:
#
# VNPForth - Compiled native Forth for IA32 Linux systems
# Copyright (C) 2005  Simon Baldwin (simon_baldwin@yahoo.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.
#

CFLAGS		= -c -g -O

# Define a standard method of compiling .ft files.  Reconstruct the
# standard method of compiling .c files.
FORTHC		= ../compiler/forthc
FORTHFLAGS	= -g -O -P -S
.SUFFIXES:
.SUFFIXES:	.ft .c .o
.ft.o:
	$(FORTHC) $(FORTHFLAGS) $<
.c.o:
	$(CC) -I ../runtime $(CFLAGS) $<

# Linker flags, and library dependencies
LFLAGS	= -L../runtime
LIBS	= -lforth
LCRT	= ../runtime/forthrt1.o

LDEPS	= ../runtime/libforth.a
LDEPD	= ../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) $(FORTHC)
	$(LD) -static -g -o sleep sleep.o $(LCRT) $(LFLAGS) $(LIBS)

printenv: printenv.o $(LDEPS) $(FORTHC)
	$(LD) -static -g -o printenv printenv.o $(LCRT) $(LFLAGS) $(LIBS)

logname: logname.o $(LDEPS) $(FORTHC)
	$(CC) -g -o logname logname.o $(LFLAGS) $(LIBS)

shell:	shell.o $(LDEPS) $(FORTHC)
	$(LD) -static -g -o shell shell.o $(LCRT) $(LFLAGS) $(LIBS)

mv:	mv.o $(LDEPS) $(FORTHC)
	$(LD) -static -g -o mv mv.o $(LCRT) $(LFLAGS) $(LIBS)

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

rm:	rm.o $(LDEPS) $(FORTHC)
	$(LD) -static -g -o rm rm.o $(LCRT) $(LFLAGS) $(LIBS)

cat:	cat.o $(LDEPS) $(FORTHC)
	$(LD) -static -g -o cat cat.o $(LCRT) $(LFLAGS) $(LIBS)

pi:	pi_c.o pi.o $(LDEPS) $(FORTHC)
	$(CC) -I../runtime -g -o pi pi.o pi_c.o $(LFLAGS) $(LIBS)

tricks:	tricks.o $(LDEPS) $(FORTHC)
	$(LD) -static -g -o tricks tricks.o $(LCRT) $(LFLAGS) $(LIBS)

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

clobber: clean
distclean: clean
maintainer-clean: distclean

# Test targets
ADDLIB = LD_LIBRARY_PATH=$(ROOT)/runtime
check:	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
