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_JOBPLUGIN_LIBS}
CPPLIBS=-lstdc++
INCLUDES=-I${GLOBUS_INCLUDES}
PROGRAMS=jobplugin.so
OBJECTS=CertInfo.o jobplugin.o init.o \
        ../../config/environment.o ../../config/config_pre.o ../../jobs/job.o \
        ../../jobs/users.o ../../rsl/parse_rsl.o ../../files/info_types.o \
        ../../files/info_files.o ../../config/config.o ../misc.o \
        ../../misc/inttostring.o ../../misc/stringtoint.o \
        ../../transfer/replica_utils.o ../../transfer/proxy.o \
        ../../config/gridmap.o ../../misc/substitute.o ../../run/run.o \
        ../../misc/canonical_dir.o ../../misc/delete.o ../../rsl/subst_rsl.o \
        ../../misc/url_options.o ../fileplugin/fileplugin.o ../userspec.o \
        ../names.o ../../misc/escaped.o ../../misc/log_time.o ../../misc/globus_error_utils.o \
        ../../auth/libauth.a ../../external/voms/api/libvomsapi.a


all: ${PROGRAMS}

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

jobplugin.so: ${OBJECTS}
	${CC} -shared -o jobplugin.so ${OBJECTS} ${LIBS} -Wl,-Bstatic ${CPPLIBS} -Wl,-Bdynamic

CertInfo.o: CertInfo.cpp CertInfo.h std.h

CertInfo.cpp:
	ln -s ../../../userinterface/CertInfo.cpp

CertInfo.h:
	ln -s ../../../userinterface/CertInfo.h

std.h:
	ln -s ../../std.h

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

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