# This file is part of kbdlock
# Copyright (C) 1999,2005,2012 Sergey Poznyakoff
#
# Kbdlock 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 3 of the License, or
# (at your option) any later version.
# 
# Kbdlock 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 kbdlock; if not, see <http://www.gnu.org/licenses/>.

# #########################################################################
# User-configurable variables
# #########################################################################

# If you have a working tputs function and the termios.h header,
# define D_CURSES as below and L_CURSES to the ld(1) option necessary
# to link with the curses library.  The two lines below should work on
# any decent GNU/Linux installation:
D_CURSES=-DHAVE_CURSES
L_CURSES=-lcurses
# If libc has the getopt_long function, define the following:
D_LONGOPT=-DGNU_STYLE_OPTIONS
# This should normally always be defined:
D_SHADOW=-D__SHADOW__

# Optimization options for cc(1):
OPT=-O
# Additional libraries, if any:
LIBS=
# Users in this group will be able to use kbdlock:
GROUP=kbdlock
# Installation directory:
INSTALLDIR=/usr/bin
MANDIR=/usr/man

# #########################################################################
# Nothing to modify below this line, but you're welcome to if you know
# what you're doing.
# #########################################################################
PROJECT=kbdlock
VERSION=2.0
SRC=main.c
OBJ=main.o
CPPFLAGS=$(D_CURSES) $(D_LONGOPT) $(D_SHADOW) $(D_DEBUG) -DVERSION=\"$(VERSION)\"
CFLAGS=$(OPT)
LDFLAGS=-lcrypt $(L_CURSES) $(LIBS)

kbdlock: $(OBJ) Makefile
	cc -okbdlock $(CFLAGS) $(LDFLAGS) $(OBJ)

main.o: main.c Makefile

.c.o:
	cc $(CFLAGS) $(CPPFLAGS) -c -o$@ $<

install: kbdlock
	grep $(GROUP) /etc/group || groupadd $(GROUP)
	install -o root -g $(GROUP) -m 4750 -s kbdlock $(INSTALLDIR)
	install kbdlock.1 $(MANDIR)/man1

clean:
	-rm -f *.o kbdlock

DISTDIR=$(PROJECT)-$(VERSION)
DISTFILES=main.c ChangeLog Makefile NEWS README kbdlock.1

distdir:
	test -d $(DISTDIR) || mkdir $(DISTDIR)
	cp $(DISTFILES) $(DISTDIR)

dist: distdir
	tar zcf $(DISTDIR).tar.gz $(DISTDIR)
	rm -rf $(DISTDIR)

distcheck: dist
	tar xfz $(DISTDIR).tar.gz
	if $(MAKE) -C $(DISTDIR) $(DISTCHECKFLAGS); then \
	  echo "$(DISTDIR).tar.gz ready for distribution"; \
	  rm -rf $(DISTDIR); \
        else \
          exit 2; \
	fi
          
