all: lensflare-test image-test create-test-image

CC=clang
CXX=clang++

LF_SOURCES=\
src/lensflare.cpp

LF_HEADERS=\
poly/truncPolySystem.hh \
elements/Propagation.hh \
elements/SphericalSpectral.hh \
elements/CylindricalSpectral.hh \
include/spectrum.h \
elements/OpticalMaterial.hh \
elements/LensSystem.hh

LDFLAGS=-lm -lstdc++
LF_LDFLAGS=-lOpenCL
CXXFLAGS=-fPIC -D_REENTRANT -D_THREAD_SAFE -D_GNU_SOURCE -fopenmp -std=c++11
CXXFLAGS+=-I. -Ipoly -Ielements -Iopencl -Iinclude -g -Wall
CFLAGS=-std=c99 -Iinclude -Wall -g
# define this if not debugging:
OPTFLAGS=-O3 -ffast-math -mfpmath=sse -march=native -DNDEBUG -fno-finite-math-only
# this yields debuggable stuff:
# OPTFLAGS=-ffast-math -mfpmath=sse -march=native -fno-finite-math-only -O0 -DDEBUG
# switches off all optimizations
# OPTFLAGS=-march=native -O0 -DDEBUG

opencl/lensflare_head.h: opencl/lensflare_head.cl
	xxd -i opencl/lensflare_head.cl > opencl/lensflare_head.h
opencl/image_head.h: opencl/image_head.cl
	xxd -i opencl/image_head.cl > opencl/image_head.h
lensflare-test: liblensflare.a Makefile test/lensflare_test.c
	${CC} ${OPTFLAGS} ${CFLAGS} test/lensflare_test.c liblensflare.a ${LDFLAGS} ${LF_LDFLAGS} -o lensflare-test
image-test: liblensflare.a Makefile test/image_test.c
	${CC} ${OPTFLAGS} ${CFLAGS} test/image_test.c liblensflare.a ${LDFLAGS} ${LF_LDFLAGS} -o image-test
create-test-image: Makefile test/testpfm.c
	${CC} ${OPTFLAGS} ${CFLAGS} test/testpfm.c -lm -o create-test-image
liblensflare.a: ${SOURCES} ${HEADERS} Makefile src/lensflare.cpp include/lensflare.h opencl/lensflare_head.h opencl/image_head.h
	${CXX} ${OPTFLAGS} ${CXXFLAGS} ${LF_SOURCES} -c
	ar r liblensflare.a lensflare.o 

clean:
	rm -f opencl/lensflare_head.h opencl/image_head.h liblensflare.a *.o lensflare-test image-test create-test-image
