OSDN Git Service

2005-11-02 Andreas Tobler <a.tobler@schweiz.ch>
[pf3gnuchains/gcc-fork.git] / libjava / testsuite / lib / libjava.exp
index 972b7be..421b3d2 100644 (file)
@@ -1,6 +1,12 @@
-# Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation
+# Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation
 
-load_lib "libgloss.exp"
+proc load_gcc_lib { filename } {
+    global srcdir
+    load_file $srcdir/../../gcc/testsuite/lib/$filename
+}
+
+load_lib libgloss.exp
+load_gcc_lib target-libpath.exp
 
 # GCJ_UNDER_TEST is the compiler under test.
 
@@ -109,10 +115,11 @@ proc bytecompile_file { file objdir {classpath {}} } {
     }
     set here [pwd]
     cd $dirname
+    send_log "byte compile: $javac -g [list $file] -d $objdir 2>@ stdout\n"
     if {[catch {
-       set q [eval exec "$javac [list $file] -d $objdir 2>@ stdout"]
+       set q [eval exec "$javac -g [list $file] -d $objdir 2>@ stdout"]
     } msg]} then {
-       verbose "couldn't compile $file: $msg"
+       send_log "couldn't compile $file: $msg\n"
        set r 0
     } else {
        set r 1
@@ -132,11 +139,15 @@ proc libjava_init { args } {
     global libjava_initialized libjava_uses_threads
     global GCJ_UNDER_TEST
     global TOOL_EXECUTABLE
-    global original_ld_library_path
     global env objdir
     global env libgcj_jar
     global tool_root_dir
     global libjava_libgcc_s_path
+    global target_triplet
+
+    # We set LC_ALL and LANG to C so that we get the same error messages as expected.
+    setenv LC_ALL C
+    setenv LANG C
 
     if { $libjava_initialized == 1 } { return; }
 
@@ -171,16 +182,6 @@ proc libjava_init { args } {
     # Always set encoding used by gcj.
     append GCJ_UNDER_TEST " --encoding=UTF-8"
 
-    if [info exists env(LD_LIBRARY_PATH)] {
-       set original_ld_library_path $env(LD_LIBRARY_PATH)
-    } else {
-       if [info exists env(SHLIB_PATH)] {
-           set original_ld_library_path $env(SHLIB_PATH)
-       } else {
-           set original_ld_library_path ""
-       }
-    }
-
     set wrapper_file "";
     set wrap_compile_flags "";
     if [target_info exists needs_status_wrapper] {
@@ -196,10 +197,17 @@ proc libjava_init { args } {
     # Finally, add the gcc build directory so that we can find the
     # shared libgcc.  This, like much of dejagnu, is hideous.
     set libjava_libgcc_s_path {}
-    set gccdir [lookfor_file $tool_root_dir gcc/libgcc_s.so]
+
+    if { [istarget "*-*-darwin*"] } {
+       set so_extension "dylib"
+    } else {
+       set so_extension "so"
+    }
+    set gccdir [lookfor_file $tool_root_dir gcc/libgcc_s.${so_extension}]
     if {$gccdir != ""} {
        set gccdir [file dirname $gccdir]
        lappend libjava_libgcc_s_path $gccdir
+       verbose "libjava_libgcc_s_path = $libjava_libgcc_s_path"
        set compiler ${gccdir}/xgcc
        if { [is_remote host] == 0 && [which $compiler] != 0 } {
            foreach i "[exec $compiler --print-multi-lib]" {
@@ -209,7 +217,7 @@ proc libjava_init { args } {
                if { "$mldir" == "." } {
                    continue
                }
-               if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] == 1 } {
+               if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.${so_extension}.*]] >= 1 } {
                    lappend libjava_libgcc_s_path "${gccdir}/${mldir}"
                }
            }
@@ -227,28 +235,31 @@ proc libjava_init { args } {
 # paths.  However we can't simply use those libraries; we still need
 # libtool for linking.
 # Don't return the the lib${name}.la files here, since this causes the
-# libraries to be linked twice: once as lib${name}.so and another time
+# libraries to be linked twice: once as lib${name}.so/dylib and another time
 # via gcj's implicit -l${name}.  This is both unnecessary and causes the
 # Solaris ld to warn: attempted multiple inclusion of file.  This warning
 # is not ignored by the dejagnu framework and cannot be disabled.
 proc libjava_find_lib {dir name} {
     global base_dir
     set gp [get_multilibs]
-    foreach sub {.libs _libs} {
-       if {$gp != ""} {
-           if {[file exists $gp/$dir/$sub/lib${name}.a]} then {
-               # Just return the `-L' option.  The library itself
-               # will be picked up via the spec file.
-               return "-L$gp/$dir/$sub"
+    foreach extension {so dll dylib a} {
+       foreach sub {.libs _libs} {
+           if {$gp != ""} {
+               if {[file exists $gp/$dir/$sub/lib${name}.${extension}]} then {
+                   # Just return the `-L' option.  The library itself
+                   # will be picked up via the spec file.
+                   return "-L$gp/$dir/$sub"
+               }
+           }
+           # Just return the `-L' option.  The library itself will be
+           # picked up via the spec file.
+           set lib [findfile \
+                      $base_dir/../../$dir/$sub/lib${name}.${extension} \
+                      "-L$base_dir/../../$dir/$sub" \
+                      ""]
+           if {$lib != ""} {
+               return $lib
            }
-       }
-       # Just return the `-L' option.  The library itself will be
-       # picked up via the spec file.
-       set lib [findfile $base_dir/../../$dir/$sub/lib${name}.a \
-                  "-L$base_dir/../../$dir/$sub" \
-                  ""]
-       if {$lib != ""} {
-           return $lib
        }
     }
     return ""
@@ -259,28 +270,22 @@ proc libjava_find_lib {dir name} {
 # is used with -B.
 proc libjava_find_spec {} {
     global objdir
-    set gp [get_multilibs]
-
-    if {[file exists $gp/libjava/libgcj.spec]} then {
-       return "$gp/libjava/"
-    }
     return "$objdir/../"
 }
 
-# Find `gij'.
+# Find `gij'.  Return empty string if not found.
 proc libjava_find_gij {} {
-    global base_dir
-    set gp [get_multilibs]
-    if {$gp != ""} {
-       set file $gp/libjava/gij
-    } else {
-       set file $base_dir/../gij
-    }
+    global base_dir objdir
 
-    if {[file exists $file]} {
-       return $file
+    set gijdir [lookfor_file [get_multilibs] libjava];
+    # Fall back if get_multilibs fails.
+    if {$gijdir == ""} {
+      set gijdir "$objdir/.."
     }
-    return gij
+    if {! [file exists $gijdir/gij]} {
+       return ""
+    }
+    return $gijdir/gij
 }
 
 # Remove a bunch of files.
@@ -303,9 +308,6 @@ proc gcj_cleanup {args} {
 proc libjava_arguments {{mode compile}} {
     global base_dir
     global LIBJAVA
-    global LIBGC
-    global LIBQTHREADS
-    global LIBZ
     global srcdir subdir objdir
     global TOOL_OPTIONS
     global GCJ_UNDER_TEST
@@ -315,6 +317,9 @@ proc libjava_arguments {{mode compile}} {
     global tool_root_dir
     global libgcj_jar
     global libjava_libgcc_s_path
+    global libjava_ld_library_path
+    global ld_library_path
+    global target_triplet
 
     if [info exists LIBJAVA] {
        set libjava $LIBJAVA;
@@ -322,39 +327,14 @@ proc libjava_arguments {{mode compile}} {
        set libjava [libjava_find_lib libjava gcj]
     }
 
-    if [info exists LIBGC] {
-       set libgc $LIBGC;
-    } else {
-       set libgc [libjava_find_lib boehm-gc gcjgc]
-    }
-
-    if [info exists LIBQTHREADS] {
-       set libqthreads $LIBQTHREADS
-    } else {
-       set libqthreads [libjava_find_lib qthreads gcjcoop]
-    }
-
-    if [info exists LIBZ] {
-       set libz $LIBZ
-    } else {
-       set libz [libjava_find_lib zlib zgcj]
-    }
-
-    # FIXME: there's no way to determine whether -lpthread is
-    # required.  We should get this info from configure, or it should
-    # just be in the compiler driver.
-
     verbose "using LIBJAVA = $libjava" 2
-    verbose "using LIBGC = $libgc" 2
-    verbose "using LIBQTHREADS = $libqthreads" 2
-    verbose "using LIBZ = $libz" 2
     set args ""
 
     # Basically we want to build up a colon separated path list from
     # the value of $libjava.
 
-    set lpath {}
-    foreach dir [list $libjava $libgc $libz] {
+    set lpath "."
+    foreach dir [list $libjava] {
        foreach item [split $dir " "] {
            switch -glob -- $item {
                "-L*" {
@@ -365,32 +345,37 @@ proc libjava_arguments {{mode compile}} {
     }
 
     set lpath [concat $lpath $libjava_libgcc_s_path]
+    verbose "lpath = $lpath ; libgcc_s_path = $libjava_libgcc_s_path"
     set ld_library_path [join $lpath :]
+    set libjava_ld_library_path "$ld_library_path"
 
     # That's enough to make things work for the normal case.
     # If we wanted to handle an arbitrary value of libjava,
     # then we'd have to do a lot more work.
 
-    # Set variables the dynamic linker looks at.
-    global original_ld_library_path
-    setenv LD_LIBRARY_PATH "$ld_library_path:$original_ld_library_path"
-    setenv SHLIB_PATH "$ld_library_path:$original_ld_library_path"
+    set_ld_library_path_env_vars
+    if [info exists env(LD_LIBRARY_PATH)] {
+       verbose "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
+    }
 
-    verbose "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
+    # Determine CLASSPATH separator
+    if { [string match "i?86-pc-mingw32*" $target_triplet] } {
+       set sep ";"
+    } else {
+       set sep ":"
+    }
 
     # Set the CLASSPATH environment variable
-    verbose "CLASSPATH is .:$srcdir/$subdir:$objdir:$libgcj_jar"
     global env
-    set env(CLASSPATH) ".:$srcdir/$subdir:$objdir:$libgcj_jar"
+    set env(CLASSPATH) \
+       [join [list . $srcdir/$subdir $objdir $libgcj_jar] $sep]
+    verbose "CLASSPATH is $env(CLASSPATH)"
 
     if {$mode == "link"} {
-       global wrapper_file wrap_compile_flags;
-       lappend args "additional_flags=$wrap_compile_flags";
-       lappend args "libs=$wrapper_file";
-       lappend args "libs=$libjava";
-       lappend args "libs=$libgc";
-       lappend args "libs=$libqthreads"
-       lappend args "libs=$libz"
+       global wrapper_file wrap_compile_flags
+       lappend args "additional_flags=$wrap_compile_flags"
+       lappend args "libs=$wrapper_file"
+       lappend args "libs=$libjava"
        lappend args debug
     }
 
@@ -427,9 +412,13 @@ proc libjava_arguments {{mode compile}} {
     # Avoid libtool wrapper scripts when possible.
     # but not if libtool warnings results in FAILs
     if {$mode == "link"} {
-        if {! [istarget "*-*-cygwin*"] && ! [istarget "*-*-mingw*"] } {
-            lappend args "additional_flags=-no-install"
-        }
+       if {! [istarget "*-*-cygwin*"] && ! [istarget "*-*-mingw*"] } {
+           lappend args "additional_flags=-no-install"
+       }
+       if { [istarget "*-*-darwin*"] } {
+           lappend args "additional_flags=-bind_at_load"
+           lappend args "additional_flags=-multiply_defined suppress"
+       }
     }
 
     return $args
@@ -460,26 +449,25 @@ proc gcj_link {program main files {options {}}} {
 # Invoke the program and see what happens.  Return 0 on failure.
 proc gcj_invoke {program expectFile ld_library_additions} {
   global env
-  set lib_path $env(LD_LIBRARY_PATH)
+  global libjava_ld_library_path
+  global ld_library_path
 
-  set newval .
+  set ld_library_path "$libjava_ld_library_path"
   if {[llength $ld_library_additions] > 0} {
-    append newval :[join $ld_library_additions :]
+    append ld_library_path :[join $ld_library_additions :]
   }
-  append newval :$lib_path
 
-  setenv LD_LIBRARY_PATH $newval
-  setenv SHLIB_PATH $newval
-
-  verbose "LD_LIBRARY_PATH=$env(LD_LIBRARY_PATH)"
+  set_ld_library_path_env_vars
+  if [info exists env(LD_LIBRARY_PATH)] {
+    verbose "LD_LIBRARY_PATH=$env(LD_LIBRARY_PATH)"
+  }
 
   set result [libjava_load ./$program]
   set status [lindex $result 0]
   set output [lindex $result 1]
 
   # Restore setting
-  setenv LD_LIBRARY_PATH $lib_path
-  setenv SHLIB_PATH $lib_path
+  restore_ld_library_path_env_vars
 
   if {$status != "pass"} {
     verbose "got $output"
@@ -504,7 +492,22 @@ proc gcj_invoke {program expectFile ld_library_additions} {
 # Invoke a program and check its output.  EXECUTABLE is the program;
 # ARGS are the arguments to the program.  Returns 1 if tests passed
 # (or things were left untested), 0 otherwise.
-proc libjava_invoke {errname testName optName executable inpfile resultfile args} {
+proc libjava_invoke {errname testName optName executable inpfile resultfile
+                     ld_library_additions args} {
+    global env
+    global libjava_ld_library_path
+    global ld_library_path
+
+    set ld_library_path "$libjava_ld_library_path"
+    if {[llength $ld_library_additions] > 0} {
+       append ld_library_path :[join $ld_library_additions :]
+    }
+
+    set_ld_library_path_env_vars
+    if [info exists env(LD_LIBRARY_PATH)] {
+       verbose "LD_LIBRARY_PATH=$env(LD_LIBRARY_PATH)"
+    }
+
     upvar $optName opts
 
     if {[info exists opts(no-exec)]} {
@@ -521,6 +524,10 @@ proc libjava_invoke {errname testName optName executable inpfile resultfile args
     set result [libjava_load $executable $args "$inpfile"]
     set status [lindex $result 0]
     set output [lindex $result 1]
+
+    # Restore LD_LIBRARY_PATH setting.
+    restore_ld_library_path_env_vars
+
     if {[info exists opts(xfail-exec)]} then {
        setup_xfail *-*-*
     }
@@ -574,8 +581,6 @@ proc libjava_invoke {errname testName optName executable inpfile resultfile args
 #
 proc test_libjava_from_source { options srcfile compile_args inpfile resultfile exec_args } {
     global base_dir
-    global LIBJAVA
-    global LIBGC
     global srcdir subdir objdir
     global TOOL_OPTIONS
     global GCJ_UNDER_TEST
@@ -669,7 +674,7 @@ proc test_libjava_from_source { options srcfile compile_args inpfile resultfile
        set opts(xfail-output) x
     }
     if {[libjava_invoke $errname "source compiled test" opts $executable \
-          $inpfile $resultfile]} {
+          $inpfile $resultfile ""]} {
        # Everything ok, so clean up.
        eval gcj_cleanup $removeList
     }
@@ -681,8 +686,6 @@ proc test_libjava_from_source { options srcfile compile_args inpfile resultfile
 #
 proc test_libjava_from_javac { options srcfile compile_args inpfile resultfile exec_args } {
     global base_dir
-    global LIBJAVA
-    global LIBGC
     global srcdir subdir objdir
     global TOOL_OPTIONS
     global GCJ_UNDER_TEST
@@ -805,11 +808,11 @@ proc test_libjava_from_javac { options srcfile compile_args inpfile resultfile e
     # We purposely ignore errors here; we still want to run the other
     # appropriate tests.
     set gij [libjava_find_gij]
-    # libjava_find_gij will return `gij' if it couldn't find the
+    # libjava_find_gij will return "" if it couldn't find the
     # program; in this case we want to skip the test.
-    if {$INTERPRETER == "yes" && $gij != "gij"} {
+    if {$INTERPRETER == "yes" && $gij != ""} {
        libjava_invoke $errname "gij test" opts $gij \
-         $inpfile $resultfile $main_name
+         $inpfile $resultfile "" $main_name
     }
 
     # Initial arguments.
@@ -872,7 +875,7 @@ proc test_libjava_from_javac { options srcfile compile_args inpfile resultfile e
        set opts(xfail-output) x
     }
     if {[libjava_invoke $errname "bytecode->native test" opts $executable \
-          $inpfile $resultfile]} {
+          $inpfile $resultfile ""]} {
        # Everything ok, so clean up.
        eval gcj_cleanup $removeList
     }
@@ -916,20 +919,6 @@ proc default_libjava_version {} {
 proc default_libjava_start { } {
 }
 
-# On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
-# called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
-# (for the 64-bit ABI).  The right way to do this would be to modify
-# unix.exp -- but that's not an option since it's part of DejaGNU
-# proper, so we do it here, by trickery.  We really only need to do 
-# this on IRIX, but it shouldn't hurt to do it anywhere else.
-
-proc ${tool}_set_ld_library_path { name element op } {
-  setenv LD_LIBRARYN32_PATH [getenv LD_LIBRARY_PATH]
-  setenv LD_LIBRARY64_PATH [getenv LD_LIBRARY_PATH]
-}
-
-trace variable env(LD_LIBRARY_PATH) w ${tool}_set_ld_library_path
-
 # Local Variables:
 # tcl-indent-level:4
 # End: