3 # Script to generate a Cygwin/Mingw 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 ($cygwin_windows_includes) ="/usr/include/w32api";
31 my ($mingw_windows_includes) ="/mingw/include";
32 my ($wine_windows_includes) ="./include";
33 my ($windows_includes)="";
35 #set the default headers to use
36 my ($default_headers) =\$cygwin_windows_includes;
38 # set this variable to your compiler options
39 my($cc_opts)= "-g -O2 -Wall -mpreferred-stack-boundary=2 -D_REENTRANT";
49 # parse command-line options
52 my $arg = shift @ARGV;
53 if ($arg eq "-h") { usage; }
56 $topobjdir = shift @ARGV;
57 usage unless (-d $topobjdir);
69 $windows_includes = shift @ARGV;
70 $default_headers = \$windows_includes;
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;
86 # check/detect topobjdir
87 # NOTE: Checking for configure is not ideal, but it seems to work
88 if (defined($topobjdir))
90 unless (-f $topobjdir . "/configure")
92 printf STDERR "Wrong -T argument, %s/configure does not exist\n", $topobjdir;
96 else # try to detect it automatically
98 if (-f "./configure") { $topobjdir = "."; }
99 elsif (-f "../configure") { $topobjdir = ".."; }
100 elsif (-f "../../configure") { $topobjdir = "../.."; }
101 elsif (-f "../../../configure") { $topobjdir = "../../.."; }
103 printf STDERR "Couldn't locate 'configure', and so no top-level directory\n";
110 open FIND_FH, "find . -type d -name tests -print |";
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
123 #WINDOWS_HEADERS = $cygwin_windows_includes
125 #WINDOWS_HEADERS = $mingw_windows_includes
127 #WINDOWS_HEADERS = $wine_windows_includes
129 WINDOWS_HEADERS = $$default_headers
135 INCLUDE_DIRS = -I\$(WINDOWS_HEADERS) -I./include
136 CC_OPTS = \$(INCLUDE_DIRS) $cc_opts -include \$(WINDOWS_HEADERS)/windows.h
140 # iterate over each 'tests' directory
141 print MAKE_FH "TEST_O_FILES_wtmain = ./programs/winetest/wtmain.o\n";
142 foreach $dir (@testdirs) {
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) {
153 ($newfile = $file) =~ s/c$/ok/;
154 push(@ok_list,$newfile);
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) {
165 if($file ne $filelist[$#filelist]) {
166 print MAKE_FH " $file\\\n";
168 print MAKE_FH " $file\n";
171 print MAKE_FH "TEST_EXE_$rootdir = $dir/$testname.exe\n";
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";
182 print MAKE_FH " $file\n";
186 print MAKE_FH "all: \$(TEST_OK_FILES)\n";
189 #define how to clean everything up
190 print MAKE_FH "clean:\n";
191 print MAKE_FH " \$(RM) \$(TEST_OK_FILES)\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";
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";
209 # define how to make to .ok files
210 foreach $file (@ok_list) {
211 my($dir,$test) = ($file =~ /^(.*[\\\/]+tests)[\\\/]+(.*)\.ok$/);
213 print MAKE_FH "$file: \$(TEST_EXE_". fix_dir($file) . ")\n";
214 print MAKE_FH " \$< $test && \$(TOUCH) \$@\n";
216 # define how to make the .o files
218 print MAKE_FH "%.o: %.c\n";
219 print MAKE_FH " \$(CC) \$(CC_OPTS) -c -o \$@ \$<\n";
222 create_archive($afile,$archive,@testdirs);
228 my($rootdir)=($dir =~ /^[^\\\/]*[\\\/]+(.+)[\\\/]+tests/);
229 $rootdir =~ s/[\\\/]+/_/g;
235 my($testname)=($dir =~ /[\\\/]+([^\\\/]+)[\\\/]+tests/i);
239 sub create_archive($$\@) {
240 my($file,$arch,$dirlist)=@_;
244 print "Creating zip archive : $file\n";
245 $cmd = "zip -r $file ";
247 print "Creating tar.gz archive : $file\n";
248 $cmd = "tar -cvzf $file ";
250 foreach $dir (@$dirlist) {
252 foreach $cfile (grep(!/\.spec/,glob "$dir/*.c")) {
256 $cmd .= " ./programs/winetest/wtmain.c";
257 $cmd .= " ./include";
258 $cmd .= " ./Makefile.win";
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
277 NOTE: You can specify either -g or -z but not both