- added instructions how to update the online documentation
[bochs-mirror.git] / build / batch-build.perl
bloba8f5c5d722092abdfc389bdde48c83303389d84b
1 #!/usr/bin/perl
2 #####################################################################
3 # $Id: batch-build.perl,v 1.12 2008/12/11 21:19:38 sshwarts Exp $
4 #####################################################################
6 # Batch build tool for multiple configurations
8 # switches:
9 # - show output vs. send it all to nohup. --nohup
10 # - serial or parallel. --parallel
12 # no args: serial, display output
13 # --nohup: serial, output to nohup.out. (Need summary.)
14 # --nohup --parallel: parallel, output to nohup.out
15 # --parallel: parallel, spawn xterm for each
18 sub usage {
19 print <<EOF;
20 Usage: $0 [--nohup] [--parallel]
21 --nohup causes the output of all compiles to go into nohup.out
22 --parallel causes all compiles to be run in parallel
24 Usage: $0 --clean
25 --clean erases the build directories and recreates them from scratch
27 Combinations of nohup and parallel:
28 no args: serial compile, output goes to stdout
29 --nohup: serial compile, output goes into individual nohup.out files
30 --nohup --parallel: parallel compile, output goes to individual nohup.out files
31 --parallel: parallel compile, spawn an xterm for each configuration
32 EOF
35 $DEBUG=0;
37 $TEST_STANDARD = 1;
38 $TEST_GUIS = 1;
39 $TEST_CPU = 1;
40 $TEST_SMP = 1;
41 $TEST_IODEV = 1;
42 $TEST_PCI = 1;
43 $TEST_X86_64 = 1;
44 $TEST_SSE = 1;
45 $TEST_PLUGINS = 1;
46 $TEST_DEVICES = 1;
48 $pwd = `pwd`;
49 chop $pwd;
51 # create all the configurations that we should test. The first argument
52 # is the configuration name, which must be a valid directory name. To be
53 # safe, don't put spaces, slashes, ".", or ".." in here.
54 if ($TEST_STANDARD) {
55 add_configuration ('normal',
56 '');
57 add_configuration ('dbg',
58 '--enable-debugger');
61 if ($TEST_PLUGINS) {
62 add_configuration ('plug',
63 '--enable-plugins');
64 add_configuration ('plug-d',
65 '--enable-plugins --enable-debugger');
66 add_configuration ('plug-allgui',
67 '--enable-plugins --with-all-libs');
68 add_configuration ('plug-allgui-d',
69 '--enable-plugins --with-all-libs --enable-debugger');
70 add_configuration ('plug-smp',
71 '--enable-plugins --enable-smp');
72 add_configuration ('plug-smp-d',
73 '--enable-plugins --enable-smp --enable-debugger');
74 add_configuration ('plug-x86-64',
75 '--enable-plugins --enable-x86-64');
76 add_configuration ('plug-wx',
77 '--enable-plugins --with-wx');
80 if ($TEST_DEVICES) {
81 add_configuration ('alldev',
82 '--enable-ne2000 --enable-pci --enable-port-e9-hack --enable-cdrom --enable-iodebug');
83 add_configuration ('ne2000',
84 '--enable-ne2000');
85 add_configuration ('pci',
86 '--enable-pci');
87 add_configuration ('port-e9-hack',
88 '--enable-port-e9-hack');
89 add_configuration ('cdrom',
90 '--enable-cdrom');
91 add_configuration ('gdbstub',
92 '--enable-gdbstub');
93 add_configuration ('iodebug',
94 '--enable-iodebug');
97 if ($TEST_GUIS) {
98 # test with various gui options
99 add_configuration ('wx',
100 '--with-wx');
101 add_configuration ('wx-d',
102 '--with-wx --enable-debugger');
103 add_configuration ('sdl',
104 '--with-sdl');
105 add_configuration ('sdl-d',
106 '--with-sdl --enable-debugger');
107 add_configuration ('term',
108 '--with-term');
109 add_configuration ('term-d',
110 '--with-term --enable-debugger');
111 add_configuration ('rfb',
112 '--with-rfb');
113 add_configuration ('rfb-d',
114 '--with-rfb --enable-debugger');
115 add_configuration ('nogui',
116 '--with-nogui');
117 add_configuration ('nogui-d',
118 '--with-nogui --enable-debugger');
121 if ($TEST_CPU) {
122 # test with various cpu options
123 add_configuration ('i386',
124 '--enable-cpu-level=3 --disable-mmx');
125 add_configuration ('i486',
126 '--enable-cpu-level=4 --disable-mmx');
127 add_configuration ('i586',
128 '--enable-cpu-level=5');
129 add_configuration ('i686',
130 '--enable-cpu-level=6');
131 add_configuration ('large-pages',
132 '--enable-large-pages');
133 add_configuration ('pae',
134 '--enable-pae');
135 add_configuration ('repeat',
136 '--enable-repeat-speedups');
137 add_configuration ('globalpg',
138 '--enable-global-pages');
139 add_configuration ('icache',
140 '--enable-icache');
141 add_configuration ('cpuall',
142 '--enable-large-pages --enable-pae --enable-global-pages --enable-all-optimizations');
145 if ($TEST_SMP) {
146 # smp
147 add_configuration ('smp',
148 '--enable-smp');
149 add_configuration ('smp-d',
150 '--enable-smp --enable-debugger');
151 add_configuration ('smp-wx',
152 '--enable-smp --with-wx');
153 add_configuration ('smp-wx-d',
154 '--enable-smp --with-wx --enable-debugger');
157 if ($TEST_X86_64) {
158 # test x86-64
159 add_configuration ('64bit',
160 '--enable-x86-64');
161 add_configuration ('64bit-d',
162 '--enable-x86-64 --enable-debugger');
163 add_configuration ('64bit-wx',
164 '--enable-x86-64 --with-wx');
165 add_configuration ('64bit-wx-d',
166 '--enable-x86-64 --with-wx --enable-debugger');
169 if ($TEST_SSE) {
170 # test SSE configurations
171 add_configuration ('sse1',
172 '--enable-sse=1');
173 add_configuration ('sse2',
174 '--enable-sse=2');
175 add_configuration ('sse3',
176 '--enable-sse=3');
177 add_configuration ('sse4',
178 '--enable-sse=4');
179 add_configuration ('sse2-dbg',
180 '--enable-sse=2 --enable-debugger');
181 add_configuration ('sse2-x86-64-wx-d',
182 '--enable-sse=2 --enable-x86-64 --with-wx --enable-debugger');
185 my $nohup = 0;
186 my $parallel = 0;
187 my $clean = 0;
188 foreach my $arg (@ARGV) {
189 if ($arg eq '--clean') {
190 $clean = 1;
191 } elsif ($arg eq '--nohup') {
192 $nohup = 1;
193 } elsif ($arg eq '--parallel') {
194 $parallel = 1;
195 } else {
196 usage(); exit 1;
200 # this script may be run from various directories, and this affects
201 # the path to the configure command. Try to figure out where the configure
202 # command is found, and set up the build.sh scripts accordingly. If it
203 # can't be found, spit out an error now instead of later.
204 my @configurepath_tries = ("configure", "../configure", "../../configure");
205 my $configurepath;
206 foreach my $trypath (@configurepath_tries) {
207 if (-x $trypath) {
208 print "Found configure at $configurepath.\n" if $DEBUG;
209 $configurepath = $trypath;
212 if (!defined $configurepath) {
213 print <<EOF;
214 ERROR I could not locate the configure script. This script is intended
215 to be run from the bochs main directory or a subdirectory of it. Examples:
216 1) cd $BOCHS; ./build/batch-build.perl
217 2) cd $BOCHS/build; ./batch-build.perl
219 Here are the places that I tried to find the configure script:
221 foreach (@configurepath_tries) {
222 print " $_\n";
224 exit 1;
227 $x = 50; $y = 50;
228 $xinc = 30;
229 $yinc = 30;
231 for (my $i=0; $i <= $#config_names; $i++) {
232 my $name = "build-$config_names[$i]";
233 my $options = $config_opts[$i];
234 die if (!defined $name || !defined $options);
235 print "Compiling '$name' with opts '$options'\n" if $DEBUG;
236 if ($clean) {
237 my $rmcmd = "rm -rf $name";
238 print "Removing directory $name\n";
239 system $rmcmd;
240 next;
242 if (! -d $name) { mkdir $name, 0755; }
243 $maybe_nohup = $nohup? "nohup" : "";
244 open (BUILD, ">$name/build.sh");
245 print BUILD <<BUILD_EOF;
246 #!/bin/bash
247 echo Running the configure script
248 export CFLAGS='-g -O2 -Wall'
249 export CXXFLAGS='-g -O2 -Wall'
250 $maybe_nohup ../$configurepath $options
251 if test $? != 0; then
252 echo Configure failed.
253 exit 1
255 echo Running make
256 $maybe_nohup make
257 if test $? != 0; then
258 echo Make failed.
259 exit 1
261 BUILD_EOF
262 close BUILD;
263 chmod 0755, "$name/build.sh";
264 $gotodir = "cd $name";
265 $startcmd = "nice $maybe_nohup ./build.sh";
266 $header = <<HEADER_EOF;
267 ====================================================================
268 Configuration name: $name
269 Directory: $pwd/$name
270 Config Options: $options
271 ====================================================================
272 HEADER_EOF
273 print $header;
275 if ($parallel && !$nohup) {
276 # special case for parallel without nohup. If you're not careful,
277 # all output from all compiles will go into the window at once, which
278 # is impossible to read. Also very hard to kill them until they have
279 # run their course. Instead, start each compile in a different xterm!
280 # What's even more useful is that after the compile stops it goes into
281 # a bash shell so that you can fix things, run the make again, etc.
283 # To do this, put the start command in a little shell script called
284 # xterm-init.sh. Start the xterm with "-e xterm-init.sh" so that it
285 # runs the script as it starts.
287 open (XTI, ">$name/xterm-init.sh");
288 print XTI <<XTI_EOF;
289 #!/bin/bash
290 cat <<EOF
291 $header
293 $startcmd
294 bash
295 exit 0
296 XTI_EOF
297 close XTI;
298 chmod 0755, "$name/xterm-init.sh";
299 $geometry = "-geom +$x+$y";
300 $x+=$xinc;
301 $y+=$yinc;
302 $startcmd = "xterm -title $name -name $name $geometry -e ./xterm-init.sh";
305 $cmd = "$gotodir && $startcmd";
306 $cmd .= "&" if $parallel;
307 print "Executing '$cmd'\n" if $DEBUG;
308 system $cmd;
311 print "\n"x2;
312 print "batch-build script is done.\n";
313 exit 0;
315 sub add_configuration {
316 my ($name, $opts) = @_;
317 push @config_names, $name;
318 push @config_opts, $opts;