# Makefile for DPS to MOSFLM, Harry Powell
#
# Version 1.0; Builds DPSLIB.a under OSF on an Alpha; if the DPS object
#              libraries don't exist, we should make them via the "make all"
#              command. Bear in mind that we are using a local version of 
#              BRAVAIS.C (bravais using four arguments rather than one), so we 
#              have to include an extra make for a local version of that 
#              library here as well.
#
#-----------------------------------------------------------------------------
#OSTYPE     = ${HOSTTYPE}
TIDY       = rm -f ________64ELEL_
BIN        = ${DPS}/bin


# 	location of the modified DPS libraries and source code
LIB        = ${DPS}/lib
SRC        = ${DPS}/src

# 	object files from local interfaces to DPS routines
HOBJS      = write_ub_matrix.o new_matrix.o

# 	object files from DPS bravais lattice generation/reduction routines
IOBJS      = bravais.o  bravais_goof.o \
        bravais_permutate.o bravais_transform.o

# these are the Cambridge _modified_ library routines from DPS
INDEX      = ${DPS}/index
DPSINDEX   = ${SRC}/dps/index
DPSBRAVAIS = ${SRC}/dps/bravais

# libraries ready for linking with MOSFLM objects
LIBRARIES  = ${LIB}/libdps.a ${LIB}/libdps_index.a \
             ${LIB}/libfftpack.a ${LIB}/libdps_bravais.a

DEBUG      = 

all:	${IOBJS} ${HOBJS} ${LIBRARIES}
	cd ${LIB} ; ${TIDY} 
	ar ru ${LIB}/dps_index.a ${IOBJS} ${HOBJS}
	cd ${LIB} ; ${TIDY} ; \
	ar x dps_index.a ; ${TIDY} ; \
	ar x libdps.a ; ${TIDY} ; \
	ar x libfftpack.a ; ${TIDY} ; \
	ar x libdps_index.a ; ${TIDY} ; \
	ar ${AR_FLAGS} DPSLIB.a `ls *.o` ; ${TIDY} ; \
	rm -f *.o ; \
	rm -f dps_index.a ; \
	cd ${DPS}

check:
# This only checks the syntax of this Makefile!
	cat -v -t -e Makefile|more

# Here are the makes for DPS libraries
${LIB}/libdps.a: 
	cd ${SRC}/dps/util; \
	make -f Makefile; \
	cd ${DPS}

${LIB}/libdps_index.a: 
	cd ${DPSINDEX} ; \
	make -f Makefile ; \
	cd ${DPS}

${LIB}/dps_index.a: 
	cd ${DPSBRAVAIS}; \
	make -f Makefile; \
	cd ${DPS}

${LIB}/libfftpack.a: 
	cd ${SRC}/dps/peak_search; \
	make -f Makefile; \
	cd ${DPS}

${LIB}/libdps_bravais.a: bravais.o
	ar ru ${LIB}/libdps_bravais.a ${IOBJS}

bravais.o: bravais.c bravais.h
	${CC} ${DEBUG} ${CFLAGS} -c -o bravais.o bravais.c

bravais_goof.o: 
	cd ${DPSBRAVAIS} ; \
	${CC} ${DEBUG} ${CFLAGS} -c -o bravais_goof.o bravais_goof.c ; \
	mv bravais_goof.o ${INDEX}/. ; \
	cd ${INDEX}

bravais_permutate.o: 
	cd ${DPSBRAVAIS} ; \
	${CC} ${DEBUG} ${CFLAGS} -c -o bravais_permutate.o \
	bravais_permutate.c ; \
	mv bravais_permutate.o ${INDEX}/. ; \
	cd ${INDEX}

bravais_transform.o: 
	cd ${DPSBRAVAIS} ; \
	${CC} ${DEBUG} ${CFLAGS} -c -o bravais_transform.o \
	bravais_transform.c ; \
	mv bravais_transform.o ${INDEX}/. ; \
	cd ${INDEX}

new_matrix.o: new_matrix.c
	${CC} ${DEBUG} ${CFLAGS} -c new_matrix.c

write_ub_matrix.o: write_ub_matrix.c
	${CC} ${DEBUG} ${CFLAGS} -c write_ub_matrix.c

clean: 
	cd ${DPS}; \
	rm -f${VERBOSE} `find ${DPS}/index -name "*.o" -print`
	rm -f${VERBOSE} `find ${DPS}/src   -name "*.o" -print`

realclean:
	cd ${DPS}; \
	rm -f${VERBOSE} `find ${DPS}/index -name "*.a" -print`
	rm -f${VERBOSE} `find ${DPS}/index -name "*.o" -print`
	rm -f${VERBOSE} `find ${DPS}/src   -name "*.a" -print`
	rm -f${VERBOSE} `find ${DPS}/src   -name "*.o" -print`
	rm -f${VERBOSE} `find ${DPS}/util   -name "*.a" -print`
	rm -f${VERBOSE} `find ${DPS}/util   -name "*.o" -print`
