#! make

# Makefile - TunnelDigger central logic
#
#    Copyright (C) 2003 Kai Henningsen <kai@debian.org>
#
#    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.
#
#    This program 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 General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

LIB	:= /usr/lib/tunneldigger

################################################
#                                              #
# You should only need to configure this part: #
#                                              #
################################################

CANAME = $(shell hostname -f )
MAINT = $(shell $(LIB)/thisuser.pl)

################################################

WORK	:= $(shell pwd)
KEYS	:= $(WORK)/keys

PATH	:= $(LIB):/usr/local/bin:/usr/bin:/bin

HK = $(KEYS)/host
CA = $(KEYS)/ca

all: confess make.deps _OUTPUTS_
confess:
	@echo "CANAME='$(CANAME)' MAINT='$(MAINT)'"

make.deps: config *.alloc
	$(LIB)/parseconfig.pl config .

# dummy to get us started
*.alloc:
	touch empty.alloc

include make.deps

%.conf: %.link
	$(LIB)/confgen.pl $@ $^ $(CANAME)

%.conf.local: $(LIB)/LINK.local
	cp -avi $^ $@

$(CA)/$(CANAME).crt: $(LIB)/openssl.cnf
	$(LIB)/keygen.sh $^ "$(CANAME)" "CA only"

$(CANAME).global: $(LIB)/CA.global
	cp -avi $^ $@

$(HK)/%.crt $(HK)/%.key: $(LIB)/openssl.cnf
	$(LIB)/keygen.sh $^ "$(CANAME)" $*

%.deb:
	$(LIB)/makedeb "$(CANAME)" "$(MAINT)" $@ $^

