# This fixes the build system of FSL. It now (mostly) uses EB.
# Ward Poelmans <wpoely86@gmail.com>
diff -ur fsl.orig/config/common/vars.mk fsl/config/common/vars.mk
--- fsl.orig/config/common/vars.mk	2016-05-24 17:44:11.000000000 +0200
+++ fsl/config/common/vars.mk	2017-05-24 09:38:05.912369589 +0200
@@ -24,14 +24,14 @@
 USRCFLAGS = 
 USRCXXFLAGS =
 
-LDFLAGS = ${ARCHLDFLAGS} ${USRLDFLAGS} -L. -L${DEVLIBDIR} -L${LIBDIR}
+LDFLAGS = ${EBVARLDFLAGS} ${ARCHLDFLAGS} ${USRLDFLAGS} -L. -L${DEVLIBDIR} -L${LIBDIR}
 
-AccumulatedIncFlags = -I${INC_BOOST} ${USRINCFLAGS} -I. -I${DEVINCDIR} -I${INCDIR}
+AccumulatedIncFlags = ${EBVARCPPFLAGS} -I${INC_BOOST} ${USRINCFLAGS} -I. -I${DEVINCDIR} -I${INCDIR}
 
-CFLAGS = ${ANSI_FLAGS} ${ANSI_CFLAGS} ${DBGFLAGS} ${USEDCSTATICFLAGS} ${USRCFLAGS} ${ARCHFLAGS} ${OPTFLAGS}  \
+CFLAGS = ${EBVARCFLAGS} ${ANSI_FLAGS} ${ANSI_CFLAGS} ${DBGFLAGS} ${USEDCSTATICFLAGS} ${USRCFLAGS} ${ARCHFLAGS} ${OPTFLAGS}  \
 	${AccumulatedIncFlags}
 
-CXXFLAGS = ${ANSI_FLAGS} ${ANSI_CXXFLAGS} ${DBGFLAGS} ${USEDCXXSTATICFLAGS} ${USRCXXFLAGS} ${ARCHFLAGS} ${OPTFLAGS}  \
+CXXFLAGS = ${EBVARCXXFLAGS} ${ANSI_FLAGS} ${ANSI_CXXFLAGS} ${DBGFLAGS} ${USEDCXXSTATICFLAGS} ${USRCXXFLAGS} ${ARCHFLAGS} ${OPTFLAGS}  \
 	${AccumulatedIncFlags}
 
 HFILES = *.h
diff -ur fsl.orig/config/generic/systemvars.mk fsl/config/generic/systemvars.mk
--- fsl.orig/config/generic/systemvars.mk	2007-07-13 13:00:20.000000000 +0200
+++ fsl/config/generic/systemvars.mk	2017-05-24 09:38:05.912369589 +0200
@@ -16,8 +16,8 @@
 
 # Compiler dependent variables
 
-CC = gcc
-CXX = c++
+CC := ${CC}
+CXX := ${CXX}
 CSTATICFLAGS = -static
 CXXSTATICFLAGS = -static
 
@@ -25,7 +25,7 @@
 
 DEPENDFLAGS = -MM
 
-OPTFLAGS =  -O3 -fexpensive-optimizations ${ARCHFLAGS}
+OPTFLAGS := ${CFLAGS} ${ARCHFLAGS}
 MACHDBGFLAGS =
 GNU_ANSI_FLAGS = -Wall -ansi -pedantic
 SGI_ANSI_FLAGS = -ansi -fullwarn
diff -ur fsl.orig/config/linux_64-gcc4.8/externallibs.mk fsl/config/linux_64-gcc4.8/externallibs.mk
--- fsl.orig/config/linux_64-gcc4.8/externallibs.mk	2017-02-18 13:20:05.000000000 +0100
+++ fsl/config/linux_64-gcc4.8/externallibs.mk	2017-05-24 09:45:04.058907856 +0200
@@ -15,7 +15,7 @@
 INC_GDC = ${FSLEXTINC}/libgdc
 
 # LIBXML2 library
-INC_XML2 = ${FSLEXTINC}/libxml2
+INC_XML2 = ${EBROOTLIBXML2}
 
 # LIBXML++ library
 INC_XML++ = ${FSLEXTINC}/libxml++-2.6
@@ -49,12 +49,12 @@
 INC_ZLIB = /usr/include
 
 # BOOST library
-BOOSTDIR = ${FSLEXTINC}/boost
-LIB_BOOST = ${BOOSTDIR}
-INC_BOOST = ${BOOSTDIR}
+BOOSTDIR = ${EBROOTBOOST}
+LIB_BOOST = ${BOOSTDIR}/lib
+INC_BOOST = ${BOOSTDIR}/include
 
 # QT library
-QTDIR = /usr/lib/qt3
+QTDIR = ${EBROOTQT}
 LIB_QT = ${QTDIR}/lib
 INC_QT = ${QTDIR}/include
 
@@ -64,10 +64,10 @@
 INC_QWT = ${QWTDIR}/include
  
 # FFTW3 library
-LIB_FFTW3 = ${FSLEXTLIB}
-INC_FFTW3 = ${FSLEXTINC}/fftw3
-
-# VTK library 
-VTKDIR_INC = /home/fs0/cowboy/var/caper_linux_64-gcc4.4/VTK7/include/vtk-7.0
-VTKDIR_LIB = /home/fs0/cowboy/var/caper_linux_64-gcc4.4/VTK7/lib
-VTKSUFFIX = -7.0
\ No newline at end of file
+LIB_FFTW3 = ${EBVARFFTW_LIB_DIR}
+INC_FFTW3 = ${EBVARFFTW_INC_DIR}
+ 
+ # VTK library
+VTKDIR_INC = ${EBROOTVTK}/include/vtk-`echo ${EBVERSIONVTK} | cut -f1-2 -d.`
+VTKDIR_LIB = ${EBROOTVTK}/lib
+VTKSUFFIX = -`echo ${EBVERSIONVTK} | cut -f1-2 -d.`
diff -ur fsl.orig/config/linux_64-gcc4.8/systemvars.mk fsl/config/linux_64-gcc4.8/systemvars.mk
--- fsl.orig/config/linux_64-gcc4.8/systemvars.mk	2017-02-18 13:20:05.000000000 +0100
+++ fsl/config/linux_64-gcc4.8/systemvars.mk	2017-05-24 09:38:05.912369589 +0200
@@ -8,7 +8,7 @@
 CP = /bin/cp
 MV = /bin/mv
 INSTALL = install -p
-TCLSH = ${FSLDIR}/bin/fsltclsh
+TCLSH = tclsh
 RANLIB = echo
 
 FSLML = ${FSLDIR}/bin/fslml
@@ -18,9 +18,9 @@
 
 # Compiler dependent variables
 
-CC = gcc
-CXX = c++
-CXX11 = scl enable devtoolset-2 -- c++
+CC := ${CC}
+CXX := ${CXX}
+CXX11 = ${CXX} -std=c++11
 CSTATICFLAGS = -static
 CXXSTATICFLAGS = -static
 
@@ -30,16 +30,16 @@
 
 DEPENDFLAGS = -MM
 
-OPTFLAGS = -g -O3 -fexpensive-optimizations ${ARCHFLAGS}
+OPTFLAGS := ${OPTFLAGS} ${ARCHFLAGS}
 MACHDBGFLAGS = -g
 GNU_ANSI_FLAGS = -Wall -ansi -pedantic -Wno-long-long
 SGI_ANSI_FLAGS = -ansi -fullwarn
 ANSI_FLAGS = ${GNU_ANSI_FLAGS}
 
 # CUDA development environment
-CUDA_INSTALLATION = /opt/cuda-7.5
+CUDA_INSTALLATION = ${EBROOTCUDA}
 GENCODE_FLAGS = $(shell ${FSLDIR}/config/common/supportedGencodes.sh ${CUDA_INSTALLATION})
 LIB_CUDA = ${CUDA_INSTALLATION}/lib64
 INC_CUDA = ${CUDA_INSTALLATION}/include
 NVCC = ${CUDA_INSTALLATION}/bin/nvcc
-NVCC11=scl enable devtoolset-2 -- ${CUDA_INSTALLATION}/bin/nvcc
+NVCC11= ${CUDA_INSTALLATION}/bin/nvcc
diff -ur fsl.orig/etc/fslconf/fsl.csh fsl/etc/fslconf/fsl.csh
--- fsl.orig/etc/fslconf/fsl.csh	2014-05-19 16:54:10.000000000 +0200
+++ fsl/etc/fslconf/fsl.csh	2017-05-24 09:38:05.912369589 +0200
@@ -25,7 +25,7 @@
 # The following variables specify paths for programs and can be changed
 #  or replaced by different programs ( e.g. FSLDISPLAY=open   for MacOSX)
 
-setenv FSLTCLSH $FSLDIR/bin/fsltclsh
+setenv FSLTCLSH tclsh
-setenv FSLWISH $FSLDIR/bin/fslwish
+setenv FSLWISH wish
 
 # The following variables are used for running code in parallel across
diff -ur fsl.orig/etc/fslconf/fsl-devel.sh fsl/etc/fslconf/fsl-devel.sh
--- fsl.orig/etc/fslconf/fsl-devel.sh	2014-05-19 16:54:10.000000000 +0200
+++ fsl/etc/fslconf/fsl-devel.sh	2017-05-24 09:38:05.912369589 +0200
@@ -26,7 +26,7 @@
 # The following variables specify paths for programs and can be changed
 #  or replaced by different programs ( e.g. FSLDISPLAY=open   for MacOSX)
 
-FSLTCLSH=$FSLDIR/bin/fsltclsh
+FSLTCLSH=tclsh
-FSLWISH=$FSLDIR/bin/fslwish
+FSLWISH=wish
 
 export FSLTCLSH FSLWISH 
diff -ur fsl.orig/etc/fslconf/fsl.sh fsl/etc/fslconf/fsl.sh
--- fsl.orig/etc/fslconf/fsl.sh	2014-05-19 16:54:10.000000000 +0200
+++ fsl/etc/fslconf/fsl.sh	2017-05-24 09:38:05.912369589 +0200
@@ -26,7 +26,7 @@
 # The following variables specify paths for programs and can be changed
 #  or replaced by different programs ( e.g. FSLDISPLAY=open   for MacOSX)
 
-FSLTCLSH=$FSLDIR/bin/fsltclsh
+FSLTCLSH=tclsh
-FSLWISH=$FSLDIR/bin/fslwish
+FSLWISH=wish
 
 export FSLTCLSH FSLWISH 
diff -ur fsl.orig/extras/src/libxml++-2.34.0/libxml++/io/istreamparserinputbuffer.cc fsl/extras/src/libxml++-2.34.0/libxml++/io/istreamparserinputbuffer.cc
--- fsl.orig/extras/src/libxml++-2.34.0/libxml++/io/istreamparserinputbuffer.cc	2010-12-15 11:41:27.000000000 +0100
+++ fsl/extras/src/libxml++-2.34.0/libxml++/io/istreamparserinputbuffer.cc	2017-05-24 09:38:05.913369598 +0200
@@ -39,6 +39,6 @@
 
   bool IStreamParserInputBuffer::do_close()
   {
-    return input_;
+    return static_cast<bool>(input_);
   }
 }
diff -ur fsl.orig/extras/src/libxml++-2.34.0/libxml++/io/ostreamoutputbuffer.cc fsl/extras/src/libxml++-2.34.0/libxml++/io/ostreamoutputbuffer.cc
--- fsl.orig/extras/src/libxml++-2.34.0/libxml++/io/ostreamoutputbuffer.cc	2010-12-15 11:41:27.000000000 +0100
+++ fsl/extras/src/libxml++-2.34.0/libxml++/io/ostreamoutputbuffer.cc	2017-05-24 09:38:05.913369598 +0200
@@ -29,13 +29,13 @@
     // here we rely on the ostream implicit conversion to boolean, to know if the stream can be used and/or if the write succeded.
     if(output_)
       output_.write(buffer, len);
-    return output_;
+    return static_cast<bool>(output_);
   }
 
   bool OStreamOutputBuffer::do_close()
   {
     if(output_)
         output_.flush();
-    return output_;
+    return static_cast<bool>(output_);
   }
 }
diff -ur fsl.orig/src/film/Makefile fsl/src/film/Makefile
--- fsl.orig/src/film/Makefile	2017-04-20 17:01:43.000000000 +0200
+++ fsl/src/film/Makefile	2017-05-24 09:38:05.913369598 +0200
@@ -28,7 +28,7 @@
 	${CXX}  ${CXXFLAGS} ${LDFLAGS} -o $@ ${OBJS} ftoz.o ${LIBS}
 
 film_gls:${OBJS} film_gls.o
-	${CXX}  ${CXXFLAGS} ${LDFLAGS} -o $@ ${OBJS} film_gls.o ${LIBS} -l giftiio
+	${CXX}  ${CXXFLAGS} ${LDFLAGS} -o $@ ${OBJS} film_gls.o ${LIBS} -lgiftiio
 
 film_gls_res:${OBJS} film_gls_res.o
 	${CXX}  ${CXXFLAGS} ${LDFLAGS} -o $@ ${OBJS} film_gls_res.o ${LIBS}
diff -ur fsl.orig/src/libmeshutils/Makefile fsl/src/libmeshutils/Makefile
--- fsl.orig/src/libmeshutils/Makefile	2012-07-23 15:25:20.000000000 +0200
+++ fsl/src/libmeshutils/Makefile	2017-05-24 09:38:05.913369598 +0200
@@ -3,7 +3,7 @@
 
 PROJNAME = meshUtils
 
-LD_LIBRARY_PATH=${FSLDIR}/lib
+#LD_LIBRARY_PATH=${FSLDIR}/lib
 
 USRINCFLAGS = -I${INC_NEWMAT} -I${INC_ZLIB} -I${INC_PROB} -I${INC_BOOST} 
 USRLDFLAGS =  -L${LIB_PROB} -L${LIB_NEWMAT} -L${LIB_ZLIB}
diff -ur fsl.orig/src/mist-clean/Makefile fsl/src/mist-clean/Makefile
--- fsl.orig/src/mist-clean/Makefile	2017-04-20 14:17:54.000000000 +0200
+++ fsl/src/mist-clean/Makefile	2017-05-24 09:38:05.913369598 +0200
@@ -2,15 +2,15 @@
 
 NLOPT_INC = ${FSLEXTINC}
 NLOPT_LIB = ${FSLEXTLIB}
-SQLITE_INC = ${FSLEXTINC}/libsqlite
-SQLITE_LIB = ${FSLEXTLIB}
+SQLITE_INC = ${EBROOTSQLITE}/include
+SQLITE_LIB = ${EBROOTSQLITE}/lib
 
 PROJNAME = mist
 
 XFILES = mist/mist
 SCRIPTS = bin/mist_1_train bin/mist_2_fit bin/mist_FA_reg bin/mist_display bin/mist_mesh_utils
 
-USRCXXFLAGS = -std=c++11
# EB: needed to correctly (dynamically) link with the Boost log libs
+USRCXXFLAGS = -std=c++11 -DBOOST_LOG_DYN_LINK
 USRINCFLAGS = -I${FSLDIR}/include/newimage -I${INC_NEWMAT} -I${INC_ZLIB} -I${INC_GDC} -I${INC_GD} -I${SQLITE_INC} -I${NLOPT_INC} -I${VTKDIR_INC} -Icommon
 USRLDFLAGS = -L${LIB_NEWMAT} -L${LIB_ZLIB} -L${LIB_BOOST} -L${LIB_GDC} -L${LIB_GD} -L${NLOPT_LIB} -L${VTKDIR_LIB}
 
