1# Makefile for an IPSec VPN client compatible with Cisco equipment.
2# Copyright (C) 2002  Geoffrey Keating
3# Copyright (C) 2003-2004  Maurice Massar
4# Copyright (C) 2006-2007 Dan Villiom Podlaski Christiansen
5
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19#
20# $Id: Makefile 312 2008-06-15 18:09:42Z Joerg Mayer $
21
22DESTDIR=
23PREFIX?=/usr/local
24ETCDIR=$(PREFIX)/etc/
25BINDIR=$(PREFIX)/bin
26SBINDIR=$(PREFIX)/sbin
27MANDIR=$(PREFIX)/share/man
28DOCDIR=$(PREFIX)/share/doc/vpnc
29
30SRCS = sysdep.c vpnc-debug.c isakmp-pkt.c tunip.c config.c dh.c math_group.c supp.c decrypt-utils.c
31BINS += vpnc
32OBJS = $(addsuffix .o,$(basename $(SRCS)))
33BINOBJS = $(addsuffix .o,$(BINS))
34BINSRCS = $(addsuffix .c,$(BINS))
35VERSION := $(shell sh mk-version)
36RELEASE_VERSION := $(shell cat VERSION)
37
38# The license of vpnc (Gpl >= 2) is quite likely incompatible with the
39# openssl license. Openssl is currently used to provide certificate
40# support for vpnc (hybrid only).
41# While it is OK for users to build their own binaries linking in openssl
42# with vpnc and even providing dynamically linked binaries it is probably
43# not OK to provide the binaries inside a distribution.
44# See http://www.gnome.org/~markmc/openssl-and-the-gpl.html for further
45# details.
46# Some distributions like Suse and Fedora seem to think otherwise.
47
48# Comment this in to obtain a binary with certificate support which is
49# GPL incompliant though.
50#OPENSSL_GPL_VIOLATION = -DOPENSSL_GPL_VIOLATION
51#OPENSSLLIBS = -lcrypto
52
53CC?=gcc
54CFLAGS +=  $(shell libgcrypt-config --cflags)
55CPPFLAGS += -DVERSION=\"$(VERSION)\" $(OPENSSL_GPL_VIOLATION)
56LDFLAGS ?= -g
57LDFLAGS += $(shell libgcrypt-config --libs) $(OPENSSLLIBS)
58
59ifeq ($(shell uname -s), SunOS)
60LDFLAGS += -lnsl -lresolv -lsocket
61endif
62ifneq (,$(findstring Apple,$(shell $(CC) --version)))
63# enabled in FSF GCC, disabled by default in Apple GCC
64CFLAGS += -fstrict-aliasing -freorder-blocks -fsched-interblock
65endif
66
67all : $(BINS) vpnc.8 vpnc-script
68
69vpnc : $(OBJS) vpnc.o
70	$(CC) -o $@ $^ $(LDFLAGS)
71
72vpnc.8 : vpnc.8.template makeman.pl vpnc
73	./makeman.pl
74
75vpnc-script : vpnc-script.in
76	sed -e 's,@''PREFIX''@,$(PREFIX),g' $< > $@ && chmod 755 $@
77
78cisco-decrypt : cisco-decrypt.o decrypt-utils.o
79	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
80
81.depend: $(SRCS) $(BINSRCS)
82	$(CC) -MM $(SRCS) $(BINSRCS) $(CFLAGS) $(CPPFLAGS) > $@
83
84vpnc-debug.c vpnc-debug.h : isakmp.h enum2debug.pl
85	LC_ALL=C perl -w ./enum2debug.pl isakmp.h >vpnc-debug.c 2>vpnc-debug.h
86
87vpnc.ps : vpnc.c
88	enscript -E -G -T 4 --word-wrap -o- $^ | psnup -2 /dev/stdin $@
89
90../vpnc-%.tar.gz : vpnc-$*.tar.gz
91
92etags :
93	etags *.[ch]
94ctags :
95	ctags *.[ch]
96
97vpnc-%.tar.gz :
98	mkdir vpnc-$*
99	LC_ALL=C svn info -R | awk -v RS='' -v FS='\n' '/Node Kind: file/ {print substr($$1,7)}' | \
100		tar -cf - -T - | tar -xf - -C vpnc-$*/
101	tar -czf ../$@ vpnc-$*
102	rm -rf vpnc-$*
103
104dist : VERSION vpnc.8 vpnc-$(RELEASE_VERSION).tar.gz
105
106clean :
107	-rm -f $(OBJS) $(BINOBJS) $(BINS) tags
108
109distclean : clean
110	-rm -f vpnc-debug.c vpnc-debug.h vpnc.ps vpnc.8 .depend vpnc-script
111
112install-common: all
113	install -d $(DESTDIR)$(ETCDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(MANDIR)/man1 $(DESTDIR)$(MANDIR)/man8 $(DESTDIR)$(DOCDIR)
114	if [ "`uname -s | cut -c-6`" = "CYGWIN" ]; then \
115		install vpnc-script-win $(DESTDIR)$(ETCDIR)/vpnc-script; \
116		install vpnc-script-win.js $(DESTDIR)$(ETCDIR); \
117	else \
118		install vpnc-script $(DESTDIR)$(ETCDIR); \
119	fi
120	install -m600 vpnc.conf $(DESTDIR)$(ETCDIR)/default.conf
121	install -m755 vpnc-disconnect $(DESTDIR)$(SBINDIR)
122	install -m755 pcf2vpnc $(DESTDIR)$(BINDIR)
123	install -m644 vpnc.8 $(DESTDIR)$(MANDIR)/man8
124	install -m644 pcf2vpnc.1 $(DESTDIR)$(MANDIR)/man1
125	install -m644 cisco-decrypt.1 $(DESTDIR)$(MANDIR)/man1
126	install -m644 COPYING $(DESTDIR)$(DOCDIR)
127
128install : install-common
129	install -m755 vpnc $(DESTDIR)$(SBINDIR)
130	install -m755 cisco-decrypt $(DESTDIR)$(BINDIR)
131
132install-strip : install-common
133	install -s -m755 vpnc $(DESTDIR)$(SBINDIR)
134	install -s -m755 cisco-decrypt $(DESTDIR)$(BINDIR)
135
136uninstall :
137	rm -f $(DESTDIR)$(SBINDIR)/vpnc \
138		$(DESTDIR)$(SBINDIR)/vpnc-disconnect \
139		$(DESTDIR)$(BINDIR)/pcf2vpnc \
140		$(DESTDIR)$(BINDIR)/cisco-decrypt \
141		$(DESTDIR)$(MANDIR)/man1/cisco-decrypt.1 \
142		$(DESTDIR)$(MANDIR)/man1/pcf2vpnc \
143		$(DESTDIR)$(MANDIR)/man8/vpnc.8
144	@echo NOTE: remove $(DESTDIR)$(ETCDIR) manually
145
146.PHONY : clean distclean dist all install install-strip uninstall
147
148#
149-include .depend
150