# --------------------------------------------------------------------------
# Makefile for Hugs (adapted for use with Plan 9)
#
# The Hugs 98 system is Copyright (c) Mark P Jones, Alastair Reid, the
# Yale Haskell Group, and the OGI School of Science & Engineering at OHSU,
# 1994-2002, All rights reserved.  It is distributed as
# free software under the license in the file "License", which is
# included in the distribution.
# --------------------------------------------------------------------------

# Targets:
#
# <default>:   	 make hugs
# hugs:    	 make minimal working system
# runhugs:   make standalone evaluator
# clean:       	 delete files not required in running system
# distclean:     delete files that can be regenerated using C compiler
# veryclean:     delete all machine generated files 
#                  (you need perl, bison/yacc, etc to rebuild these files)
# check:	 run regression tests
# TAGS:          build emacs TAGS table

# This rule goes first to make it the default choice
default		:: hugs runhugs

HUGLIB=${home}/lib/hugs

DEFINES = -DHUGSDIR=\"$(HUGLIB)\"
CC		= cc
CFLAGS		= -g -O ${DEFINES}

LD		= cc
LDFLAGS    	= 
LIBS		= 

RM		= rm -f
CP		= cp

.SUFFIXES	:
.SUFFIXES	: .c .h .o
HFILES		= prelude.h config.h options.h storage.h connect.h \
		  errors.h command.h server.h
CFILES		= hugs.c storage.c input.c static.c type.c subst.c \
		  output.c compiler.c machine.c interp.c builtin.c \
		  evaluator.c server.c ffi.c
INCFILES	= parser.c preds.c bignums.c scc.c machdep.c timer.c \
		  printer.c iomonad.c interns.c array.c
YFILES		= parser.y
SOURCES		= $(HFILES) $(CFILES) $(INCFILES) $(YFILES) 
OBJECTS		= storage.o input.o static.o type.o subst.o compiler.o \
		  plugin.o builtin.o machine.o output.o ffi.o version.o \
		  strutil.o machdep.o errors.o opts.o script.o evaluator.o \
	          module.o edit.o char.o goal.o
IOBJECTS	= hugs.o observe.o $(OBJECTS)
PRELUDE		= config.h options.h prelude.h

install:	hugs runhugs
	test -d ${HUGLIB} || mkdir ${HUGLIB}
	test -d ${HUGLIB}/lib || mkdir ${HUGLIB}/lib
	test -d ${HUGLIB}/demos || mkdir ${HUGLIB}/demos
	test -d ${HUGLIB}/demos/prolog || mkdir ${HUGLIB}/demos/prolog
	test -d ${HUGLIB}/lib/hugs || mkdir ${HUGLIB}/lib/hugs
	test -d ${HUGLIB}/lib/exts || mkdir ${HUGLIB}/lib/exts
	cp ../lib/[A-Z]* ${HUGLIB}/lib
	cp ../lib/hugs/* ${HUGLIB}/lib/hugs/
	cp ../lib/exts/* ${HUGLIB}/lib/exts/
	cp ../demos/prolog/* ${HUGLIB}/demos/prolog/
	cp ../demos/[A-Z]* ${HUGLIB}/demos/
	cp hugs ${home}/bin/${objtype}/
	cp runhugs ${home}/bin/${objtype}/


################################################################
# Hugs interpreter and standalone evaluator
################################################################

hugs	: $(IOBJECTS)  
		  $(LD) $(LDFLAGS) -o hugs $(IOBJECTS) $(LIBS)

SERVER_OBJECTS	= server.o $(OBJECTS) 

runhugs.o	: config.h options.h server.h runhugs.c
runhugs	: runhugs.o $(SERVER_OBJECTS)
		  $(LD) $(LDFLAGS) -o runhugs runhugs.o $(SERVER_OBJECTS) $(LIBS) 

################################################################
# Clean, distclean, veryclean, TAGS
################################################################

clean		::
		  $(RM) *.o
		  $(RM) *.aux
		  $(RM) *.hp
		  $(RM) *.def
		  $(RM) *.exp
		  $(RM) *.ilk
		  $(RM) *.lib
		  $(RM) *.pdb
		  $(RM) *.td2
		  $(RM) *.map
		  $(RM) *.csm
		  $(RM) *.MAP
		  $(RM) *.TR2
		  $(RM) *.RES
		  $(RM) *.DSW
		  $(RM) *.OBJ
distclean	:: clean
distclean	::
		  $(RM) hugs
		  $(RM) runhugs 
		  $(RM) *.lib
		  $(RM) *.pdf
		  $(RM) TAGS
		  $(RM) *~
veryclean	:: distclean

TAGS		::
		  etags *.[ych]

################################################################
# Dependencies
################################################################

.c.o		:
		  $(CC) -c $(CFLAGS) $(OPTFLAGS) $<

# These are compiled with less optimisation to avoid optimisation bugs in
# certain compilers.  This may be overly conservative on some compilers.
compiler.o	: compiler.c
		  $(CC) -c $(CFLAGS) compiler.c
static.o	: static.c
		  $(CC) -c $(CFLAGS) static.c


server.o	: $(PRELUDE) storage.h connect.h errors.h \
		  command.h machdep.c timer.c server.c server.h
hugs.o		: $(PRELUDE) storage.h connect.h errors.h \
		  command.h machdep.c timer.c
ffi.o		: $(PRELUDE) storage.h connect.h errors.h
storage.o	: $(PRELUDE) storage.h connect.h errors.h
input.o		: $(PRELUDE) storage.h connect.h errors.h \
		  parser.c command.h
subst.o		: $(PRELUDE) storage.h connect.h errors.h subst.h
static.o	: $(PRELUDE) storage.h connect.h errors.h subst.h \
		  scc.c
type.o		: $(PRELUDE) storage.h connect.h errors.h subst.h \
		  scc.c preds.c
output.o	: $(PRELUDE) storage.h connect.h errors.h
compiler.o	: $(PRELUDE) storage.h connect.h errors.h \
		  compiler.c
machine.o	: $(PRELUDE) storage.h connect.h errors.h
plugin.o	: $(PRELUDE) storage.h connect.h errors.h
builtin.o	: $(PRELUDE) observe.h storage.h connect.h errors.h \
		  observe.c bignums.c printer.c iomonad.c interns.c array.c
evaluator.o	: $(PRELUDE) machdep.h errors.h \
		  machdep.c errors.c

################################################################
# Regression tests (none supplied)
################################################################

check		:


################################################################
# End of Makefile
################################################################
