#!make -f
#
#          Copyright (c) mjh-EDV Beratung, 1996-1999
#     mjh-EDV Beratung - 63263 Neu-Isenburg - Rosenstrasse 12
#          Tel +49 6102 328279 - Fax +49 6102 328278
#                Email info@mjh.teddy-net.com
#
#       Author: Jordan Hrycaj <jordan@mjh.teddy-net.com>
#
#   $Id: Makefile,v 1.10 1999/04/23 10:52:04 renaud Exp $
#
#   This library is free software; you can redistribute it and/or
#   modify it under the terms of the GNU Library General Public
#   License as published by the Free Software Foundation; either
#   version 2 of the License, or (at your option) any later version.
#
#   This library is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#   Library General Public License for more details.
#
#   You should have received a copy of the GNU Library General Public
#   License along with this library; if not, write to the Free
#   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#


TOP  = ../..
SED  = sed

include $(TOP)/nessus.tmpl

MAKF = Makefile
XTRA =  rnd-pool.o common-stuff.o
CPHS =  twofish.o blowfish.o des.o md5.o rmd160.o sha1.o
STRM =  cbc-frame.o iostream.o
OBJS = 	peks-setup.o peks-baseXX.o peks-file.o peks-handshake.o \
	peks-string.o peks-rpc.o peks-svc.o \
	messages.o peks-client.o peks-server.o hostnames.o baseXX.o \
	smallprime.o crandom.o cipher.o make-primes.o elgamal.o \
	$(RNDM) $(CPHS) $(STRM) $(XTRA)

OLIB = libnessusc

all : $(OLIB).so

.SUFFIXES: .o .c

.c.o:
	$(TOP)/libtool $(CC) $(DEFS) $(include) $(CFLAGS) -c $<

# generate public interface
peks.h: $(MAKF) peks.h-begin peks.h-end
	@echo Generating $@ ...
	@(cat peks.h-begin;\
	  $(SED) '/^XPUB/!d; s/XPUB//; s/ //;' *.h;\
	  cat peks.h-end) >$@
	@echo done.

# on some gcc, the optimiser + debugging g make problems
twofish.o: twofish.c
	$(TOP)/libtool $(CC) $(DEFS) $(include) -c twofish.c

$(OBJS): peks.h iostream.h common-stuff.h peks-internal.h version.h $(MAKF)

$(OLIB).so: peks.h $(OBJS)
	$(TOP)/libtool $(CC) -o $(OLIB).la $(OBJS:.o=.lo) -rpath $(rpath)
	@cp .libs/$(OLIB).*  ${rootdir}/libs/

install : libnessusc.la
	$(TOP)/libtool --mode install $(INSTALL) libnessusc.la ${exec_prefix}/lib
	$(TOP)/libtool --finish ${exec_prefix}/lib

clean :
	@rm -f *.o *.lo *.la peks.h .libs/[!C][!V]*

distclean : clean
	@rm -f *~ *.bak *.swp


# -----------------------
# dependencies
# -----------------------

.PRECIOUS: peks-baseXX.h cbc-frame.h peks-file.h \
	   peks-client.h peks-server.h

peks-baseXX.h: baseXX.h cipher.h
cbc-frame.h: cipher.h iostream.h crandom.h
peks-file.h: messages.h peks-baseXX.h 
peks-client.h peks-server.h: peks-handshake.h peks-file.h cbc-frame.h

# -------------------------------------
# inherited sources (mostly from gnupg)
# -------------------------------------

random.o rndlinux.o rndunix.o: rnd-port.h
des.o twofish.o blowfish.o sha1.o md5.o rmd160.o: raw-port.h

# -----------------------
# other dependencies
# -----------------------

make-primes.o: peks-baseXX.h crandom.h
cbc-frame.o: cbc-frame.h
cipher.o: cipher.h
iostream.o: iostream.h
crandom.o: crandom.h
rnd-pool.o: rnd-pool.h
hostnames.o: hostnames.h

peks-baseXX.o: peks-baseXX.h crandom.h cipher.h
peks-file.o: peks-file.h hostnames.h
peks-random.o: peks-baseXX.h crandom.h
messages.o: messages.h

elgamal.o: peks-baseXX.h
peks-handshake.o: peks-baseXX.h
peks-setup.o: messages.h cipher.h peks-baseXX.h make-primes.h
peks-server.o: peks-server.h hostnames.h
peks-client.o: peks-client.h
