# sliplogin Makefile
#
# description of (hopefully) all options, see README*
#
# -DDYNAMIC_SERVER	always assume dynamic allocation of local (server) 
#			address (ignore contents of server field, replace 
#			 with the ip-address of the real hostname.)
# -DSLIPPATH=\"/etc\"	use /etc instead of /etc/slip for all config files
#
# -DFUNMESSAGE		Captain kirk's special message format
# -DOLDMESSAGE		realtivly old message format
# -DBSDMESSAGE		use old FreeBSD message format 'slip login for'
# -DCONFIGURE_MSG=1	report about dynamic configuration
# 
# -DESLIPLOGIN		to perform extended logins (see README.esliplogin)
#			 (without you may exclude sliplogin.o from binary)
# -DESLIP_AUTO		enable autocompression by default
# -DESLIP_TIMEOUT=#seconds	time for login (defaults to 180 seconds)
#
# -DLINE_ACCESS		special library to restrict the access to special 
#			lines (Phone - numbers) or a limited time.


VERSION	= 03.00.01
BUILD	= 1ajk


#
# changes made explicitly to create a slackware package.
#
ifdef PKG
  ifeq ("$(origin PKG)", "command line")
    BPATH = build
  endif
endif

ifndef BPATH
BPATH 	= 
endif

#
# path for configuration files and to install binaries / manpages
#

BETC	= /etc
BSLIP	= $(BETC)/slip
SLIP	= $(BPATH)$(BSLIP)
SBIN	= $(BPATH)/usr/sbin
BIN	= $(BPATH)/bin
MAN	= $(BPATH)/usr/share/man
PKGINF	= $(BPATH)/install
PKGDOC	= $(BPATH)/usr/share/doc/sliplogin-$(VERSION)-$(BUILD)
DOX	= CHANGES README README.access README.dynamic README.esliplogin README.nis TODO TROUBLE_SHOOTING passwd.example slip.deny.ping

CC	= gcc
LINK	= $(CC)
CFLAGS	= -Wall -m486 -O2 -pipe -D_GNU_SOURCE -Dlinux
EFLAGS	= -DESLIPLOGIN -DESLIP_AUTO -DFUNMESSAGE
DEFINES	= -DSLIPPATH=\"$(BSLIP)\" $(EFLAGS)
LDFLAGS = -s

# if you want to use the access library just uncomment the following lines
#  and define -DLINE_ACCESS in EFLAGS above; 
#  than type 'make all', 'make install_all'
#EACCESS	= -DLINE_ACCESS access.o
EOBJ	= access.o access_test express check_access watch_access

#SRC = sliplogin.c statistic.c scanfile.c translate.c
SRC = sliplogin.c statistic.c scanfile.c translate.c esliplogin.c
OBJ = $(SRC:.c=.o)
#LIBS = -lshadow	# for Linux with shadow passwd
#LIBS = -lutil		# for FreeBSD 1.x
#LIBS = -lkvm		# for FreeBSD 2.x
LIBS = -lcrypt -lnsl

CONFIGS = slip.hosts slip.route slip.passwd slip.tty slip.hosts slip.deny

#
#You should really edit /etc/group to limit access to sliplogin
#otherwise sliplogin has to be executable for the world.
#
SLIPGROUP = dialout

TARGETS = access sliplogin

all:
	@echo
	@echo
	@cat BUILDING
	@echo
	@echo

stuff: .dep $(TARGETS)

sliplogin: .dep $(OBJ) 
	$(LINK) $(OBJ) $(EACCESS) $(LIBS) $(LDFLAGS) -o $@

clean:
	rm -f *~ *.o sliplogin $(EOBJ) core .dep
	rm build -Rf
	cp Makefile.CLEAN Makefile

install:
	@echo
	@echo
	@cat BUILDING
	@echo
	@echo

install.unsafe: install_slip
	@true

install_all: install_user install_access
	@true

#	if you get an error 'text file busy' while installing
#	move the old binary to another name
#	@test -d $() || mkdir -p $()

install_user: sliplogin
	@test -d "$(BPATH)" || mkdir -vp "$(BPATH)"
	@test -d "$(SLIP)" || mkdir -vp "$(SLIP)"
	@test -d "$(SBIN)" || mkdir -vp "$(SBIN)"
	@test -d "$(BIN)" || mkdir -vp "$(BIN)"
	@test -d "$(MAN)" || mkdir -vp "$(MAN)"
	@test -d "$(PKGINF)" || mkdir -vp "$(PKGINF)"
	@test -d "$(PKGDOC)" || mkdir -vp "$(PKGDOC)"
	@groupadd -g 666 $(SLIPGROUP) || echo good.
	@for i in $(DOX) ; { install -m644 docs/$$i "$(PKGDOC)" ; }
	@mkdir -vp "$(BPATH)/install"
	@cp install/* "$(BPATH)/install/"
	@install -s -o root -m750 sliplogin "$(BIN)"
	@install -m644 sliplogin.8.gz "$(MAN)/man8"
	@cp slip.login "$(SLIP)"/new.slip.login
	@for i in $(CONFIGS) ; { cp $$i "$(SLIP)/new.$$i" ; }

install_slip: sliplogin
	test -d "$(SLIP)" || mkdir -p "$(SLIP)"
	install -s -g "$(SLIPGROUP)" -m754 sliplogin "$(SBIN)"
	@if [ -f sliplogin.8 ]; then install -m644 sliplogin.8 "$(MAN)/man8"; fi
	install slip.login "$(SLIP)"
	ln -sf slip.login "$(SLIP)/slip.logout"
	@echo "Don't forget to edit slip.hosts, slip.route, slip.passwd"
	@echo "and copy these files to the proper place ($(SLIP))."

# Line access (see README.access)
access:	.dep $(EOBJ)
	@true

access_test: access.c
	gcc -o access_test $(CFLAGS) -DACCESS_MAIN -DSTDERR -DOUTPUT access.c

express: access.c
	gcc -o express $(CFLAGS) -DEXPRESS_TEST -DOUTPUT access.c

check_access: access.c
	gcc -o check_access $(CFLAGS) -DCHECK_ACCESS access.c

watch_access: waccess.c access.o
	gcc -o watch_access $(CFLAGS) waccess.c access.o

install_access: check_access watch_access
	install -c -m 555 -o root check_access "$(SBIN)/check_access"
	install -c -m 555 -o root watch_access "$(SBIN)/watch_access"

.dep depend dep:
	makedepend -- $(CFLAGS) -- $(EFLAGS) $(DEFINES) $(SRC)
	touch .dep

slackpkg: install_all
	(cd $(BPATH) ; makepkg ../../sliplogin-$(VERSION)-i486-$(BUILD).tgz ; )

dist: sliplogin-src-$(VERSION)-$(BUILD).tgz

sliplogin-src-$(VERSION)-$(BUILD).tgz: clean
	(cd .. ; tar czvf sliplogin-src-$(VERSION)-$(BUILD).tgz sliplogin-$(VERSION)-$(BUILD) ; )

ci:
	ci -m"I hate log messages!" -t-"I hate description prompts!" -l $(SRC) Makefile

co:
	co $(SRC) Makefile

.c.o: .dep
	$(CC) $(CFLAGS) $(DEFINES) -c $<

# DO NOT DELETE

