]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - mkfiles.pl
Merge branch 'pre-0.64'
[PuTTY.git] / mkfiles.pl
1 #!/usr/bin/env perl
2 #
3 # Cross-platform Makefile generator.
4 #
5 # Reads the file `Recipe' to determine the list of generated
6 # executables and their component objects. Then reads the source
7 # files to compute #include dependencies. Finally, writes out the
8 # various target Makefiles.
9
10 # PuTTY specifics which could still do with removing:
11 #  - Mac makefile is not portabilised at all. Include directories
12 #    are hardwired, and also the libraries are fixed. This is
13 #    mainly because I was too scared to go anywhere near it.
14 #  - sbcsgen.pl is still run at startup.
15 #
16 # FIXME: no attempt made to handle !forceobj in the project files.
17
18 use warnings;
19 use FileHandle;
20 use File::Basename;
21 use Cwd;
22 use Digest::SHA qw(sha512_hex);
23
24 if ($#ARGV >= 0 and ($ARGV[0] eq "-u" or $ARGV[0] eq "-U")) {
25     # Convenience for Unix users: -u means that after we finish what
26     # we're doing here, we also run mkauto.sh and then 'configure' in
27     # the Unix subdirectory. So it's a one-stop shop for regenerating
28     # the actual end-product Unix makefile.
29     #
30     # Arguments supplied after -u go to configure.
31     #
32     # -U is identical, but runs 'configure' at the _top_ level, for
33     # people who habitually do that.
34     $do_unix = ($ARGV[0] eq "-U" ? 2 : 1);
35     shift @ARGV;
36     @confargs = @ARGV;
37 }
38
39 open IN, "Recipe" or do {
40     # We want to deal correctly with being run from one of the
41     # subdirs in the source tree. So if we can't find Recipe here,
42     # try one level up.
43     chdir "..";
44     open IN, "Recipe" or die "unable to open Recipe file\n";
45 };
46
47 # HACK: One of the source files in `charset' is auto-generated by
48 # sbcsgen.pl. We need to generate that _now_, before attempting
49 # dependency analysis.
50 eval 'chdir "charset"; require "sbcsgen.pl"; chdir ".."; select STDOUT;';
51
52 @srcdirs = ("./");
53
54 $divert = undef; # ref to scalar in which text is currently being put
55 $help = ""; # list of newline-free lines of help text
56 $project_name = "project"; # this is a good enough default
57 %makefiles = (); # maps makefile types to output makefile pathnames
58 %makefile_extra = (); # maps makefile types to extra Makefile text
59 %programs = (); # maps prog name + type letter to listref of objects/resources
60 %groups = (); # maps group name to listref of objects/resources
61
62 while (<IN>) {
63   chomp;
64   @_ = split;
65
66   # If we're gathering help text, keep doing so.
67   if (defined $divert) {
68       if ((defined $_[0]) && $_[0] eq "!end") {
69           $divert = undef;
70       } else {
71           ${$divert} .= "$_\n";
72       }
73       next;
74   }
75   # Skip comments and blank lines.
76   next if /^\s*#/ or scalar @_ == 0;
77
78   if ($_[0] eq "!begin" and $_[1] eq "help") { $divert = \$help; next; }
79   if ($_[0] eq "!end") { $divert = undef; next; }
80   if ($_[0] eq "!name") { $project_name = $_[1]; next; }
81   if ($_[0] eq "!srcdir") { push @srcdirs, $_[1]; next; }
82   if ($_[0] eq "!makefile" and &mfval($_[1])) { $makefiles{$_[1]}=$_[2]; next;}
83   if ($_[0] eq "!specialobj" and &mfval($_[1])) { $specialobj{$_[1]}->{$_[2]} = 1; next;}
84   if ($_[0] eq "!cflags" and &mfval($_[1])) {
85       ($rest = $_) =~ s/^\s*\S+\s+\S+\s+\S+\s*//; # find rest of input line
86       $rest = 1 if $rest eq "";
87       $cflags{$_[1]}->{$_[2]} = $rest;
88       next;
89   }
90   if ($_[0] eq "!forceobj") { $forceobj{$_[1]} = 1; next; }
91   if ($_[0] eq "!begin") {
92       if ($_[1] =~ /^>(.*)/) {
93           $divert = \$auxfiles{$1};
94       } elsif (&mfval($_[1])) {
95           $sect = $_[2] ? $_[2] : "end";
96           $divert = \($makefile_extra{$_[1]}->{$sect});
97       } else {
98           $dummy = '';
99           $divert = \$dummy;
100       }
101       next;
102   }
103   # If we're gathering help/verbatim text, keep doing so.
104   if (defined $divert) { ${$divert} .= "$_\n"; next; }
105   # Ignore blank lines.
106   next if scalar @_ == 0;
107
108   # Now we have an ordinary line. See if it's an = line, a : line
109   # or a + line.
110   @objs = @_;
111
112   if ($_[0] eq "+") {
113     $listref = $lastlistref;
114     $prog = undef;
115     die "$.: unexpected + line\n" if !defined $lastlistref;
116   } elsif ($_[1] eq "=") {
117     $groups{$_[0]} = [] if !defined $groups{$_[0]};
118     $listref = $groups{$_[0]};
119     $prog = undef;
120     shift @objs; # eat the group name
121   } elsif ($_[1] eq ":") {
122     $listref = [];
123     $prog = $_[0];
124     shift @objs; # eat the program name
125   } else {
126     die "$.: unrecognised line type\n";
127   }
128   shift @objs; # eat the +, the = or the :
129
130   while (scalar @objs > 0) {
131     $i = shift @objs;
132     if ($groups{$i}) {
133       foreach $j (@{$groups{$i}}) { unshift @objs, $j; }
134     } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or
135               $i eq "[X]" or $i eq "[U]" or $i eq "[MX]") and defined $prog) {
136       $type = substr($i,1,(length $i)-2);
137     } else {
138       push @$listref, $i;
139     }
140   }
141   if ($prog and $type) {
142     die "multiple program entries for $prog [$type]\n"
143         if defined $programs{$prog . "," . $type};
144     $programs{$prog . "," . $type} = $listref;
145   }
146   $lastlistref = $listref;
147 }
148
149 close IN;
150
151 foreach $aux (sort keys %auxfiles) {
152     open AUX, ">$aux";
153     print AUX $auxfiles{$aux};
154     close AUX;
155 }
156
157 # Now retrieve the complete list of objects and resource files, and
158 # construct dependency data for them. While we're here, expand the
159 # object list for each program, and complain if its type isn't set.
160 @prognames = sort keys %programs;
161 %depends = ();
162 @scanlist = ();
163 foreach $i (@prognames) {
164   ($prog, $type) = split ",", $i;
165   # Strip duplicate object names.
166   $prev = '';
167   @list = grep { $status = ($prev ne $_); $prev=$_; $status }
168           sort @{$programs{$i}};
169   $programs{$i} = [@list];
170   foreach $j (@list) {
171     # Dependencies for "x" start with "x.c" or "x.m" (depending on
172     # which one exists).
173     # Dependencies for "x.res" start with "x.rc".
174     # Dependencies for "x.rsrc" start with "x.r".
175     # Both types of file are pushed on the list of files to scan.
176     # Libraries (.lib) don't have dependencies at all.
177     if ($j =~ /^(.*)\.res$/) {
178       $file = "$1.rc";
179       $depends{$j} = [$file];
180       push @scanlist, $file;
181     } elsif ($j =~ /^(.*)\.rsrc$/) {
182       $file = "$1.r";
183       $depends{$j} = [$file];
184       push @scanlist, $file;
185     } elsif ($j !~ /\./) {
186       $file = "$j.c";
187       $file = "$j.m" unless &findfile($file);
188       $depends{$j} = [$file];
189       push @scanlist, $file;
190     }
191   }
192 }
193
194 # Scan each file on @scanlist and find further inclusions.
195 # Inclusions are given by lines of the form `#include "otherfile"'
196 # (system headers are automatically ignored by this because they'll
197 # be given in angle brackets). Files included by this method are
198 # added back on to @scanlist to be scanned in turn (if not already
199 # done).
200 #
201 # Resource scripts (.rc) can also include a file by means of:
202 #  - a line # ending `ICON "filename"';
203 #  - a line ending `RT_MANIFEST "filename"'.
204 # Files included by this method are not added to @scanlist because
205 # they can never include further files.
206 #
207 # In this pass we write out a hash %further which maps a source
208 # file name into a listref containing further source file names.
209
210 %further = ();
211 %allsourcefiles = (); # this is wanted by some makefiles
212 while (scalar @scanlist > 0) {
213   $file = shift @scanlist;
214   next if defined $further{$file}; # skip if we've already done it
215   $further{$file} = [];
216   $dirfile = &findfile($file);
217   $allsourcefiles{$dirfile} = 1;
218   open IN, "$dirfile" or die "unable to open source file $file\n";
219   while (<IN>) {
220     chomp;
221     /^\s*#include\s+\"([^\"]+)\"/ and do {
222       push @{$further{$file}}, $1;
223       push @scanlist, $1;
224       next;
225     };
226     /(RT_MANIFEST|ICON)\s+\"([^\"]+)\"\s*$/ and do {
227       push @{$further{$file}}, $2;
228       next;
229     }
230   }
231   close IN;
232 }
233
234 # Now we're ready to generate the final dependencies section. For
235 # each key in %depends, we must expand the dependencies list by
236 # iteratively adding entries from %further.
237 foreach $i (keys %depends) {
238   %dep = ();
239   @scanlist = @{$depends{$i}};
240   foreach $i (@scanlist) { $dep{$i} = 1; }
241   while (scalar @scanlist > 0) {
242     $file = shift @scanlist;
243     foreach $j (@{$further{$file}}) {
244       if (!$dep{$j}) {
245         $dep{$j} = 1;
246         push @{$depends{$i}}, $j;
247         push @scanlist, $j;
248       }
249     }
250   }
251 #  printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
252 }
253
254 # Validation of input.
255
256 sub mfval($) {
257     my ($type) = @_;
258     # Returns true if the argument is a known makefile type. Otherwise,
259     # prints a warning and returns false;
260     if (grep { $type eq $_ }
261         ("vc","vcproj","cygwin","borland","lcc","devcppproj","gtk","unix",
262          "am","osx","vstudio10","vstudio12")) {
263         return 1;
264     }
265     warn "$.:unknown makefile type '$type'\n";
266     return 0;
267 }
268
269 # Utility routines while writing out the Makefiles.
270
271 sub def {
272     my ($x) = shift @_;
273     return (defined $x) ? $x : "";
274 }
275
276 sub dirpfx {
277     my ($path) = shift @_;
278     my ($sep) = shift @_;
279     my $ret = "";
280     my $i;
281
282     while (($i = index $path, $sep) >= 0 ||
283            ($j = index $path, "/") >= 0) {
284         if ($i >= 0 and ($j < 0 or $i < $j)) {
285             $path = substr $path, ($i + length $sep);
286         } else {
287             $path = substr $path, ($j + 1);
288         }
289         $ret .= "..$sep";
290     }
291     return $ret;
292 }
293
294 sub findfile {
295   my ($name) = @_;
296   my $dir = '';
297   my $i;
298   my $outdir = undef;
299   unless (defined $findfilecache{$name}) {
300     $i = 0;
301     foreach $dir (@srcdirs) {
302       if (-f "$dir$name") {
303         $outdir = $dir;
304         $i++;
305         $outdir =~ s/^\.\///;
306       }
307     }
308     die "multiple instances of source file $name\n" if $i > 1;
309     $findfilecache{$name} = (defined $outdir ? $outdir . $name : undef);
310   }
311   return $findfilecache{$name};
312 }
313
314 sub objects {
315   my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
316   my @ret;
317   my ($i, $x, $y);
318   ($otmpl, $rtmpl, $ltmpl) = map { defined $_ ? $_ : "" } ($otmpl, $rtmpl, $ltmpl);
319   @ret = ();
320   foreach $i (@{$programs{$prog}}) {
321     $x = "";
322     if ($i =~ /^(.*)\.(res|rsrc)/) {
323       $y = $1;
324       ($x = $rtmpl) =~ s/X/$y/;
325     } elsif ($i =~ /^(.*)\.lib/) {
326       $y = $1;
327       ($x = $ltmpl) =~ s/X/$y/;
328     } elsif ($i !~ /\./) {
329       ($x = $otmpl) =~ s/X/$i/;
330     }
331     push @ret, $x if $x ne "";
332   }
333   return join " ", @ret;
334 }
335
336 sub special {
337   my ($prog, $suffix) = @_;
338   my @ret;
339   my ($i, $x, $y);
340   ($otmpl, $rtmpl, $ltmpl) = map { defined $_ ? $_ : "" } ($otmpl, $rtmpl, $ltmpl);
341   @ret = ();
342   foreach $i (@{$programs{$prog}}) {
343     if (substr($i, (length $i) - (length $suffix)) eq $suffix) {
344       push @ret, $i;
345     }
346   }
347   return (scalar @ret) ? (join " ", @ret) : undef;
348 }
349
350 sub splitline {
351   my ($line, $width, $splitchar) = @_;
352   my $result = "";
353   my $len;
354   $len = (defined $width ? $width : 76);
355   $splitchar = (defined $splitchar ? $splitchar : '\\');
356   while (length $line > $len) {
357     $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
358     $result .= $1;
359     $result .= " ${splitchar}\n\t\t" if $2 ne '';
360     $line = $2;
361     $len = 60;
362   }
363   return $result . $line;
364 }
365
366 sub deps {
367   my ($otmpl, $rtmpl, $prefix, $dirsep, $mftyp, $depchar, $splitchar) = @_;
368   my ($i, $x, $y);
369   my @deps;
370   my @ret;
371   @ret = ();
372   $depchar ||= ':';
373   foreach $i (sort keys %depends) {
374     next if $specialobj{$mftyp}->{$i};
375     if ($i =~ /^(.*)\.(res|rsrc)/) {
376       next if !defined $rtmpl;
377       $y = $1;
378       ($x = $rtmpl) =~ s/X/$y/;
379     } else {
380       ($x = $otmpl) =~ s/X/$i/;
381     }
382     @deps = @{$depends{$i}};
383     @deps = map {
384       $_ = &findfile($_);
385       s/\//$dirsep/g;
386       $_ = $prefix . $_;
387     } @deps;
388     push @ret, {obj => $x, obj_orig => $i, deps => [@deps]};
389   }
390   return @ret;
391 }
392
393 sub prognames {
394   my ($types) = @_;
395   my ($n, $prog, $type);
396   my @ret;
397   @ret = ();
398   foreach $n (@prognames) {
399     ($prog, $type) = split ",", $n;
400     push @ret, $n if index(":$types:", ":$type:") >= 0;
401   }
402   return @ret;
403 }
404
405 sub progrealnames {
406   my ($types) = @_;
407   my ($n, $prog, $type);
408   my @ret;
409   @ret = ();
410   foreach $n (@prognames) {
411     ($prog, $type) = split ",", $n;
412     push @ret, $prog if index(":$types:", ":$type:") >= 0;
413   }
414   return @ret;
415 }
416
417 sub manpages {
418   my ($types,$suffix) = @_;
419
420   # assume that all UNIX programs have a man page
421   if($suffix eq "1" && $types =~ /:X:/) {
422     return map("$_.1", &progrealnames($types));
423   }
424   return ();
425 }
426
427 $orig_dir = cwd;
428
429 # Now we're ready to output the actual Makefiles.
430
431 if (defined $makefiles{'cygwin'}) {
432     $dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
433
434     ##-- CygWin makefile
435     open OUT, ">$makefiles{'cygwin'}"; select OUT;
436     print
437     "# Makefile for $project_name under Cygwin, MinGW, or Winelib.\n".
438     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
439     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
440     # gcc command line option is -D not /D
441     ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
442     print $_;
443     print
444     "\n".
445     "# You can define this path to point at your tools if you need to\n".
446     "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
447     "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
448     "CC = \$(TOOLPATH)gcc\n".
449     "RC = \$(TOOLPATH)windres\n".
450     "# Uncomment the following two lines to compile under Winelib\n".
451     "# CC = winegcc\n".
452     "# RC = wrc\n".
453     "# You may also need to tell windres where to find include files:\n".
454     "# RCINC = --include-dir c:\\cygwin\\include\\\n".
455     "\n".
456     &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
457       " -D_NO_OLDNAMES -DNO_MULTIMON -DNO_HTMLHELP -DNO_SECUREZEROMEMORY " .
458                (join " ", map {"-I$dirpfx$_"} @srcdirs)) .
459                "\n".
460     "LDFLAGS = -mno-cygwin -s\n".
461     &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1 ".
462       "--define WINVER=0x0400 ".(join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
463     "\n".
464     &def($makefile_extra{'cygwin'}->{'vars'}) .
465     "\n".
466     ".SUFFIXES:\n".
467     "\n";
468     print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
469     print "\n\n";
470     foreach $p (&prognames("G:C")) {
471       ($prog, $type) = split ",", $p;
472       $objstr = &objects($p, "X.o", "X.res.o", undef);
473       print &splitline($prog . ".exe: " . $objstr), "\n";
474       my $mw = $type eq "G" ? " -mwindows" : "";
475       $libstr = &objects($p, undef, undef, "-lX");
476       print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
477                        "-Wl,-Map,$prog.map " .
478                        $objstr . " $libstr", 69), "\n\n";
479     }
480     foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/", "cygwin")) {
481       if ($forceobj{$d->{obj_orig}}) {
482         printf ("%s: FORCE\n", $d->{obj});
483       } else {
484         print &splitline(sprintf("%s: %s", $d->{obj},
485                          join " ", @{$d->{deps}})), "\n";
486       }
487       if ($d->{obj} =~ /\.res\.o$/) {
488           print "\t\$(RC) \$(RCFL) \$(RCFLAGS) ".$d->{deps}->[0]." -o ".$d->{obj}."\n\n";
489       } else {
490           print "\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c ".$d->{deps}->[0]."\n\n";
491       }
492     }
493     print "\n";
494     print &def($makefile_extra{'cygwin'}->{'end'});
495     print "\nclean:\n".
496     "\trm -f *.o *.exe *.res.o *.so *.map\n".
497     "\n".
498     "FORCE:\n";
499     select STDOUT; close OUT;
500
501 }
502
503 ##-- Borland makefile
504 if (defined $makefiles{'borland'}) {
505     $dirpfx = &dirpfx($makefiles{'borland'}, "\\");
506
507     %stdlibs = (  # Borland provides many Win32 API libraries intrinsically
508       "advapi32" => 1,
509       "comctl32" => 1,
510       "comdlg32" => 1,
511       "gdi32" => 1,
512       "imm32" => 1,
513       "shell32" => 1,
514       "user32" => 1,
515       "winmm" => 1,
516       "winspool" => 1,
517       "wsock32" => 1,
518     );
519     open OUT, ">$makefiles{'borland'}"; select OUT;
520     print
521     "# Makefile for $project_name under Borland C.\n".
522     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
523     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
524     # bcc32 command line option is -D not /D
525     ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
526     print $_;
527     print
528     "\n".
529     "# If you rename this file to `Makefile', you should change this line,\n".
530     "# so that the .rsp files still depend on the correct makefile.\n".
531     "MAKEFILE = Makefile.bor\n".
532     "\n".
533     "# C compilation flags\n".
534     "CFLAGS = -D_WINDOWS -DWINVER=0x0500\n".
535     "# Resource compilation flags\n".
536     "RCFLAGS = -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401\n".
537     "\n".
538     "# Get include directory for resource compiler\n".
539     "!if !\$d(BCB)\n".
540     "BCB = \$(MAKEDIR)\\..\n".
541     "!endif\n".
542     "\n".
543     &def($makefile_extra{'borland'}->{'vars'}) .
544     "\n".
545     ".c.obj:\n".
546     &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT)".
547                " \$(CFLAGS) \$(XFLAGS) ".
548                (join " ", map {"-I$dirpfx$_"} @srcdirs) .
549                " /c \$*.c",69)."\n".
550     ".rc.res:\n".
551     &splitline("\tbrcc32 \$(RCFL) -i \$(BCB)\\include -r".
552       " \$(RCFLAGS) \$*.rc",69)."\n".
553     "\n";
554     print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
555     print "\n\n";
556     foreach $p (&prognames("G:C")) {
557       ($prog, $type) = split ",", $p;
558       $objstr =  &objects($p, "X.obj", "X.res", undef);
559       print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
560       my $ap = ($type eq "G") ? "-aa" : "-ap";
561       print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n";
562     }
563     foreach $p (&prognames("G:C")) {
564       ($prog, $type) = split ",", $p;
565       print $prog, ".rsp: \$(MAKEFILE)\n";
566       $objstr = &objects($p, "X.obj", undef, undef);
567       @objlist = split " ", $objstr;
568       @objlines = ("");
569       foreach $i (@objlist) {
570         if (length($objlines[$#objlines] . " $i") > 50) {
571           push @objlines, "";
572         }
573         $objlines[$#objlines] .= " $i";
574       }
575       $c0w = ($type eq "G") ? "c0w32" : "c0x32";
576       print "\techo $c0w + > $prog.rsp\n";
577       for ($i=0; $i<=$#objlines; $i++) {
578         $plus = ($i < $#objlines ? " +" : "");
579         print "\techo$objlines[$i]$plus >> $prog.rsp\n";
580       }
581       print "\techo $prog.exe >> $prog.rsp\n";
582       $objstr = &objects($p, "X.obj", "X.res", undef);
583       @libs = split " ", &objects($p, undef, undef, "X");
584       @libs = grep { !$stdlibs{$_} } @libs;
585       unshift @libs, "cw32", "import32";
586       $libstr = join ' ', @libs;
587       print "\techo nul,$libstr, >> $prog.rsp\n";
588       print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n";
589       print "\n";
590     }
591     foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "borland")) {
592       if ($forceobj{$d->{obj_orig}}) {
593         printf("%s: FORCE\n", $d->{obj});
594       } else {
595         print &splitline(sprintf("%s: %s", $d->{obj},
596                                  join " ", @{$d->{deps}})), "\n";
597       }
598     }
599     print "\n";
600     print &def($makefile_extra{'borland'}->{'end'});
601     print "\nclean:\n".
602     "\t-del *.obj\n".
603     "\t-del *.exe\n".
604     "\t-del *.res\n".
605     "\t-del *.pch\n".
606     "\t-del *.aps\n".
607     "\t-del *.il*\n".
608     "\t-del *.pdb\n".
609     "\t-del *.rsp\n".
610     "\t-del *.tds\n".
611     "\t-del *.\$\$\$\$\$\$\n".
612     "\n".
613     "FORCE:\n".
614     "\t-rem dummy command\n";
615     select STDOUT; close OUT;
616 }
617
618 if (defined $makefiles{'vc'}) {
619     $dirpfx = &dirpfx($makefiles{'vc'}, "\\");
620
621     ##-- Visual C++ makefile
622     open OUT, ">$makefiles{'vc'}"; select OUT;
623     print
624       "# Makefile for $project_name under Visual C.\n".
625       "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
626       "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
627     print $help;
628     print
629       "\n".
630       "# If you rename this file to `Makefile', you should change this line,\n".
631       "# so that the .rsp files still depend on the correct makefile.\n".
632       "MAKEFILE = Makefile.vc\n".
633       "\n".
634       "# C compilation flags\n".
635       "CFLAGS = /nologo /W3 /O1 " .
636       (join " ", map {"-I$dirpfx$_"} @srcdirs) .
637       " /D_WINDOWS /D_WIN32_WINDOWS=0x500 /DWINVER=0x500\n".
638       "LFLAGS = /incremental:no /fixed\n".
639       "RCFLAGS = ".(join " ", map {"-I$dirpfx$_"} @srcdirs).
640       " -DWIN32 -D_WIN32 -DWINVER=0x0400\n".
641       "\n".
642       &def($makefile_extra{'vc'}->{'vars'}) .
643       "\n".
644       "\n";
645     print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
646     print "\n\n";
647     foreach $p (&prognames("G:C")) {
648         ($prog, $type) = split ",", $p;
649         $objstr = &objects($p, "X.obj", "X.res", undef);
650         print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
651         print "\tlink \$(LFLAGS) \$(XLFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
652     }
653     foreach $p (&prognames("G:C")) {
654         ($prog, $type) = split ",", $p;
655         print $prog, ".rsp: \$(MAKEFILE)\n";
656         $objstr = &objects($p, "X.obj", "X.res", "X.lib");
657         @objlist = split " ", $objstr;
658         @objlines = ("");
659         foreach $i (@objlist) {
660             if (length($objlines[$#objlines] . " $i") > 50) {
661                 push @objlines, "";
662             }
663             $objlines[$#objlines] .= " $i";
664         }
665         $subsys = ($type eq "G") ? "windows" : "console";
666         print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
667         for ($i=0; $i<=$#objlines; $i++) {
668             print "\techo$objlines[$i] >> $prog.rsp\n";
669         }
670         print "\n";
671     }
672     foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "vc")) {
673         $extradeps = $forceobj{$d->{obj_orig}} ? ["*.c","*.h","*.rc"] : [];
674         print &splitline(sprintf("%s: %s", $d->{obj},
675                                  join " ", @$extradeps, @{$d->{deps}})), "\n";
676         if ($d->{obj} =~ /.obj$/) {
677             print "\tcl \$(COMPAT) \$(CFLAGS) \$(XFLAGS) /c ".$d->{deps}->[0],"\n\n";
678         } else {
679             print "\trc \$(RCFL) -r \$(RCFLAGS) ".$d->{deps}->[0],"\n\n";
680         }
681     }
682     print "\n";
683     print &def($makefile_extra{'vc'}->{'end'});
684     print "\nclean: tidy\n".
685       "\t-del *.exe\n\n".
686       "tidy:\n".
687       "\t-del *.obj\n".
688       "\t-del *.res\n".
689       "\t-del *.pch\n".
690       "\t-del *.aps\n".
691       "\t-del *.ilk\n".
692       "\t-del *.pdb\n".
693       "\t-del *.rsp\n".
694       "\t-del *.dsp\n".
695       "\t-del *.dsw\n".
696       "\t-del *.ncb\n".
697       "\t-del *.opt\n".
698       "\t-del *.plg\n".
699       "\t-del *.map\n".
700       "\t-del *.idb\n".
701       "\t-del debug.log\n";
702     select STDOUT; close OUT;
703 }
704
705 if (defined $makefiles{'vcproj'}) {
706     $dirpfx = &dirpfx($makefiles{'vcproj'}, "\\");
707
708     ##-- MSVC 6 Workspace and projects
709     #
710     # Note: All files created in this section are written in binary
711     # mode, because although MSVC's command-line make can deal with
712     # LF-only line endings, MSVC project files really _need_ to be
713     # CRLF. Hence, in order for mkfiles.pl to generate usable project
714     # files even when run from Unix, I make sure all files are binary
715     # and explicitly write the CRLFs.
716     #
717     # Create directories if necessary
718     mkdir $makefiles{'vcproj'}
719         if(! -d $makefiles{'vcproj'});
720     chdir $makefiles{'vcproj'};
721     @deps = &deps("X.obj", "X.res", $dirpfx, "\\", "vcproj");
722     %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
723     # Create the project files
724     # Get names of all Windows projects (GUI and console)
725     my @prognames = &prognames("G:C");
726     foreach $progname (@prognames) {
727       create_vc_project(\%all_object_deps, $progname);
728     }
729     # Create the workspace file
730     open OUT, ">$project_name.dsw"; binmode OUT; select OUT;
731     print
732     "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
733     "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
734     "\r\n".
735     "###############################################################################\r\n".
736     "\r\n";
737     # List projects
738     foreach $progname (@prognames) {
739       ($windows_project, $type) = split ",", $progname;
740         print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n";
741     }
742     print
743     "\r\n".
744     "Package=<5>\r\n".
745     "{{{\r\n".
746     "}}}\r\n".
747     "\r\n".
748     "Package=<4>\r\n".
749     "{{{\r\n".
750     "}}}\r\n".
751     "\r\n".
752     "###############################################################################\r\n".
753     "\r\n".
754     "Global:\r\n".
755     "\r\n".
756     "Package=<5>\r\n".
757     "{{{\r\n".
758     "}}}\r\n".
759     "\r\n".
760     "Package=<3>\r\n".
761     "{{{\r\n".
762     "}}}\r\n".
763     "\r\n".
764     "###############################################################################\r\n".
765     "\r\n";
766     select STDOUT; close OUT;
767     chdir $orig_dir;
768
769     sub create_vc_project {
770         my ($all_object_deps, $progname) = @_;
771         # Construct program's dependency info
772         %seen_objects = ();
773         %lib_files = ();
774         %source_files = ();
775         %header_files = ();
776         %resource_files = ();
777         @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
778         foreach $object_file (@object_files) {
779             next if defined $seen_objects{$object_file};
780             $seen_objects{$object_file} = 1;
781             if($object_file =~ /\.lib$/io) {
782                 $lib_files{$object_file} = 1;
783                 next;
784             }
785             $object_deps = $all_object_deps{$object_file};
786             foreach $object_dep (@$object_deps) {
787                 if($object_dep =~ /\.c$/io) {
788                     $source_files{$object_dep} = 1;
789                     next;
790                 }
791                 if($object_dep =~ /\.h$/io) {
792                     $header_files{$object_dep} = 1;
793                     next;
794                 }
795                 if($object_dep =~ /\.(rc|ico)$/io) {
796                     $resource_files{$object_dep} = 1;
797                     next;
798                 }
799             }
800         }
801         $libs = join " ", sort keys %lib_files;
802         @source_files = sort keys %source_files;
803         @header_files = sort keys %header_files;
804         @resources = sort keys %resource_files;
805         ($windows_project, $type) = split ",", $progname;
806         mkdir $windows_project
807             if(! -d $windows_project);
808         chdir $windows_project;
809         $subsys = ($type eq "G") ? "windows" : "console";
810         open OUT, ">$windows_project.dsp"; binmode OUT; select OUT;
811         print
812         "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n".
813         "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n".
814         "# ** DO NOT EDIT **\r\n".
815         "\r\n".
816         "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n".
817         "\r\n".
818         "CFG=$windows_project - Win32 Debug\r\n".
819         "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n".
820         "!MESSAGE use the Export Makefile command and run\r\n".
821         "!MESSAGE \r\n".
822         "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n".
823         "!MESSAGE \r\n".
824         "!MESSAGE You can specify a configuration when running NMAKE\r\n".
825         "!MESSAGE by defining the macro CFG on the command line. For example:\r\n".
826         "!MESSAGE \r\n".
827         "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
828         "!MESSAGE \r\n".
829         "!MESSAGE Possible choices for configuration are:\r\n".
830         "!MESSAGE \r\n".
831         "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n".
832         "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n".
833         "!MESSAGE \r\n".
834         "\r\n".
835         "# Begin Project\r\n".
836         "# PROP AllowPerConfigDependencies 0\r\n".
837         "# PROP Scc_ProjName \"\"\r\n".
838         "# PROP Scc_LocalPath \"\"\r\n".
839         "CPP=cl.exe\r\n".
840         "MTL=midl.exe\r\n".
841         "RSC=rc.exe\r\n".
842         "\r\n".
843         "!IF  \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
844         "\r\n".
845         "# PROP BASE Use_MFC 0\r\n".
846         "# PROP BASE Use_Debug_Libraries 0\r\n".
847         "# PROP BASE Output_Dir \"Release\"\r\n".
848         "# PROP BASE Intermediate_Dir \"Release\"\r\n".
849         "# PROP BASE Target_Dir \"\"\r\n".
850         "# PROP Use_MFC 0\r\n".
851         "# PROP Use_Debug_Libraries 0\r\n".
852         "# PROP Output_Dir \"Release\"\r\n".
853         "# PROP Intermediate_Dir \"Release\"\r\n".
854         "# PROP Ignore_Export_Lib 0\r\n".
855         "# PROP Target_Dir \"\"\r\n".
856         "# ADD BASE CPP /nologo /W3 /GX /O2 ".
857           (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
858           " /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
859         "# ADD CPP /nologo /W3 /GX /O2 ".
860           (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
861           " /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
862         "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
863         "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
864         "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n".
865         "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n".
866         "BSC32=bscmake.exe\r\n".
867         "# ADD BASE BSC32 /nologo\r\n".
868         "# ADD BSC32 /nologo\r\n".
869         "LINK32=link.exe\r\n".
870         "# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:$subsys /machine:I386\r\n".
871         "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n".
872         "# SUBTRACT LINK32 /pdb:none\r\n".
873         "\r\n".
874         "!ELSEIF  \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
875         "\r\n".
876         "# PROP BASE Use_MFC 0\r\n".
877         "# PROP BASE Use_Debug_Libraries 1\r\n".
878         "# PROP BASE Output_Dir \"Debug\"\r\n".
879         "# PROP BASE Intermediate_Dir \"Debug\"\r\n".
880         "# PROP BASE Target_Dir \"\"\r\n".
881         "# PROP Use_MFC 0\r\n".
882         "# PROP Use_Debug_Libraries 1\r\n".
883         "# PROP Output_Dir \"Debug\"\r\n".
884         "# PROP Intermediate_Dir \"Debug\"\r\n".
885         "# PROP Ignore_Export_Lib 0\r\n".
886         "# PROP Target_Dir \"\"\r\n".
887         "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od ".
888           (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
889           " /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
890         "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od ".
891           (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
892           " /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
893         "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
894         "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
895         "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n".
896         "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n".
897         "BSC32=bscmake.exe\r\n".
898         "# ADD BASE BSC32 /nologo\r\n".
899         "# ADD BSC32 /nologo\r\n".
900         "LINK32=link.exe\r\n".
901         "# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
902         "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
903         "# SUBTRACT LINK32 /pdb:none\r\n".
904         "\r\n".
905         "!ENDIF \r\n".
906         "\r\n".
907         "# Begin Target\r\n".
908         "\r\n".
909         "# Name \"$windows_project - Win32 Release\"\r\n".
910         "# Name \"$windows_project - Win32 Debug\"\r\n".
911         "# Begin Group \"Source Files\"\r\n".
912         "\r\n".
913         "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
914         foreach $source_file (@source_files) {
915             print
916               "# Begin Source File\r\n".
917               "\r\n".
918               "SOURCE=..\\..\\$source_file\r\n";
919             if($source_file =~ /ssh\.c/io) {
920                 # Disable 'Edit and continue' as Visual Studio can't handle the macros
921                 print
922                   "\r\n".
923                   "!IF  \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
924                   "\r\n".
925                   "!ELSEIF  \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
926                   "\r\n".
927                   "# ADD CPP /Zi\r\n".
928                   "\r\n".
929                   "!ENDIF \r\n".
930                   "\r\n";
931             }
932             print "# End Source File\r\n";
933         }
934         print
935         "# End Group\r\n".
936         "# Begin Group \"Header Files\"\r\n".
937         "\r\n".
938         "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
939         foreach $header_file (@header_files) {
940             print
941               "# Begin Source File\r\n".
942               "\r\n".
943               "SOURCE=..\\..\\$header_file\r\n".
944               "# End Source File\r\n";
945         }
946         print
947         "# End Group\r\n".
948         "# Begin Group \"Resource Files\"\r\n".
949         "\r\n".
950         "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
951         foreach $resource_file (@resources) {
952             print
953               "# Begin Source File\r\n".
954               "\r\n".
955               "SOURCE=..\\..\\$resource_file\r\n".
956               "# End Source File\r\n";
957         }
958         print
959         "# End Group\r\n".
960         "# End Target\r\n".
961         "# End Project\r\n";
962         select STDOUT; close OUT;
963         chdir "..";
964     }
965 }
966
967 if (defined $makefiles{'vstudio10'} || defined $makefiles{'vstudio12'}) {
968
969     ##-- Visual Studio 2010+ Solution and Projects
970
971     if (defined $makefiles{'vstudio10'}) {
972         create_vs_solution('vstudio10', "2010", "11.00", "v100");
973     }
974
975     if (defined $makefiles{'vstudio12'}) {
976         create_vs_solution('vstudio12', "2012", "12.00", "v110");
977     }
978
979     sub create_vs_solution {
980         my ($makefilename, $name, $version, $toolsver) = @_;
981
982         $dirpfx = &dirpfx($makefiles{$makefilename}, "\\");
983
984         @deps = &deps("X.obj", "X.res", $dirpfx, "\\", $makefilename);
985         %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
986
987         my @prognames = &prognames("G:C");
988
989         # Create the solution file.
990         mkdir $makefiles{$makefilename}
991            if(! -f $makefiles{$makefilename});
992         chdir $makefiles{$makefilename};
993
994         open OUT, ">$project_name.sln"; select OUT;
995
996         print
997             "Microsoft Visual Studio Solution File, Format Version $version\n" .
998             "# Visual Studio $name\n";
999
1000         my %projguids = ();
1001         foreach $progname (@prognames) {
1002             ($windows_project, $type) = split ",", $progname;
1003
1004             $projguids{$windows_project} = $guid =
1005                 &invent_guid("project:$progname");
1006         
1007             print
1008                 "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"$windows_project\", \"$windows_project\\$windows_project.vcxproj\", \"{$guid}\"\n" .
1009                 "EndProject\n";
1010         }
1011
1012         print
1013             "Global\n" .
1014             "    GlobalSection(SolutionConfigurationPlatforms) = preSolution\n" .
1015             "        Debug|Win32 = Debug|Win32\n" .
1016             "        Release|Win32 = Release|Win32\n" .
1017             "    EndGlobalSection\n" .
1018             "    GlobalSection(ProjectConfigurationPlatforms) = postSolution\n" ;
1019
1020         foreach my $projguid (values %projguids) {
1021             print
1022                 "        {$projguid}.Debug|Win32.ActiveCfg = Debug|Win32\n" .
1023                 "        {$projguid}.Debug|Win32.Build.0 = Debug|Win32\n" .
1024                 "        {$projguid}.Release|Win32.ActiveCfg = Release|Win32\n" .
1025                 "        {$projguid}.Release|Win32.Build.0 = Release|Win32\n";
1026         }
1027
1028         print
1029             "    EndGlobalSection\n" .
1030             "    GlobalSection(SolutionProperties) = preSolution\n" .
1031             "        HideSolutionNode = FALSE\n" .
1032             "    EndGlobalSection\n" .
1033             "EndGlobal\n";
1034
1035         select STDOUT; close OUT;
1036
1037         foreach $progname (@prognames) {
1038             ($windows_project, $type) = split ",", $progname;
1039             create_vs_project(\%all_object_deps, $windows_project, $type, $projguids{$windows_project}, $toolsver);
1040         }
1041     
1042         chdir $orig_dir;
1043     }
1044
1045     sub create_vs_project {
1046         my ($all_object_deps, $windows_project, $type, $projguid, $toolsver) = @_;
1047
1048         # Break down the project's dependency information into the appropriate
1049         # groups.
1050         %seen_objects = ();
1051         %lib_files = ();
1052         %source_files = ();
1053         %header_files = ();
1054         %resource_files = ();
1055         %icon_files = ();
1056
1057         @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
1058         foreach $object_file (@object_files) {
1059             next if defined $seen_objects{$object_file};
1060             $seen_objects{$object_file} = 1;
1061
1062             if($object_file =~ /\.lib$/io) {
1063                 $lib_files{$object_file} = 1;
1064                 next;
1065             }
1066
1067             $object_deps = $all_object_deps{$object_file};
1068             foreach $object_dep (@$object_deps) {
1069                 if($object_dep eq $object_deps->[0]) {
1070                     if($object_dep =~ /\.c$/io) {
1071                         $source_files{$object_dep} = 1;
1072                     } elsif($object_dep =~ /\.rc$/io) {
1073                         $resource_files{$object_dep} = 1;
1074                     }
1075                 } elsif ($object_dep =~ /\.[ch]$/io) {
1076                     $header_files{$object_dep} = 1;
1077                 } elsif ($object_dep =~ /\.ico$/io) {
1078                     $icon_files{$object_dep} = 1;
1079                 }
1080             }
1081         }
1082
1083         $libs = join ";", sort keys %lib_files;
1084         @source_files = sort keys %source_files;
1085         @header_files = sort keys %header_files;
1086         @resources = sort keys %resource_files;
1087         @icons = sort keys %icon_files;
1088         $subsystem = ($type eq "G") ? "Windows" : "Console";
1089
1090         mkdir $windows_project
1091             if(! -d $windows_project);
1092         chdir $windows_project;
1093         open OUT, ">$windows_project.vcxproj"; select OUT;
1094         open FILTERS, ">$windows_project.vcxproj.filters";
1095
1096         # The bulk of the project file is just boilerplate stuff, so we
1097         # can mostly just dump it out here. Note, buried in the ClCompile
1098         # item definition, that we use a debug information format of
1099         # ProgramDatabase, which disables the edit-and-continue support
1100         # that breaks most of the project builds.
1101         print
1102             "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" .
1103             "<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n" .
1104             "  <ItemGroup Label=\"ProjectConfigurations\">\n" .
1105             "    <ProjectConfiguration Include=\"Debug|Win32\">\n" .
1106             "      <Configuration>Debug</Configuration>\n" .
1107             "      <Platform>Win32</Platform>\n" .
1108             "    </ProjectConfiguration>\n" .
1109             "    <ProjectConfiguration Include=\"Release|Win32\">\n" .
1110             "      <Configuration>Release</Configuration>\n" .
1111             "      <Platform>Win32</Platform>\n" .
1112             "    </ProjectConfiguration>\n" .
1113             "  </ItemGroup>\n" .
1114             "  <PropertyGroup Label=\"Globals\">\n" .
1115             "    <SccProjectName />\n" .
1116             "    <SccLocalPath />\n" .
1117             "    <ProjectGuid>{$projguid}</ProjectGuid>\n" .
1118             "  </PropertyGroup>\n" .
1119             "  <Import Project=\"\$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n" .
1120             "  <PropertyGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n" .
1121             "    <ConfigurationType>Application</ConfigurationType>\n" .
1122             "    <UseOfMfc>false</UseOfMfc>\n" .
1123             "    <CharacterSet>MultiByte</CharacterSet>\n" .
1124             "    <PlatformToolset>$toolsver</PlatformToolset>\n" .
1125             "  </PropertyGroup>\n" .
1126             "  <PropertyGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n" .
1127             "    <ConfigurationType>Application</ConfigurationType>\n" .
1128             "    <UseOfMfc>false</UseOfMfc>\n" .
1129             "    <CharacterSet>MultiByte</CharacterSet>\n" .
1130             "    <PlatformToolset>$toolsver</PlatformToolset>\n" .
1131             "  </PropertyGroup>\n" .
1132             "  <Import Project=\"\$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n" .
1133             "  <ImportGroup Label=\"ExtensionTargets\">\n" .
1134             "  </ImportGroup>\n" .
1135             "  <ImportGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\" Label=\"PropertySheets\">\n" .
1136             "    <Import Project=\"\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props\" Condition=\"exists('\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n" .
1137             "  </ImportGroup>\n" .
1138             "  <ImportGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Release|Win32'\" Label=\"PropertySheets\">\n" .
1139             "    <Import Project=\"\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props\" Condition=\"exists('\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n" .
1140             "  </ImportGroup>\n" .
1141             "  <PropertyGroup Label=\"UserMacros\" />\n" .
1142             "  <PropertyGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Release|Win32'\">\n" .
1143             "    <OutDir>.\\Release\\</OutDir>\n" .
1144             "    <IntDir>.\\Release\\</IntDir>\n" .
1145             "    <LinkIncremental>false</LinkIncremental>\n" .
1146             "  </PropertyGroup>\n" .
1147             "  <PropertyGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">\n" .
1148             "    <OutDir>.\\Debug\\</OutDir>\n" .
1149             "    <IntDir>.\\Debug\\</IntDir>\n" .
1150             "    <LinkIncremental>true</LinkIncremental>\n" .
1151             "  </PropertyGroup>\n" .
1152             "  <ItemDefinitionGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Release|Win32'\">\n" .
1153             "    <ClCompile>\n" .
1154             "      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\n" .
1155             "      <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>\n" .
1156             "      <StringPooling>true</StringPooling>\n" .
1157             "      <FunctionLevelLinking>true</FunctionLevelLinking>\n" .
1158             "      <Optimization>MaxSpeed</Optimization>\n" .
1159             "      <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1160             "      <WarningLevel>Level3</WarningLevel>\n" .
1161             "      <AdditionalIncludeDirectories>" . (join ";", map {"..\\..\\$dirpfx$_"} @srcdirs) . ";%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n" .
1162             "      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;POSIX;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1163             "      <AssemblerListingLocation>.\\Release\\</AssemblerListingLocation>\n" .
1164             "      <PrecompiledHeaderOutputFile>.\\Release\\$windows_project.pch</PrecompiledHeaderOutputFile>\n" .
1165             "      <ObjectFileName>.\\Release\\</ObjectFileName>\n" .
1166             "      <ProgramDataBaseFileName>.\\Release\\</ProgramDataBaseFileName>\n" .
1167             "    </ClCompile>\n" .
1168             "    <Midl>\n" .
1169             "      <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1170             "      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1171             "      <TypeLibraryName>.\\Release\\$windows_project.tlb</TypeLibraryName>\n" .
1172             "      <MkTypLibCompatible>true</MkTypLibCompatible>\n" .
1173             "      <TargetEnvironment>Win32</TargetEnvironment>\n" .
1174             "    </Midl>\n" .
1175             "    <ResourceCompile>\n" .
1176             "      <Culture>0x0809</Culture>\n" .
1177             "      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1178             "    </ResourceCompile>\n" .
1179             "    <Bscmake>\n" .
1180             "      <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1181             "      <OutputFile>.\\Release\\$windows_project.bsc</OutputFile>\n" .
1182             "    </Bscmake>\n" .
1183             "    <Link>\n" .
1184             "      <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1185             "      <SubSystem>$subsystem</SubSystem>\n" .
1186             "      <OutputFile>.\\Release\\$windows_project.exe</OutputFile>\n" .
1187             "      <AdditionalDependencies>$libs;%(AdditionalDependencies)</AdditionalDependencies>\n" .
1188             "    </Link>\n" .
1189             "  </ItemDefinitionGroup>\n" .
1190             "  <ItemDefinitionGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">\n" .
1191             "    <ClCompile>\n" .
1192             "      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\n" .
1193             "      <InlineFunctionExpansion>Default</InlineFunctionExpansion>\n" .
1194             "      <FunctionLevelLinking>false</FunctionLevelLinking>\n" .
1195             "      <Optimization>Disabled</Optimization>\n" .
1196             "      <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1197             "      <WarningLevel>Level3</WarningLevel>\n" .
1198             "      <MinimalRebuild>true</MinimalRebuild>\n" .
1199             "      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n" .
1200             "      <AdditionalIncludeDirectories>" . (join ";", map {"..\\..\\$dirpfx$_"} @srcdirs) . ";%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n" .
1201             "      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;POSIX;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1202             "      <AssemblerListingLocation>.\\Debug\\</AssemblerListingLocation>\n" .
1203             "      <PrecompiledHeaderOutputFile>.\\Debug\\$windows_project.pch</PrecompiledHeaderOutputFile>\n" .
1204             "      <ObjectFileName>.\\Debug\\</ObjectFileName>\n" .
1205             "      <ProgramDataBaseFileName>.\\Debug\\</ProgramDataBaseFileName>\n" .
1206             "      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\n" .
1207             "    </ClCompile>\n" .
1208             "    <Midl>\n" .
1209             "      <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1210             "      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1211             "      <TypeLibraryName>.\\Debug\\$windows_project.tlb</TypeLibraryName>\n" .
1212             "      <MkTypLibCompatible>true</MkTypLibCompatible>\n" .
1213             "      <TargetEnvironment>Win32</TargetEnvironment>\n" .
1214             "    </Midl>\n" .
1215             "    <ResourceCompile>\n" .
1216             "      <Culture>0x0809</Culture>\n" .
1217             "      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1218             "    </ResourceCompile>\n" .
1219             "    <Bscmake>\n" .
1220             "      <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1221             "      <OutputFile>.\\Debug\\$windows_project.bsc</OutputFile>\n" .
1222             "    </Bscmake>\n" .
1223             "    <Link>\n" .
1224             "      <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1225             "      <GenerateDebugInformation>true</GenerateDebugInformation>\n" .
1226             "      <SubSystem>$subsystem</SubSystem>\n" .
1227             "      <OutputFile>\$(TargetPath)</OutputFile>\n" .
1228             "      <AdditionalDependencies>$libs;%(AdditionalDependencies)</AdditionalDependencies>\n" .
1229             "    </Link>\n" .
1230             "  </ItemDefinitionGroup>\n";
1231
1232         # The VC++ projects don't have physical structure to them, instead
1233         # the files are organized by logical "filters" that are stored in
1234         # a separate file, so different users can organize things differently.
1235         # The filters file contains a copy of the ItemGroup elements from
1236         # the main project file that list the included items, but tack
1237         # on a filter name where needed.
1238         print FILTERS
1239             "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" .
1240             "<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n";
1241
1242         print "  <ItemGroup>\n";
1243         print FILTERS "  <ItemGroup>\n";
1244         foreach $icon_file (@icons) {
1245             $icon_file =~ s/..\\windows\\//;
1246             print "    <CustomBuild Include=\"..\\..\\$icon_file\" />\n";
1247             print FILTERS
1248                 "    <CustomBuild Include=\"..\\..\\$icon_file\">\n" .
1249                 "      <Filter>Resource Files</Filter>\n" .
1250                 "    </CustomBuild>\n";
1251         }
1252         print FILTERS "  </ItemGroup>\n";
1253         print "  </ItemGroup>\n";
1254
1255         print "  <ItemGroup>\n";
1256         print FILTERS "  <ItemGroup>\n";
1257         foreach $resource_file (@resources) {
1258             $resource_file =~ s/..\\windows\\//;
1259             print
1260                 "    <ResourceCompile Include=\"..\\..\\$resource_file\">\n" .
1261                 "      <AdditionalIncludeDirectories Condition=\"'\$(Configuration)|\$(Platform)'=='Release|Win32'\">..\\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n" .
1262                 "      <AdditionalIncludeDirectories Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n" .
1263                 "    </ResourceCompile>\n";
1264             print FILTERS
1265                 "    <ResourceCompile Include=\"..\\..\\$resource_file\">\n" .
1266                 "      <Filter>Resource Files</Filter>\n" .
1267                 "    </ResourceCompile>\n";
1268         }
1269         print FILTERS "  </ItemGroup>\n";
1270         print "  </ItemGroup>\n";
1271
1272         print "  <ItemGroup>\n";
1273         print FILTERS "  <ItemGroup>\n";
1274         foreach $source_file (@source_files) {
1275             $source_file =~ s/..\\windows\\//;
1276             print "    <ClCompile Include=\"..\\..\\$source_file\" />\n";
1277             print FILTERS
1278                 "    <ClCompile Include=\"..\\..\\$source_file\">\n" .
1279                 "      <Filter>Source Files</Filter>\n" .
1280                 "    </ClCompile>";
1281         }
1282         print FILTERS "  </ItemGroup>\n";
1283         print "  </ItemGroup>\n";
1284
1285         print "  <ItemGroup>\n";
1286         print FILTERS "  <ItemGroup>\n";
1287         foreach $header_file (@header_files) {
1288             $header_file  =~ s/..\\windows\\//;
1289             print "    <ClInclude Include=\"..\\..\\$header_file\" />\n";
1290             print FILTERS
1291                 "    <ClInclude Include=\"..\\..\\$header_file\">\n" .
1292                 "      <Filter>Header Files</Filter>\n" .
1293                 "    </ClInclude>";
1294         }
1295         print FILTERS "  </ItemGroup>\n";
1296         print "  </ItemGroup>\n";
1297
1298         print
1299             "  <Import Project=\"\$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n" .
1300             "</Project>";
1301
1302         print FILTERS
1303             "  <ItemGroup>\n" .
1304             "    <Filter Include=\"Source Files\">\n" .
1305             "      <UniqueIdentifier>{" . &invent_guid("sources:$windows_project") . "}</UniqueIdentifier>\n" .
1306             "    </Filter>\n" .
1307             "    <Filter Include=\"Header Files\">\n" .
1308             "      <UniqueIdentifier>{" . &invent_guid("headers:$windows_project") . "}</UniqueIdentifier>\n" .
1309             "    </Filter>\n" .
1310             "    <Filter Include=\"Resource Files\">\n" .
1311             "      <UniqueIdentifier>{" . &invent_guid("resources:$windows_project") . "}</UniqueIdentifier>\n" .
1312             "    </Filter>\n" .
1313             "  </ItemGroup>\n" .
1314             "</Project>";
1315
1316         select STDOUT; close OUT; close FILTERS;
1317         chdir "..";
1318     }
1319 }
1320
1321 if (defined $makefiles{'gtk'}) {
1322     $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
1323
1324     ##-- X/GTK/Unix makefile
1325     open OUT, ">$makefiles{'gtk'}"; select OUT;
1326     print
1327     "# Makefile for $project_name under X/GTK and Unix.\n".
1328     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1329     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1330     # gcc command line option is -D not /D
1331     ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
1332     print $_;
1333     print
1334     "\n".
1335     "# You can define this path to point at your tools if you need to\n".
1336     "# TOOLPATH = /opt/gcc/bin\n".
1337     "CC = \$(TOOLPATH)cc\n".
1338     "# If necessary set the path to krb5-config here\n".
1339     "KRB5CONFIG=krb5-config\n".
1340     "# You can manually set this to `gtk-config' or `pkg-config gtk+-1.2'\n".
1341     "# (depending on what works on your system) if you want to enforce\n".
1342     "# building with GTK 1.2, or you can set it to `pkg-config gtk+-2.0 x11'\n".
1343     "# if you want to enforce 2.0. The default is to try 2.0 and fall back\n".
1344     "# to 1.2 if it isn't found.\n".
1345     "GTK_CONFIG = sh -c 'pkg-config gtk+-2.0 x11 \$\$0 2>/dev/null || gtk-config \$\$0'\n".
1346     "\n".
1347     "-include Makefile.local\n".
1348     "\n".
1349     "unexport CFLAGS # work around a weird issue with krb5-config\n".
1350     "\n".
1351     &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1352                (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1353                " \$(shell \$(GTK_CONFIG) --cflags)").
1354                  " -D _FILE_OFFSET_BITS=64\n".
1355     "XLDFLAGS = \$(LDFLAGS) \$(shell \$(GTK_CONFIG) --libs)\n".
1356     "ULDFLAGS = \$(LDFLAGS)\n".
1357     "ifeq (,\$(findstring NO_GSSAPI,\$(COMPAT)))\n".
1358     "ifeq (,\$(findstring STATIC_GSSAPI,\$(COMPAT)))\n".
1359     "XLDFLAGS+= -ldl\n".
1360     "ULDFLAGS+= -ldl\n".
1361     "else\n".
1362     "CFLAGS+= -DNO_LIBDL \$(shell \$(KRB5CONFIG) --cflags gssapi)\n".
1363     "XLDFLAGS+= \$(shell \$(KRB5CONFIG) --libs gssapi)\n".
1364     "ULDFLAGS+= \$(shell \$(KRB5CONFIG) --libs gssapi)\n".
1365     "endif\n".
1366     "endif\n".
1367     "INSTALL=install\n".
1368     "INSTALL_PROGRAM=\$(INSTALL)\n".
1369     "INSTALL_DATA=\$(INSTALL)\n".
1370     "prefix=/usr/local\n".
1371     "exec_prefix=\$(prefix)\n".
1372     "bindir=\$(exec_prefix)/bin\n".
1373     "mandir=\$(prefix)/man\n".
1374     "man1dir=\$(mandir)/man1\n".
1375     "\n".
1376     &def($makefile_extra{'gtk'}->{'vars'}) .
1377     "\n".
1378     ".SUFFIXES:\n".
1379     "\n".
1380     "\n";
1381     print &splitline("all:" . join "", map { " $_" } &progrealnames("X:U"));
1382     print "\n\n";
1383     foreach $p (&prognames("X:U")) {
1384       ($prog, $type) = split ",", $p;
1385       $objstr = &objects($p, "X.o", undef, undef);
1386       print &splitline($prog . ": " . $objstr), "\n";
1387       $libstr = &objects($p, undef, undef, "-lX");
1388       print &splitline("\t\$(CC) -o \$@ " .
1389                        $objstr . " \$(${type}LDFLAGS) $libstr", 69), "\n\n";
1390     }
1391     foreach $d (&deps("X.o", undef, $dirpfx, "/", "gtk")) {
1392       if ($forceobj{$d->{obj_orig}}) {
1393         printf("%s: FORCE\n", $d->{obj});
1394       } else {
1395         print &splitline(sprintf("%s: %s", $d->{obj},
1396                                  join " ", @{$d->{deps}})), "\n";
1397       }
1398       print &splitline("\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c $d->{deps}->[0]\n");
1399     }
1400     print "\n";
1401     print &def($makefile_extra{'gtk'}->{'end'});
1402     print "\nclean:\n".
1403     "\trm -f *.o". (join "", map { " $_" } &progrealnames("X:U")) . "\n";
1404     print "\nFORCE:\n";
1405     select STDOUT; close OUT;
1406 }
1407
1408 if (defined $makefiles{'unix'}) {
1409     $dirpfx = &dirpfx($makefiles{'unix'}, "/");
1410
1411     ##-- GTK-free pure-Unix makefile for non-GUI apps only
1412     open OUT, ">$makefiles{'unix'}"; select OUT;
1413     print
1414     "# Makefile for $project_name under Unix.\n".
1415     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1416     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1417     # gcc command line option is -D not /D
1418     ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
1419     print $_;
1420     print
1421     "\n".
1422     "# You can define this path to point at your tools if you need to\n".
1423     "# TOOLPATH = /opt/gcc/bin\n".
1424     "CC = \$(TOOLPATH)cc\n".
1425     "\n".
1426     "-include Makefile.local\n".
1427     "\n".
1428     "unexport CFLAGS # work around a weird issue with krb5-config\n".
1429     "\n".
1430     &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1431                (join " ", map {"-I$dirpfx$_"} @srcdirs)).
1432                  " -D _FILE_OFFSET_BITS=64\n".
1433     "ULDFLAGS = \$(LDFLAGS)\n".
1434     "INSTALL=install\n".
1435     "INSTALL_PROGRAM=\$(INSTALL)\n".
1436     "INSTALL_DATA=\$(INSTALL)\n".
1437     "prefix=/usr/local\n".
1438     "exec_prefix=\$(prefix)\n".
1439     "bindir=\$(exec_prefix)/bin\n".
1440     "mandir=\$(prefix)/man\n".
1441     "man1dir=\$(mandir)/man1\n".
1442     "\n".
1443     &def($makefile_extra{'unix'}->{'vars'}) .
1444     "\n".
1445     ".SUFFIXES:\n".
1446     "\n".
1447     "\n";
1448     print &splitline("all:" . join "", map { " $_" } &progrealnames("U"));
1449     print "\n\n";
1450     foreach $p (&prognames("U")) {
1451       ($prog, $type) = split ",", $p;
1452       $objstr = &objects($p, "X.o", undef, undef);
1453       print &splitline($prog . ": " . $objstr), "\n";
1454       $libstr = &objects($p, undef, undef, "-lX");
1455       print &splitline("\t\$(CC) -o \$@ " .
1456                        $objstr . " \$(${type}LDFLAGS) $libstr", 69), "\n\n";
1457     }
1458     foreach $d (&deps("X.o", undef, $dirpfx, "/", "unix")) {
1459       if ($forceobj{$d->{obj_orig}}) {
1460         printf("%s: FORCE\n", $d->{obj});
1461       } else {
1462         print &splitline(sprintf("%s: %s", $d->{obj},
1463                                  join " ", @{$d->{deps}})), "\n";
1464       }
1465       print &splitline("\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c $d->{deps}->[0]\n");
1466     }
1467     print "\n";
1468     print &def($makefile_extra{'unix'}->{'end'});
1469     print "\nclean:\n".
1470     "\trm -f *.o". (join "", map { " $_" } &progrealnames("U")) . "\n";
1471     print "\nFORCE:\n";
1472     select STDOUT; close OUT;
1473 }
1474
1475 if (defined $makefiles{'am'}) {
1476     die "Makefile.am in a subdirectory is not supported\n"
1477         if &dirpfx($makefiles{'am'}, "/") ne "";
1478
1479     ##-- Unix/autoconf Makefile.am
1480     open OUT, ">$makefiles{'am'}"; select OUT;
1481     print
1482     "# Makefile.am for $project_name under Unix with Autoconf/Automake.\n".
1483     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1484     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n\n";
1485
1486     # 2014-02-22: as of automake-1.14 we begin to get complained at if
1487     # we don't use this option
1488     print "AUTOMAKE_OPTIONS = subdir-objects\n\n";
1489
1490     # Complete list of source and header files. Not used by the
1491     # auto-generated parts of this makefile, but Recipe might like to
1492     # have it available as a variable so that mandatory-rebuild things
1493     # (version.o) can conveniently be made to depend on it.
1494     @sources = ("allsources", "=", sort keys %allsourcefiles);
1495     print &splitline(join " ", @sources), "\n\n";
1496
1497     @cliprogs = ("bin_PROGRAMS", "=");
1498     foreach $p (&prognames("U")) {
1499       ($prog, $type) = split ",", $p;
1500       push @cliprogs, $prog;
1501     }
1502     @allprogs = @cliprogs;
1503     foreach $p (&prognames("X")) {
1504       ($prog, $type) = split ",", $p;
1505       push @allprogs, $prog;
1506     }
1507     print "if HAVE_GTK\n";
1508     print &splitline(join " ", @allprogs), "\n";
1509     print "else\n";
1510     print &splitline(join " ", @cliprogs), "\n";
1511     print "endif\n\n";
1512
1513     %objtosrc = ();
1514     foreach $d (&deps("X", undef, "", "/", "am")) {
1515       $objtosrc{$d->{obj}} = $d->{deps}->[0];
1516     }
1517
1518     print &splitline(join " ", "AM_CPPFLAGS", "=",
1519                      map {"-I\$(srcdir)/$_"} @srcdirs), "\n";
1520
1521     @amcflags = ("\$(COMPAT)", "\$(XFLAGS)", "\$(WARNINGOPTS)");
1522     print "if HAVE_GTK\n";
1523     print &splitline(join " ", "AM_CFLAGS", "=",
1524                      "\$(GTK_CFLAGS)", @amcflags), "\n";
1525     print "else\n";
1526     print &splitline(join " ", "AM_CFLAGS", "=", @amcflags), "\n";
1527     print "endif\n\n";
1528
1529     %amspeciallibs = ();
1530     foreach $obj (sort { $a cmp $b } keys %{$cflags{'am'}}) {
1531       print "lib${obj}_a_SOURCES = ", $objtosrc{$obj}, "\n";
1532       print &splitline(join " ", "lib${obj}_a_CFLAGS", "=", @amcflags,
1533                        $cflags{'am'}->{$obj}), "\n";
1534       $amspeciallibs{$obj} = "lib${obj}.a";
1535     }
1536     print &splitline(join " ", "noinst_LIBRARIES", "=",
1537                      sort { $a cmp $b } values %amspeciallibs), "\n\n";
1538
1539     foreach $p (&prognames("X:U")) {
1540       ($prog, $type) = split ",", $p;
1541       print "if HAVE_GTK\n" if $type eq "X";
1542       @progsources = ("${prog}_SOURCES", "=");
1543       %sourcefiles = ();
1544       @ldadd = ();
1545       $objstr = &objects($p, "X", undef, undef);
1546       foreach $obj (split / /,$objstr) {
1547         if ($amspeciallibs{$obj}) {
1548           push @ldadd, $amspeciallibs{$obj};
1549         } else {
1550           $sourcefiles{$objtosrc{$obj}} = 1;
1551         }
1552       }
1553       push @progsources, sort { $a cmp $b } keys %sourcefiles;
1554       print &splitline(join " ", @progsources), "\n";
1555       if ($type eq "X") {
1556         push @ldadd, "\$(GTK_LIBS)";
1557       }
1558       if (@ldadd) {
1559         print &splitline(join " ", "${prog}_LDADD", "=", @ldadd), "\n";
1560       }
1561       print "endif\n" if $type eq "X";
1562       print "\n";
1563     }
1564     print &def($makefile_extra{'am'}->{'end'});
1565     select STDOUT; close OUT;
1566 }
1567
1568 if (defined $makefiles{'lcc'}) {
1569     $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
1570
1571     ##-- lcc makefile
1572     open OUT, ">$makefiles{'lcc'}"; select OUT;
1573     print
1574     "# Makefile for $project_name under lcc.\n".
1575     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1576     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1577     # lcc command line option is -D not /D
1578     ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
1579     print $_;
1580     print
1581     "\n".
1582     "# If you rename this file to `Makefile', you should change this line,\n".
1583     "# so that the .rsp files still depend on the correct makefile.\n".
1584     "MAKEFILE = Makefile.lcc\n".
1585     "\n".
1586     "# C compilation flags\n".
1587     "CFLAGS = -D_WINDOWS " .
1588       (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1589       "\n".
1590     "# Resource compilation flags\n".
1591     "RCFLAGS = ".(join " ", map {"-I$dirpfx$_"} @srcdirs)."\n".
1592     "\n".
1593     "# Get include directory for resource compiler\n".
1594     "\n".
1595     &def($makefile_extra{'lcc'}->{'vars'}) .
1596     "\n";
1597     print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
1598     print "\n\n";
1599     foreach $p (&prognames("G:C")) {
1600       ($prog, $type) = split ",", $p;
1601       $objstr = &objects($p, "X.obj", "X.res", undef);
1602       print &splitline("$prog.exe: " . $objstr ), "\n";
1603       $subsystemtype = '';
1604       if ($type eq "G") { $subsystemtype = "-subsystem  windows"; }
1605       my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1606       print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1607       print "\n\n";
1608     }
1609
1610     foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "lcc")) {
1611       if ($forceobj{$d->{obj_orig}}) {
1612          printf("%s: FORCE\n", $d->{obj});
1613       } else {
1614          print &splitline(sprintf("%s: %s", $d->{obj},
1615                           join " ", @{$d->{deps}})), "\n";
1616       }
1617       if ($d->{obj} =~ /\.obj$/) {
1618           print &splitline("\tlcc -O -p6 \$(COMPAT)".
1619                            " \$(CFLAGS) \$(XFLAGS) ".$d->{deps}->[0],69)."\n";
1620       } else {
1621           print &splitline("\tlrc \$(RCFL) -r \$(RCFLAGS) ".
1622                            $d->{deps}->[0],69)."\n";
1623       }
1624     }
1625     print "\n";
1626     print &def($makefile_extra{'lcc'}->{'end'});
1627     print "\nclean:\n".
1628     "\t-del *.obj\n".
1629     "\t-del *.exe\n".
1630     "\t-del *.res\n".
1631     "\n".
1632     "FORCE:\n";
1633
1634     select STDOUT; close OUT;
1635 }
1636
1637 if (defined $makefiles{'osx'}) {
1638     $dirpfx = &dirpfx($makefiles{'osx'}, "/");
1639
1640     ##-- Mac OS X makefile
1641     open OUT, ">$makefiles{'osx'}"; select OUT;
1642     print
1643     "# Makefile for $project_name under Mac OS X.\n".
1644     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1645     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1646     # gcc command line option is -D not /D
1647     ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
1648     print $_;
1649     print
1650     "CC = \$(TOOLPATH)gcc\n".
1651     "\n".
1652     &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1653                (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1654     "MLDFLAGS = -framework Cocoa\n".
1655     "ULDFLAGS =\n".
1656     "\n" .
1657     &def($makefile_extra{'osx'}->{'vars'}) .
1658     "\n" .
1659     &splitline("all:" . join "", map { " $_" } &progrealnames("MX:U")) .
1660     "\n";
1661     foreach $p (&prognames("MX")) {
1662       ($prog, $type) = split ",", $p;
1663       $objstr = &objects($p, "X.o", undef, undef);
1664       $icon = &special($p, ".icns");
1665       $infoplist = &special($p, "info.plist");
1666       print "${prog}.app:\n\tmkdir -p \$\@\n";
1667       print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n";
1668       print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1669       $targets = "${prog}.app/Contents/MacOS/$prog";
1670       if (defined $icon) {
1671         print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1672         print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n";
1673         $targets .= " ${prog}.app/Contents/Resources/${prog}.icns";
1674       }
1675       if (defined $infoplist) {
1676         print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n";
1677         $targets .= " ${prog}.app/Contents/Info.plist";
1678       }
1679       $targets .= " \$(${prog}_extra)";
1680       print &splitline("${prog}: $targets", 69) . "\n\n";
1681       print &splitline("${prog}.app/Contents/MacOS/$prog: ".
1682                        "${prog}.app/Contents/MacOS " . $objstr), "\n";
1683       $libstr = &objects($p, undef, undef, "-lX");
1684       print &splitline("\t\$(CC) \$(MLDFLAGS) -o \$@ " .
1685                        $objstr . " $libstr", 69), "\n\n";
1686     }
1687     foreach $p (&prognames("U")) {
1688       ($prog, $type) = split ",", $p;
1689       $objstr = &objects($p, "X.o", undef, undef);
1690       print &splitline($prog . ": " . $objstr), "\n";
1691       $libstr = &objects($p, undef, undef, "-lX");
1692       print &splitline("\t\$(CC) \$(ULDFLAGS) -o \$@ " .
1693                        $objstr . " $libstr", 69), "\n\n";
1694     }
1695     foreach $d (&deps("X.o", undef, $dirpfx, "/", "osx")) {
1696       if ($forceobj{$d->{obj_orig}}) {
1697          printf("%s: FORCE\n", $d->{obj});
1698       } else {
1699          print &splitline(sprintf("%s: %s", $d->{obj},
1700                                   join " ", @{$d->{deps}})), "\n";
1701       }
1702       $firstdep = $d->{deps}->[0];
1703       if ($firstdep =~ /\.c$/) {
1704           print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS) -c \$<\n";
1705       } elsif ($firstdep =~ /\.m$/) {
1706           print "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS) -c \$<\n";
1707       }
1708     }
1709     print "\n".&def($makefile_extra{'osx'}->{'end'});
1710     print "\nclean:\n".
1711     "\trm -f *.o *.dmg". (join "", map { " $_" } &progrealnames("U")) . "\n".
1712     "\trm -rf *.app\n".
1713     "\n".
1714     "FORCE:\n";
1715     select STDOUT; close OUT;
1716 }
1717
1718 if (defined $makefiles{'devcppproj'}) {
1719     $dirpfx = &dirpfx($makefiles{'devcppproj'}, "\\");
1720     $orig_dir = cwd;
1721
1722     ##-- Dev-C++ 5 projects
1723     #
1724     # Note: All files created in this section are written in binary
1725     # mode to prevent any posibility of misinterpreted line endings.
1726     # I don't know if Dev-C++ is as touchy as MSVC with LF-only line
1727     # endings. But however, CRLF line endings are the common way on
1728     # Win32 machines where Dev-C++ is running.
1729     # Hence, in order for mkfiles.pl to generate CRLF project files
1730     # even when run from Unix, I make sure all files are binary and
1731     # explicitly write the CRLFs.
1732     #
1733     # Create directories if necessary
1734     mkdir $makefiles{'devcppproj'}
1735         if(! -d $makefiles{'devcppproj'});
1736     chdir $makefiles{'devcppproj'};
1737     @deps = &deps("X.obj", "X.res", $dirpfx, "\\", "devcppproj");
1738     %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
1739     # Make dir names FAT/NTFS compatible
1740     my @srcdirs = @srcdirs;
1741     for ($i=0; $i<@srcdirs; $i++) {
1742       $srcdirs[$i] =~ s/\//\\/g;
1743       $srcdirs[$i] =~ s/\\$//;
1744     }
1745     # Create the project files
1746     # Get names of all Windows projects (GUI and console)
1747     my @prognames = &prognames("G:C");
1748     foreach $progname (@prognames) {
1749       create_devcpp_project(\%all_object_deps, $progname);
1750     }
1751
1752     chdir $orig_dir;
1753
1754     sub create_devcpp_project {
1755       my ($all_object_deps, $progname) = @_;
1756       # Construct program's dependency info (Taken from 'vcproj', seems to work right here, too.)
1757       %seen_objects = ();
1758       %lib_files = ();
1759       %source_files = ();
1760       %header_files = ();
1761       %resource_files = ();
1762       @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
1763       foreach $object_file (@object_files) {
1764       next if defined $seen_objects{$object_file};
1765       $seen_objects{$object_file} = 1;
1766       if($object_file =~ /\.lib$/io) {
1767     $lib_files{$object_file} = 1;
1768     next;
1769       }
1770       $object_deps = $all_object_deps{$object_file};
1771       foreach $object_dep (@$object_deps) {
1772     if($object_dep =~ /\.c$/io) {
1773         $source_files{$object_dep} = 1;
1774         next;
1775     }
1776     if($object_dep =~ /\.h$/io) {
1777         $header_files{$object_dep} = 1;
1778         next;
1779     }
1780     if($object_dep =~ /\.(rc|ico)$/io) {
1781         $resource_files{$object_dep} = 1;
1782         next;
1783     }
1784       }
1785       }
1786       $libs = join " ", sort keys %lib_files;
1787       @source_files = sort keys %source_files;
1788       @header_files = sort keys %header_files;
1789       @resources = sort keys %resource_files;
1790   ($windows_project, $type) = split ",", $progname;
1791       mkdir $windows_project
1792       if(! -d $windows_project);
1793       chdir $windows_project;
1794
1795   $subsys = ($type eq "G") ? "0" : "1";  # 0 = Win32 GUI, 1 = Win32 Console
1796       open OUT, ">$windows_project.dev"; binmode OUT; select OUT;
1797       print
1798       "# DEV-C++ 5 Project File - $windows_project.dev\r\n".
1799       "# ** DO NOT EDIT **\r\n".
1800       "\r\n".
1801       # No difference between DEBUG and RELEASE here as in 'vcproj', because
1802       # Dev-C++ does not support mutiple compilation profiles in one single project.
1803       # (At least I can say this for Dev-C++ 5 Beta)
1804       "[Project]\r\n".
1805       "FileName=$windows_project.dev\r\n".
1806       "Name=$windows_project\r\n".
1807       "Ver=1\r\n".
1808       "IsCpp=1\r\n".
1809       "Type=$subsys\r\n".
1810       # Multimon is disabled here, as Dev-C++ (Version 5 Beta) does not have multimon.h
1811       "Compiler=-W -D__GNUWIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNO_MULTIMON -D_MBCS_\@\@_\r\n".
1812       "CppCompiler=-W -D__GNUWIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNO_MULTIMON -D_MBCS_\@\@_\r\n".
1813       "Includes=" . (join ";", map {"..\\..\\$dirpfx$_"} @srcdirs) . "\r\n".
1814       "Linker=-ladvapi32 -lcomctl32 -lcomdlg32 -lgdi32 -limm32 -lshell32 -luser32 -lwinmm -lwinspool_\@\@_\r\n".
1815       "Libs=\r\n".
1816       "UnitCount=" . (@source_files + @header_files + @resources) . "\r\n".
1817       "Folders=\"Header Files\",\"Resource Files\",\"Source Files\"\r\n".
1818       "ObjFiles=\r\n".
1819       "PrivateResource=${windows_project}_private.rc\r\n".
1820       "ResourceIncludes=..\\..\\..\\WINDOWS\r\n".
1821       "MakeIncludes=\r\n".
1822       "Icon=\r\n". # It's ok to leave this blank.
1823       "ExeOutput=\r\n".
1824       "ObjectOutput=\r\n".
1825       "OverrideOutput=0\r\n".
1826       "OverrideOutputName=$windows_project.exe\r\n".
1827       "HostApplication=\r\n".
1828       "CommandLine=\r\n".
1829       "UseCustomMakefile=0\r\n".
1830       "CustomMakefile=\r\n".
1831       "IncludeVersionInfo=0\r\n".
1832       "SupportXPThemes=0\r\n".
1833       "CompilerSet=0\r\n".
1834       "CompilerSettings=0000000000000000000000\r\n".
1835       "\r\n";
1836       $unit_count = 1;
1837       foreach $source_file (@source_files) {
1838       print
1839         "[Unit$unit_count]\r\n".
1840         "FileName=..\\..\\$source_file\r\n".
1841         "Folder=Source Files\r\n".
1842         "Compile=1\r\n".
1843         "CompileCpp=0\r\n".
1844         "Link=1\r\n".
1845         "Priority=1000\r\n".
1846         "OverrideBuildCmd=0\r\n".
1847         "BuildCmd=\r\n".
1848         "\r\n";
1849       $unit_count++;
1850   }
1851       foreach $header_file (@header_files) {
1852       print
1853         "[Unit$unit_count]\r\n".
1854         "FileName=..\\..\\$header_file\r\n".
1855         "Folder=Header Files\r\n".
1856         "Compile=1\r\n".
1857         "CompileCpp=1\r\n". # Dev-C++ want's to compile all header files with both compilers C and C++. It does not hurt.
1858         "Link=1\r\n".
1859         "Priority=1000\r\n".
1860         "OverrideBuildCmd=0\r\n".
1861         "BuildCmd=\r\n".
1862         "\r\n";
1863       $unit_count++;
1864   }
1865       foreach $resource_file (@resources) {
1866       if ($resource_file =~ /.*\.(ico|cur|bmp|dlg|rc2|rct|bin|rgs|gif|jpg|jpeg|jpe)/io) { # Default filter as in 'vcproj'
1867         $Compile = "0";    # Don't compile images and other binary resource files
1868         $CompileCpp = "0";
1869       } else {
1870         $Compile = "1";
1871         $CompileCpp = "1"; # Dev-C++ want's to compile all .rc files with both compilers C and C++. It does not hurt.
1872       }
1873       print
1874         "[Unit$unit_count]\r\n".
1875         "FileName=..\\..\\$resource_file\r\n".
1876         "Folder=Resource Files\r\n".
1877         "Compile=$Compile\r\n".
1878         "CompileCpp=$CompileCpp\r\n".
1879         "Link=0\r\n".
1880         "Priority=1000\r\n".
1881         "OverrideBuildCmd=0\r\n".
1882         "BuildCmd=\r\n".
1883         "\r\n";
1884       $unit_count++;
1885   }
1886       #Note: By default, [VersionInfo] is not used.
1887       print
1888       "[VersionInfo]\r\n".
1889       "Major=0\r\n".
1890       "Minor=0\r\n".
1891       "Release=1\r\n".
1892       "Build=1\r\n".
1893       "LanguageID=1033\r\n".
1894       "CharsetID=1252\r\n".
1895       "CompanyName=\r\n".
1896       "FileVersion=0.1\r\n".
1897       "FileDescription=\r\n".
1898       "InternalName=\r\n".
1899       "LegalCopyright=\r\n".
1900       "LegalTrademarks=\r\n".
1901       "OriginalFilename=$windows_project.exe\r\n".
1902       "ProductName=$windows_project\r\n".
1903       "ProductVersion=0.1\r\n".
1904       "AutoIncBuildNr=0\r\n";
1905       select STDOUT; close OUT;
1906       chdir "..";
1907     }
1908 }
1909
1910 # All done, so do the Unix postprocessing if asked to.
1911
1912 if ($do_unix) {
1913     chdir $orig_dir;
1914     system "./mkauto.sh";
1915     die "mkfiles.pl: mkauto.sh returned $?\n" if $? > 0;
1916     if ($do_unix == 1) {
1917         chdir ($targetdir = "unix")
1918             or die "$targetdir: chdir: $!\n";
1919     }
1920     system "./configure", @confargs;
1921     die "mkfiles.pl: configure returned $?\n" if $? > 0;
1922 }
1923
1924 sub invent_guid($) {
1925     my ($name) = @_;
1926
1927     # Invent a GUID for use in Visual Studio project files. We need
1928     # a few of these for every executable file we build.
1929     #
1930     # In order to avoid having to use the non-core Perl module
1931     # Data::GUID, and also arrange for GUIDs to be stable, we generate
1932     # our GUIDs by hashing a pile of fixed (but originally randomly
1933     # generated) data with the filename for which we need an id.
1934     #
1935     # Hashing _just_ the filenames would clearly be cheating (it's
1936     # quite conceivable that someone might hash the same string for
1937     # another reason and so generate a colliding GUID), but hashing a
1938     # whole SHA-512 data block of random gibberish as well should make
1939     # these GUIDs pseudo-random enough to not collide with anyone
1940     # else's.
1941
1942     my $randdata = pack "N*",
1943     0xD4AB035F,0x76998BA0,0x2DCCB0BD,0x6D3FA320,0x53638051,0xFE312F35,
1944     0xDE1CECC0,0x784DF852,0x6C9F4589,0x54B7AC23,0x14E7A1C4,0xF9BF04DF,
1945     0x19C08B6D,0x3FB69EF1,0xB2DA9043,0xDB5362F3,0x25718DB6,0x733560DA,
1946     0xFEF871B0,0xFECF7A0C,0x67D19C95,0xB492E911,0xF5D562A3,0xFCE1D478,
1947     0x02C50434,0xF7326B7E,0x93D39872,0xCF0D0269,0x9EF24C0F,0x827689AD,
1948     0x88BD20BC,0x74EA6AFE,0x29223682,0xB9AB9287,0x7EA7CE4F,0xCF81B379,
1949     0x9AE4A954,0x81C7AD97,0x2FF2F031,0xC51DA3C2,0xD311CCE7,0x0A31EB8B,
1950     0x1AB04242,0xAF53B714,0xFC574D40,0x8CB4ED01,0x29FEB16F,0x4904D7ED,
1951     0xF5C5F5E1,0xF138A4C2,0xA9D881CE,0xCEA65187,0x4421BA97,0x0EE8428E,
1952     0x9556E384,0x6D0484C9,0x561BD84B,0xD9516A40,0x6B4FD33F,0xDDFFE4C8,
1953     0x3D5DF8A5,0xFE6B7D99,0x3443371B,0xF4E30A3E,0xE62B9FDA,0x6BAA75DB,
1954     0x9EF3C2C7,0x6815CA42,0xE6536076,0xF851E6E2,0x39D16E69,0xBCDF3BB6,
1955     0x50EFFA41,0x378CDF2A,0xB5EC0D0C,0x1E94C433,0xE818241A,0x2689EB1F,
1956     0xB649CEF9,0xD7344D46,0x59C1BB13,0x27511FDF,0x7DAD1768,0xB355E29E,
1957     0xDFAE550C,0x2433005B,0x09DE10B0,0xAA00BA6B,0xC144ED2D,0x8513D007,
1958     0xB0315232,0x7A10DAB6,0x1D97654E,0xF048214D,0xE3059E75,0x83C225D1,
1959     0xFC7AB177,0x83F2B553,0x79F7A0AF,0x1C94582C,0xF5E4AF4B,0xFB39C865,
1960     0x58ABEB27,0xAAB28058,0x52C15A89,0x0EBE9741,0x343F4D26,0xF941202A,
1961     0xA32FD32F,0xDCC055B8,0x64281BF3,0x468BD7BA,0x0CEE09D3,0xBB5FD2B6,
1962     0xA528D412,0xA6A6967E,0xEAAF5DAE,0xDE7B2FAE,0xCA36887B,0x0DE196EB,
1963     0x74B95EF0,0x9EB8B7C2,0x020BFC83,0x1445086F,0xBF4B61B2,0x89AFACEC,
1964     0x80A5CD69,0xC790F744,0x435A6998,0x8DE7AC48,0x32F31BC9,0x8F760D3D,
1965     0xF02A74CB,0xD7B47E20,0x9EC91035,0x70FDE74D,0x9B531362,0x9D81739A,
1966     0x59ADC2EB,0x511555B5,0xCA84B8D5,0x3EC325FF,0x2E442A4C,0x82AF30D9,
1967     0xBFD3EC87,0x90C59E07,0x1C6DC991,0x2D16B822,0x7EA44EB5,0x3A655A39,
1968     0xAB640886,0x09311821,0x777801D9,0x489DBE61,0xA1FFEC65,0x978B49B1,
1969     0x7DB700CD,0x263CF3D6,0xF977E89F,0xBA0B3D01,0x6C6CED19,0x1BE6F23A,
1970     0x19E0ED98,0x8E71A499,0x70BA3271,0x3FB7EE98,0xABA46848,0x2B797959,
1971     0x72C6DE59,0xE08B795C,0x02936C39,0x02185CCB,0xD6F3CE18,0xD0157A40,
1972     0x833DEC3F,0x319B00C4,0x97B59513,0x900B81FD,0x9A022379,0x16E44E1A,
1973     0x0C4CC540,0xCA98E7F9,0xF9431A26,0x290BCFAC,0x406B82C0,0xBC1C4585,
1974     0x55C54528,0x811EBB77,0xD4EDD4F3,0xA70DC02E,0x8AD5C0D1,0x28D64EF4,
1975     0xBEFF5C69,0x99852C4A,0xB4BBFF7B,0x069230AC,0xA3E141FA,0x4E99FB0E,
1976     0xBC154DAA,0x323C7F15,0x86E0247E,0x2EEA3054,0xC9CA1D32,0x8964A006,
1977     0xC93978AC,0xF9B2C159,0x03F2079E,0xB051D284,0x4A7EA9A9,0xF001DA1F,
1978     0xD47A0DAA,0xCF7B6B73,0xF18293B2,0x84303E34,0xF8BC76C4,0xAFBEE24F,
1979     0xB589CA80,0x77B5BF86,0x21B9FD5B,0x1A5071DF,0xA3863110,0x0E50CA61,
1980     0x939151A5,0xD2A59021,0x83A9CDCE,0xCEC69767,0xC906BB16,0x3EE1FF4D,
1981     0x1321EAE4,0x0BF940D6,0x52471E61,0x8A087056,0x66E54293,0xF84AAB9B,
1982     0x08835EF1,0x8F12B77A,0xD86935A5,0x200281D7,0xCD3C37C9,0x30ABEC05,
1983     0x7067E8A0,0x608C4838,0xC9F51CDE,0xA6D318DE,0x41C05B2A,0x694CCE0E,
1984     0xC7842451,0xA3194393,0xFBDC2C84,0xA6D2B577,0xC91E7924,0x01EDA708,
1985     0x22FBB61E,0x662F9B7B,0xDE3150C3,0x2397058C;
1986     my $digest = sha512_hex($name . "\0" . $randdata);
1987     return sprintf("%s-%s-%04x-%04x-%s",
1988                    substr($digest,0,8),
1989                    substr($digest,8,4),
1990                    0x4000 | (0xFFF & hex(substr($digest,12,4))),
1991                    0x8000 | (0x3FFF & hex(substr($digest,16,4))),
1992                    substr($digest,20,12));
1993 }