# Generated automatically from Makefile.in by configure.
#
# Makefile for the Yorick interpreter
# If this is Makefile.in, run configure (in ..) to create Makefile
#
# $Id$
#
# Note: symbols between two ats @some thing@ are filled in by configure

# ---------------------------------------------------------------------------

# This flag should be set to whatever your compiler needs to tell it
# to optimize (-O usually) or debug (-g usually).
# C_OPTIMIZE = -g
C_OPTIMIZE = -O

# ---------------------------------------------------------------------------

# set by configure script (see definitions of Y_SITE, prefix below)
exec_prefix = $(prefix)
Y_HOME = $(exec_prefix)/yorhome

CODE_NAME = yorick

CODE_LIBRARY = libyor.a

OBJS = task.o yorick.o yinput.o parse.o ydata.o yio.o fnctn.o array.o \
       range.o ops.o ops0.o ops1.o ops2.o ops3.o opsv.o nonc.o debug.o \
       std0.o std1.o std2.o ascio.o defstr.o defmem.o hash.o sysdep.o \
       yrdwr.o bcast.o binio.o binobj.o binstd.o cache.o convrt.o \
       binpdb.o clog.o $(GRAPH_O) fortrn.o

# Codger actually ignores both std.i and graph.i where Y_INCLUDE appears
# on its execute line.  These just allow the depedencies for the ycode.c
# target to be correct in this Makefile.  Makefiles for custom versions
# of Yorick do not put std.i and graph.i here and work the way you'd
# intuitively expect.
Y_INCLUDE = std.i $(GRAPH_I)

CLEAN_UP = yorick fmcalc codger prmtyp.h grammar
TIDY_UP= y.tab.c y.output M.1 M.2 junk* include/*~ doc/*~

LD_OPTIMIZE = $(C_OPTIMIZE)

# Unused -- may be defined in other Yorick packages (e.g.- Math, Drat)
NON_SHARABLE = unused
F_OPTIMIZE =
FORTRAN_STYLE =
Y_OTHERS =
YWRAP_O =
PKG_LIBS =
PKG_OBJS =
SYS_LIBS =

# ---------------------------------------------------------------------------

all:: Maketmpl codger startup $(CODE_LIBRARY) $(CODE_NAME)

codger: codger.c
	$(CC) $(CPPFLAGS) $(CFLAGS) $(FORTRAN_LINKAGE) -o codger codger.c

prmtyp.h: fmcalc
	./fmcalc prmtyp.h

# The Maketmpl file's site specific section is identical to this Makefile's
Maketmpl::
	$(SED) -n -e "1,/^# --END-CODE/p" Maketmpl >M.2
	$(SED) -e "s,^exec_prefix.*,exec_prefix = $(exec_prefix),p" M.2 >M.1
	$(SED) -n -e "/^# -BEGIN-SITE/,$$$$p" Makefile >M.2
	cat M.1 M.2 >Maketmpl
	$(RM) M.1 M.2

grammar: yorick.y
	$(YACC) -v yorick.y
	@echo "*** Expect 1 shift/reduce conflict above ***"
	@$(MV) y.output $@
	@$(RM) y.tab.c

startup::
	if test ! -d startup; then mkdir startup; fi
	cp paths.i std.i stdx.i graph.i startup

check: $(CODE_NAME)
	./yorick -batch check.i

install: Maketmpl codger $(CODE_LIBRARY) main.o installdirs
	if test `pwd` != `cd $(Y_SITE);pwd`; then \
	  cp include/*.i $(Y_SITE)/include; \
	  cp doc/* $(Y_SITE)/doc; fi
	cp paths.i std.i stdx.i graph.i $(Y_SITE)/startup
	cp Maketmpl *.h codger main.o main.c $(Y_HOME)
	if test -x yorick; then cp yorick $(Y_BINDIR); fi
	cp libyor.a $(Y_LIBDIR)
	$(RANLIB) $(Y_LIBDIR)/libyor.a

uninstall:
	if test `pwd` != `cd $(Y_SITE);pwd`; then \
	  $(RM) -r $(Y_SITE)/include \
	  $(RM) -r $(Y_SITE)/doc; fi
	cd $(Y_SITE)/startup; $(RM) paths.i std.i stdx.i graph.i;
	cd $(Y_HOME); $(RM) Maketmpl *.h codger main.o main.c;
	$(RM) $(Y_BINDIR)/yorick
	$(RM) $(Y_LIBDIR)/libyor.a

installdirs:
	if test ! -d $(Y_SITE); then mkdir $(Y_SITE); fi
	if test ! -d $(Y_SITE)/startup; then mkdir $(Y_SITE)/startup; fi
	if test ! -d $(Y_SITE)/include; then mkdir $(Y_SITE)/include; fi
	if test ! -d $(Y_SITE)/doc; then mkdir $(Y_SITE)/doc; fi
	if test ! -d $(Y_BINDIR); then mkdir $(Y_BINDIR); fi
	if test ! -d $(Y_LIBDIR); then mkdir $(Y_LIBDIR); fi
	if test ! -d $(Y_HOME); then mkdir $(Y_HOME); fi

distclean: clean
	$(RM) Makefile
	$(SED) -n -e "1,/^# --END-CODE/p" Maketmpl >M.1
	cat M.1 >Maketmpl
	$(RM) M.1

# ---------------------------------------------------------------------------

# Note: indirectly included headers separated by three spaces

task.o: ydata.h yio.h defstr.h defmem.h   binio.h hash.h sysdep.h
# Do NOT use yorick.y -- most YACCs have limited parse stack size
yorick.c: yorick.y
	@touch yorick.c
yorick.o: yorick.c parse.h defstr.h
	$(CC) $(CPPFLAGS) $(CFLAGS) -c yorick.c
yinput.o: yio.h parse.h defstr.h defmem.h hash.h sysdep.h
parse.o: parse.h ydata.h defmem.h defstr.h   binio.h hash.h
ydata.o: bcast.h defmem.h defstr.h   ydata.h binio.h hash.h
yio.o: yio.h defstr.h defmem.h ydata.h   binio.h hash.h sysdep.h
fnctn.o: ydata.h   binio.h hash.h
array.o: ydata.h   binio.h hash.h
range.o: ydata.h   binio.h hash.h
ops.o: bcast.h defmem.h defstr.h   ydata.h binio.h hash.h
ops0.o: ydata.h   binio.h hash.h
ops1.o: ydata.h   binio.h hash.h
ops2.o: ydata.h defstr.h   binio.h hash.h
ops3.o: bcast.h defstr.h   ydata.h binio.h hash.h
opsv.o: ydata.h defmem.h prmtyp.h   binio.h hash.h
nonc.o: sysdep.h
debug.o: ydata.h yio.h defstr.h   binio.h hash.h sysdep.h
std0.o: bcast.h yio.h defstr.h   ydata.h binio.h hash.h sysdep.h
std1.o: ydata.h defstr.h   binio.h hash.h
std2.o: ydata.h yio.h defstr.h   binio.h hash.h sysdep.h
ascio.o: ydata.h yio.h defstr.h defmem.h   binio.h hash.h sysdep.h
defstr.o: defstr.h defmem.h
defmem.o: defmem.h
hash.o: hash.h defstr.h defmem.h
sysdep.o: sysdep.c ydata.h yio.h defstr.h defmem.h   binio.h hash.h sysdep.h
	$(CC) $(CPPFLAGS) $(CFLAGS) $(HAS_BSD_TIMER) -c sysdep.c
yrdwr.o: bcast.h defmem.h   ydata.h binio.h hash.h
bcast.o: bcast.h   ydata.h binio.h hash.h
binio.o: ydata.h yio.h defmem.h defstr.h   binio.h hash.h sysdep.h
binobj.o: bcast.h defmem.h defstr.h   ydata.h binio.h hash.h
binstd.o: binio.h defmem.h   hash.h
cache.o: binio.h defmem.h defstr.h yio.h   hash.h sysdep.h
convrt.o: binio.h defstr.h defmem.h   hash.h
binpdb.o: ydata.h yio.h defstr.h defmem.h   binio.h hash.h sysdep.h
clog.o: ydata.h yio.h defstr.h defmem.h   binio.h hash.h sysdep.h

D_NO_XLIB = 

graph.o: graph.c ydata.h yio.h defstr.h   binio.h hash.h sysdep.h
	$(CC) $(CPPFLAGS) $(CFLAGS) $(D_NO_XLIB) $(GISTINCL) -c graph.c

# Some make programs (e.g.- SGI) have default rule .i.c
graph.i: graph.c
	@touch graph.i

fortrn.o: fortrn.c defmem.h
	$(CC) $(CPPFLAGS) $(CFLAGS) $(FORTRAN_LINKAGE) -c fortrn.c

# Always compile main.c with -g so new packages can be debugged.
$(Y_HOME)/main.o: main.c
	$(CC) $(CPPFLAGS) -g -c main.c

main.o: main.c
	$(CC) $(CPPFLAGS) -g -c main.c

# ---------------------------------------------------------------------------

# Do not modify or remove the following line.
# --END-CODE-SPECIFIC-SECTION-----------------END-CODE-SPECIFIC-SECTION--
# -BEGIN-SITE-SPECIFIC-SECTION---------------BEGIN-SITE-SPECIFIC-SECTION-
# Do not modify or remove the preceding line.

# If you are creating a Makefile starting from the Maketmpl in order
# to build a special version of Yorick, then

#       TRY HARD NOT TO MODIFY ANYTHING BELOW THIS POINT.

# The configure script in the Yorick distribution should be able to do
# most of this correctly.  Exceptions are the Fortran section and the
# Y_LD variable; see the README in the top level distribution directory.

# ---------------------------------------------------------------------------
# This Makefile is divided into two (hopefully independent) parts:
# This second section is a site-specific section, which should not
# differ among various Yorick-based codes at a particular site.
# The first section describes how to build the Yorick-based code
# contained in this directory.
# The two parts divide between the lines which look like
#                 END-CODE-SPECIFIC-SECTION           and 
#                BEGIN-SITE-SPECIFIC-SECTION

# Generic make targets defined below--
# $(CODE_NAME):     (builds my_code custom version of Yorick)
# $(CODE_LIBRARY):  (builds my_code library)
# clean::           (removes everything except source code)
# tidy::            (removes backups and object files)
# Makefile::        (to port this Makefile to another site)
# tags:             (make TAGS file for GNU Emacs)
# index:            (make index file for vgrind C beautifier)

# ---------------------------------------------------------------------------

# The following paths may be set by the configure script:

# This should ALWAYS be absolute path names beginning with /
# NEVER relative path names beginning with . or ..
prefix = /usr/local

# I don't know whether these do what they're supposed to do (for autoconf).
srcdir = .
VPATH = .

# Directory which will contain the architecture-independent components of
# the public Yorick for this architecture.
Y_SITE = $(prefix)/Yorick

# Directories for the architecture-dependent parts of Yorick
Y_BINDIR = $(exec_prefix)/bin
Y_LIBDIR = $(exec_prefix)/lib
Y_CONTRIBDIR = $(exec_prefix)/contrib

# These are separate variables so they can be
# overridden on the make command line
YORINCL = -I$(Y_HOME)
YORLIB = -L$(Y_LIBDIR)
GISTINCL = -I$(Y_HOME)
GISTLIB = -L$(Y_LIBDIR)
Y_CONTRIB_LIB = -L$(Y_CONTRIBDIR)

# Filled in by configure script
XLOAD = -L/usr/X11R6/lib -lX11

# ---------------------------------------------------------------------------

# Redefine these to nil to get a no-graphics version of Yorick.
GRAPH_LIBS = $(GISTLIB) -lgist $(XLOAD)
# Solaris needs:    -lsocket -lnsl -lw -lintl -ldl
# when loading with -Bstatic   -- however, Sun doesn't supply libdl.a!?
GRAPH_I = graph.i
GRAPH_O = graph.o

# ---------------------------------------------------------------------------

# Choose C compiler appropriate to this machine - must be an ANSI C compiler
CC = shlicc
DEFS =  
CFLAGS = $(C_OPTIMIZE) $(DEFS) -I$(srcdir) $(YORINCL)

LDOPTS = 
LDFLAGS = $(LD_OPTIMIZE) $(LDOPTS)

# Usage:   $(Y_LD) $(OBJS) $(LIBS)
Y_LD = $(CC) $(LDFLAGS) -o $@

# The lowest level (last) libraries required on the load line go here.
# LOWLIBS = -lm -lc            (if Y_LD is not your C compiler)
LOWLIBS = -lm 

.c.o:
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $<
.c:
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)

# ---------------------------------------------------------------------------

# Repeat for FORTRAN compiler
FC = 
FFLAGS = $(F_OPTIMIZE) $(FORTRAN_STYLE)

# See comment at top of Maketmpl about FORTRAN_STYLE
# CRAY_FORTRAN = -r8 -i4       Sun SPARC workstation
# CRAY_FORTRAN = +autodbl4     HP PA-RISC workstation (OS<=8)
# CRAY_FORTRAN = -R8           HP PA-RISC workstation (OS>=9)
#             doesn't really work, and +autodblpad is totally wrong
# This is the most important case, since Crays are the only deviants:
# CRAY_FORTRAN =
# WKS_FORTRAN = -dp            UNICOS Crays
CRAY_FORTRAN = -r8 -i4
WKS_FORTRAN =

# (May be best to leave these commented out...)
# .f.o:
# 	$(FC) $(FFLAGS) -c $<
# .f:
# 	$(FC) $(FFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)

# Since the rule used to build the custom Yorick version generally
# uses the C compiler to load, the user will need to select the
# FORTRAN libraries explicitly.  Yorick packages should generally
# avoid FORTRAN I/O, so I don't put the I/O library here...
# FORTRAN_LIBS = -lf77                Sun SPARC workstation
#      On Suns, use ar to remove the file main.o from the libF77.a
#      in /usr/lang.  Call the result libf77.a and put it in Y_HOME.
#      Also, Sun FORTRAN uses yacc to stupidly cause a yyparse and
#      yylex to appear if you use any formatted I/O -- needless to
#      say, this conflicts with Yorick's parser.  I could also use
#      macros to redefine these names in yorick.y/yorick.c...
# FORTRAN_LIBS = -lF77                Sun SPARC workstation (someday)
# FORTRAN_LIBS = -lM77 -lF77          Solaris
# FORTRAN_LIBS = -lvec -lcl           HP PA-RISC workstation
# FORTRAN_LIBS = -l??                 IBM workstations
# FORTRAN_LIBS = -lf                  UNICOS Crays
FORTRAN_LIBS = 

# Codger, Yorick's automatic wrapper and initialization code generator,
# understands four possible FORTRAN external name linkage conventions:
# All lowercase or all uppercase, with or without a trailing underscore.
# Use exactly one of the following lines:
# FORTRAN_LINKAGE = -Df_linkage
# FORTRAN_LINKAGE = -Df_linkage_
# FORTRAN_LINKAGE = -DF_LINKAGE
# FORTRAN_LINKAGE = -DF_LINKAGE_
FORTRAN_LINKAGE = -Df_linkage_

# ---------------------------------------------------------------------------

# The timing routines in sysdep.c are a perennial problem.  The default
# is POSIX 1003.1 standard, but this doesn't work on Suns...
# You will need to edit sysdep.c if neither of these works.
# HAS_BSD_TIMER = -DBSD_TIMER
# HAS_BSD_TIMER =
HAS_BSD_TIMER = 

# Other utilities

SHELL = /bin/sh
MAKE = make
RM = rm -f
MV = mv
SED = sed

AR = ar
# If your ar does not take the "l" flag (local temporary files), use this.
# ARFLAGS = rc
ARFLAGS = rcl

RANLIB = ranlib

# ---------------------------------------------------------------------------

# If you are editing the original Yorick Makefile, you are done.

# ---------------------------------------------------------------------------

CODGER = $(Y_HOME)/codger

# A generic main.o is located in Y_HOME, along with main.c.
# yinit.o is made by Codger from ycode.c, which will include all the
# packages specified as Y_INCLUDE, plus the std.i package in Y_HOME.
MAIN_OBJS = $(Y_HOME)/main.o yinit.o $(PKG_OBJS)

# ---------------------------------------------------------------------------
# The first three targets are generic rules for building the custom code
# and the package library required for inserting this package into any
# version of Yorick, in combination with other packages.

OTHER_LIBS = $(GRAPH_LIBS) $(SYS_LIBS) $(LOWLIBS)
ALL_LIBS = -L. $(Y_CONTRIB_LIB) $(YORLIB) $(PKG_LIBS) -lyor $(OTHER_LIBS)

$(NON_SHARABLE): $(MAIN_OBJS)
	$(Y_LD) $(MAIN_OBJS) $(ALL_LIBS)

$(CODE_NAME): $(MAIN_OBJS) $(CODE_LIBRARY)
	$(Y_LD) $(MAIN_OBJS) $(ALL_LIBS)

# The ywrap.o file is generated by Codger from ycode.c, as controlled
# by the Y_INCLUDE variable.
$(CODE_LIBRARY): $(OBJS) $(YWRAP_O)
	$(AR) $(ARFLAGS) $@ $(OBJS) $(YWRAP_O)
	$(RANLIB) $@

Makefile::
	@echo "Merging $(Y_HOME)/Maketmpl with ./Makefile"
	$(SED) -n -e "1,/^# --END-CODE/p" ./Makefile >M.1
	$(SED) -n -e "/^# -BEGIN-SITE/,$$$$p" $(Y_HOME)/Maketmpl >M.2
	cat M.1 M.2 >Makefile
	$(RM) M.1 M.2

# The Codger code generator produces a single output file ycode.c
# which must be compiled into two object files -- ywrap.o to be
# included in an object file library for a Yorick package, and
# yinit.o to be loaded into a specific version of Yorick.
ycode.c: $(Y_INCLUDE)
	$(CODGER) $(Y_SITE) $(Y_INCLUDE) - $(GRAPH_I) $(Y_OTHERS)
ywrap.o: ycode.c $(Y_INCLUDE)
	$(CC) $(CPPFLAGS) $(CFLAGS) -DYWRAP_C -c ycode.c
	$(MV) ycode.o ywrap.o
yinit.o: ycode.c $(Y_INCLUDE)
	$(CC) $(CPPFLAGS) $(CFLAGS) -DYINIT_C -c ycode.c
	$(MV) ycode.o yinit.o

# Housekeeping targets--
#   make clean        to wipe everything but source files
#   make tidy         to clean out junk, but leave executables and libraries
clean: tidy
	$(RM) *.a $(CLEAN_UP)

tidy:
	$(RM) ycode.c *.o *~ *.bak core $(TIDY_UP)

# TAGS table for Emacs
tags:
	etags -tw *.h *.c *.y

# index for vgrind (a pretty C printing routine)
index:
	etags -twv *.h *.c >index

# ---------------------------------------------------------------------------
