--- AFNI_2010_10_19_1028.orig/Makefile	2010-11-18 17:35:31.000000000 -0500
+++ AFNI_2010_10_19_1028/Makefile	2010-11-18 15:45:59.000000000 -0500
@@ -1,7 +1,7 @@
 
 # This Makefile is for Mac OSX 10.6 (Snow Leopard) for 64 bit AFNI
 
-SW_ROOT   = /sw
+SW_ROOT   = @PREFIX@
 
 USE_ZLIB  = -DHAVE_ZLIB
 LZLIB     = -lz
@@ -6,7 +6,7 @@
 USE_ZLIB  = -DHAVE_ZLIB
 LZLIB     = -lz
 USE_GIFTI = -DHAVE_GIFTI
-LGIFTI    = $(SW_ROOT)/lib/libexpat.a
+LGIFTI    = -lexpat
 
 # ----------------------------------------------------------------------
 # X configuration
@@ -12,13 +12,13 @@
 # X configuration
 #
 # uncomment to build using local /usr/local/afniX 'X' tree
-USE_LOCAL_X_TREE = 1
+#USE_LOCAL_X_TREE = 1
 ifdef USE_LOCAL_X_TREE
     XROOT   = $(SW_ROOT)
     XROOT_I = -I$(XROOT)/include
     XROOT_L = -L$(XROOT)/lib
 else
-    XROOT = /sw
+    XROOT = @PREFIX@
     XROOT_L = -L$(XROOT)/lib
 endif
 
@@ -30,7 +30,7 @@
     XLIBS = $(XROOT)/lib64/libXm.a $(XROOT)/lib64/libXt.a
 else
     # default is static motif
-    XLIBS = $(XROOT)/lib/libXm.a -lXt
+    XLIBS = -lXm -lXt
 endif
 
 # in case user wants to override with system dynamic libs
@@ -49,8 +49,8 @@
 
 OMPFLAG = -fopenmp -DUSE_OMP
 
-IFLAGS = -I. $(XROOT_I) -I/usr/local/include -I/usr/X11R6/include -I/sw/include
-LFLAGS = -L. $(XROOT_L) -L/usr/lib -L/usr/local/lib -L/usr/X11R6/lib -L/sw/lib  -Wl,-x -Wl,-multiply_defined -Wl,warning -Wl,-bind_at_load
+IFLAGS = -I. $(XROOT_I) -I@PREFIX@/include -I/usr/X11R6/include 
+LFLAGS = -L. $(XROOT_L) -L@PREFIX@/lib -L/usr/X11R6/lib  -Wl,-x -Wl,-multiply_defined -Wl,warning -Wl,-bind_at_load
 
 CCSVD  = cc -m64 -O0 -no-cpp-precomp
 
@@ -75,8 +75,10 @@
 
 LINT = /usr/bin/lint -a -b -u -v -x $(IFLAGS) $(CCDEFS)
 
-INSTALLDIR = macosx_10.6_Intel_64
-LIBDIR = $(INSTALLDIR)
+INSTALLDIR = @INSTALLPREFIX@/bin
+LIBDIR = @INSTALLPREFIX@/lib/@PACKAGENAME@
+DOCDIR = @INSTALLPREFIX@/share/doc/@PACKAGENAME@
+INCLUDEDIR = @INSTALLPREFIX@/include/@PACKAGENAME@
 SHOWOFF = -DSHOWOFF=macosx_10.6_Intel_64
 
 INSTALL_PREREQ = suma
@@ -87,7 +89,7 @@
 
 # for dynamic linking
 
-LLIBS  = -lmri -lf2c $(XLIBS) -lXft -lfontconfig -lpng -liconv -lXmu -lXp -lXpm -lXext -lX11 $(LZLIB) $(LGIFTI) -lm -lc
+LLIBS  = -lmri -lf2c $(XLIBS) -lXft -lfontconfig -lpng -liconv -lXmu -lXpm -lXext -lX11 $(LZLIB) $(LGIFTI) -lm -lc -ljpeg
 
 # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 # For suma
diff -urN AFNI_2010_10_19_1028.orig/Makefile.INCLUDE AFNI_2010_10_19_1028/Makefile.INCLUDE
--- AFNI_2010_10_19_1028/SUMA/SUMA_Makefile.orig   2011-09-15 02:13:26.000000000 -0400
+++ AFNI_2010_10_19_1028/SUMA/SUMA_Makefile  2011-09-15 02:29:44.000000000 -0400
@@ -35,15 +35,15 @@
 CCMIN  = cc
 CCD    = $(CC) $(CCDEBS)
 # IFLAGS = -I. -I/usr/include -I/usr/include/sys -I/usr/X11R6/include
-IFLAGS = -I. -I/usr/X11R6/include -I/sw/include
-LFLAGS = -L. -L/usr/X11R6/lib -L/sw/lib -Wl,-multiply_defined -Wl,suppress
+IFLAGS = -I. -I/usr/X11R6/include -I@PREFIX@/include
+LFLAGS = -L. -L@PREFIX@/lib -L/usr/X11R6/lib -Wl,-multiply_defined -Wl,suppress
 
 CCSVD  = cc -O0 -fPIC -no-cpp-precomp
 
 PLUGIN_SUFFIX = so
 PLUGIN_LFLAGS = -flat_namespace -bundle -undefined suppress
 PLUGIN_CC     = $(CC) -dynamic -fno-common
-PLFLAGS       = -dynamic -L. -L/usr/X11R6/lib -L/sw/lib -Wl,-multiply_defined -Wl,suppress
+PLFLAGS       = -dynamic -L. -L@PREFIX@/lib -L/usr/X11R6/lib -Wl,-multiply_defined -Wl,suppress
 
 SPECIAL = -faltivec -framework Accelerate -DUSE_ALTIVEC
 endif
@@ -59,10 +59,10 @@
 
 ifndef SUMA_INCLUDE_PATH
 #Don't prepend -Igts/src -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include/  here since only one program needs them
-SUMA_INCLUDE_PATH = -I/usr/X11R6/include -I./ -I../ -Igts/src -I/sw/include/glib-2.0 -I/sw/lib/glib-2.0/include -I/sw/include
+SUMA_INCLUDE_PATH = -I./ -I../ -I@PREFIX@/include/glib-2.0 -I@PREFIX@/lib/glib-2.0/include -I@PREFIX@/include -I/usr/X11R6/include  -Igts/src 
 endif
 ifndef SUMA_LINK_PATH
-SUMA_LINK_PATH = -L/usr/lib -L/usr/X11R6/lib -L../ -L/usr/local/lib -L/sw/lib
+SUMA_LINK_PATH = -L../ -L@PREFIX@/lib -L/usr/X11R6/lib
 endif
 ifndef SUMA_LINK_LIB
 #No need for those unless you are using SUMA_MOTIF_GLXAREA
@@ -84,7 +84,7 @@
 endif
 
 ifndef TAR
-TAR = /sw/bin/tar
+TAR = @PREFIX@/bin/tar
 endif
 
 ifndef RM
--- AFNI_2010_10_19_1028.orig/Makefile.INCLUDE	2011-05-25 15:15:23.000000000 -0400
+++ AFNI_2010_10_19_1028/Makefile.INCLUDE	2011-09-15 03:17:49.000000000 -0400
@@ -46,7 +46,7 @@
 ## AFNI package, but included because they are useful.  Some of
 ## them are Open Source programs, not from the AFNI group at all.
 
-EXTRAS   = cjpeg djpeg whirlgif mpeg_encode myget Xphace rmz aiv $(EXPROGS)
+EXTRAS   = whirlgif mpeg_encode myget Xphace rmz aiv $(EXPROGS)
 
 # mpegtoppm in above list
 
@@ -213,6 +213,12 @@
 
 $(INSTALLDIR):
 	if [ ! -d $(INSTALLDIR) ]; then $(MKDIR) -p $(INSTALLDIR); echo Made directory $(INSTALLDIR); fi
+$(DOCDIR):
+	if [ ! -d $(DOCDIR) ]; then $(MKDIR) -p $(DOCDIR); echo Made directory $(DOCDIR); fi
+$(LIBDIR):
+	if [ ! -d $(LIBDIR) ]; then $(MKDIR) -p $(LIBDIR); echo Made directory $(LIBDIR); fi
+$(INCLUDEDIR):
+	if [ ! -d $(INCLUDEDIR) ]; then $(MKDIR) -p $(INCLUDEDIR); echo Made directory $(INCLUDEDIR); fi
 
 ### for those on crippled systems
 
@@ -1568,21 +1574,23 @@
 
 ### Put things in their places
 
-install: $(INSTALLDIR) $(INSTALL_PREREQ)
+install: $(DOCDIR) $(INSTALLDIR) $(INSTALL_PREREQ)
 	$(MV) $(PROGRAMS) $(INSTALLDIR)
 	$(CP) $(SCRIPTS)  $(INSTALLDIR)
 	$(CP) $(PY_DIR)/*.py  $(R_DIR)/*.R $(INSTALLDIR)
-	if [ -f README.environment ]; then $(CP) README.*    $(INSTALLDIR); fi;
-	if [ -f AFNI.afnirc        ]; then $(CP) AFNI.afnirc $(INSTALLDIR); fi;
-	if [ -f AFNI.sumarc        ]; then $(CP) AFNI.sumarc $(INSTALLDIR); fi;
+	if [ -f README.environment ]; then $(CP) README.*    $(DOCDIR); fi;
+	if [ -f AFNI.afnirc        ]; then $(CP) AFNI.afnirc $(DOCDIR); fi;
+	if [ -f AFNI.sumarc        ]; then $(CP) AFNI.sumarc $(DOCDIR); fi;
+	if [ -f TTatlas+tlrc.HEAD  ]; then $(CP) TTatlas*  $(DOCDIR); fi; 
 
 install_noplug: $(INSTALLDIR)
 	$(MV) $(PROGRAMS_NOPLUG) $(INSTALLDIR)
 	$(CP) $(SCRIPTS) $(INSTALLDIR)
 	$(CP) $(PY_DIR)/*.py $(R_DIR)/*.R $(INSTALLDIR)
 
-install_lib: $(LIBDIR)
-	$(CP) libmri.a libmrix.a libf2c.a libcoxplot.a libvolpack.a $(LIBHEADERS) $(LIBDIR)
+install_lib: $(LIBDIR) $(INCLUDEDIR)
+	$(CP) libmri.a libmrix.a libf2c.a libcoxplot.a libvolpack.a $(LIBDIR)
+	$(CP) $(LIBHEADERS) $(INCLUDEDIR)
 
 # CYGWIN: must put the .exe suffix on the "mv" command for some reason
 
@@ -1968,8 +1976,8 @@
 	$(AR) q libmrix.a $(IMOBJS)
 	$(RANLIB) libmrix.a
 
-shared_objs: $(INSTALLDIR) libmri.so libmrix.so
-	$(MV) libmri.so libmrix.so $(INSTALLDIR)
+shared_objs: $(LIBDIR) libmri.so libmrix.so
+	$(MV) libmri.so libmrix.so $(LIBDIR)
 
 ###################################################################
 # Plugin stuff
@@ -2032,10 +2040,10 @@
 
 laconte_plugins: plug_3dsvm.$(SO)
 
-install_plugins: $(INSTALLDIR)
-	$(MV) *.$(PLUGIN_SUFFIX) $(INSTALLDIR)
-	$(CP) faces/face_*.jpg faces/splash_*.jpg poems/poem_*.txt $(INSTALLDIR)
-	echo Plugins put in directory $(INSTALLDIR):
+install_plugins: $(LIBDIR)
+	$(MV) *.$(PLUGIN_SUFFIX) $(LIBDIR)
+	$(CP) faces/face_*.jpg faces/splash_*.jpg poems/poem_*.txt $(LIBDIR)
+	echo Plugins put in directory $(LIBDIR):
 	echo Do not forget to setenv AFNI_PLUGINPATH appropriately
 
 .c.$(SO):afni_plugin.h afni.h 3ddata.h
@@ -2736,6 +2744,7 @@
 	( cd SUMA ;	\
 	rm -f libSUMA.a	;\
 	$(MAKE) -f $(SUMA_MAKEFILE_NAME) clean MarchingCubes.o libSUMA.a 'INSTALLDIR=$(INSTALLDIR)' \
+	'LIBDIR=$(LIBDIR)' \
 	'SUMA_INCLUDE_PATH=$(SUMA_INCLUDE_PATH)' \
 	'SUMA_BIN_ARCHIVE=$(SUMA_BIN_ARCHIVE)' \
 	'RANLIB=$(RANLIB)' \
@@ -2743,8 +2752,8 @@
 	'CC=$(CC)' 'RM=$(RM)' 'CEXTRA=$(CEXTRA)' 'MV=$(MV)' 'CP=$(CP)'	\
 	'TAR=$(TAR)' 'MKDIR=$(MKDIR)';	\
 	cd ../	;	\
-	if [ ! -d $(INSTALLDIR) ]; then $(MKDIR) -p $(INSTALLDIR); echo WARNING: directory $(INSTALLDIR) has been created. ; fi	;\
-	$(CP) SUMA/libSUMA.a ${INSTALLDIR}; \
+	if [ ! -d $(LIBDIR) ]; then $(MKDIR) -p $(LIBDIR); echo WARNING: directory $(LIBDIR) has been created. ; fi ;\
+	$(CP) SUMA/libSUMA.a ${LIBDIR}; \
 	$(CP) SUMA/libSUMA.a ./;	)
 
 libgts.a:
@@ -2752,14 +2761,15 @@
 	rm -f libgts.a	;\
 	$(MAKE) -f $(SUMA_MAKEFILE_NAME) libgts.a ;	\
 	cd ../	;	\
-	if [ ! -d $(INSTALLDIR) ]; then $(MKDIR) -p $(INSTALLDIR); echo WARNING: directory $(INSTALLDIR) has been created. ; fi	;\
-	$(CP) SUMA/libgts.a ${INSTALLDIR}; \
+	if [ ! -d $(LIBDIR) ]; then $(MKDIR) -p $(LIBDIR); echo WARNING: directory $(LIBDIR) has been created. ; fi ;\
+	$(CP) SUMA/libgts.a ${LIBDIR}; \
 	$(CP) SUMA/libgts.a ./;	)
 
 libGLws.a:
 	( cd SUMA ;	\
 	rm -f libGLws.a	;\
 	$(MAKE) -f $(SUMA_MAKEFILE_NAME) libGLws.a 'INSTALLDIR=$(INSTALLDIR)' \
+	'LIBDIR=$(LIBDIR)' \
 	'SUMA_INCLUDE_PATH=$(SUMA_INCLUDE_PATH)' \
 	'SUMA_BIN_ARCHIVE=$(SUMA_BIN_ARCHIVE)' \
 	'RANLIB=$(RANLIB)' \
@@ -2767,8 +2777,8 @@
 	'CC=$(CC)' 'RM=$(RM)' 'CEXTRA=$(CEXTRA)' 'MV=$(MV)' 'CP=$(CP)'	\
 	'TAR=$(TAR)' 'MKDIR=$(MKDIR)';	\
 	cd ../	;	\
-	if [ ! -d $(INSTALLDIR) ]; then $(MKDIR) -p $(INSTALLDIR); echo WARNING: directory $(INSTALLDIR) has been created. ; fi	;\
-	$(CP) SUMA/libGLws.a ${INSTALLDIR}; \
+	if [ ! -d $(LIBDIR) ]; then $(MKDIR) -p $(LIBDIR); echo WARNING: directory $(LIBDIR) has been created. ; fi ;\
+	$(CP) SUMA/libGLws.a ${LIBDIR}; \
 	$(CP) SUMA/libGLws.a ./;	)
 ###
 #link executables but check for libraries first and create them if needed	
--- AFNI_2010_10_19_1028/siemens_dicom_csa.c.orig	2012-12-27 14:01:22.000000000 -0500
+++ AFNI_2010_10_19_1028/siemens_dicom_csa.c	2012-12-27 14:07:04.000000000 -0500
@@ -452,7 +452,7 @@
 
    if( ! mstr ) {
       if( g_MDH_verb > 2 ) fprintf(stderr, "-- CFMST, no Mosaic string\n");
-      return;
+      return 0;
    }
 
    off = mstr - instr;  /* offset of Mosaic string into field */
@@ -470,7 +470,7 @@
 
    if( s2 ) rem = rem2;  /* after verbose, update remaining length */
 
-   if( rem <= 0 ) return;
+   if( rem <= 0 ) return 0;
 
    process_csa_data((unsigned char *)instr, el_len, g_MDH_verb,
                                             g_MDH_verb>3, start_txt);
--- AFNI_2010_10_19_1028/thd_brainormalize.c.orig	2012-12-27 14:50:40.000000000 -0500
+++ AFNI_2010_10_19_1028/thd_brainormalize.c	2012-12-27 14:51:30.000000000 -0500
@@ -650,7 +650,7 @@
    int *hsv , *csv ;
    shortvox *tar ;
 
-   if( n < 2 || ar == NULL ) return ;
+   if( n < 2 || ar == NULL ) return 0;
 
    /* decreasing order desired?  flip values */
 
@@ -669,7 +669,7 @@
      else if( sval > stop ) stop = sval ;
    }
    nsv = stop-sbot+1 ;   /* number of distinct values */
-   if( nsv <= 1 ) return ;
+   if( nsv <= 1 ) return 0;
 
    /* build hsv[i] = how many have value = sbot+i
             csv[i] = how many have value < sbot+i, i=0..nsv-1 */
@@ -727,7 +727,7 @@
    if( dec )
      for( ii=0 ; ii < n ; ii++ ) ar[ii].val = -ar[ii].val ;
 
-   return ;
+   return 0;
 }
 
 /*--------------------------------------------------------------------------*/
--- AFNI_2010_10_19_1028/mri_warp.c.orig	2012-12-27 15:25:38.000000000 -0500
+++ AFNI_2010_10_19_1028/mri_warp.c	2012-12-27 15:32:03.000000000 -0500
@@ -23,7 +23,7 @@
 
 static float sx_scale , sy_scale ;  /* global scaler data */
 
-INLINE void xxMRI_scaler( float xpr, float ypr, float *xx , float *yy )
+static inline void xxMRI_scaler( float xpr, float ypr, float *xx , float *yy )
 {
    *xx = sx_scale * xpr ;
    *yy = sy_scale * ypr ;
@@ -338,7 +338,7 @@
 
 static float rot_dx , rot_dy , rot_cph , rot_sph ;    /* global rotfunc data */
 
-INLINE void xxMRI_rotfunc( float xpr , float ypr , float *xx , float *yy )
+static inline void xxMRI_rotfunc( float xpr , float ypr , float *xx , float *yy )
 {
    *xx =  rot_cph * xpr + rot_sph * ypr + rot_dx ;
    *yy = -rot_sph * xpr + rot_cph * ypr + rot_dy ;
--- AFNI_2010_10_19_1028/svm/3dsvm_common.c.orig	2012-12-27 15:48:28.000000000 -0500
+++ AFNI_2010_10_19_1028/svm/3dsvm_common.c	2012-12-27 15:49:46.000000000 -0500
@@ -1566,7 +1566,7 @@
           kernelName);
     }
 
-    EXRETURN;
+    RETURN(0);
   }
 
   /* --- allocate memory ---*/
@@ -1577,7 +1577,7 @@
   Clear2c(maps->names, maps->nmaps);
   Clear2d(maps->data, maps->nmaps, maps->nvox);
 
-  EXRETURN;
+  RETURN(0);
 }
 
 freeModelMaps(MODEL_MAPS *maps) 
@@ -1587,7 +1587,7 @@
   free2d(maps->data, maps->nmaps);
   free2c(maps->names, maps->nmaps);
   
-  EXRETURN;
+  RETURN(0);
 }
 
 void addToModelMap_bucket ( MODEL_MAPS *maps, AFNI_MODEL *afni_model,
