3 # Script to generate a Cygwin makefile for running unit tests.
5 # Copyright 2002 Geoffrey Hausheer
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 sub create_archive($$\@);
29 # set this variable to point to your windows headers
30 my ($windows_includes) ="/usr/include/w32api";
31 # set this variable to your compiler options
32 my($cc_opts)= "-g -O2 -Wall -mpreferred-stack-boundary=2 -D_REENTRANT";
42 # parse command-line options
45 my $arg = shift @ARGV;
46 if ($arg eq "-h") { usage; }
49 $topobjdir = shift @ARGV;
50 usage unless (-d $topobjdir);
63 # check/detect topobjdir
64 # NOTE: Checking for configure is not ideal, but it seems to work
65 if (defined($topobjdir))
67 unless (-f $topobjdir . "/configure")
69 printf STDERR "Wrong -T argument, %s/configure does not exist\n", $topobjdir;
73 else # try to detect it automatically
75 if (-f "./configure") { $topobjdir = "."; }
76 elsif (-f "../configure") { $topobjdir = ".."; }
77 elsif (-f "../../configure") { $topobjdir = "../.."; }
78 elsif (-f "../../../configure") { $topobjdir = "../../.."; }
80 printf STDERR "Couldn't locate 'configure', and so no top-level directory\n";
87 open FIND_FH, "find . -type d -name tests -print |";
94 #start writing the makefile in the root directory
95 open MAKE_FH,">Makefile.cyg";
96 print MAKE_FH "CC = gcc\n";
97 print MAKE_FH "WINDOWS_HEADERS = $windows_includes\n";
98 print MAKE_FH "INCLUDE_DIRS = -I\$(WINDOWS_HEADERS) -I./include\n";
99 print MAKE_FH "CC_OPTS = \$(INCLUDE_DIRS) $cc_opts -include \$(WINDOWS_HEADERS)/windows.h\n";
101 # iterate over each 'tests' directory
102 foreach $dir (@testdirs) {
104 my($testname)=get_testname($dir);
105 $rootdir=fix_dir($dir);
106 unlink("$dir/testlist.c");
107 # Locate all '.c' files that arent 'spec'
108 my(@filelist)=grep(!/\.spec/,glob "$dir/*.c");
109 if(scalar(@filelist)) {
110 # Create a global list of all tests
111 foreach $file (@filelist) {
113 ($newfile = $file) =~ s/c$/ok/;
114 push(@ok_list,$newfile);
116 # create the testslist.c file for each directory
117 system("./programs/winetest/make_ctests $dir/*.c > $dir/testlist.c");
118 push @filelist,"$dir/testlist.c";
119 push(@gooddirs,$dir);
120 print MAKE_FH "# $dir\n";
121 # List all object files needed for this test
122 print MAKE_FH "TEST_O_FILES_$rootdir = \\\n";
123 foreach $file (@filelist) {
125 if($file ne $filelist[$#filelist]) {
126 print MAKE_FH " $file\\\n";
128 print MAKE_FH " $file\n";
131 print MAKE_FH "TEST_EXE_$rootdir = $dir/$testname.exe\n";
134 die "No C files found\n" if (!scalar(@gooddirs));
135 # The prerequisites for the tests are that the .ok fiels get created
136 print MAKE_FH "TEST_OK_FILES = \\\n";
137 foreach $file (@ok_list) {
138 if($file ne $ok_list[$#ok_list]) {
139 print MAKE_FH " $file\\\n";
141 print MAKE_FH " $file\n";
145 print MAKE_FH "all: \$(TEST_OK_FILES)\n";
148 #define how to make the executables
149 foreach $dir (@gooddirs) {
150 my($rootdir)=fix_dir($dir);
151 print MAKE_FH "\$(TEST_EXE_${rootdir}): \$(TEST_O_FILES_${rootdir}) ./programs/winetest/wtmain.o\n";
152 print MAKE_FH " \$(CC) \$(CC_OPTS) \$(TEST_O_FILES_${rootdir}) ./programs/winetest/wtmain.o -o \$@\n";
155 # define how to make to .ok files
156 foreach $file (@ok_list) {
157 my($dir,$test) = ($file =~ /^(.*[\\\/]+tests)[\\\/]+(.*)\.ok$/);
159 print MAKE_FH "$file: \$(TEST_EXE_". fix_dir($file) . ")\n";
160 print MAKE_FH " \$< $test && touch \$@\n";
162 # define how to make the .o files
164 print MAKE_FH "%.o: %.c\n";
165 print MAKE_FH " \$(CC) \$(CC_OPTS) -c -o \$@ \$<\n";
168 create_archive($afile,$archive,@testdirs);
180 -v verbose mode (can be specified multiple times)
181 -T dir set Wine tree top directory (autodetected if not specified)
182 -z file archive (zip) all needed files for test
183 -g file archive (tar.gz) all needed files for test
185 NOTE: You can specify either -g or -z but not both
191 my($rootdir)=($dir =~ /^[^\\\/]*[\\\/]+(.+)[\\\/]+tests/);
192 $rootdir =~ s/[\\\/]+/_/g;
198 my($testname)=($dir =~ /[\\\/]+([^\\\/]+)[\\\/]+tests/i);
202 sub create_archive($$\@) {
203 my($file,$arch,$dirlist)=@_;
207 print "Creating zip archive : $file\n";
208 $cmd = "zip -r $file ";
210 print "Creating tar.gz archive : $file\n";
211 $cmd = "tar -cvzf $file ";
213 foreach $dir (@$dirlist) {
215 foreach $cfile (grep(!/\.spec/,glob "$dir/*.c")) {
219 $cmd .= " ./programs/winetest/wtmain.c";
220 $cmd .= " ./include/wine";
221 $cmd .= " ./Makefile.cyg";