# Makefile for Regina REXX system

#
#  The Regina Rexx Interpreter
#  Copyright (C) 1992  Anders Christensen <anders@solan.unit.no>
#
#  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., 675 Mass Ave, Cambridge, MA 02139, USA.
#

#
# Some settings that you may wish to change, these are used only 
# for the 'install' target:
#
#   TOPDIR    The top of the directory hierarchy in which to install
#   BINDIR    Where to install the compiled 'rexx' program
#   LIBDIR    Where to install the 'regina' library
#   MANEXT    The extention of the manual page
#   MANDIR    Where to install the manual page
#   PROGNAME  What to call the compiled program
#
TOPDIR = /local
BINDIR = $(TOPDIR)/bin
LIBDIR = $(TOPDIR)/lib
MANEXT = l
MANDIR = $(TOPDIR)/man/man$(MANEXT)
PROGNAME = rexx
PROGEXT =


#
# The definitions above are suited for Unix systems, to compile under 
# OS/2, try commenting in these modification to the above definitions
#
#PROGEXT = .exe


#
# Below is listed some combinations of compiler/machine/os that 
# Regina has been built on, choose the one that suits you best.
#

ELIBS = -ll


#
# If nothing else fits, try something like this one. It will also work 
# for several of the 'configurations' listed below. 
#
CC = cc
CEXTRA = -D_POSIX_SOURCE 

#
# Using Digital's c89 on decstation 5000/200 under Ultrix 4.2 
#CC = c89 -YPOSIX -Olimit 700
#CEXTRA = -std -Dultrix -D_POSIX_SOURCE

#
# Using cc on decstation 3100 under OSF/1 v.1.00 
#CC = cc -Olimit 700
#CEXTRA = -std -D_POSIX_SOURCE

# Using cc (really: gcc) on a PC running Linux 0.99.pl4-48
#CC = cc
#CEXTRA = -ansi -Dlinux -D_POSIX_SOURCE #-pedantic -Wall -Dlint
#ELIBS = 

#
# Using FSF's gcc v2.x on various machines and operating systems 
#CC = gcc
#CEXTRA = -ansi -D_POSIX_SOURCE #-pedantic -Wall #-Dlint

#
# Using Sun ANSI C 1.1 (acc) under SunOS 4.1.1 on Sparc 
#    will give a few warning on memcpy/memcmp, ignore that
#CC = acc
#CEXTRA = -D_POSIX_SOURCE -Dsparc #-Xc

#
# Using GCC 2.1 under SunOS 4.1.1 on Sparc or Sun3
#    the SunKludges fix the missing div() and missing definitions of 
#    SEEK_{SET,CUR,END}, and several missing prototypes
#    For sun3, use -Dmc68000 instead of -Dsparc. It is essensial that you
#    define _one_ of them, else you will not get important code included
#    in some of the systems include files. 
#CC = gcc
#CEXTRA = -ansi -D_POSIX_SOURCE -Dsparc -DSunKludges # -Wall -pedantic

#
# Using SGI's cc on IRIX Indigo under 4.0.1 
#CC = cc
#CEXTRA = -DSGIkludges -ansiposix #-fullwarn -woff 269,270,302

#
# Using cc on DECstation under OSF/1 V1.0
#CC = cc
#CEXTRA = -D_POSIX_SOURCE -Xc

#
# Using c89 HP/UX 8.05 
#CC = c89 -D_POSIX_SOURCE -Dhpux -Wl,-a,archive +OS +O3 -s
#CEXTRA = -Aa 

#
# Using c89 on IBM RS6000 running under AIX
#CC = c89 
#CEXTRA = -D_POSIX_SOURCE

#
# Using emx 0.8f and gcc 2.3.3 under OS/2 2.x
#CC = gcc
#CEXTRA = -DPOSIX_SOURCE -DOS2


MISCDEFS = #-DR2PERL
DEBUG  = #-g #-Dlint
PROF	 = #-p #g
OPTIMIZE = -O -DNDEBUG

COPT = $(DEBUG) $(CEXTRA) $(OPTIMIZE) $(PROF) $(MISCDEFS)
LINKOPT = $(DEBUG) $(OPTIMIZE) $(PROF)
OTHERCOPT = $(DEBUG) $(OPTIMIZE) $(PROF)

LIBS = -lm $(ELIBS) #-lcurses -ltermcap -L./ndld -ldyn

YACC = yacc
#YACC = bison -ly #-lyt

LEX = lex
#LEX = flex #-d # -8

RCSDIFF = rcsdiff
DISTDIR = testdist
LEVEL = a

IFACE = rxiface.c rxiface.h rexxsaa.h

FILES = rexx funcs builtin error variable interpret debug dbgfuncs \
	memory parsing files misc unixfuncs cmsfuncs shell rexxext stack \
	tracing interp cmath convert strings library strmath signals \
	macros client envir extlib #r2perl

#CSRCFILES = $(addsuffix .c, $(FILES))
CSRCFILES = rexx.c funcs.c builtin.c error.c variable.c \
	interpret.c debug.c dbgfuncs.c memory.c parsing.c files.c \
	misc.c unixfuncs.c cmsfuncs.c shell.c rexxext.c stack.c \
	tracing.c interp.c cmath.c convert.c strings.c library.c \
	strmath.c signals.c macros.c client.c envir.c expr.c \
	extlib.c #r2perl.c

#OFILES = $(addsuffix .o, $(FILES)) yaccsrc.o lexsrc.o
OFILES = rexx.o funcs.o builtin.o error.o variable.o \
	interpret.o debug.o dbgfuncs.o memory.o parsing.o files.o \
	misc.o unixfuncs.o cmsfuncs.o shell.o rexxext.o stack.o \
	tracing.o interp.o cmath.o convert.o strings.o library.o \
	strmath.o signals.o macros.o client.o envir.o expr.o\
	extlib.o yaccsrc.o lexsrc.o #r2perl.o

TRIPFILES = trip/*.rexx trip/testing
DOCFILES  = doc/*.tex doc/README
DEMOFILES = demo/*.rexx 

HFILES = rexx.h defs.h extern.h types.h config.h strings.h
CFILES = yaccsrc.c lexsrc.c $(CSRCFILES)

BACKUP = /home/ludvigc/anders/rexx

YACCOUTPUT = yaccsrc.c yaccsrc.output symbols.h y.output
LEXOUTPUT = lexsrc.c 
JUNKFILES = core *~ gmon.out mon.out *.aux *.dvi *.log rexx.tar.Z rexx.tar
JUNK = $(OFILES) $(LEXOUTPUT) $(YACCOUTPUT) $(JUNKFILES) rexx yaccsrc.tab.* \
	hanoi hanoi.o execiser execiser.o libregina.a rxiface.o

AUXFILES = COPYING

CODESRC = $(HFILES) $(CSRCFILES) lexsrc.l yaccsrc.y
ALLSRC = $(HFILES) $(CSRCFILES) $(DOCFILES) lexsrc.l yaccsrc.y Makefile

lexsrc = parse.c rexx.h rexx.c
lexobj = parse.o rexx.o


all : rexx libregina #execiser hanoi

$(CSRCFILES) : rexx.h

rexx.h : extern.h config.h strings.h defs.h types.h

rexx : $(OFILES) #ndld/libdyn.a
	$(CC) $(LINKOPT) -o rexx$(PROGEXT) $(OFILES) $(LIBS)

hanoi : hanoi.o libregina.a
	$(CC) $(LINKOPT) -o hanoi$(PROGEXT) hanoi.o -L. -lregina -lcurses -ltermcap

execiser : execiser.o libregina.a
	$(CC) $(LINKOPT) -o execiser$(PROGEXT) execiser.o -L. -lregina

libregina : libregina.a

r2p : $(OFILES)
	$(CC) $(LINKOPT) -o r2p $(PFILES) $(LIBS)

vmsrexx : rexx.exe

libregina.a : rxiface.o
	ar rvc libregina.a rxiface.o
# some systems don't have/use ranlib, make sure we survive that
	-ranlib libregina.a

ndld/libdyn.a : 
	( cd ndld ; make ) 

lexsrc.o : lexsrc.c rexx.h symbols.h
	$(CC) $(OTHERCOPT) -c lexsrc.c 

lexsrc.c : lexsrc.l 
	@echo 'This may take some time ...'
	$(LEX) lexsrc.l
	mv lex.yy.c lexsrc.c

yaccsrc.o : yaccsrc.c defs.h rexx.h 
	$(CC) $(OTHERCOPT) -c -DYYMAXDEPTH=10000 yaccsrc.c

yaccsrc.c symbols.h : yaccsrc.y
	@echo 'Please expect 7 shift/reduce conflicts'
	$(YACC) -dv yaccsrc.y
	mv y.tab.h symbols.h
	mv y.tab.c yaccsrc.c

.c.o :
	$(CC) $(COPT) -c $*.c

flags.h : defs.h 
	echo 'struct ' > flags.h
	cat defs.h |\
	tr -s '\011' '\040' |\
	sed s/X_// |\
	awk - '{printf("   { %s, \"%s\" },\n",$$3,$$2)}' >> flags.h
	echo '  "dummy", 9999 } ;' >> flags.h

curses : curses.o 
	mv curses.o curses 
#	$(CC) -r -o curses curses.o -lcurses -ltermcap

install: rexx libregina
	strip rexx 
	cp rexx$(PROGEXT) $(BINDIR)/$(PROGNAME)$(PROGEXT)
	cp ../rexx.1 $(MANDIR)/rexx.$(MANEXT)
	cp libregina.a $(LIBDIR)/lib/regina.a
	ranlib $(LIBDIR)/libregina.a

backup : 
	tar -cvf rexx-bck.tar $(ALLSRC) RCS code trip contrib misc
	compress -f rexx-bck.tar
	rm -f $(BACKUP)/rexx-bck.tar.Z.old
	touch $(BACKUP)/rexx-bck.tar.Z
	mv -f $(BACKUP)/rexx-bck.tar.Z $(BACKUP)/rexx-bck.tar.Z.old
	cp rexx-bck.tar.Z $(BACKUP)/rexx-bck.tar.Z
	rm -f rexx-bck.tar.Z

depend:
	makedepend $(CSRCFILES)

dist: 
	tar -cvf rexx.tar $(ALLSRC) $(TRIPFILES) $(DEMOS)	
	compress -f rexx.tar

clean: 
	rm -f $(JUNK) \#*\#

rcsdiff:
	for var in $(CODESRC) ; \
		do echo -n "`$(RCSDIFF) $$var 2>/dev/null | wc -l`" ; \
		echo ' '$$var ; \
	done


# DO NOT DELETE THIS LINE -- make depend depends on it.
