Added some support for cross-compilation using mingw32.
[wine/dcerpc.git] / programs / winetest / runtest
blob5b3974b7d584e2cd0105b769454ff63494228262
1 #!/usr/bin/perl
3 # Wrapper script to run tests from inside the Wine tree
5 # Usage: runtest [options] input_file [perl_args...]
7 # Copyright 2002 Alexandre Julliard
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 use strict;
26 sub usage
28 print STDERR <<EOF;
30 Usage: $0 [options] input_file [perl_args...]
32 Options:
33 -q quiet mode
34 -v verbose mode (can be specified multiple times)
35 -s announce successful tests
36 -p prog name of the program to run for C tests
37 -I dir prepend dir to Perl include path
38 -P name set the current platform name
39 -M names set the module names to be tested
40 -T dir set Wine tree top directory (autodetected if not specified)
42 EOF
43 exit 1;
46 # default values
47 my $platform = $ENV{WINETEST_PLATFORM};
48 $ENV{WINETEST_DEBUG} ||= 1;
50 my $topobjdir;
51 my $infile;
52 my $program;
53 my @include_dirs;
54 my @modules;
56 # parse command-line options
57 while ($#ARGV >= 0)
59 my $arg = shift @ARGV;
60 if ($arg eq "-h") { usage; }
61 if ($arg eq "-p") { $program = shift @ARGV; next; }
62 if ($arg eq "-q") { $ENV{WINETEST_DEBUG} = 0; next; }
63 if ($arg eq "-v") { $ENV{WINETEST_DEBUG}++; next; }
64 if ($arg eq "-s") { $ENV{WINETEST_REPORT_SUCCESS} = 1; next;}
65 if ($arg eq "-P") { $platform = shift @ARGV; next; }
66 if ($arg eq "-M") { push @modules, split /,/, shift @ARGV; next; }
67 if ($arg eq "-I") { push @include_dirs, shift @ARGV; next; }
68 if ($arg eq "-T")
70 $topobjdir = shift @ARGV;
71 usage unless (-d $topobjdir);
72 next;
74 $infile = $arg;
75 last;
78 # we must have found an input file
79 usage unless defined($infile);
81 if ($infile =~ /\.c$/ && !defined($program))
83 # set program to the .c file base name if not specified otherwise
84 ($program = $infile) =~ s/\.c$//;
87 # check/detect topobjdir
88 if (defined($topobjdir))
90 unless (-f $topobjdir . "/server/wineserver")
92 printf STDERR "Wrong -T argument, %s/server/wineserver does not exist\n", $topobjdir;
93 usage;
96 else # try to detect it automatically
98 if (-f "./server/wineserver") { $topobjdir = "."; }
99 elsif (-f "../server/wineserver") { $topobjdir = ".."; }
100 elsif (-f "../../server/wineserver") { $topobjdir = "../.."; }
101 elsif (-f "../../../server/wineserver") { $topobjdir = "../../.."; }
104 # check for include/ dir in script source directory and append it to search path
105 my $basedir = $0;
106 if ($basedir =~ /\//) { $basedir =~ s!/[^/]+$!!; }
107 else { $basedir = "."; }
108 if (-d $basedir . "/include") { push @include_dirs, $basedir . "/include"; }
110 $ENV{PERL5LIB} = join( ":", @include_dirs, split( ":", $ENV{PERL5LIB} ) );
111 if (@modules)
113 if (defined($ENV{WINEOPTIONS})) { $ENV{WINEOPTIONS} .= " "; }
114 $ENV{WINEOPTIONS} .= "--dll " . join(',',@modules) . "=b";
117 # set environment variables needed for Wine
118 if (defined($topobjdir))
120 chop($topobjdir = `cd $topobjdir && pwd`);
121 $ENV{LD_LIBRARY_PATH} = $topobjdir . ":" . $ENV{LD_LIBRARY_PATH};
122 $ENV{WINEDLLPATH} = $topobjdir . "/dlls";
123 $ENV{WINESERVER} = $topobjdir . "/server/wineserver";
124 $ENV{WINELOADER} = $topobjdir . "/wine";
125 $ENV{WINETEST_PLATFORM} = $platform || "wine";
126 $program ||= $topobjdir . "/programs/winetest/winetest";
128 else
130 $ENV{WINETEST_PLATFORM} = $platform || "windows";
133 # and now exec the program
134 $program ||= "winetest";
135 exec $program, $infile, @ARGV;
136 print STDERR "Could not exec $program\n";
137 exit 1;