#
# Makefile for EPS PAM modules (auth, passwd)
#

########################################################################
# some options... uncomment to take effect
########################################################################

# do you want to use lckpwdf?
USE_LCKPWDF=-D"USE_LCKPWDF"

# do you need to include the one in this source?
#NEED_LCKPWDF=-D"NEED_LCKPWDF"

# Where the SRP and support libraries live
SRPLIB=-L../../libsrp -lsrp -L../../libmp -lgmp

# Linux-PAM
LDSHARED = -x --shared
# Solaris2.6-PAM
LDSHARED = -G

########################################################################

CFLAGS += $(USE_LCKPWDF) $(NEED_LCKPWDF) -I../../include

LIBAUTHSH = pam_eps_auth.so
LIBPASSWDSH = pam_eps_passwd.so

LIBAUTHOBJ = pam_eps_auth.o support.o
LIBAUTHSRC = pam_eps_auth.c support.c
LIBPASSWDSRC = pam_eps_passwd.c
LIBPASSWDOBJ = pam_eps_passwd.o
LIBOBJ = $(LIBAUTHOBJ) $(LIBPASSWDOBJ)
LIBSRC = $(LIBAUTHSRC) $(LIBPASSWDSRC)

LIBSHARED = $(LIBAUTHSH) $(LIBPASSWDSH)

LIBOBJD = $(addprefix dynamic/,$(LIBOBJ))
LIBOBJS = $(addprefix static/,$(LIBOBJ))

dynamic/%.o : %.c
	$(CC) $(CFLAGS) $(DYNAMIC) $(CPPFLAGS) -c $< -o $@

static/%.o: %.c
	$(CC) $(CFLAGS) $(STATIC) $(CPPFLAGS) -c $< -o $@


########################### don't edit below #######################

all: dirs $(LIBSHARED) $(LIBSTATIC)

dirs:
	mkdir -p ./dynamic

$(LIBOBJD): $(LIBSRC)

$(LIBAUTHSH):	$(LIBAUTHSRC) $(LIBOBJD)
		$(LD) $(LDSHARED) -o $@ $(addprefix dynamic/,$(LIBAUTHOBJ)) $(SRPLIB)

$(LIBPASSWDSH):	$(LIBPASSWDSRC) $(LIBOBJD)
		$(LD) $(LDSHARED) -o $@ $(addprefix dynamic/,$(LIBPASSWDOBJ)) $(SRPLIB)

install: all
	mkdir -p $(FAKEROOT)$(SECUREDIR)
	install -m644 $(LIBSHARED) $(FAKEROOT)$(SECUREDIR)

remove:
	cd $(FAKEROOT)$(SECUREDIR) && rm -f $(LIBSHARED)

clean:
	rm -f $(LIBOBJD) $(LIBOBJS) a.out core *~

extraclean: clean
	rm -f *.a *.out *.o *.so *.bak

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