# Makefile for RADIUS plugin
#
# Copyright 2002 Roaring Penguin Software Inc.
#
-include .sub_build.base

MANDIR=/usr/man
PLUGIN=radius.so radattr.so
CFLAGS=-I../.. -I../../../include -Iradiusclient/include -O2

# Uncomment the next line to include support for Microsoft's
# MS-CHAP authentication protocol.
CHAPMS=y
# Uncomment the next line to include support for MPPE.
MPPE=y

ifdef CHAPMS
CFLAGS += -DCHAPMS=1
ifdef MPPE
CFLAGS += -DMPPE=1
endif
endif

all: $(PLUGIN)

install: all
	$(MAKE) $(MFLAGS) -C radiusclient install
	$(INSTALL) -d -m 755 $(LIBDIR)
	$(INSTALL) -s -c -m 755 radius.so $(LIBDIR)
	$(INSTALL) -s -c -m 755 radattr.so $(LIBDIR)
	$(INSTALL) -c -m 444 pppd-radius.8 $(MANDIR)/man8
	$(INSTALL) -c -m 444 pppd-radattr.8 $(MANDIR)/man8

radius.so: radiusclient/lib/.libs/libradiusclient.a radius.o
	gcc -o radius.so -shared radius.o radiusclient/lib/.libs/libradiusclient.a

radattr.so: radattr.o
	gcc -o radattr.so -shared radattr.o

radius.o: radius.c
	gcc $(CFLAGS) -c -o radius.o -fPIC radius.c

radattr.o: radattr.c
	gcc $(CFLAGS) -c -o radattr.o -fPIC radattr.c

radiusclient/lib/.libs/libradiusclient.a:
	test -r radiusclient/Makefile ||           \
		(cd radiusclient;                  \
		 ./configure --prefix=/usr         \
			     --sysconfdir=/etc     \
			     --enable-shared       \
			     --enable-static)
	$(MAKE) -C radiusclient

clean:
	$(MAKE) $(MFLAGS) -C radiusclient clean
	rm -f *.o *.so

distclean:
	rm -f *.o *.so
	$(MAKE) $(MFLAGS) -C radiusclient distclean

dist-clean: distclean
-include .sub_build.base

#CFLAGS	= -g -O2 -I.. -I../../include -D_linux_=1 -fPIC
CFLAGS	= -O2 -I.. -I../../include -D_linux_=1 -fPIC
LDFLAGS	= -shared
INSTALL	= install -o root

SUBDIRS = rp-pppoe radius
PLUGINS = minconn.so passprompt.so passwordfd.so

# include dependencies if present
ifeq (.depend,$(wildcard .depend))
include .depend
endif

all:	$(PLUGINS)
	for d in $(SUBDIRS); do $(MAKE) $(MFLAGS) -C $$d all; done

%.so: %.c
	$(CC) -o $@ $(LDFLAGS) $(CFLAGS) $^

VERSION = $(shell awk -F '"' '/VERSION/ { print $$2; }' ../patchlevel.h)
LIBDIR	= $(DESTDIR)/usr/lib/pppd/$(VERSION)

install: $(PLUGINS)
	$(INSTALL) -d $(LIBDIR)
	$(INSTALL) $? $(LIBDIR)
	for d in $(SUBDIRS); do $(MAKE) $(MFLAGS) -C $$d INSTALL=$(INSTALL) \
				LIBDIR=$(LIBDIR) install; done

clean:
	rm -f *.o *.so *.a
	for d in $(SUBDIRS); do $(MAKE) $(MFLAGS) -C $$d clean; done

depend:
	$(CPP) -M $(CFLAGS) *.c >.depend
	for d in $(SUBDIRS); do $(MAKE) $(MFLAGS) -C $$d depend; done

#
# EDX Start
#
pre_romfs:
	$(Q)mkdir -p $(ROMFS_DIR)/bin && \
	$(STRIP) pppd -o $(ROMFS_DIR)/bin/pppd

make_env:
	$(Q)ln -sf $(ABS_SUB_BUILD_FILE) $(SUB_BUILD_FILE) && \
	$(MAKE) $(MAKEFLAGS) -C rp-pppoe $@
#
# EDX End
#
