##
## Makefile for parallel ion placement tool
##

# Command (if any) needed to patch the Intel C/C++ compiler's 
# resulting binary so it can run unhindered on AMD processors.
# By default this is set to 'touch', since it only matters on x86
# platforms, and only then when using Intel C/C++ compilers.
HACKICCBINARY = touch

default:
	@echo "Pick a build:"
	@echo "---------------"
	@echo "  aix5-xlc         (32-bit)"
	@echo "  aix5-64-xlc      (64-bit)"
	@echo "  irix6-cc         (32-bit, mips3)"
	@echo "  irix6-64-cc      (64-bit, mips4)"
	@echo "  linux-gcc        (32-bit)"
	@echo "  linux-gcc-simple (32-bit)"
	@echo "  linux-gcc-amd    (64-bit)"
	@echo "  linux-gcc-amd2   (64-bit)"
	@echo "  linux-gcc-debug  (32-bit)"
	@echo "  linux-icc        (32-bit, P4/Xeon tuned)"
	@echo "  linux-icc-thr    (32-bit, P4/Xeon tuned, SSE, multithreaded)"
	@echo "  linux-icc-sse2   (32-bit, P4/Xeon tuned, SSE2)"
	@echo "  linux-icc-sse3   (32-bit, P4/Xeon tuned, SSE3)"
	@echo "  linux-ia64-thr   (64-bit, Itanium2 tuned, NCSA Altix)"
	@echo "  solaris          (32-bit)"
	@echo "  solaris-64       (64-bit)"
	@echo "---------------"
	@echo "  make <build>"


aix5-xlc:
	$(MAKE) all \
	"CC  = xlc" \
	"CFLAGS   = -w -qinlglue -qarch=com -qtune=pwr3" \
	"LFLAGS = -lm"

aix5-64-xlc:
	$(MAKE) all \
	"CC  = xlc" \
	"CFLAGS   =  -w -qinlglue -q64 -qarch=com -qtune=pwr4" \
	"LFLAGS = -lm"

irix6-cc:
	$(MAKE) all \
	"CC  = xlc" \
	"CFLAGS   =  -O2 -fullwarn -n32 -mips3" \
	"LFLAGS = -lm"

irix6-64-cc:
	$(MAKE) all \
	"CC  = xlc" \
	"CFLAGS   =  -O2 -fullwarn -64 -mips4" \
	"LFLAGS = -lm"

linux-gcc:
	$(MAKE) all \
	"CC  = cc" \
	"CFLAGS   = -Wall -m32 -O5 -ffast-math -fomit-frame-pointer -fno-math-errno" \
	"LFLAGS = -lm"

linux-gcc-simple:
	$(MAKE) all \
	"CC  = cc" \
	"CFLAGS   = -Wall -m32 -O2 " \
	"LFLAGS = -lm"

linux-gcc-amd:
	$(MAKE) all \
	"CC  = cc" \
	"CFLAGS   = -Wall -m64 -O5 -ffast-math -fomit-frame-pointer -fno-math-errno" \
	"LFLAGS = -lm"

linux-gcc-amd2:
	$(MAKE) all \
	"CC  = cc" \
	"CFLAGS   = -Wall -m64 -O5 -ffast-math -fomit-frame-pointer -fno-math-errno -fno-trapping-math -ffinite-math-only" \
	"LFLAGS = -lm"

linux-gcc-debug:
	$(MAKE) all \
	"CC  = cc" \
	"CFLAGS   = -Wall -m32 -g -DDEBUG" \
	"LFLAGS = -lm"

linux-ia64-thr:
	$(MAKE) all \
	"CC  = icc" \
	"CFLAGS   = -fast -static -DTHR" \
	"LFLAGS = -lm -lpthread"

linux-icc:
	$(MAKE) all \
	"CC  = icc" \
	"CFLAGS   = -axW -fno-exceptions -fomit-frame-pointer -fno-math-errno -no-prec-sqrt -pc32 -vec-report=3 -ipo -O3 -static" \
	"LFLAGS = -lm"

linux-icc-thr:
	$(MAKE) all \
	"CC  = icc" \
	"CFLAGS   = -axW -fno-exceptions -fomit-frame-pointer -fno-math-errno -no-prec-sqrt -pc32 -vec-report=3 -ipo -O3 -static -DTHR" \
	"LFLAGS = -lm -lpthread"

linux-icc-sse2:
	$(MAKE) all \
	"CC  = icc" \
	"CFLAGS   = -fno-exceptions -fomit-frame-pointer -fno-math-errno -fast -no-prec-sqrt -pc32 -axP -vec-report=3" \
	"HACKICCBINARY = ../icchack/intel_check_executable_patch" \
	"LFLAGS = -lm"

linux-icc-sse3:
	$(MAKE) all \
	"CC  = icc" \
	"CFLAGS   = -fno-exceptions -fomit-frame-pointer -fno-math-errno -fast -no-prec-sqrt -pc32 -msse3 -vec-report=3" \
	"HACKICCBINARY = ../icchack/intel_check_executable_patch" \
	"LFLAGS = -lm"

linux-icc-sse3-64:
	$(MAKE) all \
	"CC  = icc" \
	"CFLAGS   = -m64 -fno-exceptions -fomit-frame-pointer -fno-math-errno -fast -no-prec-sqrt -pc32 -msse3 -vec-report=3" \
	"HACKICCBINARY = ../icchack/intel_check_executable_patch" \
	"LFLAGS = -lm"

solaris:
	$(MAKE) all \
	"CC  = cc" \
	"CFLAGS   = -v -native -xarch=native -fast" \
	"LFLAGS = -lm"
	
solaris-64:
	$(MAKE) all \
	"CC  = cc" \
	"CFLAGS   = -v -xarch=native64 -fast -native" \
	"LFLAGS = -lm"


IONBINS = ionize 
IONOBJS = ionize.o util.o threads.o energythr.o

all: $(IONBINS)

.c.o:
	$(CC) $(CFLAGS) -c $<

ionize: $(IONOBJS)
	$(CC) $(CFLAGS) $(IONOBJS) -o $@ $(LFLAGS)
	$(HACKICCBINARY) $@

test: 
	./ionize -n 4 -b 10 -r 3.0 -i 1.0 -g 0.5 -p 24 ../testfiles/helix.pdb testoutput.pdb
	@echo "Comparing test output with known-correct run results..."
	diff testoutput.pdb ../testfiles/output.pdb.test

test-runionize:
	../scripts/runionize.pl ../testfiles/runionize.conf
	@echo "Comparing test output with known-correct run results..."
	diff testoutput-runionize.pdb ../testfiles/output.pdb.test

clean:
	rm -f $(IONBINS) $(IONOBJS) ./*~ *.s testoutput*.pdb

