# The object files will be compiled into the BIN directory.  BIN is
# expected to be defined in the "make" command line.  It should be set
# to the hardware type for which the .o files are to be created.  For
# example, "make BIN=sun3-4".

BIN=sun4-5
B=$(BIN)/
QPC=qpc

OBJECTS = $Bavl.o $Bkdb.o
BINARIES = $(OBJECTS) $Blibbuiltins_d.so

QOFS=	tavl.qof kdb.qof

CC=cc -c $(CFLAGS)

.SUFFIXES: .qof .pl

.pl.qof:
	${QPC} -cH $?

all:	  $(BIN) $(QOFS)

sun3-4 sun4-4:	make_sun
sun4-5:		make_svr4

make_sun:
	@ [ -d $(BIN) ] || ( mkdir $(BIN) && chmod 775 $(BIN) )
	@ $(MAKE) BIN=$(BIN) CFLAGS="-O -I../../embed -pic" binaries

make_svr4:
	@ [ -d $(BIN) ] || ( mkdir $(BIN) && chmod 775 $(BIN) )
	@ $(MAKE) BIN=$(BIN) CFLAGS="-O -I../../embed -DSYSV -K pic" \
	  LDSOFLAG=-G binaries LIBS="-L/usr/ucblib -lucb -lsocket -lnsl -lelf"

binaries: $(BINARIES)

$Bkdb.o : kdb.c
	$(CC) kdb.c -o $@
	chmod a+r $@

$Bavl.o : avl.c
	$(CC) avl.c -o $@
	chmod a+r $@

$Blibbuiltins_d.so: $(OBJECTS)
	LD_RUN_PATH=/usr/ucblib ld $(LDSOFLAG) -o $@ $(OBJECTS) $(LIBS)
	chmod a+r $@

clean: 
	\rm -f $(BINARIES) $(QOFS)
	\rmdir $(BIN)
