#***********************************************************************
#
# Licensed Materials - Property of IBM
#
# (C) Copyright IBM Corp. 2009
# All Rights Reserved
#
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
#***********************************************************************

MPI_INC_DIR = $(shell /bin/ls -d /usr/include/openmpi-ppc /usr/include/openmpi-ppc /usr/lib/openmpi/*/include /usr/lib/mpi/gcc/openmpi/include 2>/dev/null|sort -rg |head -1)
MPI_LIB_DIR = $(shell /bin/ls -d /usr/lib/openmpi/lib /usr/lib/openmpi/*/lib /usr/lib/mpi/gcc/openmpi/lib 2>/dev/null|sort -rg |head -1)
ifeq "${MPI_INC_DIR}" ""
  $(error openmpi and openmpi-devel packages need to be installed. See readme.jacsolver.txt.)
endif

CC	= gcc
BITS 	= -m32
CFLAGS	= -Wall -std=c99 -I. -I../../clu -I${MPI_INC_DIR} -g -O3 ${BITS} -fno-strict-aliasing
LDFLAGS	=  -lOpenCL ${BITS} -lm -lstdc++ -lmpi -L${MPI_LIB_DIR} -Wl,-R -Wl,${MPI_LIB_DIR}

OBJS	= jacsolver.o clu.o
KERNELS = jacsolver_kernel.cl


vpath	%.c	../src ../../clu

DEPS    = $(OBJS:.o=.d)

%.d: %.c
	@$(CC) -M $(CFLAGS) $< | sed 's/$*.o/& $@/g' > $@

.PHONY: all
all: jacsolver $(KERNELS)

jacsolver: $(OBJS)

jacsolver_kernel.cl:
	@ln -s -f ../src/$@

-include $(DEPS)

.PHONY: clean
clean:
	@rm -f jacsolver *.ocl_bin $(OBJS) $(KERNELS) $(DEPS)

