#--------------------------------------------------------------------------------------
#
#  Makefile  : Makefile for compiling CImg examples on Unix
#
#  Copyright : David Tschumperle (http://www.greyc.ensicaen.fr/~dtschump/)
#
# -----------------------------------------------------------------------------------

# Set correct variables and paths
CC      = g++
X11PATH = /usr/X11R6
CFLAGS  = -Wall -W -ansi -pedantic -ffast-math -I$(X11PATH)/include
LDFLAGS = -lm
CIMGVER = 1.15

CIMGFILES = CImg_demo \
	    fade_images \
	    greycstoration \
            greycstoration4integration \
	    hough_transform \
	    image_registration \
	    image2ascii \
	    image_surface \
	    mcf_levelsets \
	    nlmeans \
	    mcf_levelsets3D \
	    odykill \
	    pslider \
	    pde_heatflow2D \
	    pde_TschumperleDeriche2D \
	    tetris \
	    tutorial \
	    wavelet_atrous \
	    inrcast

# Compilation rules
.cpp:
	@echo
	@echo "** Compiling '$* ($(CIMGVER))' with '`$(CC) -v 2>&1 | grep version`'"
	@echo
	$(CC) -o $* $< $(CFLAGS) $(LDFLAGS) $(ARCHFLAGS)
menu:
	@echo
	@echo "CImg Library $(CIMGVER) : Examples"
	@echo "-----------------------------"
	@echo "  > dlinux   : Compile for Linux/MacOSX, with debug informations."
	@echo "  > linux    : Compile for Linux/MacOSX, with standard options."
	@echo "  > olinux   : Compile for Linux/MacOSX, with optimizations."
	@echo
	@echo "  > dsolaris : Compile for Solaris, with debug informations."
	@echo "  > solaris  : Compile for Solaris, with standard options."
	@echo "  > osolaris : Compile for Solaris, with optimizations."
	@echo
	@echo "  > dminimal : Compile with minimal dependancies, with debug informations."
	@echo "  > minimal  : Compile with minimal dependancies, with standard options."
	@echo "  > ominimal : Compile with minimal dependancies, with optimizations."
	@echo
	@echo "  > clean    : Clean generated files."
	@echo
	@echo "Choose your option :"
	@read CHOICE; echo; make $$CHOICE; echo; echo "> Next time, you can bypass the menu by typing directly 'make $$CHOICE'"; echo;

all: $(CIMGFILES)

clean:
	rm -f *.exe *~ $(CIMGFILES)

# Linux/Mac OSX targets
linux:
	make "ARCHFLAGS=-L$(X11PATH)/lib -lpthread -lX11" all
dlinux:
	make "ARCHFLAGS=-Dcimg_debug=2 -g -L$(X11PATH)/lib -lpthread -lX11" all
olinux:
	make "ARCHFLAGS=-O3 -L$(X11PATH)/lib -lpthread -lX11  -Dcimg_use_xshm -lXext -Dcimg_use_xrandr -lXrandr" all

# Sun Solaris targets
solaris:
	make "ARCHFLAGS=-L$(X11PATH)/lib -R$(X11PATH)/lib -lpthread -lX11 -lrt -lnsl -lsocket" all
dsolaris:
	make "ARCHFLAGS=-Dcimg_debug=2 -g -L$(X11PATH)/lib -R$(X11PATH)/lib -lpthread -lX11 -lrt -lnsl -lsocket" all
osolaris:
	make "ARCHFLAGS=-O3 -L$(X11PATH)/lib -R$(X11PATH)/lib -lpthread -lX11 -lrt -lnsl -lsocket -Dcimg_use_xshm -lXext -Dcimg_use_xrandr -lXrandr" all

# targets with minimal dependancies
minimal:
	make "ARCHFLAGS=-Dcimg_display_type=0" all
dminimal:
	make "ARCHFLAGS=-Dcimg_display_type=0 -Dcimg_debug=2 -g" all
ominimal:
	make "ARCHFLAGS=-Dcimg_display_type=0 -O2" all
