##################################################################
#
#	Makefile for slipsh
#
##################################################################

# The BSD_SOURCE flag below is needed to get the prototypes for
# strcasecmp, fchown, and strdup (which, quite surprisingly, is
# not defined by POSIX).
CFLAGS	= -O2 -Wall -D_POSIX_SOURCE -D_BSD_SOURCE
#CFLAGS	= -g -Wall -D_POSIX_SOURCE -D_BSD_SOURCE

# TCL needs libm...
LIBS	= -ltcl -lm

# where to install all the stuff
#PREFIX	= /usr
PREFIX	= /usr/local
BINDIR	= $(PREFIX)/sbin
LIBDIR	= $(PREFIX)/lib/slipsh

UTILS	= slipsh
SUPPORT	= scripts/common.tcl scripts/sliphup
SCRIPTS	= scripts/clientA scripts/clientB scripts/clientC \
	  scripts/slipmon

##################################################################
OBJS	= slipsh.o tty.o chat.o mdm_posix.o net.o signal.o system.o \
	  kern.o

slipsh:	$(OBJS)
	$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)

install::$(UTILS)
	if [ ! -d $(BINDIR) ]; then \
		install -o root -g root -m 755 -d $(BINDIR); \
	fi
	install -o root -g root -m 755 $(UTILS) $(BINDIR)

install::
	if [ ! -d $(LIBDIR) ]; then \
		install -o root -g root -m 755 -d $(LIBDIR); \
	fi
	install -o root -g root -m 444 $(SUPPORT) $(LIBDIR)
	install -o root -g root -m 500 $(SCRIPTS) $(LIBDIR)

dist:
	rm -f MANIFEST
	find * > MANIFEST
	PWD=`pwd`; package=`basename $$PWD`; \
	cd .. && tar cfvz $$package.tar.gz $$package/*

realclean clean::
	rm -f $(OBJS) core

realclean::
	rm -f slipsh test
