# -*- makefile -*-
# Makefile for Unix with gcc compiler

CC=gcc
# if you use egcs-2.90.* version of GCC please add option -fno-exceptions 
# to reduce code size and increase performance

# Debug version
#CFLAGS = -c -Wall -O0 -g -DDEBUG=DEBUG_TRACE

# Optimized version
CFLAGS = -c -Wall -O6 -g -DDEBUG=DEBUG_CHECK

# Optimized version with switched off asserts
#CFLAGS = -c -Wall -O6 -g -DNDEBUG

LFLAGS=-g
AR=ar
ARFLAGS=-cru 

EXAMPLES=guess testtree

INSTALL_DIR=/usr/lib

HEADERS=stdtp.h file.h storage.h classinfo.h object.h

all: libstorage.a $(EXAMPLES)

file.o: file.cxx $(HEADERS)
	$(CC) $(CFLAGS) file.cxx

storage.o: storage.cxx $(HEADERS)
	$(CC) $(CFLAGS) storage.cxx

classinfo.o: classinfo.cxx $(HEADERS)
	$(CC) $(CFLAGS) classinfo.cxx

libstorage.a: storage.o classinfo.o file.o
	$(AR) $(ARFLAGS) libstorage.a storage.o classinfo.o file.o

install: libstorage.a
	cp libstorage.a $(INSTALL_DIR)

#
# Examples
#

guess.o: guess.cxx $(HEADERS)
	$(CC) $(CFLAGS) guess.cxx

guess: guess.o comptime.cxx libstorage.a
	$(CC) $(LFLAGS) -o guess guess.o comptime.cxx libstorage.a

awltree.o: awltree.cxx awltree.h $(HEADERS)
	$(CC) $(CFLAGS) awltree.cxx

hashtab.o: hashtab.cxx hashtab.h $(HEADERS)
	$(CC) $(CFLAGS) hashtab.cxx

testtree.o: testtree.cxx awltree.h hashtab.h $(HEADERS)
	$(CC) $(CFLAGS) testtree.cxx

testtree: testtree.o awltree.o hashtab.o comptime.cxx libstorage.a
	$(CC) $(LFLAGS) -o testtree testtree.o awltree.o hashtab.o \
		comptime.cxx libstorage.a

testrans.o: testrans.cxx awltree.h $(HEADERS)
	$(CC) $(CFLAGS) testrans.cxx

testrans: testrans.o comptime.cxx libstorage.a
	$(CC) $(LFLAGS) -o testrans testrans.o comptime.cxx libstorage.a



#
# Service targets
#

cleanobj:
	rm -f *.o core *~ $(EXAMPLES) testrans

cleandbs: 
	rm -f *.odb .*.odb

clean: cleanobj cleandbs

cleanall: clean
	rm -f *.a


tgz:	cleanall
	cd ..; tar cvzf post.tgz post

copytgz: tgz
	mcopy -o ../post.tgz a:
