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_LOCATION}/lib ${GLOBUS_CACHE_LIBS} -lpthread
CPPLIBS=-lstdc++
INCLUDES=-I${GLOBUS_LOCATION}/include/${GLOBUS_FLAVOR}
PROGRAMS=cache-cleaner
CFLAGS=-g -O0 -ansi
OBJECTS=cache.o ../misc/log_time.o \
        ../config/environment.o \
        ../jobs/users.o ../jobs/states.o ../jobs/job.o \
        ../files/info_files.o ../files/info_types.o \
        ../config/config.o ../config/config_file.o ../config/gridmap.o \
        ../misc/substitute.o ../misc/inttostring.o ../misc/job_log.o \
        ../misc/stringtoint.o ../misc/delete.o ../misc/canonical_dir.o \
        ../misc/url_options.o ../misc/escaped.o \
        ../rsl/parse_rsl.o ../rsl/subst_rsl.o \
        ../transfer/replica_utils.o \
        ../mail/send_mail.o \
        ../run/run.o

all: ${PROGRAMS}

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

client:
	@echo "Nothing for client here"

client-static:
	@echo "Nothing for client here"

cache-cleaner: cache_cleaner.cc ${OBJECTS}
	${CPP} ${INCLUDES} ${CFLAGS} -D__CREATE_EXEC__ -o cache-cleaner cache_cleaner.cc ${OBJECTS} ${LIBS} -Wl,-Bstatic ${CPPLIBS} -Wl,-Bdynamic

clean:
	@rm -f ${PROGRAMS} cache_cleaner.o ${OBJECTS}
	
install: ${PROGRAMS}
	@echo "Actual installation is performed in base directory"

install-client:
	@echo "Nothing for client here"
