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