#
# File: makefile
# By: Alex Theo de Jong
# Created: September 1995
# Description:
# Makefile for utilities and support functions
# 
# Note
# Edit the CC and CPP variables to set either the Sprac
# C++ compiler or the GNU g++ compiler.


# Operating System
OS = -DSOLARIS

# Directories
PIDRDIR   = .
INSTBIN   = ../../Bin/Solaris
INSTLIB   = ../../../Lib
INSTINC   = ../../../Inc
ATMINC    = /usr/fore/include

# Tools
CP        = cp
MV        = mv
CHMOD     = chmod 666
RM        = rm -f
CC        = /opt/SUNWspro/bin/cc # gcc
CPP       = CC # g++ -V2.7.2 # -V2.6.3

# Compiler options
EXTERNAL  = # -fexternal-templates
ATM       = -DFORE_ATM
PROTOTYPE = # -fno-strict-prototype
DEBUG     = -g # gdb -DTRACE # -DDEBUG
WARNINGS  = # -Wall # List all warnings # -w # Suppress warnings #
OPTIMIZE  = # -O6 # -O2

# Compiler flags
CPPFLAGS  = $(DEBUG) $(WARNINGS) $(OPTIMIZE) $(OS) $(ATM) \
            $(EXTERNAL) $(PROTOTYPE) -I$(PIDRDIR) -I$(INSTINC) -I$(ATMINC)

# Loader/linker flags
LDFLAGS   = -L$(INSTLIB)
LDLIBS    = -lutil -latm -lnsl -lsocket

# Things to compile
# when using Sparc Compiler: 
SUNHDRS   = String.h Regex.h
SUNOBJS   = String.o Regex.o gnu_error.o xexit.o xmalloc.o alloca.o rx.o
OBJECTS   = $(SUNOBJS) athread.o network.o
HEADERS   = $(SUNHDRS) athread.hh network.hh debug.hh error.hh util.hh TDPList.hh
PROGRAM   = test
LIBRARY   = libutil.a

# Compile lines

all: $(PROGRAM) $(LIBRARY)

install: $(LIBRARY)

clean: installclean

installclean:
	$(RM) *.o *~ *.~?~ core $(PROGRAM)

%.a: $(OBJECTS)
	$(AR) vrus $(INSTLIB)/$*.a $(OBJECTS)
	$(CP) *.hh $(INSTINC)
	$(CHMOD) $(INSTINC)/*.hh
	$(CP) *.h $(INSTINC)
	$(CHMOD) $(INSTINC)/*.h

.cc.o:
	$(RM) $@
	$(CPP) $(CPPFLAGS) -c $<

.c.o:
	$(RM) $@
	$(CC) $(CPPFLAGS) -w -c $<

test: test.cc $(LIBRARY)
	$(RM) $@
	$(CPP) $(CPPFLAGS) -o test test.cc $(LDFLAGS) $(LDLIBS)

# Dependencies
network.o: network.hh athread.hh
athread.o: athread.hh
String.o: String.h 
Regex.o: Regex.h ansidecl.h libiberty.h builtin.h
rx.o: rx.h ansidecl.h libiberty.h
alloca.o: ansidecl.h libiberty.h
xmalloc.o: ansidecl.h libiberty.h
xexit.o: ansidecl.h libiberty.h
gnu_error.o: ansidecl.h