# Toplevel Makefile for pSather

include pSather.options 

CFLAGS=-g -Wall 
MM=$(MAKE) PSATHER='$(PSATHER)'

include Make.config

all:	$(ARCH)

Make.config:
	touch Make.config

linux:;	./bin/mkconfig Make.Linux
	cd lwp ; $(MM) install ; cd ..
	cd am ;  $(MM) install ; cd ..
	cd pSather ;  $(MM) install ; cd ..
	
sun:;	./bin/mkconfig Make.SunOS4
	cd lwp ; $(MM) install ; cd ..
	cd am ;  $(MM) install ; cd ..
	cd pSather ; $(MM) install ; cd ..

sun-no-threads:
	@echo "*** This configuration does not work for pSather"
	@echo "*** but is useful for debugging reasons."
	./bin/mkconfig Make.SunOS4-no-threads
	cd lwp ; $(MM) install ; cd ..
	cd am ;  $(MM) install ; cd ..

solaris:
	./bin/mkconfig Make.Solaris2.4
#	cd am ; $(MM) install ; cd ..
	cp lib/libam_solaris.a lib/libam.a
	cd pSather ; $(MM) install ; cd ..

solaris-tcpip:
	./bin/mkconfig Make.Solaris2.4-tcpip
#	cd am ; $(MM) install ; cd ..
	cp lib/libam_solaris_tcp.a lib/libam.a
	cd pSather ; $(MM) install ; cd ..

solaris-tcpip-no-threads:
	@echo "*** This configuration does not work for pSather"
	@echo "*** but is useful for debugging reasons."
	./bin/mkconfig Make.Solaris2.4-tcpip-no-threads
	cd am ; $(MM) install ; cd ..

solaris-myrinet:
	./bin/mkconfig Make.Solaris2.4-myrinet
#	$(MM) lcp.dat
#	cd am ; $(MM) install ; cd ..
	cp lib/libam_myrinet.a lib/libam.a
	cd pSather ; $(MM) install ; cd ..

solaris-myrinet-no-threads:
	@echo "*** This configuration does not work for pSather"
	@echo "*** but is useful for debugging reasons."
	./bin/mkconfig Make.Solaris2.4-myrinet-no-threads
#	$(MM) lcp.dat
	cd am ; $(MM) install ; cd ..

solaris-no-threads:
	@echo "*** This configuration does not work for pSather"
	@echo "*** but is useful for debugging reasons."
	./bin/mkconfig Make.Solaris2.4-no-threads
	cd am ; $(MM) install ; cd ..

lcp.dat:
	cd config/lanai/lcp ; sh -c $(COMPILE_LANAI)

meiko:
	./bin/mkconfig Make.Meiko
#	cd am ; $(MM) install ; cd ..
	cp lib/libam_meiko.a lib/libam.a
	cd pSather ; $(MM) install ; cd ..

meiko-no-threads:
	./bin/mkconfig Make.Meiko-no-threads
	cd am ; $(MM) install ; cd ..
	cd pSather ; $(MM) install ; cd ..

# Make a copy of the directory in "DIR". Dir has to be passed
# as an argument. Example:  make DIR=/u/fleiner/pSather/c.code copy
# DIR must already exist. It will create the directory pSather in
# DIR. It assumes that it is running in $SATHER_CONFIG/System/pSather
# 
# To safe time and space, this rule checks first to see if
# the pSather install directory is writable. If so, it will
# only install a link to it. This avoids the copy and possibly 
# recompilation too.

copy:
	@if [ ! -d "${DIR}" ]; then \
		echo "Sorry, ${DIR} does not exist, aborting" ; \
		exit 1 ; \
	fi 
	@if [ -d "${DIR}/pSather" ]; then \
		$(RM) -rf ${DIR}/pSather ; \
	fi
	@if [ -h "${DIR}/pSather" ]; then \
		$(RM) -f ${DIR}/pSather ; \
	fi
	@if [ -w Makefile ]; then \
		ln -s ${SATHER_HOME}/System/pSather ${DIR}/pSather ; \
		if cmp ${DIR}/sather.h include/sather.h 2>&1 > /dev/null; then :; else touch Makefile; fi; \
		cp ${DIR}/*.h include ; \
	else \
		mkdir ${DIR}/pSather ; \
		mkdir ${DIR}/pSather/am ; \
		mkdir ${DIR}/pSather/lwp ; \
		mkdir ${DIR}/pSather/lib ; \
		mkdir ${DIR}/pSather/include ; \
		mkdir ${DIR}/pSather/pSather ; \
		ln -s ${SATHER_HOME}/System/pSather/lib/libam_* ${DIR}/pSather/lib ; \
		cp ${SATHER_HOME}/System/pSather/include/am.h ${DIR}/pSather/include ; \
		cp *.options Make.config Makefile ${DIR}/pSather ; \
		cp lwp/*.[ch] lwp/Makefile ${DIR}/pSather/lwp ; \
		cp am/*.[ch] am/Makefile ${DIR}/pSather/am ; \
		cp pSather/*.[ch] pSather/Makefile ${DIR}/pSather/pSather ; \
		ln -s ${SATHER_HOME}/System/pSather/config ${DIR}/pSather/config ; \
		ln -s ${SATHER_HOME}/System/pSather/bin ${DIR}/pSather/bin ; \
	fi

