Index: /trunk/psconfig/pschecklibs
===================================================================
--- /trunk/psconfig/pschecklibs	(revision 12495)
+++ /trunk/psconfig/pschecklibs	(revision 12496)
@@ -167,5 +167,5 @@
 set nonomatch
 foreach f ( $needlibs )
-    foreach g ( $syslibpath $libdir $libpath )
+    foreach g ( $libdir $libpath $syslibpath )
         if (! -e $g) continue
 	set name = $g/lib$f.a
@@ -184,5 +184,5 @@
 # check for termcap, curses, etc
 foreach f ( ncurses curses termcap )
-    foreach g ( $syslibpath $libdir $libpath )
+    foreach g ( $libdir $libpath $syslibpath )
 	set name = $g/lib$f.a
 	if (-e $name[1]) goto got_curses;
@@ -207,4 +207,11 @@
 endif    
 
+# add the CPATH
+if ($?CPATH) then 
+  set incpath = `echo $CPATH | tr ':' ' '`
+else
+  set incpath = ""
+endif
+
 # check for headers
 echo ""
@@ -213,5 +220,5 @@
 set incdirs = ""
 foreach f ( $needincs )
-  foreach g ( $sysincpath $incdir )
+  foreach g ( $incdir $incpath $sysincpath )
     set name = "$g/$f"
     if (-e $name) goto got_inc;
Index: /trunk/psconfig/psconfig.sh
===================================================================
--- /trunk/psconfig/psconfig.sh	(revision 12495)
+++ /trunk/psconfig/psconfig.sh	(revision 12496)
@@ -97,4 +97,5 @@
 setenv PSVERSION $args[1]
 
+if ($?CPATH == 0) setenv CPATH
 if ($?LD_LIBRARY_PATH == 0) setenv LD_LIBRARY_PATH
 if ($?PKG_CONFIG_PATH == 0) setenv PKG_CONFIG_PATH
@@ -204,4 +205,32 @@
 endif 
 
+# set CPATH, used to find include files
+set incdir  = {$PSCONFDIR}/{$PSCONFIG}/include
+set newpath = ""
+set pathlist = `echo $CPATH | tr ':' '\n'`
+foreach name ($pathlist)
+  echo $name | grep $PSCONFDIR > /dev/null
+  if ($status == 0) continue
+  if ($newpath == "") then
+    set newpath = {$name}:
+  else
+    set newpath = {$newpath}{$name}:
+  endif
+end
+if ("$PSCONFIG" == "none") then
+  if ("$newpath" == "") then
+    unsetenv CPATH
+  else
+    setenv CPATH {$newpath}
+  endif 
+else
+  if ("$newpath" == "") then
+    setenv CPATH {$incdir}:
+  else
+    setenv CPATH {$incdir}:{$newpath}
+  endif 
+endif 
+
+# set LIBRARY_PATH and LD_LIBRARY_PATH, used to find libraries
 set libdir  = {$PSCONFDIR}/{$PSCONFIG}/lib
 set newpath = ""
@@ -219,12 +248,16 @@
   if ("$newpath" == "") then
     unsetenv LD_LIBRARY_PATH
+    unsetenv LIBRARY_PATH
   else
     setenv LD_LIBRARY_PATH {$newpath}
+    setenv LIBRARY_PATH {$newpath}
   endif 
 else
   if ("$newpath" == "") then
     setenv LD_LIBRARY_PATH {$libdir}:
+    setenv LIBRARY_PATH {$libdir}:
   else
     setenv LD_LIBRARY_PATH {$libdir}:{$newpath}
+    setenv LIBRARY_PATH {$libdir}:{$newpath}
   endif 
 endif 
@@ -291,6 +324,6 @@
   alias  psperlbuild perl Build.PL
 else
-  alias  psconfigure configure --prefix={$PSCONFDIR}/{$PSCONFIG} --bindir=$bindir --libdir=$libdir --includedir={$PSCONFDIR}/{$PSCONFIG}/include --sysconfdir={$PSCONFDIR}/{$PSCONFIG}/etc --datadir={$PSCONFDIR}/share --mandir={$PSCONFDIR}/man
-  alias  psautogen autogen.sh --bindir=$bindir --libdir=$libdir --mandir=$mandir --includedir={$PSCONFDIR}/{$PSCONFIG}/include --sysconfdir={$PSCONFDIR}/{$PSCONFIG}/etc --datadir={$PSCONFDIR}/share
+  alias  psconfigure configure --prefix={$PSCONFDIR}/{$PSCONFIG} --bindir=$bindir --libdir=$libdir --mandir=$mandir --includedir=$incdir --sysconfdir={$PSCONFDIR}/{$PSCONFIG}/etc --datadir={$PSCONFDIR}/share
+  alias  psautogen autogen.sh  --prefix={$PSCONFDIR}/{$PSCONFIG} --bindir=$bindir --libdir=$libdir --mandir=$mandir --includedir=$incdir --sysconfdir={$PSCONFDIR}/{$PSCONFIG}/etc --datadir={$PSCONFDIR}/share
   alias  psperlbuild perl Build.PL --prefix {$PSCONFDIR}/{$PSCONFIG} --install_path script=$bindir --install_path arch=$bindir --install_path bin=$bindir --install_path lib=$libdir --install_path bindoc={$PSCONFDIR}/man/man1 --install_path libdoc={$PSCONFDIR}/man/man3
   setenv ACLOCAL_FLAGS "-I $PSCONFDIR/share/aclocal"
