#
# $Id$
#

TARGET      = @targetname@
SRCS        = rlm_eap.c eap.c mem.c
HEADERS     = eap.h rlm_eap.h
RLM_CFLAGS  = -Ilibeap
CLIENTLIBS  = libeap/$(LIBPREFIX)freeradius-eap.la $(LIBRADIUS)
RLM_LIBS    = libeap/$(LIBPREFIX)freeradius-eap.la $(LIBLTDL)
RLM_INSTALL = install-subdirs
RLM_SUBDIRS = libeap @eaptypes@
RLM_UTILS   = radeapclient$(EXEEXT)

#
# Not using shared libraries, add in ALL known static modules
# at build time.
#
#ifneq ($(USE_SHARED_LIBS),yes)
#RLM_LIBS  += $(shell for x in types/rlm_eap*/rlm_eap*.la;do echo -dlpreopen $$x;done)
#endif

.PHONY: all install-subdirs common

#
# We need $(LIBPREFIX)freeradius-eap.la before we can build anything else
#
all: common

$(LT_OBJS): $(HEADERS)

## this uses the RLM_CFLAGS and RLM_LIBS and SRCS defs to make TARGET.
# This needs to be before the radeapclient rule, as the lhs $(EXEECT)
# expansion is done as soon as the Makefile is loaded
include ../rules.mak

radeapclient$(EXEEXT): radeapclient.lo $(CLIENTLIBS)
	$(LIBTOOL) --mode=link --tag=CC $(CC) $(LDFLAGS) $(RLM_LDFLAGS) -o radeapclient$(EXEEXT) radeapclient.lo $(LIBRADIUS) $(CLIENTLIBS) $(LIBS)

radeapclient.lo: radeapclient.c $(HEADERS)
	$(LIBTOOL) --mode=compile --tag=CC $(CC) $(CFLAGS) $(RLM_CFLAGS) -c radeapclient.c

install-subdirs:
	@$(MAKE) $(MFLAGS) WHAT_TO_MAKE=install common
	$(LIBTOOL) --mode=install $(INSTALL) -m 755 $(INSTALLSTRIP) radeapclient$(EXEEXT) $(R)$(bindir)

.PHONY: common $(RLM_SUBDIRS)

common: $(RLM_SUBDIRS)

types: libeap

$(RLM_SUBDIRS):
	@echo "Making $(WHAT_TO_MAKE) in $@..."
	@$(MAKE) $(MFLAGS) -C $@ $(WHAT_TO_MAKE)

libeap/$(LIBPREFIX)freeradius-eap.la: libeap
