# Makefile for MAPS
# Chris Siefert, College of William and Mary, 2000.

CC=gcc
CXX=g++

FC=g77
GT=gtar
AR=ar
RANLIB=ranlib
FFLAGS=-O
CFLAGS=-Wall -O 
CXXFLAGS=-Wall -g -O $(DFLAGS)
LDFLAGS=-L./ -lLAPACK -lBLAS -lf2c -lm 

DFLAGS=-DDEBUG=1 
# For an older compiler add -DOLD_LIBC to the above line.
# Add -DNO_BOOLS if your compiler doesn't support bools.
# If you want to compile MAPS in with your executable, add
# -DFUNCTION_COMPILED_MODE to the above line.

OFILES=testMPG.o maps.o PSGrid.o InitialDesign.o LatinHCDesign.o\
	DirectSearch.o PatternSearch.o CompassSearch.o \
	MultiCompassSearch.o ParamEstimate.o KrigApprox.o Approximate.o \
	rngs.o rvgs.o SearchCriterion.o objective.o

CLASSICOFILES=testClassic.o maps.o PSGrid.o InitialDesign.o LatinHCDesign.o\
	DirectSearch.o PatternSearch.o CompassSearch.o \
	MultiCompassSearch.o ParamEstimate.o KrigApprox.o Approximate.o \
	rngs.o rvgs.o SearchCriterion.o objective.o

VERSION=maps_04a

maps: $(OFILES) shekel
	$(CXX) $(CXXFLAGS) -o $@ $(OFILES) $(LDFLAGS)

classic: sample2.o $(CLASSICOFILES)
	@echo "Edit here to compile with your data"
	@echo "Be sure to use -DFUNCTION_COMPILED_MODE"
	$(CXX) $(CXXFLAGS) -o $@ sample2.o $(CLASSICOFILES) $(LDFLAGS)

install:
	$(GT) zxvf netlibfiles.tgz
	$(FC) $(FFLAGS) -c blas/*.f
	$(AR) r libBLAS.a *.o
	$(RANLIB) libBLAS.a || /bin/true
	rm -f *.o
	$(CC) -O -c clapack/double/*.c
	$(AR) r libLAPACK.a *.o
	$(RANLIB) libLAPACK.a || /bin/true
	rm -f *.o
	(cd libf2c; make -f makefile.u;mv libf2c.a ..)

shekel: shekel.cc
	$(CXX) $(CXXFLAGS) -o shekel shekel.cc -lm

testMPG.o: testMPG.cc
	$(CXX) $(CXXFLAGS) -c -o $@ $^

# You may ask why the Makefile is listed as a dependency for 
# all the .o files.  The answer is simple - this allows you to
# change the DEBUG flag if needed, and have make recompile everything.

ParamEstimate.o: ParamEstimate.cc ParamEstimate.h Makefile
	$(CXX) $(CXXFLAGS) -c -o $@ ParamEstimate.cc

SearchCriterion.o: SearchCriterion.cc SearchCriterion.h Makefile
	$(CXX) $(CXXFLAGS) -c -o $@ SearchCriterion.cc

Approximate.o: Approximate.cc Approximate.h 
	$(CXX) $(CXXFLAGS) -c Approximate.cc -o $@

InitialDesign.o: InitialDesign.cc InitialDesign.h Makefile
	$(CXX) $(CXXFLAGS) -c -o $@ InitialDesign.cc

LatinHCDesign.o: LatinHCDesign.cc LatinHCDesign.h Makefile
	$(CXX) $(CXXFLAGS) -c -o $@ LatinHCDesign.cc

KrigApprox.o: KrigApprox.cc KrigApprox.h Makefile
	$(CXX) $(CXXFLAGS) -c -o $@ KrigApprox.cc

PSGrid.o: PSGrid.cc PSGrid.h Makefile
	$(CXX) $(CXXFLAGS) -c -o $@ PSGrid.cc

maps.o: maps.cc maps.h Makefile
	$(CXX) $(CXXFLAGS) -c -o $@ maps.cc

PatternSearch.o: PatternSearch.cc PatternSearch.h 
	$(CXX) $(CXXFLAGS) -c -o $@ PatternSearch.cc

CompassSearch.o: CompassSearch.cc CompassSearch.h 
	$(CXX) $(CXXFLAGS) -c -o $@ CompassSearch.cc

MultiCompassSearch.o: MultiCompassSearch.cc MultiCompassSearch.h 
	$(CXX) $(CXXFLAGS) -c -o $@ MultiCompassSearch.cc

sample2.o: sample2.cc
	$(CXX) $(CXXFLAGS) -c -o $@ sample2.cc

rngs.o: rngs.c
	$(CXX) $(CCFLAGS) -c rngs.c

rvgs.o: rvgs.c
	$(CXX) $(CCFLAGS) -c rvgs.c


clean: 
	rm -f core *.o || /bin/true

