#
# ipppd makefile for Linux
# $Id: Makefile.in,v 1.3 1997/05/19 10:15:24 hipp Exp $
#

HAVE_LIBBSD   := @HAVE_LIBBSD@
HAVE_LIBDES   := @HAVE_LIBDES@
HAVE_LIBCRYPT := @HAVE_LIBCRYPT@
HAVE_SHADOW_H := @HAVE_SHADOW_H@
CC            := @CC@
INSTALL       := @INSTALL@
INSTALL_DIR   := $(INSTALL) -m 0755 -o 0 -g 0 -d
INSTALL_SBIN  := $(INSTALL) -m 0700 -o 0 -g 0
INSTALL_BIN   := $(INSTALL) -m 0755 -o 0 -g 0
INSTALL_DATA  := $(INSTALL) -m 0644 -o 0 -g 0

ifeq (../.config,$(wildcard ../.config))
	include ../.config
	SBINDIR                 = $(CONFIG_SBINDIR)
	MANDIR                  = $(CONFIG_MANDIR)
	ifeq ($(CONFIG_IPPPD_MSCHAP),y)
		USE_MSCHAP = 1
	endif
else
	SBINDIR                 = /sbin
	MANDIR                  = /usr/man
endif


PPPDSRCS = main.c magic.c fsm.c lcp.c ipcp.c upap.c chap.c md5.c ccp.c \
	   ipxcp.c auth.c options.c sys-linux.c cbcp.c
HEADERS =  callout.h pathnames.h patchlevel.h chap.h md5.h \
	   ipxcp.h cbcp.h
MANPAGES = pppd.8
PPPDOBJS = main.o magic.o fsm.o lcp.o ipcp.o upap.o chap.o md5.o ccp.o \
		auth.o options.o sys-linux.o cbcp.o ipxcp.o

ifeq ($(HAVE_LIBBSD),1)
all: ipppd

uninstall:
	rm -f $(SBINDIR)/ipppd $(MANDIR)/man8/ipppd.8

install: ipppd
	$(INSTALL_DIR) $(SBINDIR)
	$(INSTALL_DIR) $(MANDIR)/man8
	$(INSTALL_SBIN) ipppd $(SBINDIR)/ipppd
	$(INSTALL_DATA) ipppd.8 $(MANDIR)/man8/ipppd.8

else
all:
	@echo -n "\n\nLibrary libbsd not found, ipppd NOT built\n\n"

install:
	@echo -n "\n\nLibrary libbsd not found, ipppd NOT installed\n\n"

endif
#
# include dependancies if present and backup if as a header file
ifeq (.depend,$(wildcard .depend))
include .depend
HEADERS := $(HEADERS) .depend
endif

DEBUG_FLAGS   = -DDEBUGALL
COMPILE_FLAGS = 
COPTS         =
CFLAGS        = -O2 -fomit-frame-pointer -m486 -Wall
VER           = 2.2.0
LIBS          = -lbsd

SOURCE = RELNOTES configure *.in $(PPPDSRCS) $(HEADERS) $(MANPAGES)

MSG    = ''
ifdef USE_MSCHAP
	ifeq ($(HAVE_LIBDES),1)
		PPPDSRCS += md4.c chap_ms.c
		PPPDOBJS += md4.o chap_ms.o
		HEADERS  += md4.h chap_ms.h
		COPTS    += -DUSE_MSCHAP
		LIBS     += -ldes
	else
		MSG = '\n\nLibrary libdes not found, USE_MSCHAP disabled\n\n'
	endif
endif

ifeq ($(HAVE_SHADOW_H),1)
PPPDOBJS += isexpired.o
PPPDSRCS += isexpired.c
endif

%.o: %.c
	$(CC) $(CFLAGS) $(COPTS) $(DEBUG_FLAGS) $(COMPILE_FLAGS) -c -o $@ $<

ipppd: $(PPPDOBJS)
	$(CC) $(CFLAGS) -o ipppd $(PPPDOBJS) $(LIBS)
	@echo -n $(MSG)

pppd.tar: $(SOURCE)
	tar -cvf pppd.tar $(SOURCE)

pppd.tar.gz: pppd.tar
	gzip pppd.tar

clean:
	rm -f $(PPPDOBJS) ipppd *~ #* core

distclean: clean
	rm -f config.h config.status config.cache config.log Makefile

depend:
	$(CPP) -M $(CFLAGS) $(COPTS) $(DEBUG_FLAGS) $(COMPILE_FLAGS) $(PPPDSRCS) >.depend
