# $Id: Makefile 199 2011-07-07 18:14:33Z townsend $

# Variables

TARGETS=test_legendre test_hough_matrix test_hough texmex_pulse

# Flags

#OMP=yes
#MPI=yes
DOUBLE_PRECISION=yes
#DEBUG=yes
DEBUG_NOTRAP=yes
HDF5=yes

LDFLAGS=`mesasdk_hdf5_link` `mesasdk_lapack95_link`

# Include other makefiles

SUBDIRS=core:base:astro

include ../Make.inc

# Add c interoperability of texmex_pulse

include ../../common.mk

BLOCK_SIZE=128

EXTRA_LDFLAGS += -lGLU -lGL -lGLEW -lSDL -lpng -lglfw -lpython2.7 `mesasdk_lapack95_link`  `mesasdk_hdf5_link` -lz

EXTRA_NVCCFLAGS += -DBLOCK_SIZE=${BLOCK_SIZE} -DLINEAR_TEXTURE -DUSE_SDK
INCLUDES += -I/usr/include/python2.7/ -I/usr/lib64/python2.7/site-packages/numpy/core/include/

C_COMPILER=/usr/bin/gcc
C_FLAGS=-std=c99
CF_FLAGS=-lgfortran

F_COMPILER=${MESASDK_ROOT}/bin/gfortran

OBJS := pulsation_vbo.o texmex_py.o core_kinds.o core_hgroup.o core_constants.o texmex_map.o texmex_map_set.o texmex_mode.o texmex_hough.o texmex_legendre.o texmex_hough_matrix.o astro_hough.o


c_interop: pulsation_vbo.so

pulsation_vbo.so: $(OBJS)	
	$(GCC) -shared $(C_FLAGS) -o $@ $(OBJS) $(CF_FLAGS) ${LDFLAGS} $(EXTRA_LDFLAGS) -lpython2.7 -lm -lc -fPIC -DUNIX

pulsation_vbo.o: pulsation_vbo.cu pulsation_vbo_extra.cu ../../src/bog_draw.cu ../../src/bog_io.cu ../../src/bog_kernel.cu ../../src/bog_device.cu ../../src/bog_init.cu ../../src/bog_memory.cu ../../src/bog_obs.cu
	export PATH="/usr/bin:${PATH}"
	$(NVCC) -shared -Xcompiler -fPIC $(NVCCFLAGS) $(EXTRA_NVCCFLAGS) $(GENCODE_FLAGS) $(INCLUDES) -o $@ -c $< 

%_py.f90: %_py.fpp
	ln -s $*_py.fpp $*_py.f90

%_py.o: %_py.f90
	export PATH="${MESASDK_ROOT}/bin:${PATH}"		
	$(F_COMPILER) -fPIC -I/. -I${MESASDK_ROOT}/include -c $*_py.f90

py_clean:
	rm -f pulsation_vbo.so pulsation_vbo.o texmex_py.o
