#
# This file is a Makefile for Util.  If it has the name "Makefile.in"
# then it is a template for a Makefile;  to generate the actual Makefile,
# run "./configure", which is a configuration script generated by the
# "autoconf" program (constructs like "@foo@" will get replaced in the
# actual Makefile.
#

# Current version;  used in various names.
PACKAGE = util
VERSION = 1.0

DISTNAME = util-${VERSION}
DISTDIR = ../export/${DISTNAME}
FTPDIR	= ../ftp

#----------------------------------------------------------------
# Things you can change to personalize the Makefile for your own
# site (you can make these changes in either Makefile.in or
# Makefile, but changes to Makefile will get lost if you re-run
# the configuration script).
#----------------------------------------------------------------

# Default top-level directories in which to install architecture-
# specific files (exec_prefix) and machine-independent files such
# as scripts (prefix).  The values specified here may be overridden
# at configure-time with the --exec-prefix and --prefix options
# to the "configure" script.

prefix =		/home/eric
exec_prefix =		${prefix}

# The following definition can be set to non-null for special systems
# like AFS with replication.  It allows the pathnames used for installation
# to be different than those used for actually reference files at
# run-time.  INSTALL_ROOT is prepended to $prefix and $exec_prefix
# when installing files.
INSTALL_ROOT =

# Directory in which to install the .a, .so, and .o files:
LIB_INSTALL_DIR =	$(INSTALL_ROOT)$(exec_prefix)/lib

# Directory in which to install the programs:
BIN_INSTALL_DIR =	$(INSTALL_ROOT)$(exec_prefix)/bin

# Directory in which to install the include files:
INCLUDE_INSTALL_DIR =	$(INSTALL_ROOT)$(prefix)/include

# extra includes for compiling
INCLUDES =

# extra libs
EXTRA_LIBS	=  -ldl

# zlib directory
ZDIR	= ./zlib-1.2.3
ZOBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
       zutil.o inflate.o infback.o inftrees.o inffast.o

# zlib 1.1.4
# ZOBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
#       zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o

# the full set of libraries for linking
LIBS	= -lm

# To change the compiler switches, for example to change from -O
# to -g, change the following line:
CFLAGS = 		-g -W -Wall -Wno-implicit-int -fPIC

# To add ld switches, change the following line:
LDFLAGS =		-g -rdynamic

# Some versions of make, like SGI's, use the following variable to
# determine which shell to use for executing commands:
SHELL =			/bin/sh

# extra modules added by configure.in to fix OS bugs
EXTRA_OBJS = 		$(ZOBJS)

# There are just too many different versions of "install" around;
# better to use the install-sh script that comes with the distribution,
# which is slower but guaranteed to work.

INSTALL = 		./install-sh -c
INSTALL_PROGRAM =	${INSTALL}
INSTALL_DATA =		${INSTALL} -m 644

OBJPATH	=		\"$(LIB_INSTALL_DIR):.\"

#----------------------------------------------------------------
# The information below is modified by the configure script when
# Makefile is generated from Makefile.in.  You shouldn't normally
# modify any of this stuff by hand.
#----------------------------------------------------------------

AC_FLAGS =		-DHAVE_CONFIG_H
RANLIB =		ranlib

#----------------------------------------------------------------
# The information below should be usable as is.  The configure
# script won't modify it and you shouldn't need to modify it
# either.
#----------------------------------------------------------------

CC =		gcc

CC_SWITCHES =	-I. ${CFLAGS} -DUSE_DL=1 ${INCLUDES} ${AC_FLAGS}

DEPEND_SWITCHES = -I. ${CFLAGS} ${INCLUDES} ${AC_FLAGS}

SRCS =		file.c find.c gio.c xlaunch.c \
		macro.c mainlib.c mkrtemp.c nan.c parse.c \
		strtod.c swap.c word.c winprocess.c xalloc.c zprocess.c 

OBJS =		file.o find.o gio.o xlaunch.o \
		macro.o mainlib.o mkrtemp.o nan.o parse.o \
		strtod.o swap.o word.o  winprocess.o xalloc.o zprocess.o \
		$(EXTRA_OBJS)


# these are all the modules going into the "normal" filt library
LIBOBJS =	${OBJS}

# the default library for this package
DEFLIB =	libutil.a
# the actual library we are building (if this is a subpackage)
LIB =		/proj/rd/eric/funtools-1.4.4/libfuntools.a

TESTPROGS =	tparse tlaunch tlaunch2

PROGS =		gcat

all:		$(LIB) $(PROGS)

testall:	$(TESTPROGS)

All:		all testall

install:	install-binaries

$(LIB):		$(LIBOBJS)
		ar cruv $(LIB) $(LIBOBJS)
		$(RANLIB) $(LIB)

libutil:	$(LIBOBJS)
		ar cruv libutil.a $(LIBOBJS)
		$(RANLIB) libutil.a

# these are the zlib routines:
adler32.o:	$(ZDIR)/adler32.c
		$(CC) -I$(ZDIR) -c $(CFLAGS) $(ZDIR)/adler32.c
compress.o:	$(ZDIR)/compress.c
		$(CC) -I$(ZDIR) -c $(CFLAGS) $(ZDIR)/compress.c
crc32.o:	$(ZDIR)/crc32.c
		$(CC) -I$(ZDIR) -c $(CFLAGS) $(ZDIR)/crc32.c
gzio.o:		$(ZDIR)/gzio.c
		$(CC) -I$(ZDIR) -c $(CFLAGS) $(ZDIR)/gzio.c
uncompr.o:	$(ZDIR)/uncompr.c
		$(CC) -I$(ZDIR) -c $(CFLAGS) $(ZDIR)/uncompr.c
deflate.o:	$(ZDIR)/deflate.c
		$(CC) -I$(ZDIR) -c $(CFLAGS) $(ZDIR)/deflate.c
trees.o:	$(ZDIR)/trees.c
		$(CC) -I$(ZDIR) -c $(CFLAGS) $(ZDIR)/trees.c
zutil.o:	$(ZDIR)/zutil.c
		$(CC) -I$(ZDIR) -c $(CFLAGS) $(ZDIR)/zutil.c
inflate.o:	$(ZDIR)/inflate.c
		$(CC) -I$(ZDIR) -c $(CFLAGS) $(ZDIR)/inflate.c
infblock.o:	$(ZDIR)/infblock.c
		$(CC) -I$(ZDIR) -c $(CFLAGS) $(ZDIR)/infblock.c
inftrees.o:	$(ZDIR)/inftrees.c
		$(CC) -I$(ZDIR) -c $(CFLAGS) $(ZDIR)/inftrees.c
infback.o:	$(ZDIR)/infback.c
		$(CC) -I$(ZDIR) -c $(CFLAGS) $(ZDIR)/infback.c
inffast.o:	$(ZDIR)/inffast.c
		$(CC) -I$(ZDIR) -c $(CFLAGS) $(ZDIR)/inffast.c

gio.o:		gio.c gio.h
		$(CC) -c $(CC_SWITCHES) -I$(ZDIR) gio.c

gcat.o:		gcat.c gio.h

gcat:		gcat.o $(LIB)
		$(CC) $(LDFLAGS) gcat.o -o gcat $(LIB) $(LIBS) $(EXTRA_LIBS)

tparse.o:	tparse.c

tparse:		tparse.o parse.o $(LIB)
		$(CC) $(LDFLAGS) tparse.o parse.o -o tparse $(LIB) $(LIBS) \
		$(EXTRA_LIBS)

tlaunch.o:	tlaunch.c

tlaunch:	tlaunch.o xlaunch.o $(LIB)
		$(CC) $(LDFLAGS) tlaunch.o xlaunch.o -o tlaunch $(LIB) $(LIBS) \
		$(EXTRA_LIBS)

tlaunch2.o:	tlaunch2.c

tlaunch2:	tlaunch2.o
		$(CC) $(LDFLAGS) tlaunch2.o -o tlaunch2

install-binaries: $(LIB) $(PROGS)
	@for i in $(LIB_INSTALL_DIR) $(INCLUDE_INSTALL_DIR) $(BIN_INSTALL_DIR) ; \
	    do \
	    if [ ! -d $$i ] ; then \
		echo "Making directory $$i"; \
		mkdir $$i; \
		chmod 755 $$i; \
		else true; \
		fi; \
	    done;
	@for i in $(PROGS) ; \
	  do \
	  echo "Installing $$i$(EXE)" ; \
	  $(INSTALL_PROGRAM) $$i$(EXE) $(BIN_INSTALL_DIR)/$$i$(EXE) ; \
	  done;
	@if [ "$(LIB)" = "$(DEFLIB)" ] ; then \
	    XLIB=`basename $(LIB)`; \
	    echo "Installing $$XLIB"; \
	    $(INSTALL_DATA) $$XLIB $(LIB_INSTALL_DIR)/$$XLIB; \
	    (cd $(LIB_INSTALL_DIR); $(RANLIB) $$XLIB); \
	    chmod 555 $(LIB_INSTALL_DIR)/$$XLIB; \
        fi;
	@for i in imregions.o evregions.o ; \
	    do \
		if [ -f $$i ] ; then \
		  echo "Installing $$i" ; \
		  $(INSTALL_DATA) $$i $(LIB_INSTALL_DIR)/$$i ; \
		fi; \
	    done;
	@for i in NaN.h conf.h file.h find.h gio.h xlaunch.h longlong.h \
	macro.h mainlib.h tclmainlib.h mkrtemp.h parse.h prsetup.h \
	xalloc.h strtod.h swap.h word.h xport.h winprocess.h xfileio.h \
	zprocess.h; \
	    do \
		if [ -f $$i ] ; then \
		  echo "Installing $$i" ; \
		  $(INSTALL_DATA) $$i $(INCLUDE_INSTALL_DIR)/$$i ; \
		fi; \
	    done;

Makefile:	Makefile.in
		$(SHELL) config.status

RM = 		rm -f

clean:
		$(RM) *.a *.so *.o *.exe core errs *pure* .nfs* \
			foo* *~ *.log \#* TAGS *.E a.out errors \
			$(PROGS) $(TESTPROGS) \
			gmon.out *.pg *.bak \
			config.info config.log \
			doc/*~
		$(RM) -r autom4te.cache

distclean:	clean
		$(RM) Makefile config.status config.cache config.log

depend:
		makedepend -- $(DEPEND_SWITCHES) -- $(SRCS)

.c.o:
		$(CC) -c $(CC_SWITCHES) $<

configure:	configure.in
		autoconf configure.in

pure:		tlaunch.pure

tlaunch.pure:	tlaunch.o xlaunch.o $(LIB)
		purift $(CC) $(LDFLAGS) tlaunch.o xlaunch.o -o tlaunch \
		$(LIB) $(LIBS) $(EXTRA_LIBS)

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