📄 libjava.exp
字号:
# Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundationload_lib "libgloss.exp"# GCJ_UNDER_TEST is the compiler under test.global tmpdirif ![info exists tmpdir] { set tmpdir "/tmp"}# This is like `prune_warnings', but it also prunes away a warning# from the bytecode front end that we don't care about.proc libjava_prune_warnings {text} { set text [prune_warnings $text] set tlist [split $text \n] set len [llength $tlist] for {set i [expr {$len - 1}]} {$i >= 2} {incr i -1} { if {[string match "*unreachable bytecode*" [lindex $tlist $i]]} { # Delete this line, all other unreachable warnings and the previous # two lines containing the method and class. set j [expr {$i - 1}] while {[string match "*unreachable bytecode*" [lindex $tlist $j]]} { incr j -1 } incr j -1 set tlist [lreplace $tlist $j $i] set i $j } } return [join $tlist \n]}# This is like `target_compile' but it does some surgery to work# around stupid DejaGNU bugs. In particular DejaGNU has very poor# quoting, so for instance a `$' will be re-evaluated at spawn time.# We don't want that.proc libjava_tcompile {source destfile type options} { # This strange-looking expression really does quote the `$'. regsub -all -- {\$} $source {\$} source regsub -all -- {\$} $destfile {\$} destfile return [target_compile $source $destfile $type $options]}# Read an `xfail' file if it exists. Returns a list of xfail tokens.proc libjava_read_xfail {file} { if {! [file exists $file]} { return "" } set fd [open $file r] set tokens [string trim [read $fd]] close $fd return $tokens}# Find a particular executable. FIXME: this relies on DejaGnu# internals. These should probably be exposed in a better way.proc libjava_find_program {prog} { global tool_root_dir set file [lookfor_file $tool_root_dir $prog] if { $file == "" } { set file [lookfor_file $tool_root_dir gcc/$prog]; } if {$file == ""} { set file $prog } return $file}# Find `jv-scan'.proc find_jvscan {} { return [libjava_find_program jv-scan]}# Find `gcjh'.proc find_gcjh {} { return [libjava_find_program gcjh]}proc find_javac {} { global SUN_JAVAC GCJ_UNDER_TEST env libgcj_jar # If JDK doesn't run on your platform but some other # JDK-compatible javac does, you may set SUN_JAVAC to point to it. # One of the most important properties of a SUN_JAVAC is that it # must create class-files even for classes that have not been # specified in the command line, but that were needed to compile # those that have. For example, Pizza won't do it, but you can # use `kaffe sun.tools.javac.Main', if you have Sun's classes.zip # in the kaffe's default search path. if {![info exists SUN_JAVAC]} { if {[info exists env(SUN_JAVAC)]} { set SUN_JAVAC $env(SUN_JAVAC) } else { set SUN_JAVAC "$GCJ_UNDER_TEST -C -I$libgcj_jar" } } return $SUN_JAVAC}proc bytecompile_file { file objdir {classpath {}} } { global env set dirname [file dirname $file] set javac [find_javac] if {$classpath != ""} then { set env(CLASSPATH) $classpath } set here [pwd] cd $dirname if {[catch { set q [eval exec "$javac [list $file] -d $objdir 2>@ stdout"] } msg]} then { verbose "couldn't compile $file: $msg" set r 0 } else { set r 1 } cd $here return $r}set libjava_initialized 0## Build the status wrapper library as needed.#proc libjava_init { args } { global wrapper_file; global wrap_compile_flags; 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 if { $libjava_initialized == 1 } { return; } if ![info exists GCJ_UNDER_TEST] { if [info exists TOOL_EXECUTABLE] { set GCJ_UNDER_TEST $TOOL_EXECUTABLE; } else { if [info exists env(GCJ)] { set GCJ_UNDER_TEST $env(GCJ) } else { set GCJ_UNDER_TEST "[find_gcj]" } } } # Find the libgcj jar file. set libgcj_jar [glob $objdir/../libgcj-*.jar] verbose "jar file is $libgcj_jar" # FIXME: This finds libgcj.spec for the default multilib. # If thread models differ between multilibs, this has to be moved # to libjava_arguments set specdir [libjava_find_spec] # The -B is so we find libgcj.spec. set text [eval exec "$GCJ_UNDER_TEST -B$specdir -v 2>@ stdout"] regexp -- "Thread model: (\[^\n\]+)\n" $text ignore model set libjava_uses_threads [expr {! ($model == "no" || $model == "none" || $model == "single")}] # 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] { set result [build_wrapper "testglue.o"]; if { $result != "" } { set wrapper_file [lindex $result 0]; set wrap_compile_flags [lindex $result 1]; } else { warning "Status wrapper failed to build." } } # 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 {$gccdir != ""} { set gccdir [file dirname $gccdir] lappend libjava_libgcc_s_path $gccdir set compiler ${gccdir}/xgcc if { [is_remote host] == 0 && [which $compiler] != 0 } { foreach i "[exec $compiler --print-multi-lib]" { set mldir "" regexp -- "\[a-z0-9=/\.-\]*;" $i mldir set mldir [string trimright $mldir "\;@"] if { "$mldir" == "." } { continue } if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] == 1 } { lappend libjava_libgcc_s_path "${gccdir}/${mldir}" } } } } set libjava_initialized 1}# Find a library. We know where libtool puts the actual libraries,# and we look there. The implementation is fairly hacky. We can't# compile with -nodefaultlibs, because that will also eliminate the# system libraries we need. In order to have gcj still work, it must# find the appropriate libraries so we must add -L options for their# 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# 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" } } # 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 ""}# Find libgcj.spec. We need to use the file corresponding to the multilib# under test since they might differ. Append a trailing slash since this# 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'.proc libjava_find_gij {} { global base_dir set gp [get_multilibs] if {$gp != ""} { set file $gp/libjava/gij } else { set file $base_dir/../gij } if {[file exists $file]} { return $file } return gij}# Remove a bunch of files.proc gcj_cleanup {args} { foreach file $args { if {[string match *.o $file]} { verbose "removing [file rootname $file].lo" file delete -force [file rootname $file].lo } file delete -force -- $file verbose "removing $file" } # It is simplest to do this instead of trying to figure out what # bits in .libs ought to be removed. catch {system "rm -rf .libs"}}# Compute arguments needed for compiler. MODE is a libtool mode:# either compile or link.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 global tmpdir global runtests global env global tool_root_dir global libgcj_jar global libjava_libgcc_s_path if [info exists LIBJAVA] { set libjava $LIBJAVA; } else { 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] { foreach item [split $dir " "] { switch -glob -- $item { "-L*" { lappend lpath [string range $item 2 end] } } } } set lpath [concat $lpath $libjava_libgcc_s_path] set ld_library_path [join $lpath :] # 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" verbose "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)" # Set the CLASSPATH environment variable verbose "CLASSPATH is .:$srcdir/$subdir:$objdir:$libgcj_jar" global env set env(CLASSPATH) ".:$srcdir/$subdir:$objdir:$libgcj_jar" 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" lappend args debug } if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } { lappend args "libs=${gluefile}" lappend args "ldflags=$wrap_flags" } if [info exists TOOL_OPTIONS] { lappend args "additional_flags=$TOOL_OPTIONS" } # Determine libgcj.spec corresponding to multilib under test. set specdir [libjava_find_spec] # Search for libtool. We need it to link. set found_compiler 0 set d [absolute $objdir] foreach x {. .. ../.. ../../..} { if {[file exists $d/$x/libtool]} then { # We have to run silently to avoid DejaGNU lossage. lappend args \ "compiler=$d/$x/libtool --silent --tag=GCJ --mode=$mode $GCJ_UNDER_TEST -B$specdir" set found_compiler 1 break } } if {! $found_compiler} { # Append -B$specdir so that we find libgcj.spec before it # is installed. lappend args "compiler=$GCJ_UNDER_TEST -B$specdir" } # 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" } } return $args}# Link a bunch of objects into a program. MAIN is the name of the# class holding `main'. Return 0 on failure.proc gcj_link {program main files {options {}}} { set arguments [libjava_arguments link] if {[llength $options]} { eval lappend arguments $options } lappend arguments "additional_flags=--main=$main" set x [libjava_prune_warnings \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -