# --------------------------------------------------------------------------
# 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.
# Make sure you have tabs
# --------------------------------------------------------------------------

# 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
HOME=/home/fernan
BIN=$(HOME)/bin/386/haskell
HUGSDIR=$(HOME)/lib/haskell

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

LD		= cc
LDFLAGS = -lm
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 scc.c interp.c builtin.c \
              evaluator.c server.c 
INCFILES	= parser.c preds.c bignums.c machdep.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 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 ${HUGSDIR} || mkdir ${HUGSDIR}
			test -d ${HUGSDIR}/lib || mkdir ${HUGSDIR}/lib
			cp -R ../hugslib/* ${HUGSDIR}/lib/
			test -d $(BIN) || mkdir $(BIN)
			cp hugs $(BIN)
			cp runhugs $(BIN)
	
updatebin: hugs runhugs 
	cp hugs $(BIN)
	cp runhugs $(BIN)
        
updatelib:: 
	test -d ${HUGSDIR} || mkdir ${HUGSDIR}
	test -d ${HUGSDIR}/lib || mkdir ${HUGSDIR}/lib
	cp -R ../hugslib/* ${HUGSDIR}/lib/
	test -d $(BIN) || mkdir $(BIN)

################################################################
# 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
		  $(RM) *.exe
		  $(RM) *.core
		  $(RM) hugs
		  $(RM) runhugs		  
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 server.c server.h
hugs.o		: $(PRELUDE) storage.h connect.h errors.h \
              command.h machdep.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
################################################################
