#   -*-Makefile-*- template for PKCIPE
#
#   Copyright 2000 Olaf Titz <olaf@bigred.inka.de>
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License
#   as published by the Free Software Foundation; either version
#   2 of the License, or (at your option) any later version.

# $Id: Makefile.in,v 1.11 2000/12/16 18:27:35 olaf Exp $

lib:=../lib

WARN	:= -Wno-strict-prototypes
CC	:= @CC@
CFLAGS	:= @CFLAGS@ $(WARN)
CPPFLAGS:= @CPPFLAGS@ -I.. -I$(lib)
DEFS	:= @DEFS@ $(EXTRADEFS)
LDFLAGS	:= @LDFLAGS@
LIBS	:= @LIBS@ -L$(lib) -lcipe

INSTALL	:= install
prefix	:= @prefix@
exec_prefix:= @exec_prefix@
bindir	:= @bindir@
sbindir	:= @sbindir@

all: pkcipe

OBJS=proto.o negotiate.o main.o packet.o lock.o p_sha1.o
SRCS=$(OBJS:.o=.c) pkcipe.h rsa-keygen.in Makefile.in README PKCIPE-Protocol

pkcipe: $(OBJS) $(lib)/libcipe.a
	$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)

$(lib)/libcipe.a: $(lib)/*.[hc]
	$(MAKE) -C $(lib) libcipe.a

install: all
	-mkdir -p $(bindir) $(sbindir)
	$(INSTALL) -m 755 rsa-keygen $(bindir)
	$(INSTALL) -m 755 pkcipe $(sbindir)
	[ -d /etc/cipe/pk ] || mkdir -p /etc/cipe/pk
	[ -d /var/run/cipe ] || mkdir -p /var/run/cipe
	chmod 700 /etc/cipe /etc/cipe/pk /var/run/cipe
	@if [ ! -f /etc/cipe/identity.priv ] ; then \
		echo "*** Generating new identity (host) key ***" ;\
		rsa-keygen /etc/cipe/identity ;\
	fi

clean:
	rm -f *.[oaisd] *.out core pkcipe

realclean distclean: clean
	rm -f *.tmp .tmp Makefile config.h rsa-keygen

%.o: %.c
	$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFS) $(CFLAGS_$*) -MD -c $<

%.i: %.c
	$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFS) $(CFLAGS_$*) -E -dD $< >$@

%.s: %.c
	$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFS) $(CFLAGS_$*) -fverbose-asm \
		-o $@ -S $<

.PHONY: dummy all install clean realclean distclean

%.d: %.o

.SECONDARY: %.d

DEPS:=$(patsubst %.o,%.d,$(OBJS))

ifeq (,$(findstring n,$(MAKEFLAGS)))
ifeq (,$(filter clean dep% %.i %.s,$(MAKECMDGOALS)))
-include $(DEPS)
endif
endif

