# --------------------------------------------------------------------------
# Makefile for Hugs (adapted for use with djgpp2)
#
# Copyright (c) The University of Nottingham and Yale University, 1994-1997.
# All rights reserved. See NOTICE for details and conditions of use etc...
# Hugs version 1.4, November 1997
# --------------------------------------------------------------------------

# Targets:
#
# <default>:   	 make hugs.exe
# hugs.exe:    	 make minimal working system
# runhugs.exe:   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
#                  (you need perl and /bin/sh to run these)
# TAGS:          build emacs TAGS table

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

CC		= gcc
CFLAGS		= -g -O

LD		= gcc
LDFLAGS    	= 
LIBS		= 

YACC		= bison -y
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 \
		  output.c compiler.c machine.c interp.c builtin.c \
		  server.c
INCFILES	= parser.c preds.c bignums.c kind.c subst.c machdep.c timer.c \
		  printer.c iomonad.c interns.c stmonad.c array.c
YFILES		= parser.y
SOURCES		= $(HFILES) $(CFILES) $(INCFILES) $(YFILES) 
OBJECTS		= storage.o input.o static.o type.o compiler.o \
		  plugin.o builtin.o machine.o output.o
IOBJECTS	= hugs.o $(OBJECTS)
PRELUDE		= config.h options.h prelude.h win-text.h

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

hugs.exe	: $(IOBJECTS)  
		  $(LD) $(LDFLAGS) -o hugs.exe $(IOBJECTS) $(LIBS)
#		  strip hugs.exe
#		  coff2exe hugs.exe		# for DJGPP2

SERVER_OBJECTS	= server.o $(OBJECTS) 

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

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

clean		::
		  $(RM) *.o *.aux *.hp
		  $(RM) *.def *.exp *.ilk *.lib *.pdb
		  $(RM) *.td2 *.map *.csm *.MAP
		  $(RM) *.TR2 *.RES *.DSW *.OBJ
distclean	:: clean
distclean	::
		  $(RM) hugs.exe runhugs.exe 
		  $(RM) *.lib *.pdf TAGS *~
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

# parser.c	: parser.y
# 		  -$(YACC) parser.y
# 		  mv y.tab.c parser.c
# veryclean	::
# 		  $(RM) parser.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 winhugs.c 
storage.o	: $(PRELUDE) storage.h connect.h errors.h
input.o		: $(PRELUDE) storage.h connect.h errors.h \
		  parser.c command.h
static.o	: $(PRELUDE) storage.h connect.h errors.h
type.o		: $(PRELUDE) storage.h connect.h errors.h \
		  preds.c kind.c subst.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) storage.h connect.h errors.h \
		  bignums.c printer.c iomonad.c interns.c stmonad.c array.c

################################################################
# Regression tests (Unix only).  Run "make install" first
# 
# Uses runstdtest (from ghc-0.26/ghc/glafp-utils/scripts), perl 5
# and /bin/sh (Bourne shell).
#
# "make check" generates a lot of output to explain what is going on
# and reassure you that progress is being made.  This is great if you've
# never run these tests before - but if you just want to reassure yourself
# that nothing has broken since the last release, you might prefer to
# run this command which removes all the explanations and success
# stories - leaving just the useful output.
#
#  make check | grep -v "^--" -
#
################################################################

check		: hugs
		  - /bin/sh Tests/testScript static
		  - /bin/sh Tests/testScript tcheck
		  - /bin/sh Tests/testScript rts
		  - /bin/sh Tests/testScript libs
		  - /bin/sh Tests/testScript demos
clean		::
		  $(RM) testFile

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