#
#  Standard macros
#
#
#----------------------------------------------------------------------------
# Project specific path defintions.
#----------------------------------------------------------------------------
LIBINCLDIR = ../include
LIBINSTDIR = ../lib

PROJDIR    = .
SRC        = $(PROJDIR)/src
INCL       = $(PROJDIR)/include
OBJ        = $(PROJDIR)/obj
LIB        = $(PROJDIR)/lib
BIN        = $(PROJDIR)/bin
TESTDIR    = $(PROJDIR)/test
PROJS      = ./..
INSTALLDIR = $(PROJS)/bin


#----------------------------------------------------------------------------
# LINCLUDES and LDEFINES are appended to CFLAGS and C++FLAGS
#----------------------------------------------------------------------------
LDEFINES    = -DNO_RANGE_CHECK
LINCLUDES = -I$(INCL) -I$(LIBINCLDIR) 
#
# LDEFINES is added to compilation command line.
#
LDEFINES    = -DNO_RANGE_CHECK
#----------------------------------------------------------------------------
# Include the appropriate compiler/platform definitions ...
#----------------------------------------------------------------------------
include ../etc/Makefile.platform

LIBS    = $(LIBINSTDIR)/libvalidation.a \
          $(LIBINSTDIR)/libndbfilter.a \
          $(LIBINSTDIR)/libconnect.a \
          $(LIBINSTDIR)/libciffileobj.a \
          $(LIBINSTDIR)/libcifobj.a \
          $(LIBINSTDIR)/libistable.a \
          $(LIBINSTDIR)/libregex.a \
          $(LIBINSTDIR)/libtblindex.a \
          $(LIBINSTDIR)/libcifstr.a \
          $(LIBINSTDIR)/libndbmisc.a

LIBS1   = $(LIBINSTDIR)/liberfiolib.a \
          $(LIBINSTDIR)/liberfutil.a \
          $(LIBINSTDIR)/libciffileobj.a \
          $(LIBINSTDIR)/libcifobj.a \
          $(LIBINSTDIR)/libistable.a \
          $(LIBINSTDIR)/libtblindex.a \
          $(LIBINSTDIR)/libcifstr.a \
          $(LIBINSTDIR)/libndbmisc.a

LIBS2   = $(LIBINSTDIR)/liberfiolib.a \
          $(LIBINSTDIR)/libconnect.a \
          $(LIBINSTDIR)/libciffileobj.a \
          $(LIBINSTDIR)/libcifobj.a \
          $(LIBINSTDIR)/libistable.a \
          $(LIBINSTDIR)/libregex.a \
          $(LIBINSTDIR)/libtblindex.a \
          $(LIBINSTDIR)/libcifstr.a \
          $(LIBINSTDIR)/libndbmisc.a
#
NDBLIB     = $(LIB)/libmaxit.a
#
TARGET1    = $(BIN)/maxit-v8.01-O
TARGET2    = $(BIN)/pdb2cif_corres
TARGET3    = $(BIN)/prefilter
#
HFILES  = $(INCL)/remark_300s.h   \
			$(INCL)/remark_cryoem.h \
                        $(INCL)/cif_standard.h \
			$(INCL)/derived_features_global.h \
			$(INCL)/remark_3_prolsqs.h  \
			$(INCL)/remark_general.h \
			$(INCL)/erf_category.h \
			$(INCL)/remark_3_refmac5.h \
			$(INCL)/remark.h \
			$(INCL)/_maxit.h \
			$(INCL)/remark_3_shelxl.h \
			$(INCL)/remark_olds.h \
			$(INCL)/remark_100s.h \
			$(INCL)/remark_3_tnt.h \
			$(INCL)/remark_solution.h \
			$(INCL)/remark_200s.h \
			$(INCL)/remark_3_xplors.h

TESTFILES = $(TESTDIR)/1a02.pdb $(TESTDIR)/1f1t.pdb $(TESTDIR)/1f6i.pdb \
            $(TESTDIR)/1fdg.cif $(TESTDIR)/1fms.cif $(TESTDIR)/1a35.pdb \
            $(TESTDIR)/1f6c.pdb $(TESTDIR)/1fd5.cif $(TESTDIR)/1fix.cif \
            $(TESTDIR)/1fn1.cif $(TESTDIR)/test.sh

#
OBJ1       = $(OBJ)/maxit_main.o
OBJ2       = $(OBJ)/pdb2cif_corr.o
OBJ3       = $(OBJ)/prefilter.o
# 
#
OBJS    = $(OBJ)/_maxit.o \
          $(OBJ)/addcard_util.o \
          $(OBJ)/cif_standard.o \
          $(OBJ)/cif_to_ndb.o \
          $(OBJ)/derived_features.o \
          $(OBJ)/ebi_remark_500.o \
          $(OBJ)/erf_category.o \
          $(OBJ)/find_sheet.o \
          $(OBJ)/maxit.o \
          $(OBJ)/ndb_to_cif.o \
          $(OBJ)/ndb_to_pdb.o \
          $(OBJ)/pdb_to_ndb.o \
          $(OBJ)/promotif.o
#
all:	$(NDBLIB)

$(NDBLIB):	$(OBJS) $(HFILES)
		$(AR) $(AR_PUTFLAGS) $(NDBLIB) $(OBJS)
		$(RANLIB) $(NDBLIB)
		@echo $(NDBLIB) " is up to date."

#
#  Making applications
#
$(TARGET1): $(LIBS) $(HFILES) $(NDBLIB) $(OBJ1)
	$(CCC) $(C++FLAGS) -o $@  $(OBJ1) $(NDBLIB) $(LIBS) $(LDFLAGS) -lm

$(TARGET2): $(LIBS1) $(OBJ)/erf_category.o $(OBJ2)
	$(CCC) $(C++FLAGS) -o $@ $(OBJ2) $(OBJ)/erf_category.o $(LIBS1) $(LDFLAGS) -lm

$(TARGET3): $(LIBS2) $(OBJ3)
	$(CCC) $(C++FLAGS) -o $@ $(OBJ3) $(LIBS2) $(LDFLAGS) -lm

# Creating object files
#
$(OBJ)/_maxit.o  : $(SRC)/_maxit.C
	$(CCC) $(C++FLAGS) -c $(SRC)/_maxit.C  -o $@ 

$(OBJ)/addcard_util.o : $(SRC)/addcard_util.C
	$(CCC) $(C++FLAGS_NONANSI) -c $(SRC)/addcard_util.C -o $@ 

$(OBJ)/cif_standard.o : $(SRC)/cif_standard.C
	$(CCC) $(C++FLAGS_NONANSI) -c $(SRC)/cif_standard.C -o $@ 

$(OBJ)/cif_to_ndb.o : $(SRC)/cif_to_ndb.C
	$(CCC) $(C++FLAGS_NONANSI) -c $(SRC)/cif_to_ndb.C -o $@ 

$(OBJ)/derived_features.o  : $(SRC)/derived_features.C
	$(CCC) $(C++FLAGS) -c $(SRC)/derived_features.C  -o $@ 

$(OBJ)/erf_category.o : $(SRC)/erf_category.C
	$(CCC) $(C++FLAGS_NONANSI) -c $(SRC)/erf_category.C -o $@ 

$(OBJ)/ebi_remark_500.o : $(SRC)/ebi_remark_500.C
	$(CCC) $(C++FLAGS_NONANSI) -c $(SRC)/ebi_remark_500.C -o $@ 

$(OBJ)/find_sheet.o  : $(SRC)/find_sheet.C
	$(CCC) $(C++FLAGS) -c $(SRC)/find_sheet.C  -o $@ 

$(OBJ)/maxit.o : $(SRC)/maxit.C
	$(CCC) $(C++FLAGS_NONANSI) -c $(SRC)/maxit.C -o $@ 

$(OBJ)/maxit_main.o  : $(SRC)/maxit_main.C
	$(CCC) $(C++FLAGS_NONANSI) -c $(SRC)/maxit_main.C  -o $@ 

$(OBJ)/ndb_to_cif.o  : $(SRC)/ndb_to_cif.C
	$(CCC) $(C++FLAGS_NONANSI) -c $(SRC)/ndb_to_cif.C  -o $@ 

$(OBJ)/ndb_to_pdb.o  : $(SRC)/ndb_to_pdb.C
	$(CCC) $(C++FLAGS_NONANSI) -c $(SRC)/ndb_to_pdb.C  -o $@ 

$(OBJ)/pdb_to_ndb.o  : $(SRC)/pdb_to_ndb.C
	$(CCC) $(C++FLAGS_NONANSI) -c $(SRC)/pdb_to_ndb.C -o $@ 

$(OBJ)/pdb2cif_corr.o  : $(SRC)/pdb2cif_corr.C
	$(CCC) $(C++FLAGS_NONANSI) -c $(SRC)/pdb2cif_corr.C -o $@ 

$(OBJ)/prefilter.o  : $(SRC)/prefilter.C
	$(CCC) $(C++FLAGS_NONANSI) -c $(SRC)/prefilter.C -o $@ 

$(OBJ)/promotif.o  : $(SRC)/promotif.C
	$(CCC) $(C++FLAGS_NONANSI) -c $(SRC)/promotif.C -o $@ 
#
test: all
	@sh -c 'cd $(TESTDIR); ./test.sh'

install: $(NDBLIB) $(TARGET1) $(TARGET2) $(TARGET3)
	 $(INSTALL) $(INSTALLOPTS) $(NDBLIB) $(LIBINSTDIR)/.
	cp $(TARGET1) $(INSTALLDIR)/.
	cp $(TARGET3) $(INSTALLDIR)/.

clean :
	rm -f core; rm -f $(OBJ)/*.o $(NDBLIB) $(TARGET1) $(TARGET2)
	@rm -rf Template.DB


SRCFILES = $(SRC)/addcard_util.C \
			$(SRC)/find_sheet.C \
			$(SRC)/ndb_to_cif.C \
			$(SRC)/promotif.C \
			$(SRC)/derived_features.C \
			$(SRC)/_maxit.C \
			$(SRC)/ndb_to_pdb.C \
			$(SRC)/cif_standard.C  \
			$(SRC)/ebi_remark_500.C \
			$(SRC)/maxit.C \
			$(SRC)/pdb2cif_corr.C \
			$(SRC)/cif_to_ndb.C \
			$(SRC)/erf_category.C \
			$(SRC)/maxit_main.C  \
			$(SRC)/pdb_to_ndb.C \
			$(SRC)/prefilter.C




export:
	mkdir -p $(EXPORT_DIR)
	@cd $(EXPORT_DIR); mkdir -p $(INCL)
	$(EXPORT) $(EXPORT_LIST) $(HFILES) $(EXPORT_DIR)/$(INCL)
	@cd $(EXPORT_DIR); mkdir -p $(SRC)
	$(EXPORT) $(EXPORT_LIST) $(SRCFILES) $(EXPORT_DIR)/$(SRC)
	@cd $(EXPORT_DIR); mkdir -p $(TESTDIR)
	@cp $(TESTFILES) $(EXPORT_DIR)/$(TESTDIR)
	@cd $(EXPORT_DIR); mkdir -p $(BIN)
	@cd $(EXPORT_DIR); mkdir -p $(LIB)
	@cd $(EXPORT_DIR); mkdir -p $(OBJ)
	@cp Makefile $(EXPORT_DIR)
