# Makefile for library - util
#
# History:  95/12/05 kmflynn

# Usage:  make [libdir=path_to_install_to] [install] [| tee makeout]
#
# Examples:  make 
#            make install libdir=/usr/lib
#            make install libdir=$HOME/lib

# Compiler flags (Fortran - Green Hills):
#    C - check subranges and array bounds
#    u - default data type for undeclareds is undefined
#    g - generate source level symbolic debug information
# ansi - compile in accordance with rules for ANSI C, flag violations
#   OM - optimization
# (NOTE: set OpgDbg to: OptM to generate optimized code
#                       DbgF to generate debug code
#        set DbgC to -g to generate debug C code)
DbgC   =
DbgF   = -g
OptM   = -OM
OptDbg =
FFLAGS = -u $(OptDbg)
CFLAGS = -ansi $(DbgC)

# Compiler names
F77    = f77
CC     = gcc

# symbol table for library archive may need to be explicitly built;
# System V ar does this automatically, BSD ar does not
BSD    = ranlib $@
SYS_V  =
SymTbl = $(SYS_V)

# library archive options
#    r - replace the named files in the archive file
#    v - give a verbose file-by-file description of the making
#    c - suppress the message that is produced by default when
#        the archive file is created
#    q - quickly append the named files to the end of the
#        archive file
ArOpt = rv

# this description file uses the Bourne shell
SHELL = /bin/sh

# Object files, installation specific
# where utcp[gn ux].o copy arrays (fortran and c versions)
#       dttm[dg pc pr sg sn dc].o calls to system routines for date and time
#       ckfs[dg pc].o wild card file name matching
#       uscn[vt ux pc].o screen addressing
#       utsc[dg lh ot pc pr vx].o get/put single character from/to screen
#       tty[ux].o get/put single character
ObjDG   = utcpux.o dttmdg.o ckfsdg.o uscnvt.o utscdg.o ttyux.o
ObjSun  = utcpux.o dttmsn.o ckfsdg.o uscnvt.o utscdg.o ttyux.o
ObjSGI  = utcpux.o dttmsg.o ckfsdg.o uscnvt.o utscdg.o ttyux.o
ObjRISC =
ObjDec  = utcpux.o dttmdc.o ckfsdg.o uscnvt.o utscdg.o ttyux.o
ObjHP   = utcpux.o dttmhp.o ckfsdg.o uscnvt.o utscdg.o ttyux.o
ObjVrsn = $(ObjDG)

#*******************************************************************
#***** You should not need to modify anything below this line. *****
#*******************************************************************

library = utillib.a
Objects = utchar.o  utdate.o  utgnrl.o utnumb.o utsort.o utscxx.o \
          dirlis_.o getdir_.o Malloc.o FileName.o

libdir  = ../../lib
binary  = ../../lib
libMake = $(binary)/$(library)
libInst = $(libdir)/$(library)

# Rules
all: $(binary) $(libMake) install
	@echo "\nDone making all for util, files are now up-to-date.\n"

# Library and utility dependencies:
$(libMake):   $(Objects) $(ObjVrsn)
	@echo "\n" making $(libMake)
	ar $(ArOpt) $@ $?
	$(SymTbl)
$(binary):
	@if [ ! -d $(binary) ]   ; then        \
	   mkdir $(binary)  ;                  \
	   echo Created directory $(binary) ;  \
        fi
install:
# Create directory for binary file, if necessary
	@if [ ! -d $(libdir) ]   ; then        \
	   mkdir $(libdir) ;                   \
	   echo  Created directory $(libdir) ; \
	fi
# Link executable to libdir if installing elsewhere
	@if [ ! -s $(libMake) ] ; then                              \
	   echo library $(libMake) does not exist, ;                \
	   echo use one of the following commands to generate it:;  \
	   echo "     make" ;  echo "     make all" ;               \
	else                                                        \
	   if [ $(libdir) != $(binary) ] ; then                     \
	      rm -f $(libInst) ;                               \
	      cd ../..; ln -s `pwd`/lib/$(library) $(libInst); \
	      chmod 644 $(libInst) ;                           \
	      echo "\n"Library $(libInst) has been updated.;   \
	   fi ; \
	fi
clean:
	@if [ $(libdir) != $(binary) ] ; then rm -f $(libInst) ; fi
	rm -f *.o $(libMake)
	@echo Removed files generated by make."\n"

# Define object file dependencies:
utchar.o:     const.inc
utnumb.o:     const.inc  fversn.inc
utscxx.o:     color.inc
utscot.o:     color.inc
utscpc.o:     color.inc

# system include files
#utcpux.o:    <string.h>
#FileName.o:  <stdlib.h> <string.h>
#Malloc.o:    <stdlib.h>
#dirlis_.o:   <stdlib.h> <string.h> <stdio.h>
#getdir_.o:   <stdlib.h> <string.h> <memory.h>
#ttyux.o:     <signal.h> <stdio.h>  <termios.h>

# end of make
