# 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.
#

INSTALL		= /usr/bin/install -c
INSTALL_PROGRAM	= ${INSTALL}
INSTALL_DATA	= ${INSTALL} -m 644
prefix		= /usr/local
exec_prefix	= ${prefix}
bindir		= ${exec_prefix}/bin
mandir		= ${prefix}/man
GZIP		= /usr/bin/gzip

CXXFLAGS= -O2 -D_ISOC99_SOURCE -Wall -W $(DEBUG) $(CXXEXTRA)
LDFLAGS = $(DEBUG) $(LDEXTRA)
OBJECTS	= cmdline.o data.o dattable.o symbol.o symtable.o \
	  opcode.o optable.o mangler.o srcfile.o parser.o program.o \
	  compiler.o codegen.o forth.o forth.tab.o

all: default
default: forthc

forthc: $(OBJECTS)
	$(CXX) $(LDFLAGS) -static -o forthc $(OBJECTS) -lfl

cmdline.o:  options.h cmdline.h cmdline.cc
data.o:     util.h dattable.h data.h data.cc
dattable.o: data.h dattable.h dattable.cc
symbol.o:   util.h mangler.h symtable.h symbol.h symbol.cc
symtable.o: symbol.h mangler.h symtable.h symtable.cc
opcode.o:   util.h data.h optable.h operand.h register.h stack.h symbol.h \
            opcode.h opcode.cc
optable.o:  register.h stack.h operand.h opcode.h symbol.h optable.h optable.cc
mangler.o:  mangler.h mangler.cc
srcfile.o:  srcfile.h srcfile.cc
parser.o:   data.h dattable.h symbol.h symtable.h register.h stack.h opcode.h \
            optable.h operand.h parser.h parser.cc
program.o:  dattable.h symtable.h optable.h parser.h srcfile.h cmdline.h \
            options.h program.h program.cc
codegen.o:  stack.h register.h program.h options.h dattable.h data.h \
            symtable.h symbol.h optable.h operand.h opcode.h
compiler.o: mangler.h options.h cmdline.h symtable.h dattable.h optable.h \
            program.h compiler.cc

forth.tab.cc forth.tab.hh: forth.y operand.h parser.h
	bison -y -v -d -o forth.tab.cc forth.y

forth.tab.o: forth.tab.cc

forth.cc: forth.l operand.h parser.h
	flex -oforth.cc forth.l

forth.o: forth.cc forth.tab.hh
	$(CXX) $(CXXFLAGS) -Wno-unused-function -c forth.cc

install:
	$(INSTALL) -d $(bindir) $(mandir)/man1
	$(INSTALL_PROGRAM) forthc $(bindir)/forthc
	$(INSTALL_DATA) forthc.1 $(mandir)/man1/forthc.1
	$(GZIP) -f -9 $(mandir)/man1/forthc.1

install-strip:
	$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install

uninstall:
	rm -f $(bindir)/forthc
	rm -f $(mandir)/man1/forthc.1 $(mandir)/man1/forthc.1.gz

clean:
	rm -f *.o forthc forth.tab.cc forth.tab.hh forth.output forth.cc
	rm -f core gmon.out

clobber: clean
distclean: clean
maintainer-clean: clean
