# Edit here
GLOBUS_LOCATION=/opt/globus
GLOBUS_FLAVOR=gcc32dbgpthr
NORDUGRID_LOCATION=/opt/nordugrid
USE_GLOBUS_GPT=${GLOBUS_LOCATION}/bin/globus-makefile-header

# Do not edit here
GLOBUS_LIBS=${GLOBUS_LOCATION}/lib
GLOBUS_INCLUDES=${GLOBUS_LOCATION}/include/${GLOBUS_FLAVOR}

ifneq ($(MAKECMDGOALS),clean)
-include version.mk
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_UI_LIBS} -lpthread -L../grid-manager -lui
CPPLIBS=-lstdc++
INCLUDES=-I${GLOBUS_INCLUDES} -I../grid-manager

CC=gcc
CPP=c++
LD=ld
AR=ar r

PROGRAMS=ngsub ngstat ngkill ngget ngclean ngsync ngcat ngrenew

#use -DGLOBUS_2_0 when linking against globus 2.0
#use -DGLOBUS_2_2 when linking against globus 2.2

CFLAGS=-g -DHAVE_SSTREAM -DVERSION='"${VERSION}"' -DGLOBUS_2_2

#use these CFLAGS for redhat 6.2
#CFLAGS=-g -ftemplate-depth-25 -DVERSION='"${VERSION}"' -DGLOBUS_2_2

OBJECTS=main.o ngsub.o ngstat.o ngkill.o ngget.o ngclean.o ngsync.o ngcat.o \
	ngrenew.o \
	Preferences.o CertInfo.o MdsQuery.o LdapQuery.o Xrsl.o Giis.o \
	DateTime.o RemoteFile.o Target.o Utils.o Environment.o

all: ${PROGRAMS}

ngsub: ${OBJECTS}
	${CC} -o $@ ${OBJECTS} ${LIBS} -Wl,-Bstatic ${CPPLIBS} -Wl,-Bdynamic

ngstat ngkill ngget ngclean ngsync ngcat ngrenew: ngsub
	ln -s ngsub $@

.cpp.o:
	${CPP} ${CFLAGS} ${INCLUDES} -c $< -o $@

.c.o:
	${CC} ${CFLAGS} ${INCLUDES} -c $< -o $@

clean:
	rm -f ${PROGRAMS} *.o *.mk 

install: ${PROGRAMS}
	mkdir -p ${INSTALL_BASE}/bin
	cp ngsub ${INSTALL_BASE}/bin
	for prog in ngstat ngkill ngget ngclean ngsync ngcat ngrenew; do \
	ln -fs ngsub ${INSTALL_BASE}/bin/$${prog}; \
	done
	mkdir -p ${INSTALL_BASE}/etc
	cp giislist ${INSTALL_BASE}/etc

globus_makefile.mk:
	${USE_GLOBUS_GPT} -flavor=${GLOBUS_FLAVOR} \
	globus_common globus_openldap globus_rsl globus_ftp_control \
	globus_ftp_client globus_gass_copy globus_gram_client \
	globus_replica_catalog globus_rls_client | \
	grep '^GLOBUS_PKG_LIBS' | \
	sed s/^GLOBUS_PKG_LIBS/GLOBUS_UI_LIBS/g > globus_makefile.mk

version.mk:
	if [ -f CVS/Tag ]; then \
		echo VERSION=`cat CVS/Tag | cut -f2- -d_ | sed s/_/./g` \
		> version.mk; \
	else \
		echo VERSION=untagged > version.mk; \
	fi
