#
# Makefile for Regina REXX Interpreter
#

#
# 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 = /usr/local
BINDIR = $(TOPDIR)/bin
LIBDIR = $(TOPDIR)/lib
MANEXT = l
MANDIR = $(TOPDIR)/man/man$(MANEXT)
PROGNAME = rexx
LIBFILE = regina
PROGEXT =
MV = mv 
OBJECTS = $(OFILES)
LDEXTRA = echo

# 
# Some further symbols
#
# DYN_LINK  - definitions needed when one or more object file are linked 
#             into a dynamically linkable module or external built-in 
#             functions. 
#
# DYN_COMP  - definitions needed for compiling code that is to be 
#             dynamically loaded.
#
# EEXTRA    - extra options to the linking of the Rexx interpreter
#
DYN_LINK = 
DYN_COMP =
EEXTRA =
SHL_TYPE =
DYN_LIBS = -lc
DYN_LD = ld 
LL = -ll
EXTRAPROGS =

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

#
# If nothing else fits, try something like this one. It will also work 
# for several of the 'configurations' listed below. Note: this does not 
# give you any dynamic linking. If you want that, you need to define
# anything sensible for ELIBS and SHL_TYPE, see examples below.
#
CC = cc
CEXTRA = -ansi -D_POSIX_SOURCE 
ELIBS = -ll
SHL_TYPE = 


#
# Using Digital's c89 on decstation 5000/200 under Ultrix 4.2, which is
# not able to do dynamic/shared linking. This configuration doesn't have
# dynamic linking.
#
#CC = c89 -YPOSIX -Olimit 700 
#CEXTRA = -std -Dultrix -D_POSIX_SOURCE #-w0

#
# 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 FSF's gcc v2.x under Solaris, in addition, you may have to use
# flex and bison in stead of yacc and lex.
#
#CC = gcc
#CEXTRA = -ansi -D_POSIX_SOURCE #-pedantic -Wall -Dlint
#SHL_TYPE = -DDYNAMIC_DLOPEN
#ELIBS = -ldl
#DYN_LD=gcc -r

#
# Using Sun ANSI C 1.1 (acc) under SunOS 4.1.1 on Sparc 
#    will give a few warning on memcpy/memcmp, but you can ignore that
#
#CC = acc
#SHL_TYPE = -DDYNAMIC_DLOPEN
#DYN_COMP = #-pic
#DYN_LINK = #-assert pure-text
#ELIBS = -dl -ll
#DYN_LIBS =
#CEXTRA = -D_POSIX_SOURCE -Dsparc #-Xc

#
# Using GCC 2.1 under SunOS 4.1.x on Sparc or Sun3. 
#    You may need to remove -DSunKludges from CEXTRA, see README.
#    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 -DSunKludges
#CEXTRA = -ansi -D_POSIX_SOURCE -Dsparc #-Wall -pedantic -Dlint
#SHL_TYPE = -DDYNAMIC_DLOPEN
#DYN_COMP = -DNDEBUG
#DYN_LIBS =


#
# 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 DJGPP 1.10 under MS-DOS
#
#CC = gcc
#CEXTRA = -DPOSIX_SOURCE -DDOS
#MV = +ren
#LDEXTRA = aout2exe
#OBJECTS = @go32.rsp
#ELIBS = 
#LIBFILE = regna

#
# Using c89 HP/UX 8.05 
#
#CC = c89 
#CEXTRA = -Aa -D_POSIX_SOURCE -Dhpux #-Wl,-a,archive +OS +O3 -s
#SHL_TYPE = -DDYNAMIC_HPSHLOAD
#DYN_LINK = -b -q -n
#EEXTRA = -Wl,-E 
#DYN_COMP = +z -Wl,r $(COPT)
#ELIBS = -ldld -ll

#
# Using c89 on IBM RS6000 running under AIX
#
#CC = c89 
#CEXTRA = -D_POSIX_SOURCE
#EEXTRA = -bE:rexx.ext
#DYN_LINK = -bM:SRE -bI:rexx.ext -e initial
#SHL_TYPE = -DDYNAMIC_AIXLOAD
#DYN_LD = c89

#
# 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) $(EEXTRA)
OTHERCOPT = $(DEBUG) $(OPTIMIZE) $(PROF)

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

LEX = lex
#LEX = flex #-d #-8
#LL = -L/store/lib -lfl

RCSDIFF = rcsdiff
DISTDIR = testdist
LEVEL = a

LIBS = -lm $(ELIBS) $(LL) #-lcurses -ltermcap -L./ndld -ldyn 
IFACE = rxiface.c rxiface.h rexxsaa.h

FILES = funcs builtin error variable interprt debug dbgfuncs \
	memory parsing files misc unxfuncs cmsfuncs shell rexxext stack \
	tracing interp cmath convert strings library strmath signals \
	macros envir extlib wrappers options doscmd #r2perl

#CSRCFILES = $(addsuffix .c, $(FILES))
CSRCFILES = funcs.c builtin.c error.c variable.c \
	interprt.c debug.c dbgfuncs.c memory.c parsing.c files.c \
	misc.c unxfuncs.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 envir.c expr.c \
	extlib.c wrappers.c options.c doscmd.c #r2perl.c 

#OFILES = $(addsuffix .o, $(FILES)) yaccsrc.o lexsrc.o
OFILES = funcs.o builtin.o error.o variable.o \
	interprt.o debug.o dbgfuncs.o memory.o parsing.o files.o \
	misc.o unxfuncs.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 envir.o expr.o \
	extlib.o yaccsrc.o lexsrc.o wrappers.o options.o doscmd.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) rexx.c client.c

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 lib$(LIBFILE).a rxiface.o curses.o \
	curses.rxlib rexx.o client.o 

AUXFILES = COPYING

CODESRC = $(HFILES) $(CSRCFILES) lexsrc.l yaccsrc.y rexx.c client.c
ALLSRC = $(HFILES) $(CSRCFILES) $(DOCFILES) lexsrc.l yaccsrc.y Makefile \
	rexx.c client.c

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


all : rexx $(EXTRAPROGS) lib$(LIBFILE).a #curses.rxlib # execiser

$(CSRCFILES) : rexx.h

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

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

drexx.o : rexx.c
	$(CC) $(COPT) -c -DRXLIB rexx.c
	$(MV) rexx.o drexx.o

lib$(LIBFILE).a: $(OFILES) client.o drexx.o rexxsaa.o
	ar cr lib$(LIBFILE).a $(OFILES) client.o drexx.o rexxsaa.o
	-ranlib lib$(LIBFILE).a

execiser : execiser.o lib$(LIBFILE).a
	$(CC) $(LINKOPT) -o execiser$(PROGEXT) execiser.o -L. -l$(LIBFILE)
	$(LDEXTRA) execiser

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

lexsrc.c : lexsrc.l 
	$(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
	$(YACC) -dv yaccsrc.y
	$(MV) y.tab.h symbols.h
	$(MV) y.tab.c yaccsrc.c

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

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

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

curses.o : curses.c
	$(CC) $(DYN_COMP) -c curses.c

curses.rxlib : curses.o 
	$(DYN_LD) $(DYN_LINK) -o curses.rxlib curses.o \
		-lcurses -ltermcap $(DYN_LIBS)


install: rexx lib$(LIBFILE).a
	cp rexx$(PROGEXT) $(BINDIR)/$(PROGNAME)$(PROGEXT)
	cp ../rexx.1 $(MANDIR)/rexx.$(MANEXT)
	cp lib$(LIBFILE).a $(LIBDIR)/lib$(LIBFILE).a
	ranlib $(LIBDIR)/lib$(LIBFILE).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.
