--- examples/Makefile.orig	2018-04-11 12:39:15 UTC
+++ examples/Makefile
@@ -84,7 +84,7 @@ EXTRA_FILES = use_tiff_stream use_jpeg_b
 # Set correct variables and paths
 #---------------------------------
 VERSION = `grep 'cimg_version\ ' ../CImg.h | tail -c4 | head -c3`
-X11PATH      = /usr/X11R6
+X11PATH      = $(LOCALBASE)
 EXEPFX       =
 ifeq ($(MSYSTEM),MINGW32)
 EXESFX       = .exe
@@ -107,7 +107,7 @@ CXXVER       = "icpc \( `$(CXX) -v 2>&1`
 CFLAGS       = -I..
 LIBS         =
 else
-CFLAGS       = -I.. -Wall -Wextra -Wfatal-errors
+CFLAGS       = -I.. -Wall -Wextra $(CPPFLAGS)
 LIBS         = -lm
 endif
 
@@ -131,12 +131,12 @@ VT100_CFLAGS = -Dcimg_use_vt100
 
 # Flags to enable code optimization by the compiler.
 ifeq ($(notdir $(CXX)),g++)
-OPT_CFLAGS = -Ofast -mtune=generic
+OPT_CFLAGS = -mtune=generic
 else
 ifeq ($(notdir $(CXX)),icpc)
 OPT_CFLAGS = -fast
 else
-OPT_CFLAGS = -Ofast
+OPT_CFLAGS = # -Ofast - handled by the port CFLAGS
 endif
 endif
 
@@ -203,7 +203,7 @@ JPEG_LIBS = -ljpeg
 TIFF_DEFINE = -Dcimg_use_tiff
 TIFF_INCDIR =
 TIFF_CFLAGS = $(TIFF_DEFINE) $(TIFF_INCDIR)
-TIFF_LIBS = -ltiff
+TIFF_LIBS = -ltiff  -ltiffxx
 
 # Flags to enable native support for MINC2 image files, using the MINC2 library.
 # ( http://en.wikibooks.org/wiki/MINC/Reference/MINC2.0_Users_Guide )
@@ -215,16 +215,16 @@ MINC2_LIBS = -lminc_io -lvolume_io2 -lmi
 # Flags to enable native support for EXR image files, using the OpenEXR library.
 # ( http://www.openexr.com/ )
 OPENEXR_DEFINE = -Dcimg_use_openexr
-OPENEXR_INCDIR = -I/usr/include/OpenEXR
+OPENEXR_INCDIR = -I$(LOCALBASE)/include/OpenEXR
 OPENEXR_CFLAGS = $(OPENEXR_DEFINE) $(OPENEXR_INCDIR)
 OPENEXR_LIBS = -lIlmImf -lHalf
 
 # Flags to enable native support for various video files, using the FFMPEG library.
 # ( http://www.ffmpeg.org/ )
-FFMPEG_DEFINE = -Dcimg_use_ffmpeg -D__STDC_CONSTANT_MACROS
-FFMPEG_INCDIR = -I/usr/include/libavcodec -I/usr/include/libavformat -I/usr/include/libswscale -I/usr/include/ffmpeg
-FFMPEG_CFLAGS = $(FFMPEG_DEFINE) $(FFMPEG_INCDIR)
-FFMPEG_LIBS = -lavcodec -lavformat -lswscale
+#FFMPEG_DEFINE = -Dcimg_use_ffmpeg -D__STDC_CONSTANT_MACROS
+FFMPEG_INCDIR = -I$(LOCALBASE)/include/libavcodec -I$(LOCALBASE)/include/libavformat -I$(LOCALBASE)/include/libswscale -I$(LOCALBASE)/include/ffmpeg
+#FFMPEG_CFLAGS = $(FFMPEG_DEFINE) $(FFMPEG_INCDIR)
+#FFMPEG_LIBS = -lavcodec -lavformat -lswscale
 
 # Flags to enable native support for compressed .cimgz files, using the Zlib library.
 # ( http://www.zlib.net/ )
@@ -260,18 +260,21 @@ endif
 
 # Flags to enable the use of LAPACK routines for matrix computation
 # ( http://www.netlib.org/lapack/ )
-LAPACK_DEFINE = -Dcimg_use_lapack
+#LAPACK_DEFINE = -Dcimg_use_lapack
 LAPACK_INCDIR =
-LAPACK_CFLAGS = $(LAPACK_DEFINE) $(LAPACK_INCDIR)
-LAPACK_LIBS = -lblas -llapack
+#LAPACK_CFLAGS = $(LAPACK_DEFINE) $(LAPACK_INCDIR)
+#LAPACK_LIBS = -lblas -llapack
 
 # Flags to enable the use of the Board library
 # ( http://libboard.sourceforge.net/ )
 BOARD_DEFINE = -Dcimg_use_board
-BOARD_INCDIR = -I/usr/include/board
+BOARD_INCDIR = -I$(LOCALBASE)/include/board
 BOARD_CFLAGS = $(BOARD_DEFINE) $(BOARD_INCDIR)
 BOARD_LIBS = -lboard
 
+# Flags to compile on FreeBSD
+FREEBSD_LDFLAGS = $(LDFLAGS) -ffast-math  -I$(X11PATH)/include $(EXTRA_FLAGS) -lX11 -L$(X11PATH)/lib
+
 # Flags to compile on Sun Solaris
 SOLARIS_LIBS = -R$(X11PATH)/lib -lrt -lnsl -lsocket
 
@@ -347,6 +350,7 @@ $(X11_LIBS) \
 $(TIFF_LIBS) \
 $(LAPACK_LIBS) \
 $(XSHM_LIBS)" \
+$(PTHREAD_LIBS)" \
 all $(EXTRA_FILES)
 
 # Linux/BSD/Mac OSX targets, with X11 display.
@@ -439,8 +443,10 @@ $(ZLIB_CFLAGS) \
 $(CURL_CFLAGS) \
 $(OPENCV_CFLAGS) \
 $(MAGICK_CFLAGS) \
+$(LAPACK_CFLAGS) \
 $(FFTW3_CFLAGS)" \
 "CONF_LIBS = \
+$(FREEBSD_LDFLAGS) \
 $(X11_LIBS) \
 $(XSHM_LIBS) \
 $(XRANDR_LIBS) \
@@ -452,6 +458,7 @@ $(ZLIB_LIBS) \
 $(CURL_LIBS) \
 $(OPENCV_LIBS) \
 $(MAGICK_LIBS) \
+$(LAPACK_LIBS) \
 $(FFTW3_LIBS)" \
 "STRIP_EXE=true" \
 all $(EXTRA_FILES)
