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