# Compile control routines and put .o files into standard directory
# to be wrapped up into library with other routines by master Makefile.
# Determines what to make by whether C binding is up-to-date relative to
# source, but compiles both C and Fortran binding versions.
# Phil Farrell, Stanford Earth Sciences
# 29 March 1989

# MARGS can be used in testing to pass argument to recursive make call.
MARGS=
# LIBGKS may be overridden by top level makefile.
LIBGKS = ../libgks.a
# Expects CFLAGS to be supplied by top level makefile.
# Routine ./control/gopks.c uses a low-level routine from the BSD UNIX
# f77 I/O compiler library in the Fortran binding.  The name of this
# routine is "now_acc" in 4.2BSD or "now_writing" in 4.3BSD.  If you have
# 4.2BSD, the BSDFLAG macro should be undefined.  If you have 4.3BSD
# (default at Earth Sciences), the BSDFLAG macro should have the value
# -DFOURTHREEBSD.
BSDFLAG=-DFOURTHREEBSD

CFILES = gwsconf.c gopks.c gopwk.c gclrwk.c guwk.c gclwk.c gacwk.c gdacwk.c
OFILES = gwsconf.o gopks.o gopwk.o gclrwk.o guwk.o gclwk.o gacwk.o gdacwk.o

# all compiled modules put into OBJDIR to be wrapped up later into library.
OBJDIR = ../.objects

default: $(LIBGKS)

# Top level Makefile has already de-archived library into OBJDIR.
# If library is out of date with regard to any of the source files here, 
# first move the de-archived object files to this directory, then
# recursively call make to only update the specific ones that are changed.
$(LIBGKS): ${CFILES}
	-thisdir=`pwd`; cd $(OBJDIR); mv $(OFILES) $$thisdir > /dev/null 2>&1
	make $(MARGS) CFLAGS="$(CFLAGS)" objs
	-mv *.o $(OBJDIR)

objs: $(OFILES)

# If C binding routine out of date, also make Fortran binding version
.c.o:
	cc -c $(CFLAGS) $*.c
	cp $*.c $*_.c
	cc -c $(BSDFLAG) $(CFLAGS) -DFORTRAN $*_.c
	rm -f $*_.c

clean:
	-rm -f *.o *_.c
	-cd $(OBJDIR); rm -f $(OFILES)

