#---*- Makefile -*-------------------------------------------------------
#$Author: saulius $
#$Date: 2019-03-07 15:28:04 +0000 (Thu, 07 Mar 2019) $
#$Revision: 182 $
#$URL: svn+ssh://saulius-grazulis.lt/home/saulius/svn-repositories/makefiles/importcns/Makelocal-importcns $
#------------------------------------------------------------------------

# Typically, a 'Makeconfig-importcns' configuration file should
# accompny this Makefile, and it should define the necessary
# variables:

CNS_DIR   ?= ../refmac

RCS_REPOSITORY ?= ${wildcard RCS/*build*,v}
RCS_BASENAME   ?= ${notdir ${RCS_REPOSITORY}}
BUILD_PDB      ?= ${RCS_BASENAME:%,v=%}

RCS_FILE  ?= RCS/${BUILD_PDB},v
ORIG_FILE ?= ${CNS_DIR}/inputs/import.pdb

REFINED_PDB = \
    ${shell ./bin/Rfactors ${CNS_DIR}/outputs/*.pdb \
	| sort -n -k 6 \
	| head -n 1 \
	| awk '{print $$1}' \
     }

.PHONY: all import

all: import

import: ${RCS_FILE}

${RCS_FILE}: ${REFINED_PDB}
	./bin/import-refined \
		${BUILD_PDB} \
		$< \
		${ORIG_FILE}
