include ../Make.inc
include ../Make.rules

ifneq ($(MAKECMDGOALS),clean)
ifneq (,$(USE_GLOBUS_GPT))
-include globus_makefile.mk
else
include globus_makefile.mk.pre
endif
endif

INSTALL_BASE=${NORDUGRID_LOCATION}
LIBS=-L${GLOBUS_LIBS} ${GLOBUS_AUTH_LIBS} -lpthread
CPPLIBS=-lstdc++
INCLUDES=-I${GLOBUS_INCLUDES} -I../external/voms/api -I../external/voms/include
PROGRAMS=libauth.a
OBJECTS=auth.o auth_subject.o auth_file.o auth_ldap.o auth_voms.o LdapQuery.o
AAA_OBJECTS=aaa.o libauth.a ../external/voms/api/libvomsapi.a \
        ../misc/url_options.o ../misc/log_time.o ../misc/inttostring.o \
        ../misc/stringtoint.o ../misc/escaped.o ../misc/globus_error_utils.o
OTHER_OBJECTS=

all: ${PROGRAMS}

globus_makefile.mk:
	@export GLOBUS_LOCATION=$(GLOBUS_LOCATION) ; \
	${USE_GLOBUS_GPT} \
	-flavor=${GLOBUS_FLAVOR} globus_openldap globus_gsi_credential globus_gss_assist | \
	grep '^GLOBUS_PKG_LIBS' | sed 's/^GLOBUS_PKG_LIBS/GLOBUS_AUTH_LIBS/' \
	>globus_makefile.mk ; \
	RESULT=$$? ; \
	if [ $$RESULT -ne 0 ] ; then rm -f globus_makefile.mk ; fi ; \
	exit $$RESULT

libauth.a: LdapQuery.cpp ${OBJECTS}
	${AR} libauth.a ${OBJECTS}

aaa: LdapQuery.cpp ${AAA_OBJECTS}
	${CC} -o aaa ${AAA_OBJECTS} ${LIBS} -Wl,-Bstatic ${CPPLIBS} -Wl,-Bdynamic

../external/voms/api/libvomsapi.a:
	make -C ../external/voms

LdapQuery.cpp:
	ln -s ../../userinterface/LdapQuery.cpp
	ln -s ../../userinterface/LdapQuery.h
	ln -s ../std.h

clean:
	@rm -f ${PROGRAMS} ${OBJECTS} ${AAA_OBJECTS} ${OTHER_OBJECTS} LdapQuery.cpp LdapQuery.h std.h globus_makefile.mk aaa

install: ${PROGRAMS} 
	@echo "Actual installation is performed in base directory"
