]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - mkfiles.pl
Stop copying the licence text into C source code.
[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, and licence.h is likewise generated by licence.pl. We
49 # need to generate those _now_, before attempting dependency analysis.
50 eval 'chdir "charset"; require "sbcsgen.pl"; chdir ".."; select STDOUT;';
51 eval 'require "licence.pl"; select STDOUT;';
52
53 @srcdirs = ("./");
54
55 $divert = undef; # ref to scalar in which text is currently being put
56 $help = ""; # list of newline-free lines of help text
57 $project_name = "project"; # this is a good enough default
58 %makefiles = (); # maps makefile types to output makefile pathnames
59 %makefile_extra = (); # maps makefile types to extra Makefile text
60 %programs = (); # maps prog name + type letter to listref of objects/resources
61 %groups = (); # maps group name to listref of objects/resources
62
63 while (<IN>) {
64   chomp;
65   @_ = split;
66
67   # If we're gathering help text, keep doing so.
68   if (defined $divert) {
69       if ((defined $_[0]) && $_[0] eq "!end") {
70           $divert = undef;
71       } else {
72           ${$divert} .= "$_\n";
73       }
74       next;
75   }
76   # Skip comments and blank lines.
77   next if /^\s*#/ or scalar @_ == 0;
78
79   if ($_[0] eq "!begin" and $_[1] eq "help") { $divert = \$help; next; }
80   if ($_[0] eq "!end") { $divert = undef; next; }
81   if ($_[0] eq "!name") { $project_name = $_[1]; next; }
82   if ($_[0] eq "!srcdir") { push @srcdirs, $_[1]; next; }
83   if ($_[0] eq "!makefile" and &mfval($_[1])) { $makefiles{$_[1]}=$_[2]; next;}
84   if ($_[0] eq "!specialobj" and &mfval($_[1])) { $specialobj{$_[1]}->{$_[2]} = 1; next;}
85   if ($_[0] eq "!cflags" and &mfval($_[1])) {
86       ($rest = $_) =~ s/^\s*\S+\s+\S+\s+\S+\s*//; # find rest of input line
87       $rest = 1 if $rest eq "";
88       $cflags{$_[1]}->{$_[2]} = $rest;
89       next;
90   }
91   if ($_[0] eq "!forceobj") { $forceobj{$_[1]} = 1; next; }
92   if ($_[0] eq "!begin") {
93       if ($_[1] =~ /^>(.*)/) {
94           $divert = \$auxfiles{$1};
95       } elsif (&mfval($_[1])) {
96           $sect = $_[2] ? $_[2] : "end";
97           $divert = \($makefile_extra{$_[1]}->{$sect});
98       } else {
99           $dummy = '';
100           $divert = \$dummy;
101       }
102       next;
103   }
104   # If we're gathering help/verbatim text, keep doing so.
105   if (defined $divert) { ${$divert} .= "$_\n"; next; }
106   # Ignore blank lines.
107   next if scalar @_ == 0;
108
109   # Now we have an ordinary line. See if it's an = line, a : line
110   # or a + line.
111   @objs = @_;
112
113   if ($_[0] eq "+") {
114     $listref = $lastlistref;
115     $prog = undef;
116     die "$.: unexpected + line\n" if !defined $lastlistref;
117   } elsif ($_[1] eq "=") {
118     $groups{$_[0]} = [] if !defined $groups{$_[0]};
119     $listref = $groups{$_[0]};
120     $prog = undef;
121     shift @objs; # eat the group name
122   } elsif ($_[1] eq ":") {
123     $listref = [];
124     $prog = $_[0];
125     shift @objs; # eat the program name
126   } else {
127     die "$.: unrecognised line type\n";
128   }
129   shift @objs; # eat the +, the = or the :
130
131   while (scalar @objs > 0) {
132     $i = shift @objs;
133     if ($groups{$i}) {
134       foreach $j (@{$groups{$i}}) { unshift @objs, $j; }
135     } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or
136               $i eq "[X]" or $i eq "[U]" or $i eq "[MX]") and defined $prog) {
137       $type = substr($i,1,(length $i)-2);
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 . " $prog.rsp"), "\n";
652         print "\tlink \$(LFLAGS) \$(XLFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
653     }
654     foreach $p (&prognames("G:C")) {
655         ($prog, $type) = split ",", $p;
656         print $prog, ".rsp: \$(MAKEFILE)\n";
657         $objstr = &objects($p, "X.obj", "X.res", "X.lib");
658         @objlist = split " ", $objstr;
659         @objlines = ("");
660         foreach $i (@objlist) {
661             if (length($objlines[$#objlines] . " $i") > 50) {
662                 push @objlines, "";
663             }
664             $objlines[$#objlines] .= " $i";
665         }
666         $subsys = ($type eq "G") ? "windows" : "console";
667         print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
668         for ($i=0; $i<=$#objlines; $i++) {
669             print "\techo$objlines[$i] >> $prog.rsp\n";
670         }
671         print "\n";
672     }
673     foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "vc")) {
674         $extradeps = $forceobj{$d->{obj_orig}} ? ["*.c","*.h","*.rc"] : [];
675         print &splitline(sprintf("%s: %s", $d->{obj},
676                                  join " ", @$extradeps, @{$d->{deps}})), "\n";
677         if ($d->{obj} =~ /.obj$/) {
678             print "\tcl \$(COMPAT) \$(CFLAGS) \$(XFLAGS) /c ".$d->{deps}->[0],"\n\n";
679         } else {
680             print "\trc \$(RCFL) -r \$(RCFLAGS) ".$d->{deps}->[0],"\n\n";
681         }
682     }
683     print "\n";
684     print &def($makefile_extra{'vc'}->{'end'});
685     print "\nclean: tidy\n".
686       "\t-del *.exe\n\n".
687       "tidy:\n".
688       "\t-del *.obj\n".
689       "\t-del *.res\n".
690       "\t-del *.pch\n".
691       "\t-del *.aps\n".
692       "\t-del *.ilk\n".
693       "\t-del *.pdb\n".
694       "\t-del *.rsp\n".
695       "\t-del *.dsp\n".
696       "\t-del *.dsw\n".
697       "\t-del *.ncb\n".
698       "\t-del *.opt\n".
699       "\t-del *.plg\n".
700       "\t-del *.map\n".
701       "\t-del *.idb\n".
702       "\t-del debug.log\n";
703     select STDOUT; close OUT;
704 }
705
706 if (defined $makefiles{'vcproj'}) {
707     $dirpfx = &dirpfx($makefiles{'vcproj'}, "\\");
708
709     ##-- MSVC 6 Workspace and projects
710     #
711     # Note: All files created in this section are written in binary
712     # mode, because although MSVC's command-line make can deal with
713     # LF-only line endings, MSVC project files really _need_ to be
714     # CRLF. Hence, in order for mkfiles.pl to generate usable project
715     # files even when run from Unix, I make sure all files are binary
716     # and explicitly write the CRLFs.
717     #
718     # Create directories if necessary
719     mkdir $makefiles{'vcproj'}
720         if(! -d $makefiles{'vcproj'});
721     chdir $makefiles{'vcproj'};
722     @deps = &deps("X.obj", "X.res", $dirpfx, "\\", "vcproj");
723     %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
724     # Create the project files
725     # Get names of all Windows projects (GUI and console)
726     my @prognames = &prognames("G:C");
727     foreach $progname (@prognames) {
728       create_vc_project(\%all_object_deps, $progname);
729     }
730     # Create the workspace file
731     open OUT, ">$project_name.dsw"; binmode OUT; select OUT;
732     print
733     "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
734     "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
735     "\r\n".
736     "###############################################################################\r\n".
737     "\r\n";
738     # List projects
739     foreach $progname (@prognames) {
740       ($windows_project, $type) = split ",", $progname;
741         print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n";
742     }
743     print
744     "\r\n".
745     "Package=<5>\r\n".
746     "{{{\r\n".
747     "}}}\r\n".
748     "\r\n".
749     "Package=<4>\r\n".
750     "{{{\r\n".
751     "}}}\r\n".
752     "\r\n".
753     "###############################################################################\r\n".
754     "\r\n".
755     "Global:\r\n".
756     "\r\n".
757     "Package=<5>\r\n".
758     "{{{\r\n".
759     "}}}\r\n".
760     "\r\n".
761     "Package=<3>\r\n".
762     "{{{\r\n".
763     "}}}\r\n".
764     "\r\n".
765     "###############################################################################\r\n".
766     "\r\n";
767     select STDOUT; close OUT;
768     chdir $orig_dir;
769
770     sub create_vc_project {
771         my ($all_object_deps, $progname) = @_;
772         # Construct program's dependency info
773         %seen_objects = ();
774         %lib_files = ();
775         %source_files = ();
776         %header_files = ();
777         %resource_files = ();
778         @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
779         foreach $object_file (@object_files) {
780             next if defined $seen_objects{$object_file};
781             $seen_objects{$object_file} = 1;
782             if($object_file =~ /\.lib$/io) {
783                 $lib_files{$object_file} = 1;
784                 next;
785             }
786             $object_deps = $all_object_deps{$object_file};
787             foreach $object_dep (@$object_deps) {
788                 if($object_dep =~ /\.c$/io) {
789                     $source_files{$object_dep} = 1;
790                     next;
791                 }
792                 if($object_dep =~ /\.h$/io) {
793                     $header_files{$object_dep} = 1;
794                     next;
795                 }
796                 if($object_dep =~ /\.(rc|ico)$/io) {
797                     $resource_files{$object_dep} = 1;
798                     next;
799                 }
800             }
801         }
802         $libs = join " ", sort keys %lib_files;
803         @source_files = sort keys %source_files;
804         @header_files = sort keys %header_files;
805         @resources = sort keys %resource_files;
806         ($windows_project, $type) = split ",", $progname;
807         mkdir $windows_project
808             if(! -d $windows_project);
809         chdir $windows_project;
810         $subsys = ($type eq "G") ? "windows" : "console";
811         open OUT, ">$windows_project.dsp"; binmode OUT; select OUT;
812         print
813         "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n".
814         "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n".
815         "# ** DO NOT EDIT **\r\n".
816         "\r\n".
817         "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n".
818         "\r\n".
819         "CFG=$windows_project - Win32 Debug\r\n".
820         "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n".
821         "!MESSAGE use the Export Makefile command and run\r\n".
822         "!MESSAGE \r\n".
823         "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n".
824         "!MESSAGE \r\n".
825         "!MESSAGE You can specify a configuration when running NMAKE\r\n".
826         "!MESSAGE by defining the macro CFG on the command line. For example:\r\n".
827         "!MESSAGE \r\n".
828         "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
829         "!MESSAGE \r\n".
830         "!MESSAGE Possible choices for configuration are:\r\n".
831         "!MESSAGE \r\n".
832         "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n".
833         "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n".
834         "!MESSAGE \r\n".
835         "\r\n".
836         "# Begin Project\r\n".
837         "# PROP AllowPerConfigDependencies 0\r\n".
838         "# PROP Scc_ProjName \"\"\r\n".
839         "# PROP Scc_LocalPath \"\"\r\n".
840         "CPP=cl.exe\r\n".
841         "MTL=midl.exe\r\n".
842         "RSC=rc.exe\r\n".
843         "\r\n".
844         "!IF  \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
845         "\r\n".
846         "# PROP BASE Use_MFC 0\r\n".
847         "# PROP BASE Use_Debug_Libraries 0\r\n".
848         "# PROP BASE Output_Dir \"Release\"\r\n".
849         "# PROP BASE Intermediate_Dir \"Release\"\r\n".
850         "# PROP BASE Target_Dir \"\"\r\n".
851         "# PROP Use_MFC 0\r\n".
852         "# PROP Use_Debug_Libraries 0\r\n".
853         "# PROP Output_Dir \"Release\"\r\n".
854         "# PROP Intermediate_Dir \"Release\"\r\n".
855         "# PROP Ignore_Export_Lib 0\r\n".
856         "# PROP Target_Dir \"\"\r\n".
857         "# ADD BASE CPP /nologo /W3 /GX /O2 ".
858           (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
859           " /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
860         "# ADD CPP /nologo /W3 /GX /O2 ".
861           (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
862           " /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
863         "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
864         "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
865         "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n".
866         "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n".
867         "BSC32=bscmake.exe\r\n".
868         "# ADD BASE BSC32 /nologo\r\n".
869         "# ADD BSC32 /nologo\r\n".
870         "LINK32=link.exe\r\n".
871         "# 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".
872         "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n".
873         "# SUBTRACT LINK32 /pdb:none\r\n".
874         "\r\n".
875         "!ELSEIF  \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
876         "\r\n".
877         "# PROP BASE Use_MFC 0\r\n".
878         "# PROP BASE Use_Debug_Libraries 1\r\n".
879         "# PROP BASE Output_Dir \"Debug\"\r\n".
880         "# PROP BASE Intermediate_Dir \"Debug\"\r\n".
881         "# PROP BASE Target_Dir \"\"\r\n".
882         "# PROP Use_MFC 0\r\n".
883         "# PROP Use_Debug_Libraries 1\r\n".
884         "# PROP Output_Dir \"Debug\"\r\n".
885         "# PROP Intermediate_Dir \"Debug\"\r\n".
886         "# PROP Ignore_Export_Lib 0\r\n".
887         "# PROP Target_Dir \"\"\r\n".
888         "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od ".
889           (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
890           " /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
891         "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od ".
892           (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
893           " /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
894         "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
895         "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
896         "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n".
897         "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n".
898         "BSC32=bscmake.exe\r\n".
899         "# ADD BASE BSC32 /nologo\r\n".
900         "# ADD BSC32 /nologo\r\n".
901         "LINK32=link.exe\r\n".
902         "# 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".
903         "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
904         "# SUBTRACT LINK32 /pdb:none\r\n".
905         "\r\n".
906         "!ENDIF \r\n".
907         "\r\n".
908         "# Begin Target\r\n".
909         "\r\n".
910         "# Name \"$windows_project - Win32 Release\"\r\n".
911         "# Name \"$windows_project - Win32 Debug\"\r\n".
912         "# Begin Group \"Source Files\"\r\n".
913         "\r\n".
914         "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
915         foreach $source_file (@source_files) {
916             print
917               "# Begin Source File\r\n".
918               "\r\n".
919               "SOURCE=..\\..\\$source_file\r\n";
920             if($source_file =~ /ssh\.c/io) {
921                 # Disable 'Edit and continue' as Visual Studio can't handle the macros
922                 print
923                   "\r\n".
924                   "!IF  \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
925                   "\r\n".
926                   "!ELSEIF  \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
927                   "\r\n".
928                   "# ADD CPP /Zi\r\n".
929                   "\r\n".
930                   "!ENDIF \r\n".
931                   "\r\n";
932             }
933             print "# End Source File\r\n";
934         }
935         print
936         "# End Group\r\n".
937         "# Begin Group \"Header Files\"\r\n".
938         "\r\n".
939         "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
940         foreach $header_file (@header_files) {
941             print
942               "# Begin Source File\r\n".
943               "\r\n".
944               "SOURCE=..\\..\\$header_file\r\n".
945               "# End Source File\r\n";
946         }
947         print
948         "# End Group\r\n".
949         "# Begin Group \"Resource Files\"\r\n".
950         "\r\n".
951         "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
952         foreach $resource_file (@resources) {
953             print
954               "# Begin Source File\r\n".
955               "\r\n".
956               "SOURCE=..\\..\\$resource_file\r\n".
957               "# End Source File\r\n";
958         }
959         print
960         "# End Group\r\n".
961         "# End Target\r\n".
962         "# End Project\r\n";
963         select STDOUT; close OUT;
964         chdir "..";
965     }
966 }
967
968 if (defined $makefiles{'vstudio10'} || defined $makefiles{'vstudio12'}) {
969
970     ##-- Visual Studio 2010+ Solution and Projects
971
972     if (defined $makefiles{'vstudio10'}) {
973         create_vs_solution('vstudio10', "2010", "11.00", "v100");
974     }
975
976     if (defined $makefiles{'vstudio12'}) {
977         create_vs_solution('vstudio12', "2012", "12.00", "v110");
978     }
979
980     sub create_vs_solution {
981         my ($makefilename, $name, $version, $toolsver) = @_;
982
983         $dirpfx = &dirpfx($makefiles{$makefilename}, "\\");
984
985         @deps = &deps("X.obj", "X.res", $dirpfx, "\\", $makefilename);
986         %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
987
988         my @prognames = &prognames("G:C");
989
990         # Create the solution file.
991         mkdir $makefiles{$makefilename}
992            if(! -f $makefiles{$makefilename});
993         chdir $makefiles{$makefilename};
994
995         open OUT, ">$project_name.sln"; select OUT;
996
997         print
998             "Microsoft Visual Studio Solution File, Format Version $version\n" .
999             "# Visual Studio $name\n";
1000
1001         my %projguids = ();
1002         foreach $progname (@prognames) {
1003             ($windows_project, $type) = split ",", $progname;
1004
1005             $projguids{$windows_project} = $guid =
1006                 &invent_guid("project:$progname");
1007         
1008             print
1009                 "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"$windows_project\", \"$windows_project\\$windows_project.vcxproj\", \"{$guid}\"\n" .
1010                 "EndProject\n";
1011         }
1012
1013         print
1014             "Global\n" .
1015             "    GlobalSection(SolutionConfigurationPlatforms) = preSolution\n" .
1016             "        Debug|Win32 = Debug|Win32\n" .
1017             "        Release|Win32 = Release|Win32\n" .
1018             "    EndGlobalSection\n" .
1019             "    GlobalSection(ProjectConfigurationPlatforms) = postSolution\n" ;
1020
1021         foreach my $projguid (values %projguids) {
1022             print
1023                 "        {$projguid}.Debug|Win32.ActiveCfg = Debug|Win32\n" .
1024                 "        {$projguid}.Debug|Win32.Build.0 = Debug|Win32\n" .
1025                 "        {$projguid}.Release|Win32.ActiveCfg = Release|Win32\n" .
1026                 "        {$projguid}.Release|Win32.Build.0 = Release|Win32\n";
1027         }
1028
1029         print
1030             "    EndGlobalSection\n" .
1031             "    GlobalSection(SolutionProperties) = preSolution\n" .
1032             "        HideSolutionNode = FALSE\n" .
1033             "    EndGlobalSection\n" .
1034             "EndGlobal\n";
1035
1036         select STDOUT; close OUT;
1037
1038         foreach $progname (@prognames) {
1039             ($windows_project, $type) = split ",", $progname;
1040             create_vs_project(\%all_object_deps, $windows_project, $type, $projguids{$windows_project}, $toolsver);
1041         }
1042     
1043         chdir $orig_dir;
1044     }
1045
1046     sub create_vs_project {
1047         my ($all_object_deps, $windows_project, $type, $projguid, $toolsver) = @_;
1048
1049         # Break down the project's dependency information into the appropriate
1050         # groups.
1051         %seen_objects = ();
1052         %lib_files = ();
1053         %source_files = ();
1054         %header_files = ();
1055         %resource_files = ();
1056         %icon_files = ();
1057
1058         @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
1059         foreach $object_file (@object_files) {
1060             next if defined $seen_objects{$object_file};
1061             $seen_objects{$object_file} = 1;
1062
1063             if($object_file =~ /\.lib$/io) {
1064                 $lib_files{$object_file} = 1;
1065                 next;
1066             }
1067
1068             $object_deps = $all_object_deps{$object_file};
1069             foreach $object_dep (@$object_deps) {
1070                 if($object_dep eq $object_deps->[0]) {
1071                     if($object_dep =~ /\.c$/io) {
1072                         $source_files{$object_dep} = 1;
1073                     } elsif($object_dep =~ /\.rc$/io) {
1074                         $resource_files{$object_dep} = 1;
1075                     }
1076                 } elsif ($object_dep =~ /\.[ch]$/io) {
1077                     $header_files{$object_dep} = 1;
1078                 } elsif ($object_dep =~ /\.ico$/io) {
1079                     $icon_files{$object_dep} = 1;
1080                 }
1081             }
1082         }
1083
1084         $libs = join ";", sort keys %lib_files;
1085         @source_files = sort keys %source_files;
1086         @header_files = sort keys %header_files;
1087         @resources = sort keys %resource_files;
1088         @icons = sort keys %icon_files;
1089         $subsystem = ($type eq "G") ? "Windows" : "Console";
1090
1091         mkdir $windows_project
1092             if(! -d $windows_project);
1093         chdir $windows_project;
1094         open OUT, ">$windows_project.vcxproj"; select OUT;
1095         open FILTERS, ">$windows_project.vcxproj.filters";
1096
1097         # The bulk of the project file is just boilerplate stuff, so we
1098         # can mostly just dump it out here. Note, buried in the ClCompile
1099         # item definition, that we use a debug information format of
1100         # ProgramDatabase, which disables the edit-and-continue support
1101         # that breaks most of the project builds.
1102         print
1103             "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" .
1104             "<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n" .
1105             "  <ItemGroup Label=\"ProjectConfigurations\">\n" .
1106             "    <ProjectConfiguration Include=\"Debug|Win32\">\n" .
1107             "      <Configuration>Debug</Configuration>\n" .
1108             "      <Platform>Win32</Platform>\n" .
1109             "    </ProjectConfiguration>\n" .
1110             "    <ProjectConfiguration Include=\"Release|Win32\">\n" .
1111             "      <Configuration>Release</Configuration>\n" .
1112             "      <Platform>Win32</Platform>\n" .
1113             "    </ProjectConfiguration>\n" .
1114             "  </ItemGroup>\n" .
1115             "  <PropertyGroup Label=\"Globals\">\n" .
1116             "    <SccProjectName />\n" .
1117             "    <SccLocalPath />\n" .
1118             "    <ProjectGuid>{$projguid}</ProjectGuid>\n" .
1119             "  </PropertyGroup>\n" .
1120             "  <Import Project=\"\$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n" .
1121             "  <PropertyGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n" .
1122             "    <ConfigurationType>Application</ConfigurationType>\n" .
1123             "    <UseOfMfc>false</UseOfMfc>\n" .
1124             "    <CharacterSet>MultiByte</CharacterSet>\n" .
1125             "    <PlatformToolset>$toolsver</PlatformToolset>\n" .
1126             "  </PropertyGroup>\n" .
1127             "  <PropertyGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n" .
1128             "    <ConfigurationType>Application</ConfigurationType>\n" .
1129             "    <UseOfMfc>false</UseOfMfc>\n" .
1130             "    <CharacterSet>MultiByte</CharacterSet>\n" .
1131             "    <PlatformToolset>$toolsver</PlatformToolset>\n" .
1132             "  </PropertyGroup>\n" .
1133             "  <Import Project=\"\$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n" .
1134             "  <ImportGroup Label=\"ExtensionTargets\">\n" .
1135             "  </ImportGroup>\n" .
1136             "  <ImportGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\" Label=\"PropertySheets\">\n" .
1137             "    <Import Project=\"\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props\" Condition=\"exists('\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n" .
1138             "  </ImportGroup>\n" .
1139             "  <ImportGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Release|Win32'\" Label=\"PropertySheets\">\n" .
1140             "    <Import Project=\"\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props\" Condition=\"exists('\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n" .
1141             "  </ImportGroup>\n" .
1142             "  <PropertyGroup Label=\"UserMacros\" />\n" .
1143             "  <PropertyGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Release|Win32'\">\n" .
1144             "    <OutDir>.\\Release\\</OutDir>\n" .
1145             "    <IntDir>.\\Release\\</IntDir>\n" .
1146             "    <LinkIncremental>false</LinkIncremental>\n" .
1147             "  </PropertyGroup>\n" .
1148             "  <PropertyGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">\n" .
1149             "    <OutDir>.\\Debug\\</OutDir>\n" .
1150             "    <IntDir>.\\Debug\\</IntDir>\n" .
1151             "    <LinkIncremental>true</LinkIncremental>\n" .
1152             "  </PropertyGroup>\n" .
1153             "  <ItemDefinitionGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Release|Win32'\">\n" .
1154             "    <ClCompile>\n" .
1155             "      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\n" .
1156             "      <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>\n" .
1157             "      <StringPooling>true</StringPooling>\n" .
1158             "      <FunctionLevelLinking>true</FunctionLevelLinking>\n" .
1159             "      <Optimization>MaxSpeed</Optimization>\n" .
1160             "      <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1161             "      <WarningLevel>Level3</WarningLevel>\n" .
1162             "      <AdditionalIncludeDirectories>" . (join ";", map {"..\\..\\$dirpfx$_"} @srcdirs) . ";%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n" .
1163             "      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;POSIX;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1164             "      <AssemblerListingLocation>.\\Release\\</AssemblerListingLocation>\n" .
1165             "      <PrecompiledHeaderOutputFile>.\\Release\\$windows_project.pch</PrecompiledHeaderOutputFile>\n" .
1166             "      <ObjectFileName>.\\Release\\</ObjectFileName>\n" .
1167             "      <ProgramDataBaseFileName>.\\Release\\</ProgramDataBaseFileName>\n" .
1168             "    </ClCompile>\n" .
1169             "    <Midl>\n" .
1170             "      <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1171             "      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1172             "      <TypeLibraryName>.\\Release\\$windows_project.tlb</TypeLibraryName>\n" .
1173             "      <MkTypLibCompatible>true</MkTypLibCompatible>\n" .
1174             "      <TargetEnvironment>Win32</TargetEnvironment>\n" .
1175             "    </Midl>\n" .
1176             "    <ResourceCompile>\n" .
1177             "      <Culture>0x0809</Culture>\n" .
1178             "      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1179             "    </ResourceCompile>\n" .
1180             "    <Bscmake>\n" .
1181             "      <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1182             "      <OutputFile>.\\Release\\$windows_project.bsc</OutputFile>\n" .
1183             "    </Bscmake>\n" .
1184             "    <Link>\n" .
1185             "      <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1186             "      <SubSystem>$subsystem</SubSystem>\n" .
1187             "      <OutputFile>.\\Release\\$windows_project.exe</OutputFile>\n" .
1188             "      <AdditionalDependencies>$libs;%(AdditionalDependencies)</AdditionalDependencies>\n" .
1189             "    </Link>\n" .
1190             "  </ItemDefinitionGroup>\n" .
1191             "  <ItemDefinitionGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">\n" .
1192             "    <ClCompile>\n" .
1193             "      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\n" .
1194             "      <InlineFunctionExpansion>Default</InlineFunctionExpansion>\n" .
1195             "      <FunctionLevelLinking>false</FunctionLevelLinking>\n" .
1196             "      <Optimization>Disabled</Optimization>\n" .
1197             "      <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1198             "      <WarningLevel>Level3</WarningLevel>\n" .
1199             "      <MinimalRebuild>true</MinimalRebuild>\n" .
1200             "      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n" .
1201             "      <AdditionalIncludeDirectories>" . (join ";", map {"..\\..\\$dirpfx$_"} @srcdirs) . ";%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n" .
1202             "      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;POSIX;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1203             "      <AssemblerListingLocation>.\\Debug\\</AssemblerListingLocation>\n" .
1204             "      <PrecompiledHeaderOutputFile>.\\Debug\\$windows_project.pch</PrecompiledHeaderOutputFile>\n" .
1205             "      <ObjectFileName>.\\Debug\\</ObjectFileName>\n" .
1206             "      <ProgramDataBaseFileName>.\\Debug\\</ProgramDataBaseFileName>\n" .
1207             "      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\n" .
1208             "    </ClCompile>\n" .
1209             "    <Midl>\n" .
1210             "      <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1211             "      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1212             "      <TypeLibraryName>.\\Debug\\$windows_project.tlb</TypeLibraryName>\n" .
1213             "      <MkTypLibCompatible>true</MkTypLibCompatible>\n" .
1214             "      <TargetEnvironment>Win32</TargetEnvironment>\n" .
1215             "    </Midl>\n" .
1216             "    <ResourceCompile>\n" .
1217             "      <Culture>0x0809</Culture>\n" .
1218             "      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1219             "    </ResourceCompile>\n" .
1220             "    <Bscmake>\n" .
1221             "      <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1222             "      <OutputFile>.\\Debug\\$windows_project.bsc</OutputFile>\n" .
1223             "    </Bscmake>\n" .
1224             "    <Link>\n" .
1225             "      <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1226             "      <GenerateDebugInformation>true</GenerateDebugInformation>\n" .
1227             "      <SubSystem>$subsystem</SubSystem>\n" .
1228             "      <OutputFile>\$(TargetPath)</OutputFile>\n" .
1229             "      <AdditionalDependencies>$libs;%(AdditionalDependencies)</AdditionalDependencies>\n" .
1230             "    </Link>\n" .
1231             "  </ItemDefinitionGroup>\n";
1232
1233         # The VC++ projects don't have physical structure to them, instead
1234         # the files are organized by logical "filters" that are stored in
1235         # a separate file, so different users can organize things differently.
1236         # The filters file contains a copy of the ItemGroup elements from
1237         # the main project file that list the included items, but tack
1238         # on a filter name where needed.
1239         print FILTERS
1240             "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" .
1241             "<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n";
1242
1243         print "  <ItemGroup>\n";
1244         print FILTERS "  <ItemGroup>\n";
1245         foreach $icon_file (@icons) {
1246             $icon_file =~ s/..\\windows\\//;
1247             print "    <CustomBuild Include=\"..\\..\\$icon_file\" />\n";
1248             print FILTERS
1249                 "    <CustomBuild Include=\"..\\..\\$icon_file\">\n" .
1250                 "      <Filter>Resource Files</Filter>\n" .
1251                 "    </CustomBuild>\n";
1252         }
1253         print FILTERS "  </ItemGroup>\n";
1254         print "  </ItemGroup>\n";
1255
1256         print "  <ItemGroup>\n";
1257         print FILTERS "  <ItemGroup>\n";
1258         foreach $resource_file (@resources) {
1259             $resource_file =~ s/..\\windows\\//;
1260             print
1261                 "    <ResourceCompile Include=\"..\\..\\$resource_file\">\n" .
1262                 "      <AdditionalIncludeDirectories Condition=\"'\$(Configuration)|\$(Platform)'=='Release|Win32'\">..\\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n" .
1263                 "      <AdditionalIncludeDirectories Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n" .
1264                 "    </ResourceCompile>\n";
1265             print FILTERS
1266                 "    <ResourceCompile Include=\"..\\..\\$resource_file\">\n" .
1267                 "      <Filter>Resource Files</Filter>\n" .
1268                 "    </ResourceCompile>\n";
1269         }
1270         print FILTERS "  </ItemGroup>\n";
1271         print "  </ItemGroup>\n";
1272
1273         print "  <ItemGroup>\n";
1274         print FILTERS "  <ItemGroup>\n";
1275         foreach $source_file (@source_files) {
1276             $source_file =~ s/..\\windows\\//;
1277             print "    <ClCompile Include=\"..\\..\\$source_file\" />\n";
1278             print FILTERS
1279                 "    <ClCompile Include=\"..\\..\\$source_file\">\n" .
1280                 "      <Filter>Source Files</Filter>\n" .
1281                 "    </ClCompile>";
1282         }
1283         print FILTERS "  </ItemGroup>\n";
1284         print "  </ItemGroup>\n";
1285
1286         print "  <ItemGroup>\n";
1287         print FILTERS "  <ItemGroup>\n";
1288         foreach $header_file (@header_files) {
1289             $header_file  =~ s/..\\windows\\//;
1290             print "    <ClInclude Include=\"..\\..\\$header_file\" />\n";
1291             print FILTERS
1292                 "    <ClInclude Include=\"..\\..\\$header_file\">\n" .
1293                 "      <Filter>Header Files</Filter>\n" .
1294                 "    </ClInclude>";
1295         }
1296         print FILTERS "  </ItemGroup>\n";
1297         print "  </ItemGroup>\n";
1298
1299         print
1300             "  <Import Project=\"\$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n" .
1301             "</Project>";
1302
1303         print FILTERS
1304             "  <ItemGroup>\n" .
1305             "    <Filter Include=\"Source Files\">\n" .
1306             "      <UniqueIdentifier>{" . &invent_guid("sources:$windows_project") . "}</UniqueIdentifier>\n" .
1307             "    </Filter>\n" .
1308             "    <Filter Include=\"Header Files\">\n" .
1309             "      <UniqueIdentifier>{" . &invent_guid("headers:$windows_project") . "}</UniqueIdentifier>\n" .
1310             "    </Filter>\n" .
1311             "    <Filter Include=\"Resource Files\">\n" .
1312             "      <UniqueIdentifier>{" . &invent_guid("resources:$windows_project") . "}</UniqueIdentifier>\n" .
1313             "    </Filter>\n" .
1314             "  </ItemGroup>\n" .
1315             "</Project>";
1316
1317         select STDOUT; close OUT; close FILTERS;
1318         chdir "..";
1319     }
1320 }
1321
1322 if (defined $makefiles{'gtk'}) {
1323     $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
1324
1325     ##-- X/GTK/Unix makefile
1326     open OUT, ">$makefiles{'gtk'}"; select OUT;
1327     print
1328     "# Makefile for $project_name under X/GTK and Unix.\n".
1329     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1330     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1331     # gcc command line option is -D not /D
1332     ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
1333     print $_;
1334     print
1335     "\n".
1336     "# You can define this path to point at your tools if you need to\n".
1337     "# TOOLPATH = /opt/gcc/bin\n".
1338     "CC = \$(TOOLPATH)cc\n".
1339     "# If necessary set the path to krb5-config here\n".
1340     "KRB5CONFIG=krb5-config\n".
1341     "# You can manually set this to `gtk-config' or `pkg-config gtk+-1.2'\n".
1342     "# (depending on what works on your system) if you want to enforce\n".
1343     "# building with GTK 1.2, or you can set it to `pkg-config gtk+-2.0 x11'\n".
1344     "# if you want to enforce 2.0. The default is to try 2.0 and fall back\n".
1345     "# to 1.2 if it isn't found.\n".
1346     "GTK_CONFIG = sh -c 'pkg-config gtk+-2.0 x11 \$\$0 2>/dev/null || gtk-config \$\$0'\n".
1347     "\n".
1348     "-include Makefile.local\n".
1349     "\n".
1350     "unexport CFLAGS # work around a weird issue with krb5-config\n".
1351     "\n".
1352     &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1353                (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1354                " \$(shell \$(GTK_CONFIG) --cflags)").
1355                  " -D _FILE_OFFSET_BITS=64\n".
1356     "XLDFLAGS = \$(LDFLAGS) \$(shell \$(GTK_CONFIG) --libs)\n".
1357     "ULDFLAGS = \$(LDFLAGS)\n".
1358     "ifeq (,\$(findstring NO_GSSAPI,\$(COMPAT)))\n".
1359     "ifeq (,\$(findstring STATIC_GSSAPI,\$(COMPAT)))\n".
1360     "XLDFLAGS+= -ldl\n".
1361     "ULDFLAGS+= -ldl\n".
1362     "else\n".
1363     "CFLAGS+= -DNO_LIBDL \$(shell \$(KRB5CONFIG) --cflags gssapi)\n".
1364     "XLDFLAGS+= \$(shell \$(KRB5CONFIG) --libs gssapi)\n".
1365     "ULDFLAGS+= \$(shell \$(KRB5CONFIG) --libs gssapi)\n".
1366     "endif\n".
1367     "endif\n".
1368     "INSTALL=install\n".
1369     "INSTALL_PROGRAM=\$(INSTALL)\n".
1370     "INSTALL_DATA=\$(INSTALL)\n".
1371     "prefix=/usr/local\n".
1372     "exec_prefix=\$(prefix)\n".
1373     "bindir=\$(exec_prefix)/bin\n".
1374     "mandir=\$(prefix)/man\n".
1375     "man1dir=\$(mandir)/man1\n".
1376     "\n".
1377     &def($makefile_extra{'gtk'}->{'vars'}) .
1378     "\n".
1379     ".SUFFIXES:\n".
1380     "\n".
1381     "\n";
1382     print &splitline("all:" . join "", map { " $_" } &progrealnames("X:U"));
1383     print "\n\n";
1384     foreach $p (&prognames("X:U")) {
1385       ($prog, $type) = split ",", $p;
1386       $objstr = &objects($p, "X.o", undef, undef);
1387       print &splitline($prog . ": " . $objstr), "\n";
1388       $libstr = &objects($p, undef, undef, "-lX");
1389       print &splitline("\t\$(CC) -o \$@ " .
1390                        $objstr . " \$(${type}LDFLAGS) $libstr", 69), "\n\n";
1391     }
1392     foreach $d (&deps("X.o", undef, $dirpfx, "/", "gtk")) {
1393       if ($forceobj{$d->{obj_orig}}) {
1394         printf("%s: FORCE\n", $d->{obj});
1395       } else {
1396         print &splitline(sprintf("%s: %s", $d->{obj},
1397                                  join " ", @{$d->{deps}})), "\n";
1398       }
1399       print &splitline("\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c $d->{deps}->[0]\n");
1400     }
1401     print "\n";
1402     print &def($makefile_extra{'gtk'}->{'end'});
1403     print "\nclean:\n".
1404     "\trm -f *.o". (join "", map { " $_" } &progrealnames("X:U")) . "\n";
1405     print "\nFORCE:\n";
1406     select STDOUT; close OUT;
1407 }
1408
1409 if (defined $makefiles{'unix'}) {
1410     $dirpfx = &dirpfx($makefiles{'unix'}, "/");
1411
1412     ##-- GTK-free pure-Unix makefile for non-GUI apps only
1413     open OUT, ">$makefiles{'unix'}"; select OUT;
1414     print
1415     "# Makefile for $project_name under Unix.\n".
1416     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1417     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1418     # gcc command line option is -D not /D
1419     ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
1420     print $_;
1421     print
1422     "\n".
1423     "# You can define this path to point at your tools if you need to\n".
1424     "# TOOLPATH = /opt/gcc/bin\n".
1425     "CC = \$(TOOLPATH)cc\n".
1426     "\n".
1427     "-include Makefile.local\n".
1428     "\n".
1429     "unexport CFLAGS # work around a weird issue with krb5-config\n".
1430     "\n".
1431     &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1432                (join " ", map {"-I$dirpfx$_"} @srcdirs)).
1433                  " -D _FILE_OFFSET_BITS=64\n".
1434     "ULDFLAGS = \$(LDFLAGS)\n".
1435     "INSTALL=install\n".
1436     "INSTALL_PROGRAM=\$(INSTALL)\n".
1437     "INSTALL_DATA=\$(INSTALL)\n".
1438     "prefix=/usr/local\n".
1439     "exec_prefix=\$(prefix)\n".
1440     "bindir=\$(exec_prefix)/bin\n".
1441     "mandir=\$(prefix)/man\n".
1442     "man1dir=\$(mandir)/man1\n".
1443     "\n".
1444     &def($makefile_extra{'unix'}->{'vars'}) .
1445     "\n".
1446     ".SUFFIXES:\n".
1447     "\n".
1448     "\n";
1449     print &splitline("all:" . join "", map { " $_" } &progrealnames("U"));
1450     print "\n\n";
1451     foreach $p (&prognames("U")) {
1452       ($prog, $type) = split ",", $p;
1453       $objstr = &objects($p, "X.o", undef, undef);
1454       print &splitline($prog . ": " . $objstr), "\n";
1455       $libstr = &objects($p, undef, undef, "-lX");
1456       print &splitline("\t\$(CC) -o \$@ " .
1457                        $objstr . " \$(${type}LDFLAGS) $libstr", 69), "\n\n";
1458     }
1459     foreach $d (&deps("X.o", undef, $dirpfx, "/", "unix")) {
1460       if ($forceobj{$d->{obj_orig}}) {
1461         printf("%s: FORCE\n", $d->{obj});
1462       } else {
1463         print &splitline(sprintf("%s: %s", $d->{obj},
1464                                  join " ", @{$d->{deps}})), "\n";
1465       }
1466       print &splitline("\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c $d->{deps}->[0]\n");
1467     }
1468     print "\n";
1469     print &def($makefile_extra{'unix'}->{'end'});
1470     print "\nclean:\n".
1471     "\trm -f *.o". (join "", map { " $_" } &progrealnames("U")) . "\n";
1472     print "\nFORCE:\n";
1473     select STDOUT; close OUT;
1474 }
1475
1476 if (defined $makefiles{'am'}) {
1477     die "Makefile.am in a subdirectory is not supported\n"
1478         if &dirpfx($makefiles{'am'}, "/") ne "";
1479
1480     ##-- Unix/autoconf Makefile.am
1481     open OUT, ">$makefiles{'am'}"; select OUT;
1482     print
1483     "# Makefile.am for $project_name under Unix with Autoconf/Automake.\n".
1484     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1485     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n\n";
1486
1487     # 2014-02-22: as of automake-1.14 we begin to get complained at if
1488     # we don't use this option
1489     print "AUTOMAKE_OPTIONS = subdir-objects\n\n";
1490
1491     # Complete list of source and header files. Not used by the
1492     # auto-generated parts of this makefile, but Recipe might like to
1493     # have it available as a variable so that mandatory-rebuild things
1494     # (version.o) can conveniently be made to depend on it.
1495     @sources = ("allsources", "=", sort keys %allsourcefiles);
1496     print &splitline(join " ", @sources), "\n\n";
1497
1498     @cliprogs = ("bin_PROGRAMS", "=");
1499     foreach $p (&prognames("U")) {
1500       ($prog, $type) = split ",", $p;
1501       push @cliprogs, $prog;
1502     }
1503     @allprogs = @cliprogs;
1504     foreach $p (&prognames("X")) {
1505       ($prog, $type) = split ",", $p;
1506       push @allprogs, $prog;
1507     }
1508     print "if HAVE_GTK\n";
1509     print &splitline(join " ", @allprogs), "\n";
1510     print "else\n";
1511     print &splitline(join " ", @cliprogs), "\n";
1512     print "endif\n\n";
1513
1514     %objtosrc = ();
1515     foreach $d (&deps("X", undef, "", "/", "am")) {
1516       $objtosrc{$d->{obj}} = $d->{deps}->[0];
1517     }
1518
1519     print &splitline(join " ", "AM_CPPFLAGS", "=",
1520                      map {"-I\$(srcdir)/$_"} @srcdirs), "\n";
1521
1522     @amcflags = ("\$(COMPAT)", "\$(XFLAGS)", "\$(WARNINGOPTS)");
1523     print "if HAVE_GTK\n";
1524     print &splitline(join " ", "AM_CFLAGS", "=",
1525                      "\$(GTK_CFLAGS)", @amcflags), "\n";
1526     print "else\n";
1527     print &splitline(join " ", "AM_CFLAGS", "=", @amcflags), "\n";
1528     print "endif\n\n";
1529
1530     %amspeciallibs = ();
1531     foreach $obj (sort { $a cmp $b } keys %{$cflags{'am'}}) {
1532       print "lib${obj}_a_SOURCES = ", $objtosrc{$obj}, "\n";
1533       print &splitline(join " ", "lib${obj}_a_CFLAGS", "=", @amcflags,
1534                        $cflags{'am'}->{$obj}), "\n";
1535       $amspeciallibs{$obj} = "lib${obj}.a";
1536     }
1537     print &splitline(join " ", "noinst_LIBRARIES", "=",
1538                      sort { $a cmp $b } values %amspeciallibs), "\n\n";
1539
1540     foreach $p (&prognames("X:U")) {
1541       ($prog, $type) = split ",", $p;
1542       print "if HAVE_GTK\n" if $type eq "X";
1543       @progsources = ("${prog}_SOURCES", "=");
1544       %sourcefiles = ();
1545       @ldadd = ();
1546       $objstr = &objects($p, "X", undef, undef);
1547       foreach $obj (split / /,$objstr) {
1548         if ($amspeciallibs{$obj}) {
1549           push @ldadd, $amspeciallibs{$obj};
1550         } else {
1551           $sourcefiles{$objtosrc{$obj}} = 1;
1552         }
1553       }
1554       push @progsources, sort { $a cmp $b } keys %sourcefiles;
1555       print &splitline(join " ", @progsources), "\n";
1556       if ($type eq "X") {
1557         push @ldadd, "\$(GTK_LIBS)";
1558       }
1559       if (@ldadd) {
1560         print &splitline(join " ", "${prog}_LDADD", "=", @ldadd), "\n";
1561       }
1562       print "endif\n" if $type eq "X";
1563       print "\n";
1564     }
1565     print &def($makefile_extra{'am'}->{'end'});
1566     select STDOUT; close OUT;
1567 }
1568
1569 if (defined $makefiles{'lcc'}) {
1570     $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
1571
1572     ##-- lcc makefile
1573     open OUT, ">$makefiles{'lcc'}"; select OUT;
1574     print
1575     "# Makefile for $project_name under lcc.\n".
1576     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1577     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1578     # lcc command line option is -D not /D
1579     ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
1580     print $_;
1581     print
1582     "\n".
1583     "# If you rename this file to `Makefile', you should change this line,\n".
1584     "# so that the .rsp files still depend on the correct makefile.\n".
1585     "MAKEFILE = Makefile.lcc\n".
1586     "\n".
1587     "# C compilation flags\n".
1588     "CFLAGS = -D_WINDOWS " .
1589       (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1590       "\n".
1591     "# Resource compilation flags\n".
1592     "RCFLAGS = ".(join " ", map {"-I$dirpfx$_"} @srcdirs)."\n".
1593     "\n".
1594     "# Get include directory for resource compiler\n".
1595     "\n".
1596     &def($makefile_extra{'lcc'}->{'vars'}) .
1597     "\n";
1598     print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
1599     print "\n\n";
1600     foreach $p (&prognames("G:C")) {
1601       ($prog, $type) = split ",", $p;
1602       $objstr = &objects($p, "X.obj", "X.res", undef);
1603       print &splitline("$prog.exe: " . $objstr ), "\n";
1604       $subsystemtype = '';
1605       if ($type eq "G") { $subsystemtype = "-subsystem  windows"; }
1606       my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1607       print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1608       print "\n\n";
1609     }
1610
1611     foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "lcc")) {
1612       if ($forceobj{$d->{obj_orig}}) {
1613          printf("%s: FORCE\n", $d->{obj});
1614       } else {
1615          print &splitline(sprintf("%s: %s", $d->{obj},
1616                           join " ", @{$d->{deps}})), "\n";
1617       }
1618       if ($d->{obj} =~ /\.obj$/) {
1619           print &splitline("\tlcc -O -p6 \$(COMPAT)".
1620                            " \$(CFLAGS) \$(XFLAGS) ".$d->{deps}->[0],69)."\n";
1621       } else {
1622           print &splitline("\tlrc \$(RCFL) -r \$(RCFLAGS) ".
1623                            $d->{deps}->[0],69)."\n";
1624       }
1625     }
1626     print "\n";
1627     print &def($makefile_extra{'lcc'}->{'end'});
1628     print "\nclean:\n".
1629     "\t-del *.obj\n".
1630     "\t-del *.exe\n".
1631     "\t-del *.res\n".
1632     "\n".
1633     "FORCE:\n";
1634
1635     select STDOUT; close OUT;
1636 }
1637
1638 if (defined $makefiles{'osx'}) {
1639     $dirpfx = &dirpfx($makefiles{'osx'}, "/");
1640
1641     ##-- Mac OS X makefile
1642     open OUT, ">$makefiles{'osx'}"; select OUT;
1643     print
1644     "# Makefile for $project_name under Mac OS X.\n".
1645     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1646     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1647     # gcc command line option is -D not /D
1648     ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
1649     print $_;
1650     print
1651     "CC = \$(TOOLPATH)gcc\n".
1652     "\n".
1653     &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1654                (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1655     "MLDFLAGS = -framework Cocoa\n".
1656     "ULDFLAGS =\n".
1657     "\n" .
1658     &def($makefile_extra{'osx'}->{'vars'}) .
1659     "\n" .
1660     &splitline("all:" . join "", map { " $_" } &progrealnames("MX:U")) .
1661     "\n";
1662     foreach $p (&prognames("MX")) {
1663       ($prog, $type) = split ",", $p;
1664       $objstr = &objects($p, "X.o", undef, undef);
1665       $icon = &special($p, ".icns");
1666       $infoplist = &special($p, "info.plist");
1667       print "${prog}.app:\n\tmkdir -p \$\@\n";
1668       print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n";
1669       print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1670       $targets = "${prog}.app/Contents/MacOS/$prog";
1671       if (defined $icon) {
1672         print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1673         print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n";
1674         $targets .= " ${prog}.app/Contents/Resources/${prog}.icns";
1675       }
1676       if (defined $infoplist) {
1677         print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n";
1678         $targets .= " ${prog}.app/Contents/Info.plist";
1679       }
1680       $targets .= " \$(${prog}_extra)";
1681       print &splitline("${prog}: $targets", 69) . "\n\n";
1682       print &splitline("${prog}.app/Contents/MacOS/$prog: ".
1683                        "${prog}.app/Contents/MacOS " . $objstr), "\n";
1684       $libstr = &objects($p, undef, undef, "-lX");
1685       print &splitline("\t\$(CC) \$(MLDFLAGS) -o \$@ " .
1686                        $objstr . " $libstr", 69), "\n\n";
1687     }
1688     foreach $p (&prognames("U")) {
1689       ($prog, $type) = split ",", $p;
1690       $objstr = &objects($p, "X.o", undef, undef);
1691       print &splitline($prog . ": " . $objstr), "\n";
1692       $libstr = &objects($p, undef, undef, "-lX");
1693       print &splitline("\t\$(CC) \$(ULDFLAGS) -o \$@ " .
1694                        $objstr . " $libstr", 69), "\n\n";
1695     }
1696     foreach $d (&deps("X.o", undef, $dirpfx, "/", "osx")) {
1697       if ($forceobj{$d->{obj_orig}}) {
1698          printf("%s: FORCE\n", $d->{obj});
1699       } else {
1700          print &splitline(sprintf("%s: %s", $d->{obj},
1701                                   join " ", @{$d->{deps}})), "\n";
1702       }
1703       $firstdep = $d->{deps}->[0];
1704       if ($firstdep =~ /\.c$/) {
1705           print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS) -c \$<\n";
1706       } elsif ($firstdep =~ /\.m$/) {
1707           print "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS) -c \$<\n";
1708       }
1709     }
1710     print "\n".&def($makefile_extra{'osx'}->{'end'});
1711     print "\nclean:\n".
1712     "\trm -f *.o *.dmg". (join "", map { " $_" } &progrealnames("U")) . "\n".
1713     "\trm -rf *.app\n".
1714     "\n".
1715     "FORCE:\n";
1716     select STDOUT; close OUT;
1717 }
1718
1719 if (defined $makefiles{'devcppproj'}) {
1720     $dirpfx = &dirpfx($makefiles{'devcppproj'}, "\\");
1721     $orig_dir = cwd;
1722
1723     ##-- Dev-C++ 5 projects
1724     #
1725     # Note: All files created in this section are written in binary
1726     # mode to prevent any posibility of misinterpreted line endings.
1727     # I don't know if Dev-C++ is as touchy as MSVC with LF-only line
1728     # endings. But however, CRLF line endings are the common way on
1729     # Win32 machines where Dev-C++ is running.
1730     # Hence, in order for mkfiles.pl to generate CRLF project files
1731     # even when run from Unix, I make sure all files are binary and
1732     # explicitly write the CRLFs.
1733     #
1734     # Create directories if necessary
1735     mkdir $makefiles{'devcppproj'}
1736         if(! -d $makefiles{'devcppproj'});
1737     chdir $makefiles{'devcppproj'};
1738     @deps = &deps("X.obj", "X.res", $dirpfx, "\\", "devcppproj");
1739     %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
1740     # Make dir names FAT/NTFS compatible
1741     my @srcdirs = @srcdirs;
1742     for ($i=0; $i<@srcdirs; $i++) {
1743       $srcdirs[$i] =~ s/\//\\/g;
1744       $srcdirs[$i] =~ s/\\$//;
1745     }
1746     # Create the project files
1747     # Get names of all Windows projects (GUI and console)
1748     my @prognames = &prognames("G:C");
1749     foreach $progname (@prognames) {
1750       create_devcpp_project(\%all_object_deps, $progname);
1751     }
1752
1753     chdir $orig_dir;
1754
1755     sub create_devcpp_project {
1756       my ($all_object_deps, $progname) = @_;
1757       # Construct program's dependency info (Taken from 'vcproj', seems to work right here, too.)
1758       %seen_objects = ();
1759       %lib_files = ();
1760       %source_files = ();
1761       %header_files = ();
1762       %resource_files = ();
1763       @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
1764       foreach $object_file (@object_files) {
1765       next if defined $seen_objects{$object_file};
1766       $seen_objects{$object_file} = 1;
1767       if($object_file =~ /\.lib$/io) {
1768     $lib_files{$object_file} = 1;
1769     next;
1770       }
1771       $object_deps = $all_object_deps{$object_file};
1772       foreach $object_dep (@$object_deps) {
1773     if($object_dep =~ /\.c$/io) {
1774         $source_files{$object_dep} = 1;
1775         next;
1776     }
1777     if($object_dep =~ /\.h$/io) {
1778         $header_files{$object_dep} = 1;
1779         next;
1780     }
1781     if($object_dep =~ /\.(rc|ico)$/io) {
1782         $resource_files{$object_dep} = 1;
1783         next;
1784     }
1785       }
1786       }
1787       $libs = join " ", sort keys %lib_files;
1788       @source_files = sort keys %source_files;
1789       @header_files = sort keys %header_files;
1790       @resources = sort keys %resource_files;
1791   ($windows_project, $type) = split ",", $progname;
1792       mkdir $windows_project
1793       if(! -d $windows_project);
1794       chdir $windows_project;
1795
1796   $subsys = ($type eq "G") ? "0" : "1";  # 0 = Win32 GUI, 1 = Win32 Console
1797       open OUT, ">$windows_project.dev"; binmode OUT; select OUT;
1798       print
1799       "# DEV-C++ 5 Project File - $windows_project.dev\r\n".
1800       "# ** DO NOT EDIT **\r\n".
1801       "\r\n".
1802       # No difference between DEBUG and RELEASE here as in 'vcproj', because
1803       # Dev-C++ does not support mutiple compilation profiles in one single project.
1804       # (At least I can say this for Dev-C++ 5 Beta)
1805       "[Project]\r\n".
1806       "FileName=$windows_project.dev\r\n".
1807       "Name=$windows_project\r\n".
1808       "Ver=1\r\n".
1809       "IsCpp=1\r\n".
1810       "Type=$subsys\r\n".
1811       # Multimon is disabled here, as Dev-C++ (Version 5 Beta) does not have multimon.h
1812       "Compiler=-W -D__GNUWIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNO_MULTIMON -D_MBCS_\@\@_\r\n".
1813       "CppCompiler=-W -D__GNUWIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNO_MULTIMON -D_MBCS_\@\@_\r\n".
1814       "Includes=" . (join ";", map {"..\\..\\$dirpfx$_"} @srcdirs) . "\r\n".
1815       "Linker=-ladvapi32 -lcomctl32 -lcomdlg32 -lgdi32 -limm32 -lshell32 -luser32 -lwinmm -lwinspool_\@\@_\r\n".
1816       "Libs=\r\n".
1817       "UnitCount=" . (@source_files + @header_files + @resources) . "\r\n".
1818       "Folders=\"Header Files\",\"Resource Files\",\"Source Files\"\r\n".
1819       "ObjFiles=\r\n".
1820       "PrivateResource=${windows_project}_private.rc\r\n".
1821       "ResourceIncludes=..\\..\\..\\WINDOWS\r\n".
1822       "MakeIncludes=\r\n".
1823       "Icon=\r\n". # It's ok to leave this blank.
1824       "ExeOutput=\r\n".
1825       "ObjectOutput=\r\n".
1826       "OverrideOutput=0\r\n".
1827       "OverrideOutputName=$windows_project.exe\r\n".
1828       "HostApplication=\r\n".
1829       "CommandLine=\r\n".
1830       "UseCustomMakefile=0\r\n".
1831       "CustomMakefile=\r\n".
1832       "IncludeVersionInfo=0\r\n".
1833       "SupportXPThemes=0\r\n".
1834       "CompilerSet=0\r\n".
1835       "CompilerSettings=0000000000000000000000\r\n".
1836       "\r\n";
1837       $unit_count = 1;
1838       foreach $source_file (@source_files) {
1839       print
1840         "[Unit$unit_count]\r\n".
1841         "FileName=..\\..\\$source_file\r\n".
1842         "Folder=Source Files\r\n".
1843         "Compile=1\r\n".
1844         "CompileCpp=0\r\n".
1845         "Link=1\r\n".
1846         "Priority=1000\r\n".
1847         "OverrideBuildCmd=0\r\n".
1848         "BuildCmd=\r\n".
1849         "\r\n";
1850       $unit_count++;
1851   }
1852       foreach $header_file (@header_files) {
1853       print
1854         "[Unit$unit_count]\r\n".
1855         "FileName=..\\..\\$header_file\r\n".
1856         "Folder=Header Files\r\n".
1857         "Compile=1\r\n".
1858         "CompileCpp=1\r\n". # Dev-C++ want's to compile all header files with both compilers C and C++. It does not hurt.
1859         "Link=1\r\n".
1860         "Priority=1000\r\n".
1861         "OverrideBuildCmd=0\r\n".
1862         "BuildCmd=\r\n".
1863         "\r\n";
1864       $unit_count++;
1865   }
1866       foreach $resource_file (@resources) {
1867       if ($resource_file =~ /.*\.(ico|cur|bmp|dlg|rc2|rct|bin|rgs|gif|jpg|jpeg|jpe)/io) { # Default filter as in 'vcproj'
1868         $Compile = "0";    # Don't compile images and other binary resource files
1869         $CompileCpp = "0";
1870       } else {
1871         $Compile = "1";
1872         $CompileCpp = "1"; # Dev-C++ want's to compile all .rc files with both compilers C and C++. It does not hurt.
1873       }
1874       print
1875         "[Unit$unit_count]\r\n".
1876         "FileName=..\\..\\$resource_file\r\n".
1877         "Folder=Resource Files\r\n".
1878         "Compile=$Compile\r\n".
1879         "CompileCpp=$CompileCpp\r\n".
1880         "Link=0\r\n".
1881         "Priority=1000\r\n".
1882         "OverrideBuildCmd=0\r\n".
1883         "BuildCmd=\r\n".
1884         "\r\n";
1885       $unit_count++;
1886   }
1887       #Note: By default, [VersionInfo] is not used.
1888       print
1889       "[VersionInfo]\r\n".
1890       "Major=0\r\n".
1891       "Minor=0\r\n".
1892       "Release=1\r\n".
1893       "Build=1\r\n".
1894       "LanguageID=1033\r\n".
1895       "CharsetID=1252\r\n".
1896       "CompanyName=\r\n".
1897       "FileVersion=0.1\r\n".
1898       "FileDescription=\r\n".
1899       "InternalName=\r\n".
1900       "LegalCopyright=\r\n".
1901       "LegalTrademarks=\r\n".
1902       "OriginalFilename=$windows_project.exe\r\n".
1903       "ProductName=$windows_project\r\n".
1904       "ProductVersion=0.1\r\n".
1905       "AutoIncBuildNr=0\r\n";
1906       select STDOUT; close OUT;
1907       chdir "..";
1908     }
1909 }
1910
1911 # All done, so do the Unix postprocessing if asked to.
1912
1913 if ($do_unix) {
1914     chdir $orig_dir;
1915     system "./mkauto.sh";
1916     die "mkfiles.pl: mkauto.sh returned $?\n" if $? > 0;
1917     if ($do_unix == 1) {
1918         chdir ($targetdir = "unix")
1919             or die "$targetdir: chdir: $!\n";
1920     }
1921     system "./configure", @confargs;
1922     die "mkfiles.pl: configure returned $?\n" if $? > 0;
1923 }
1924
1925 sub invent_guid($) {
1926     my ($name) = @_;
1927
1928     # Invent a GUID for use in Visual Studio project files. We need
1929     # a few of these for every executable file we build.
1930     #
1931     # In order to avoid having to use the non-core Perl module
1932     # Data::GUID, and also arrange for GUIDs to be stable, we generate
1933     # our GUIDs by hashing a pile of fixed (but originally randomly
1934     # generated) data with the filename for which we need an id.
1935     #
1936     # Hashing _just_ the filenames would clearly be cheating (it's
1937     # quite conceivable that someone might hash the same string for
1938     # another reason and so generate a colliding GUID), but hashing a
1939     # whole SHA-512 data block of random gibberish as well should make
1940     # these GUIDs pseudo-random enough to not collide with anyone
1941     # else's.
1942
1943     my $randdata = pack "N*",
1944     0xD4AB035F,0x76998BA0,0x2DCCB0BD,0x6D3FA320,0x53638051,0xFE312F35,
1945     0xDE1CECC0,0x784DF852,0x6C9F4589,0x54B7AC23,0x14E7A1C4,0xF9BF04DF,
1946     0x19C08B6D,0x3FB69EF1,0xB2DA9043,0xDB5362F3,0x25718DB6,0x733560DA,
1947     0xFEF871B0,0xFECF7A0C,0x67D19C95,0xB492E911,0xF5D562A3,0xFCE1D478,
1948     0x02C50434,0xF7326B7E,0x93D39872,0xCF0D0269,0x9EF24C0F,0x827689AD,
1949     0x88BD20BC,0x74EA6AFE,0x29223682,0xB9AB9287,0x7EA7CE4F,0xCF81B379,
1950     0x9AE4A954,0x81C7AD97,0x2FF2F031,0xC51DA3C2,0xD311CCE7,0x0A31EB8B,
1951     0x1AB04242,0xAF53B714,0xFC574D40,0x8CB4ED01,0x29FEB16F,0x4904D7ED,
1952     0xF5C5F5E1,0xF138A4C2,0xA9D881CE,0xCEA65187,0x4421BA97,0x0EE8428E,
1953     0x9556E384,0x6D0484C9,0x561BD84B,0xD9516A40,0x6B4FD33F,0xDDFFE4C8,
1954     0x3D5DF8A5,0xFE6B7D99,0x3443371B,0xF4E30A3E,0xE62B9FDA,0x6BAA75DB,
1955     0x9EF3C2C7,0x6815CA42,0xE6536076,0xF851E6E2,0x39D16E69,0xBCDF3BB6,
1956     0x50EFFA41,0x378CDF2A,0xB5EC0D0C,0x1E94C433,0xE818241A,0x2689EB1F,
1957     0xB649CEF9,0xD7344D46,0x59C1BB13,0x27511FDF,0x7DAD1768,0xB355E29E,
1958     0xDFAE550C,0x2433005B,0x09DE10B0,0xAA00BA6B,0xC144ED2D,0x8513D007,
1959     0xB0315232,0x7A10DAB6,0x1D97654E,0xF048214D,0xE3059E75,0x83C225D1,
1960     0xFC7AB177,0x83F2B553,0x79F7A0AF,0x1C94582C,0xF5E4AF4B,0xFB39C865,
1961     0x58ABEB27,0xAAB28058,0x52C15A89,0x0EBE9741,0x343F4D26,0xF941202A,
1962     0xA32FD32F,0xDCC055B8,0x64281BF3,0x468BD7BA,0x0CEE09D3,0xBB5FD2B6,
1963     0xA528D412,0xA6A6967E,0xEAAF5DAE,0xDE7B2FAE,0xCA36887B,0x0DE196EB,
1964     0x74B95EF0,0x9EB8B7C2,0x020BFC83,0x1445086F,0xBF4B61B2,0x89AFACEC,
1965     0x80A5CD69,0xC790F744,0x435A6998,0x8DE7AC48,0x32F31BC9,0x8F760D3D,
1966     0xF02A74CB,0xD7B47E20,0x9EC91035,0x70FDE74D,0x9B531362,0x9D81739A,
1967     0x59ADC2EB,0x511555B5,0xCA84B8D5,0x3EC325FF,0x2E442A4C,0x82AF30D9,
1968     0xBFD3EC87,0x90C59E07,0x1C6DC991,0x2D16B822,0x7EA44EB5,0x3A655A39,
1969     0xAB640886,0x09311821,0x777801D9,0x489DBE61,0xA1FFEC65,0x978B49B1,
1970     0x7DB700CD,0x263CF3D6,0xF977E89F,0xBA0B3D01,0x6C6CED19,0x1BE6F23A,
1971     0x19E0ED98,0x8E71A499,0x70BA3271,0x3FB7EE98,0xABA46848,0x2B797959,
1972     0x72C6DE59,0xE08B795C,0x02936C39,0x02185CCB,0xD6F3CE18,0xD0157A40,
1973     0x833DEC3F,0x319B00C4,0x97B59513,0x900B81FD,0x9A022379,0x16E44E1A,
1974     0x0C4CC540,0xCA98E7F9,0xF9431A26,0x290BCFAC,0x406B82C0,0xBC1C4585,
1975     0x55C54528,0x811EBB77,0xD4EDD4F3,0xA70DC02E,0x8AD5C0D1,0x28D64EF4,
1976     0xBEFF5C69,0x99852C4A,0xB4BBFF7B,0x069230AC,0xA3E141FA,0x4E99FB0E,
1977     0xBC154DAA,0x323C7F15,0x86E0247E,0x2EEA3054,0xC9CA1D32,0x8964A006,
1978     0xC93978AC,0xF9B2C159,0x03F2079E,0xB051D284,0x4A7EA9A9,0xF001DA1F,
1979     0xD47A0DAA,0xCF7B6B73,0xF18293B2,0x84303E34,0xF8BC76C4,0xAFBEE24F,
1980     0xB589CA80,0x77B5BF86,0x21B9FD5B,0x1A5071DF,0xA3863110,0x0E50CA61,
1981     0x939151A5,0xD2A59021,0x83A9CDCE,0xCEC69767,0xC906BB16,0x3EE1FF4D,
1982     0x1321EAE4,0x0BF940D6,0x52471E61,0x8A087056,0x66E54293,0xF84AAB9B,
1983     0x08835EF1,0x8F12B77A,0xD86935A5,0x200281D7,0xCD3C37C9,0x30ABEC05,
1984     0x7067E8A0,0x608C4838,0xC9F51CDE,0xA6D318DE,0x41C05B2A,0x694CCE0E,
1985     0xC7842451,0xA3194393,0xFBDC2C84,0xA6D2B577,0xC91E7924,0x01EDA708,
1986     0x22FBB61E,0x662F9B7B,0xDE3150C3,0x2397058C;
1987     my $digest = sha512_hex($name . "\0" . $randdata);
1988     return sprintf("%s-%s-%04x-%04x-%s",
1989                    substr($digest,0,8),
1990                    substr($digest,8,4),
1991                    0x4000 | (0xFFF & hex(substr($digest,12,4))),
1992                    0x8000 | (0x3FFF & hex(substr($digest,16,4))),
1993                    substr($digest,20,12));
1994 }