Added support for BTrees in file header reading.
[wine] / programs / winetest / make_cygwin_makefiles
1 #!/usr/bin/perl -w
2 #
3 # Script to generate a Cygwin/Mingw makefile for running unit tests.
4 #
5 # Copyright 2002 Geoffrey Hausheer
6 #
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.
11 #
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.
16 #
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
20 #
21
22 use strict;
23
24 sub usage;
25 sub fix_dir;
26 sub get_testname;
27 sub create_archive($$\@);
28
29 # set this variable to point to your windows headers
30 my ($cygwin_windows_includes) ="/usr/include/w32api";
31 my ($mingw_windows_includes) ="/mingw/include";
32 my ($wine_windows_includes) ="./include";
33 my ($windows_includes)="";
34
35 #set the default headers to use
36 my ($default_headers) =\$cygwin_windows_includes;
37
38 # set this variable to your compiler options
39 my($cc_opts)= "-g -O2 -Wall -mpreferred-stack-boundary=2 -D_REENTRANT";
40
41 my($topobjdir);
42 my(@testdirs);
43 my(@gooddirs);
44 my(@ok_list)=();
45 my($dir);
46 my($file);
47 my($afile)="";
48 my($archive)="";
49 # parse command-line options
50 while ($#ARGV >= 0)
51 {
52     my $arg = shift @ARGV;
53     if ($arg eq "-h") { usage; }
54     if ($arg eq "-T")
55     {
56         $topobjdir = shift @ARGV;
57         usage unless (-d $topobjdir);
58         next;
59     }
60     if ($arg eq "-z") {
61       $afile = shift @ARGV;
62       $archive = "z";
63     }
64     if ($arg eq "-g") {
65       $afile = shift @ARGV;
66       $archive = "g";
67     }
68     if ($arg eq "-i") {
69       $windows_includes = shift @ARGV;
70       $default_headers = \$windows_includes;
71     }
72     if ($arg eq "-s") {
73       my($sys) = shift @ARGV;
74       if ($sys eq "cygwin") {
75         $default_headers = \$cygwin_windows_includes;
76       } elsif ($sys eq "mingw") {
77         $default_headers = \$mingw_windows_includes;
78       } elsif ($sys eq "wine") {
79         $default_headers = \$wine_windows_includes;
80       } else {
81         usage;
82       }
83     }
84 }
85
86 # check/detect topobjdir
87 # NOTE: Checking for configure is not ideal, but it seems to work
88 if (defined($topobjdir))
89 {
90     unless (-f $topobjdir . "/configure")
91     {
92         printf STDERR "Wrong -T argument, %s/configure does not exist\n", $topobjdir;
93         usage;
94     }
95 }
96 else  # try to detect it automatically
97 {
98     if (-f "./configure") { $topobjdir = "."; }
99     elsif (-f "../configure") { $topobjdir = ".."; }
100     elsif (-f "../../configure") { $topobjdir = "../.."; }
101     elsif (-f "../../../configure") { $topobjdir = "../../.."; }
102     else {
103       printf STDERR "Couldn't locate 'configure', and so no top-level directory\n";
104       usage;
105     }
106 }
107
108 chdir $topobjdir;
109 # Locate all tests
110 open FIND_FH, "find . -type d -name tests -print |";
111 while(<FIND_FH>) {
112   chomp;
113   push @testdirs,$_;
114 }
115 close FIND_FH;
116
117 #start writing the makefile in the root directory
118 open MAKE_FH,">Makefile.win";
119 print MAKE_FH <<EOH ;
120 #Define WINDOWS_HEADERS to point at the directory where windows.h lives
121 #Here are some examples
122 # For Cygwin
123 #WINDOWS_HEADERS = $cygwin_windows_includes
124 # For Mingw
125 #WINDOWS_HEADERS = $mingw_windows_includes
126 # For Wine
127 #WINDOWS_HEADERS = $wine_windows_includes
128
129 WINDOWS_HEADERS = $$default_headers
130
131 CC = gcc
132 RM = rm -f
133 TOUCH = touch
134
135 INCLUDE_DIRS = -I\$(WINDOWS_HEADERS) -I./include
136 CC_OPTS = \$(INCLUDE_DIRS) $cc_opts -include \$(WINDOWS_HEADERS)/windows.h
137
138 EOH
139
140 # iterate over each 'tests' directory
141 print MAKE_FH "TEST_O_FILES_wtmain = ./programs/winetest/wtmain.o\n";
142 foreach $dir (@testdirs) {
143   my($rootdir);
144   my($testname)=get_testname($dir);
145   $rootdir=fix_dir($dir);
146   unlink("$dir/testlist.c");
147   # Locate all '.c' files that arent 'spec'
148   my(@filelist)=grep(!/\.spec/,glob "$dir/*.c");
149   if(scalar(@filelist)) {
150     # Create a global list of all tests
151     foreach $file (@filelist) {
152       my($newfile);
153       ($newfile = $file) =~ s/c$/ok/;
154       push(@ok_list,$newfile);
155     }
156     # create the testslist.c file for each directory
157     system("./programs/winetest/make_ctests @filelist > $dir/testlist.c");
158     push @filelist,"$dir/testlist.c";
159     push(@gooddirs,$dir);
160     print MAKE_FH "# $dir\n";
161     # List all object files needed for this test
162     print MAKE_FH "TEST_O_FILES_$rootdir = \\\n";
163     foreach $file (@filelist) {
164       $file =~ s/c$/o/;
165       if($file ne $filelist[$#filelist]) {
166         print MAKE_FH " $file\\\n";
167       } else {
168         print MAKE_FH " $file\n";
169       }
170     }
171     print MAKE_FH "TEST_EXE_$rootdir = $dir/$testname.exe\n";
172   }
173 }
174 die "No C files found\n" if (!scalar(@gooddirs));
175 # The prerequisites for the tests are that the .ok fiels get created
176 print MAKE_FH "\n# .ok result files\n";
177 print MAKE_FH "TEST_OK_FILES = \\\n";
178 foreach $file (@ok_list) {
179   if($file ne $ok_list[$#ok_list]) {
180     print MAKE_FH "     $file\\\n";
181   } else {
182     print MAKE_FH "     $file\n";
183   }
184 }
185 print MAKE_FH "\n";
186 print MAKE_FH "all: \$(TEST_OK_FILES)\n";
187 print MAKE_FH "\n";
188
189 #define how to clean everything up
190 print MAKE_FH "clean:\n";
191 print MAKE_FH " \$(RM) \$(TEST_OK_FILES)\n";
192 print MAKE_FH "\n";
193 print MAKE_FH "distclean:\n";
194 print MAKE_FH " \$(RM) \$(TEST_OK_FILES)\n";
195 print MAKE_FH " \$(RM) \$(TEST_O_FILES_wtmain)\n";
196 foreach $dir (@gooddirs) {
197   my($rootdir)=fix_dir($dir);
198   print MAKE_FH "       \$(RM) \$(TEST_EXE_${rootdir}) \$(TEST_O_FILES_${rootdir})\n";
199 }
200 print MAKE_FH "\n";
201
202 #define how to make the executables
203 foreach $dir (@gooddirs) {
204   my($rootdir)=fix_dir($dir);
205   print MAKE_FH "\$(TEST_EXE_${rootdir}): \$(TEST_O_FILES_${rootdir}) \$(TEST_O_FILES_wtmain)\n";
206   print MAKE_FH "       \$(CC) \$(CC_OPTS) \$(TEST_O_FILES_${rootdir}) \$(TEST_O_FILES_wtmain) -o \$@\n";
207 }
208
209 # define how to make to .ok files
210 foreach $file (@ok_list) {
211   my($dir,$test) = ($file =~ /^(.*[\\\/]+tests)[\\\/]+(.*)\.ok$/);
212
213   print MAKE_FH "$file: \$(TEST_EXE_". fix_dir($file) . ")\n";
214   print MAKE_FH "       \$< $test && \$(TOUCH) \$@\n";
215 }
216 # define how to make the .o files
217
218 print MAKE_FH "%.o: %.c\n";
219 print MAKE_FH " \$(CC) \$(CC_OPTS) -c -o \$@ \$<\n";
220 close MAKE_FH;
221 if($archive ne "") {
222   create_archive($afile,$archive,@testdirs);
223 }
224 exit 0;
225
226 sub fix_dir {
227   my($dir)=shift @_;
228   my($rootdir)=($dir =~ /^[^\\\/]*[\\\/]+(.+)[\\\/]+tests/);
229   $rootdir =~ s/[\\\/]+/_/g;
230   return($rootdir);
231 }
232
233 sub get_testname {
234   my($dir)=shift @_;
235   my($testname)=($dir =~ /[\\\/]+([^\\\/]+)[\\\/]+tests/i);
236   return $testname;
237 }
238
239 sub create_archive($$\@) {
240   my($file,$arch,$dirlist)=@_;
241   my($dir);
242   my($cmd);
243   if($arch eq "z") {
244     print "Creating zip archive : $file\n";
245     $cmd = "zip -r $file ";
246   } else {
247     print "Creating tar.gz archive : $file\n";
248    $cmd = "tar -cvzf $file ";
249   }
250   foreach $dir (@$dirlist) {
251     my($cfile);
252     foreach $cfile (grep(!/\.spec/,glob "$dir/*.c")) {
253       $cmd .= "$cfile ";
254     }
255   }
256   $cmd .= " ./programs/winetest/wtmain.c";
257   $cmd .= " ./include";
258   $cmd .= " ./Makefile.win";
259   system "$cmd";
260 }
261
262 sub usage
263 {
264     print STDERR <<EOF;
265
266 Usage: $0 [options]
267
268 Options:
269     -v       verbose mode (can be specified multiple times)
270     -T dir   set Wine tree top directory (autodetected if not specified)
271     -z file  archive (zip) all needed files for test
272     -g file  archive (tar.gz) all needed files for test
273     -i dir   specify directory where windows.h lives
274     -s sys   specify system to build on (this sets the default header dir)
275              Valid values for 'sys' are: cygwin, mingw, and wine
276     -h       Show this message
277     NOTE: You can specify either -g or -z but not both
278 EOF
279     exit 1;
280 }