Description: Configure Debian-specific installation paths
  This allows for splitting libraries, plugins and pure data into /usr/lib
  and /usr/share, instead of having to dump everything into a single directory.
Author: Michael Hanke <michael.hanke@gmail.com>
Last-Update: 2010-09-29
--- a/afni_func.c
+++ b/afni_func.c
@@ -6437,6 +6437,8 @@
    /*----- get path to search -----*/
 
                        epath = getenv("AFNI_PLUGINPATH") ;
+   /* Debian puts them into a separate dir */
+   epath = "/usr/share/afni/poems";
    if( epath == NULL ) epath = getenv("AFNI_PLUGIN_PATH") ;
    if( epath == NULL ) epath = getenv("PATH") ;
    if( epath == NULL ){ num_poem=-1; EXRETURN ; }
--- a/afni_splash.c
+++ b/afni_splash.c
@@ -666,6 +666,8 @@
    /*----- get path to search -----*/
 
                        epath = getenv("AFNI_PLUGINPATH") ;
+   /* Debian puts them into a separate dir */
+   epath = "/usr/share/afni/pics";
    if( epath == NULL ) epath = getenv("AFNI_PLUGIN_PATH") ;
    if( epath == NULL ) epath = getenv("PATH") ;
    if( epath == NULL ) epath = getenv("HOME") ;
--- a/thd_ttatlas_query.c
+++ b/thd_ttatlas_query.c
@@ -553,6 +553,8 @@
    if( !first ) return adnam ;
    first = 0 ;
                        epath = getenv("AFNI_PLUGINPATH") ;
+   /* Debian puts them into a separate dir */
+   epath = "/usr/share/afni/atlases";
    if( epath == NULL ) epath = getenv("AFNI_PLUGIN_PATH") ;
    if( epath == NULL ) epath = getenv("PATH") ;
    if( epath == NULL ) return NULL ;  /* this is bad */
@@ -635,6 +637,8 @@
       /*----- get path to search -----*/
 
                           epath = getenv("AFNI_PLUGINPATH") ;
+      /* Debian puts them into a separate dir */
+      epath = "/usr/share/afni/atlases";
       if( epath == NULL ) epath = getenv("AFNI_PLUGIN_PATH") ;
       if( epath == NULL ) epath = getenv("PATH") ;
       if( epath == NULL ) RETURN(dset) ;
--- a/afni.c
+++ b/afni.c
@@ -4614,12 +4614,31 @@
       /*-- 20 Dec 2001: Try to read a "global" session --*/
       /*-- 11 May 2002: Move read global session up here --*/
 
+      char debian_atlases[30] = "/usr/share/afni/atlases";
       eee = getenv( "AFNI_GLOBAL_SESSION" ) ;   /* where it's supposed to be */
+      /* Debian: if there is now global session, use the atlases */
+      if( eee == NULL ){
+         eee = debian_atlases ;
+         REPORT_PROGRESS("ONLY ATLASES");
+      }
       if( eee != NULL ){
          THD_3dim_dataset *dset ;
          STATUS("reading global session") ;
          gss =
           GLOBAL_library.session = THD_init_session( eee ); /* try to read datasets */
+         /* Debian: always add the global atlas dir, if not the only global
+          * session */
+         if( gss != NULL ){
+             /* do not add twice */
+             if ( eee != debian_atlases ){
+                 REPORT_PROGRESS("PLUS ATLASES");
+                 AFNI_append_sessions(gss, THD_init_session( debian_atlases));
+             }
+         } else {
+            /* try reading the atlases (again) in case failure on custom
+             * session dir caused nothing to be loaded */
+            gss = GLOBAL_library.session = THD_init_session( debian_atlases );
+         }
 
          if( gss != NULL ){                               /* got at least one */
             gss->parent = NULL ;                          /* parentize them */
