Description: Alternative CMAKE-based buildsystem and shared lib configuration
 This new build-system allows for more streamlined build-config adjustments than
 the old one, instead for countless dedicated scenario makefiles all
 configurations options can be adjusted on a very fine grained level.
 .
 This patch also introduces changes that are required to build all AFNI-internal
 libraries as shared libs -- dramatically reducing the size of the binary build.
Forwarded: Rick Reynolds <reynoldr@mail.nih.gov>
Author: Michael Hanke <michael.hanke@gmail.com>, Bernd Feige <bernd.feige@uniklinik-freiburg.de>
Last-Update: 2010-09-21
--- a/src/SUMA/SUMA_gts.h
+++ b/src/SUMA/SUMA_gts.h
@@ -20,7 +20,6 @@
 #include "gts/config.h"
 #endif
 #include "gts.h"
-#include "gts-private.h"
 
 #include "SUMA_suma.h"
 
--- a/src/SUMA/SUMA_gts_insert.c
+++ b/src/SUMA/SUMA_gts_insert.c
@@ -7,6 +7,8 @@ inserting them via:
 #include "../../SUMA_gts_insert.c" 
 gts's surface.c works just fine
 */
+#include <stdlib.h>
+#include "gts.h"
 
 static int debug;
 
--- a/src/cs_qmed.c
+++ b/src/cs_qmed.c
@@ -18,6 +18,10 @@ float qmean_float( int n , float *ar )
    sum /= n ; return sum ;
 }
 
+#ifdef USE_OMP
+#include <omp.h>
+#endif
+
 /*------------------------------------------------------------------------
    Compute the median of an array of floats.  Will rearrange (partially
    sort) the array in the process.  The algorithm is based on Quicksort,
--- a/src/mri_dicom_hdr.c
+++ b/src/mri_dicom_hdr.c
@@ -95,18 +95,18 @@ int mri_siemens_slice_times(int * nalloc
 
 /* Dimon needs to compile without libmri     18 May 2006 */
 /* (this allows removal of rickr/l_mri_dicom_hdr.c)      */
-#ifndef FOR_DIMON
+/*#ifndef FOR_DIMON // causes problems linking to libmri (duplicate symbols)*/
 
 #include "mcw_malloc.h"
 #include "Amalloc.h"
 #include "debugtrace.h"    /* 10 Sep 2002 */
 
-#else
-
-#include "Amalloc.h"
-#include "dbtrace.h"
-
-#endif
+/* #else
+ * #include "Amalloc.h"
+ * #include "dbtrace.h"
+ *
+ * #endif
+ */
 
 /* cast int to pointer and vice-versa without warning messages */
 
--- a/src/mri_nstats.c
+++ b/src/mri_nstats.c
@@ -1,10 +1,7 @@
 #include "mrilib.h"
 
-/** if using OpenMP, this file should be #include-d into the main program! **/
-
 #ifdef USE_OMP
 #include <omp.h>
-#include "cs_qmed.c"
 #endif
 
 /* default fill and unfill values */
--- a/src/rickr/Dimon.c
+++ b/src/rickr/Dimon.c
@@ -212,6 +212,7 @@ static char * g_history[] =
 #define MAIN
 #define IFM_PROG_NAME   "Dimon"
 
+#include "mcw_malloc.h"
 #include "mrilib.h"
 #include "Dimon.h"      /* broken off from Imon.h */
 #include "realtime.h"
@@ -291,7 +292,7 @@ static int set_ftype(param_t * p, char *
 #include "l_mcw_glob.h"
 #include "thd_iochan.h"
 #include "mri_image.h"
-#include "dbtrace.h"
+#include "debugtrace.h"
 
 extern char  DI_MRL_orients[8];
 extern float DI_MRL_tr;
--- a/src/rickr/dimon_afni.c
+++ b/src/rickr/dimon_afni.c
@@ -8,8 +8,9 @@
 #include "mri_image.h"
 #include "mri_dicom_hdr.h"
 #include "vecmat.h"
+#include "mcw_malloc.h"
 #include "Amalloc.h"
-#include "dbtrace.h"
+#include "debugtrace.h"
 
 /*----------------------------------------------------------------------
  * dimon_afni.c
--- a/src/suma_gifti.c
+++ b/src/suma_gifti.c
@@ -262,9 +262,14 @@ static  gifti_image *afni_surf_to_gifti_
    }
    
    /* form image */
+/* Since this goes into a shared lib, we better do not rely on global symbols --
+ * should not have a huge impact, since this is just a debug message
+ */
+#if 0
    if( G.verb > 1 ) {  
       fprintf(stderr,"++ creating gifti_image \n" );
    }
+#endif
    
    /* basic step - create empty image (with a version string) 
       from gifti_create_image */
@@ -375,10 +380,15 @@ static  gifti_image *afni_surf_to_gifti_
       RETURN(gim);
    }
 
+/* Since this goes into a shared lib, we better do not rely on global symbols --
+ * should not have a huge impact, since this is just a debug message
+ */
+#if 0
    if( G.verb > 1 ) {  
       gifti_disp_gifti_image("afni_surf_to_gifti_surf :",gim, G.verb > 3);  
    }
-   
+#endif
+
    RETURN(gim);
 }
  
--- a/src/R_scripts/AFNIio.R
+++ b/src/R_scripts/AFNIio.R
@@ -9,7 +9,7 @@ SHOW_TRC <<- FALSE
 # Functions for library loading
 #------------------------------------------------------------------
 find.in.path <- function(file) { #Pretty much same as first.in.path
-   ff <- paste(strsplit(Sys.getenv('PATH'),':')[[1]],'/', file, sep='')
+   ff <- paste(strsplit(paste(Sys.getenv('PATH'),'/usr/lib/afni/lib', sep=':'),':')[[1]],'/', file, sep='')
    ff <- ff[lapply(ff,file.exists)==TRUE];
    aa <- gsub('//','/',ff[1], fixed=TRUE)
    if (is.na(aa)) aa <- NULL
@@ -155,12 +155,12 @@ exit.AFNI <- function(str='The piano has
 #Locate and load R_io.so
 set_R_io <- function() {
    rio <- 0
-   ll <- find.in.path('R_io.so')
+   ll <- find.in.path('librio.so')
    if (!is.null(ll)) {
       dd <- try(dyn.load(ll), silent=TRUE)
       # newer versions might return R_io.so   8 Dec 2017 [rickr]
-      if (dd[[1]]!="R_io" && dd[[1]]!="R_io.so") {
-         warn.AFNI(paste("Failed to load R_io.so with this error message:\n"));
+      if (dd[[1]]!="librio" && dd[[1]]!="librio.so") {
+         warn.AFNI(paste("Failed to load librio.so with this error message:\n"));
          dyn.load(ll)
       } else {
          rio <- 1
@@ -616,7 +616,7 @@ compressed.AFNI.name <- function(an) {
 
 modify.AFNI.name <- function (name, what="append", val="_new", cwd=NULL) {
    if (!is.loaded('R_SUMA_ParseModifyName')) {
-      err.AFNI("Missing R_io.so");
+      err.AFNI("Missing librio.so");
       return(NULL);
    }
    an <- .Call("R_SUMA_ParseModifyName", 
@@ -2922,7 +2922,7 @@ read.AFNI <- function(filename, verb = 0
 
 read.c.AFNI <- function(filename, verb = 0, ApplyScale = 1, PercMask=0.0) {
    if (!is.loaded('R_THD_load_dset')) {
-      err.AFNI("Missing R_io.so");
+      err.AFNI("Missing librio.so");
       return(NULL);
    }
    if (ApplyScale != 1 || PercMask != 0.0) {
@@ -3095,7 +3095,7 @@ write.c.AFNI <- function( filename, dset
    }
    
    if (!is.loaded('R_THD_write_dset')) {
-      err.AFNI("Missing R_io.so.");
+      err.AFNI("Missing librio.so.");
       return(NULL);
    } 
    
--- a/src/powell_int.c
+++ b/src/powell_int.c
@@ -19,7 +19,7 @@
 /** cf. powell_newuoa.[fc] **/
 
 #ifdef USE_OMP
-# include "powell_newuoa.c"
+//# include "powell_newuoa.c"
 #else
   extern int newuoa_(integer *n, integer *npt, doublereal *x,
                      doublereal *rhobeg, doublereal *rhoend, integer *maxfun,
