3 # Cross-platform Makefile generator.
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.
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.
16 # FIXME: no attempt made to handle !forceobj in the project files.
22 use Digest::SHA qw(sha512_hex);
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.
30 # Arguments supplied after -u go to configure.
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);
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,
44 open IN, "Recipe" or die "unable to open Recipe file\n";
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;';
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
67 # If we're gathering help text, keep doing so.
68 if (defined $divert) {
69 if ((defined $_[0]) && $_[0] eq "!end") {
76 # Skip comments and blank lines.
77 next if /^\s*#/ or scalar @_ == 0;
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
88 # Make sure this file doesn't get lumped together with any
89 # other file's cflags.
92 # Give this file a specific set of cflags, but permit it to
93 # go together with other files using the same set.
96 $cflags{$_[1]}->{$_[2]} = $rest;
99 if ($_[0] eq "!forceobj") { $forceobj{$_[1]} = 1; next; }
100 if ($_[0] eq "!begin") {
101 if ($_[1] =~ /^>(.*)/) {
102 $divert = \$auxfiles{$1};
103 } elsif (&mfval($_[1])) {
104 $sect = $_[2] ? $_[2] : "end";
105 $divert = \($makefile_extra{$_[1]}->{$sect});
112 # If we're gathering help/verbatim text, keep doing so.
113 if (defined $divert) { ${$divert} .= "$_\n"; next; }
114 # Ignore blank lines.
115 next if scalar @_ == 0;
117 # Now we have an ordinary line. See if it's an = line, a : line
122 $listref = $lastlistref;
124 die "$.: unexpected + line\n" if !defined $lastlistref;
125 } elsif ($_[1] eq "=") {
126 $groups{$_[0]} = [] if !defined $groups{$_[0]};
127 $listref = $groups{$_[0]};
129 shift @objs; # eat the group name
130 } elsif ($_[1] eq ":") {
133 shift @objs; # eat the program name
135 die "$.: unrecognised line type\n";
137 shift @objs; # eat the +, the = or the :
139 while (scalar @objs > 0) {
142 foreach $j (@{$groups{$i}}) { unshift @objs, $j; }
143 } elsif (($i =~ /^\[([A-Z]*)\]$/) and defined $prog) {
144 $type = substr($i,1,(length $i)-2);
145 die "unrecognised program type for $prog [$type]\n"
146 if ! grep { $type eq $_ } qw(G C X U MX XT UT);
151 if ($prog and $type) {
152 die "multiple program entries for $prog [$type]\n"
153 if defined $programs{$prog . "," . $type};
154 $programs{$prog . "," . $type} = $listref;
156 $lastlistref = $listref;
161 foreach $aux (sort keys %auxfiles) {
163 print AUX $auxfiles{$aux};
167 # Now retrieve the complete list of objects and resource files, and
168 # construct dependency data for them. While we're here, expand the
169 # object list for each program, and complain if its type isn't set.
170 @prognames = sort keys %programs;
173 foreach $i (@prognames) {
174 ($prog, $type) = split ",", $i;
175 # Strip duplicate object names.
177 @list = grep { $status = ($prev ne $_); $prev=$_; $status }
178 sort @{$programs{$i}};
179 $programs{$i} = [@list];
181 # Dependencies for "x" start with "x.c" or "x.m" (depending on
183 # Dependencies for "x.res" start with "x.rc".
184 # Dependencies for "x.rsrc" start with "x.r".
185 # Both types of file are pushed on the list of files to scan.
186 # Libraries (.lib) don't have dependencies at all.
187 if ($j =~ /^(.*)\.res$/) {
189 $depends{$j} = [$file];
190 push @scanlist, $file;
191 } elsif ($j =~ /^(.*)\.rsrc$/) {
193 $depends{$j} = [$file];
194 push @scanlist, $file;
195 } elsif ($j !~ /\./) {
197 $file = "$j.m" unless &findfile($file);
198 $depends{$j} = [$file];
199 push @scanlist, $file;
204 # Scan each file on @scanlist and find further inclusions.
205 # Inclusions are given by lines of the form `#include "otherfile"'
206 # (system headers are automatically ignored by this because they'll
207 # be given in angle brackets). Files included by this method are
208 # added back on to @scanlist to be scanned in turn (if not already
211 # Resource scripts (.rc) can also include a file by means of:
212 # - a line # ending `ICON "filename"';
213 # - a line ending `RT_MANIFEST "filename"'.
214 # Files included by this method are not added to @scanlist because
215 # they can never include further files.
217 # In this pass we write out a hash %further which maps a source
218 # file name into a listref containing further source file names.
221 %allsourcefiles = (); # this is wanted by some makefiles
222 while (scalar @scanlist > 0) {
223 $file = shift @scanlist;
224 next if defined $further{$file}; # skip if we've already done it
225 $further{$file} = [];
226 $dirfile = &findfile($file);
227 $allsourcefiles{$dirfile} = 1;
228 open IN, "$dirfile" or die "unable to open source file $file\n";
231 /^\s*#include\s+\"([^\"]+)\"/ and do {
232 push @{$further{$file}}, $1;
236 /(RT_MANIFEST|ICON)\s+\"([^\"]+)\"\s*$/ and do {
237 push @{$further{$file}}, $2;
244 # Now we're ready to generate the final dependencies section. For
245 # each key in %depends, we must expand the dependencies list by
246 # iteratively adding entries from %further.
247 foreach $i (keys %depends) {
249 @scanlist = @{$depends{$i}};
250 foreach $i (@scanlist) { $dep{$i} = 1; }
251 while (scalar @scanlist > 0) {
252 $file = shift @scanlist;
253 foreach $j (@{$further{$file}}) {
256 push @{$depends{$i}}, $j;
261 # printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
264 # Validation of input.
268 # Returns true if the argument is a known makefile type. Otherwise,
269 # prints a warning and returns false;
270 if (grep { $type eq $_ }
271 ("vc","vcproj","cygwin","borland","lcc","devcppproj","gtk","unix",
272 "am","osx","vstudio10","vstudio12","clangcl")) {
275 warn "$.:unknown makefile type '$type'\n";
279 # Utility routines while writing out the Makefiles.
283 return (defined $x) ? $x : "";
287 my ($path) = shift @_;
288 my ($sep) = shift @_;
292 while (($i = index $path, $sep) >= 0 ||
293 ($j = index $path, "/") >= 0) {
294 if ($i >= 0 and ($j < 0 or $i < $j)) {
295 $path = substr $path, ($i + length $sep);
297 $path = substr $path, ($j + 1);
309 unless (defined $findfilecache{$name}) {
311 foreach $dir (@srcdirs) {
312 if (-f "$dir$name") {
315 $outdir =~ s/^\.\///;
318 die "multiple instances of source file $name\n" if $i > 1;
319 $findfilecache{$name} = (defined $outdir ? $outdir . $name : undef);
321 return $findfilecache{$name};
325 my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
328 ($otmpl, $rtmpl, $ltmpl) = map { defined $_ ? $_ : "" } ($otmpl, $rtmpl, $ltmpl);
330 foreach $i (@{$programs{$prog}}) {
332 if ($i =~ /^(.*)\.(res|rsrc)/) {
334 ($x = $rtmpl) =~ s/X/$y/;
335 } elsif ($i =~ /^(.*)\.lib/) {
337 ($x = $ltmpl) =~ s/X/$y/;
338 } elsif ($i !~ /\./) {
339 ($x = $otmpl) =~ s/X/$i/;
341 push @ret, $x if $x ne "";
343 return join " ", @ret;
347 my ($prog, $suffix) = @_;
350 ($otmpl, $rtmpl, $ltmpl) = map { defined $_ ? $_ : "" } ($otmpl, $rtmpl, $ltmpl);
352 foreach $i (@{$programs{$prog}}) {
353 if (substr($i, (length $i) - (length $suffix)) eq $suffix) {
357 return (scalar @ret) ? (join " ", @ret) : undef;
361 my ($line, $width, $splitchar) = @_;
364 $len = (defined $width ? $width : 76);
365 $splitchar = (defined $splitchar ? $splitchar : '\\');
366 while (length $line > $len) {
367 $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
369 $result .= " ${splitchar}\n\t\t" if $2 ne '';
373 return $result . $line;
377 my ($otmpl, $rtmpl, $prefix, $dirsep, $mftyp, $depchar, $splitchar) = @_;
383 foreach $i (sort keys %depends) {
384 next if $specialobj{$mftyp}->{$i};
385 if ($i =~ /^(.*)\.(res|rsrc)/) {
386 next if !defined $rtmpl;
388 ($x = $rtmpl) =~ s/X/$y/;
390 ($x = $otmpl) =~ s/X/$i/;
392 @deps = @{$depends{$i}};
398 push @ret, {obj => $x, obj_orig => $i, deps => [@deps]};
405 my ($n, $prog, $type);
408 foreach $n (@prognames) {
409 ($prog, $type) = split ",", $n;
410 push @ret, $n if index(":$types:", ":$type:") >= 0;
417 my ($n, $prog, $type);
420 foreach $n (@prognames) {
421 ($prog, $type) = split ",", $n;
422 push @ret, $prog if index(":$types:", ":$type:") >= 0;
428 my ($types,$suffix) = @_;
430 # assume that all UNIX programs have a man page
431 if($suffix eq "1" && $types =~ /:X:/) {
432 return map("$_.1", &progrealnames($types));
439 # Now we're ready to output the actual Makefiles.
441 if (defined $makefiles{'clangcl'}) {
442 $dirpfx = &dirpfx($makefiles{'clangcl'}, "/");
444 ##-- Makefile for cross-compiling using clang-cl, lld-link, and
445 ## MinGW's windres for resource compilation.
447 # This makefile allows a complete Linux-based cross-compile, but
448 # using the real Visual Studio header files and libraries. In
449 # order to run it, you will need:
451 # - MinGW windres on your PATH.
452 # * On Ubuntu as of 16.04, you can apt-get install
453 # binutils-mingw-w64-x86-64 and binutils-mingw-w64-i686
454 # which will provide (respectively) 64- and 32-bit versions,
455 # under the names to which RCCMD is defined below.
456 # - clang-cl and lld-link on your PATH.
457 # * I built these from the up-to-date LLVM project trunk git
458 # repositories, as of 2017-02-05.
459 # - case-mashed copies of the Visual Studio include directories.
460 # * On a real VS installation, run vcvars32.bat and look at
461 # the resulting value of %INCLUDE%. Take a full copy of each
462 # of those directories, and inside the copy, for each
463 # include file that has an uppercase letter in its name,
464 # make a lowercased symlink to it. Additionally, one of the
465 # directories will contain files called driverspecs.h and
466 # specstrings.h, and those will need symlinks called
467 # DriverSpecs.h and SpecStrings.h.
468 # * Now, on Linux, define the environment variable INCLUDE to
469 # be a list, separated by *semicolons* (in the Windows
470 # style), of those directories, but before all of them you
471 # must also include lib/clang/5.0.0/include from the clang
472 # installation area (which contains in particular a
473 # clang-compatible stdarg.h overriding the Visual Studio
475 # - similarly case-mashed copies of the library directories.
476 # * Again, on a real VS installation, run vcvars32 or
477 # vcvarsx86_amd64 (as appropriate), look at %LIB%, make a
478 # copy of each directory, and provide symlinks within that
479 # directory so that all the files can be opened as
481 # * Then set LIB to be a semicolon-separated list of those
482 # directories (but you'll need to change which set of
483 # directories depending on whether you want to do a 32-bit
485 # - for a 64-bit build, set 'Platform=x64' in the environment as
486 # well, or else on the make command line.
487 # * This is a variable understood only by this makefile - none
488 # of the tools we invoke will know it - but it's consistent
489 # with the way the VS scripts like vcvarsx86_amd64.bat set
490 # things up, and since the environment has to change
491 # _anyway_ between 32- and 64-bit builds (different set of
492 # paths in $LIB) it's reasonable to have the choice of
493 # compilation target driven by another environment variable
494 # set in parallel with that one.
496 open OUT, ">$makefiles{'clangcl'}"; select OUT;
498 "# Makefile for cross-compiling $project_name using clang-cl, lld-link,\n".
499 "# and MinGW's windres, using GNU make on Linux.\n".
500 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
501 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
505 "CCCMD = clang-cl\n".
506 "ifeq (\$(Platform),x64)\n".
507 "CCTARGET = x86_64-pc-windows-msvc18.0.0\n".
508 "RCCMD = x86_64-w64-mingw32-windres\n".
510 "CCTARGET = i386-pc-windows-msvc18.0.0\n".
511 "RCCMD = i686-w64-mingw32-windres\n".
513 "CC = \$(CCCMD) --target=\$(CCTARGET)\n".
514 &splitline("RC = \$(RCCMD) --preprocessor=\$(CCCMD) ".
515 "--preprocessor-arg=/TC --preprocessor-arg=/E")."\n".
518 "# C compilation flags\n".
519 &splitline("CFLAGS = /nologo /W3 /O1 " .
520 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
521 " /D_WINDOWS /D_WIN32_WINDOWS=0x500 /DWINVER=0x500 ".
522 "/D_CRT_SECURE_NO_WARNINGS")."\n".
523 "LFLAGS = /incremental:no /dynamicbase /nxcompat\n".
524 &splitline("RCFLAGS = ".(join " ", map {"-I$dirpfx$_"} @srcdirs).
525 " -DWIN32 -D_WIN32 -DWINVER=0x0400")."\n".
527 &def($makefile_extra{'clangcl'}->{'vars'}) .
530 print &splitline("all:" . join "", map { " \$(BUILDDIR)$_.exe" } &progrealnames("G:C"));
532 foreach $p (&prognames("G:C")) {
533 ($prog, $type) = split ",", $p;
534 $objstr = &objects($p, "\$(BUILDDIR)X.obj", "\$(BUILDDIR)X.res.o", undef);
535 print &splitline("\$(BUILDDIR)$prog.exe: " . $objstr), "\n";
537 $objstr = &objects($p, "\$(BUILDDIR)X.obj", "\$(BUILDDIR)X.res.o", "X.lib");
538 $subsys = ($type eq "G") ? "windows" : "console";
539 print &splitline("\t\$(LD) \$(LFLAGS) \$(XLFLAGS) ".
540 "/out:\$(BUILDDIR)$prog.exe ".
541 "/lldmap:\$(BUILDDIR)$prog.map ".
542 "/subsystem:$subsys\$(SUBSYSVER) $objstr")."\n\n";
544 foreach $d (&deps("\$(BUILDDIR)X.obj", "\$(BUILDDIR)X.res.o", $dirpfx, "/", "vc")) {
545 $extradeps = $forceobj{$d->{obj_orig}} ? ["*.c","*.h","*.rc"] : [];
546 print &splitline(sprintf("%s: %s", $d->{obj},
547 join " ", @$extradeps, @{$d->{deps}})), "\n";
548 if ($d->{obj} =~ /\.res\.o$/) {
549 print "\t\$(RC) \$(RCFLAGS) ".$d->{deps}->[0]." -o ".$d->{obj}."\n\n";
551 print "\t\$(CC) /Fo\$(BUILDDIR) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) /c \$<\n\n";
555 print &def($makefile_extra{'clangcl'}->{'end'});
557 &splitline("\trm -f \$(BUILDDIR)*.obj \$(BUILDDIR)*.exe ".
558 "\$(BUILDDIR)*.res.o \$(BUILDDIR)*.map ".
559 "\$(BUILDDIR)*.exe.manifest")."\n";
560 select STDOUT; close OUT;
563 if (defined $makefiles{'cygwin'}) {
564 $dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
566 ##-- MinGW/CygWin makefile (called 'cygwin' for historical reasons)
567 open OUT, ">$makefiles{'cygwin'}"; select OUT;
569 "# Makefile for $project_name under MinGW, Cygwin, or Winelib.\n".
570 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
571 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
572 # gcc command line option is -D not /D
573 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
577 "# You can define this path to point at your tools if you need to\n".
578 "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
579 "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
580 "# TOOLPATH = i686-w64-mingw32-\n".
581 "CC = \$(TOOLPATH)gcc\n".
582 "RC = \$(TOOLPATH)windres\n".
583 "# Uncomment the following two lines to compile under Winelib\n".
586 "# You may also need to tell windres where to find include files:\n".
587 "# RCINC = --include-dir c:\\cygwin\\include\\\n".
589 &splitline("CFLAGS = -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
591 (join " ", map {"-I$dirpfx$_"} @srcdirs)) .
594 &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1 ".
595 "--define WINVER=0x0400 ".(join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
597 &def($makefile_extra{'cygwin'}->{'vars'}) .
601 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
603 foreach $p (&prognames("G:C")) {
604 ($prog, $type) = split ",", $p;
605 $objstr = &objects($p, "X.o", "X.res.o", undef);
606 print &splitline($prog . ".exe: " . $objstr), "\n";
607 my $mw = $type eq "G" ? " -mwindows" : "";
608 $libstr = &objects($p, undef, undef, "-lX");
609 print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
610 "-Wl,-Map,$prog.map " .
611 $objstr . " $libstr", 69), "\n\n";
613 foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/", "cygwin")) {
614 if ($forceobj{$d->{obj_orig}}) {
615 printf ("%s: FORCE\n", $d->{obj});
617 print &splitline(sprintf("%s: %s", $d->{obj},
618 join " ", @{$d->{deps}})), "\n";
620 if ($d->{obj} =~ /\.res\.o$/) {
621 print "\t\$(RC) \$(RCFL) \$(RCFLAGS) ".$d->{deps}->[0]." -o ".$d->{obj}."\n\n";
623 print "\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c ".$d->{deps}->[0]."\n\n";
627 print &def($makefile_extra{'cygwin'}->{'end'});
629 "\trm -f *.o *.exe *.res.o *.so *.map\n".
632 select STDOUT; close OUT;
636 ##-- Borland makefile
637 if (defined $makefiles{'borland'}) {
638 $dirpfx = &dirpfx($makefiles{'borland'}, "\\");
640 %stdlibs = ( # Borland provides many Win32 API libraries intrinsically
652 open OUT, ">$makefiles{'borland'}"; select OUT;
654 "# Makefile for $project_name under Borland C.\n".
655 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
656 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
657 # bcc32 command line option is -D not /D
658 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
662 "# If you rename this file to `Makefile', you should change this line,\n".
663 "# so that the .rsp files still depend on the correct makefile.\n".
664 "MAKEFILE = Makefile.bor\n".
666 "# C compilation flags\n".
667 "CFLAGS = -D_WINDOWS -DWINVER=0x0500\n".
668 "# Resource compilation flags\n".
669 "RCFLAGS = -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401\n".
671 "# Get include directory for resource compiler\n".
673 "BCB = \$(MAKEDIR)\\..\n".
676 &def($makefile_extra{'borland'}->{'vars'}) .
679 &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT)".
680 " \$(CFLAGS) \$(XFLAGS) ".
681 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
682 " /c \$*.c",69)."\n".
684 &splitline("\tbrcc32 \$(RCFL) -i \$(BCB)\\include -r".
685 " \$(RCFLAGS) \$*.rc",69)."\n".
687 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
689 foreach $p (&prognames("G:C")) {
690 ($prog, $type) = split ",", $p;
691 $objstr = &objects($p, "X.obj", "X.res", undef);
692 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
693 my $ap = ($type eq "G") ? "-aa" : "-ap";
694 print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n";
696 foreach $p (&prognames("G:C")) {
697 ($prog, $type) = split ",", $p;
698 print $prog, ".rsp: \$(MAKEFILE)\n";
699 $objstr = &objects($p, "X.obj", undef, undef);
700 @objlist = split " ", $objstr;
702 foreach $i (@objlist) {
703 if (length($objlines[$#objlines] . " $i") > 50) {
706 $objlines[$#objlines] .= " $i";
708 $c0w = ($type eq "G") ? "c0w32" : "c0x32";
709 print "\techo $c0w + > $prog.rsp\n";
710 for ($i=0; $i<=$#objlines; $i++) {
711 $plus = ($i < $#objlines ? " +" : "");
712 print "\techo$objlines[$i]$plus >> $prog.rsp\n";
714 print "\techo $prog.exe >> $prog.rsp\n";
715 $objstr = &objects($p, "X.obj", "X.res", undef);
716 @libs = split " ", &objects($p, undef, undef, "X");
717 @libs = grep { !$stdlibs{$_} } @libs;
718 unshift @libs, "cw32", "import32";
719 $libstr = join ' ', @libs;
720 print "\techo nul,$libstr, >> $prog.rsp\n";
721 print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n";
724 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "borland")) {
725 if ($forceobj{$d->{obj_orig}}) {
726 printf("%s: FORCE\n", $d->{obj});
728 print &splitline(sprintf("%s: %s", $d->{obj},
729 join " ", @{$d->{deps}})), "\n";
733 print &def($makefile_extra{'borland'}->{'end'});
744 "\t-del *.\$\$\$\$\$\$\n".
747 "\t-rem dummy command\n";
748 select STDOUT; close OUT;
751 if (defined $makefiles{'vc'}) {
752 $dirpfx = &dirpfx($makefiles{'vc'}, "\\");
754 ##-- Visual C++ makefile
755 open OUT, ">$makefiles{'vc'}"; select OUT;
757 "# Makefile for $project_name under Visual C.\n".
758 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
759 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
763 "# If you rename this file to `Makefile', you should change this line,\n".
764 "# so that the .rsp files still depend on the correct makefile.\n".
765 "MAKEFILE = Makefile.vc\n".
767 "# C compilation flags\n".
768 "CFLAGS = /nologo /W3 /O1 " .
769 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
770 " /D_WINDOWS /D_WIN32_WINDOWS=0x500 /DWINVER=0x500 /D_CRT_SECURE_NO_WARNINGS\n".
771 "LFLAGS = /incremental:no /dynamicbase /nxcompat\n".
772 "RCFLAGS = ".(join " ", map {"-I$dirpfx$_"} @srcdirs).
773 " -DWIN32 -D_WIN32 -DWINVER=0x0400\n".
775 &def($makefile_extra{'vc'}->{'vars'}) .
778 print &splitline("all:" . join "", map { " \$(BUILDDIR)$_.exe" } &progrealnames("G:C"));
780 foreach $p (&prognames("G:C")) {
781 ($prog, $type) = split ",", $p;
782 $objstr = &objects($p, "\$(BUILDDIR)X.obj", "\$(BUILDDIR)X.res", undef);
783 print &splitline("\$(BUILDDIR)$prog.exe: " . $objstr), "\n";
785 $objstr = &objects($p, "\$(BUILDDIR)X.obj", "\$(BUILDDIR)X.res", "X.lib");
786 $subsys = ($type eq "G") ? "windows" : "console";
787 $inlinefilename = "link_$prog";
788 print "\ttype <<$inlinefilename\n";
789 @objlist = split " ", $objstr;
791 foreach $i (@objlist) {
792 if (length($objlines[$#objlines] . " $i") > 72) {
795 $objlines[$#objlines] .= " $i";
797 for ($i=0; $i<=$#objlines; $i++) {
798 print "$objlines[$i]\n";
801 print "\tlink \$(LFLAGS) \$(XLFLAGS) -out:\$(BUILDDIR)$prog.exe -map:\$(BUILDDIR)$prog.map -nologo -subsystem:$subsys\$(SUBSYSVER) \@$inlinefilename\n\n";
803 foreach $d (&deps("\$(BUILDDIR)X.obj", "\$(BUILDDIR)X.res", $dirpfx, "\\", "vc")) {
804 $extradeps = $forceobj{$d->{obj_orig}} ? ["*.c","*.h","*.rc"] : [];
805 print &splitline(sprintf("%s: %s", $d->{obj},
806 join " ", @$extradeps, @{$d->{deps}})), "\n";
807 if ($d->{obj} =~ /.res$/) {
808 print "\trc /Fo@{[$d->{obj}]} \$(RCFL) -r \$(RCFLAGS) ".$d->{deps}->[0],"\n\n";
812 foreach $real_srcdir ("", @srcdirs) {
813 $srcdir = $real_srcdir;
816 $srcdir = $dirpfx . $srcdir;
817 $srcdir =~ s!\\\.\\!\\!;
818 $srcdir = "{$srcdir}";
820 # The double colon at the end of the line makes this a
821 # 'batch-mode inference rule', which means that nmake will
822 # aggregate multiple invocations of the rule and issue just
823 # one cl command with multiple source-file arguments. That
824 # noticeably speeds up builds, since starting up the cl
825 # process is a noticeable overhead and now has to be done far
827 print "${srcdir}.c.obj::\n\tcl /Fo\$(BUILDDIR) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) /c \$<\n\n";
829 print &def($makefile_extra{'vc'}->{'end'});
830 print "\nclean: tidy\n".
831 "\t-del \$(BUILDDIR)*.exe\n\n".
833 "\t-del \$(BUILDDIR)*.obj\n".
834 "\t-del \$(BUILDDIR)*.res\n".
835 "\t-del \$(BUILDDIR)*.pch\n".
836 "\t-del \$(BUILDDIR)*.aps\n".
837 "\t-del \$(BUILDDIR)*.ilk\n".
838 "\t-del \$(BUILDDIR)*.pdb\n".
839 "\t-del \$(BUILDDIR)*.rsp\n".
840 "\t-del \$(BUILDDIR)*.dsp\n".
841 "\t-del \$(BUILDDIR)*.dsw\n".
842 "\t-del \$(BUILDDIR)*.ncb\n".
843 "\t-del \$(BUILDDIR)*.opt\n".
844 "\t-del \$(BUILDDIR)*.plg\n".
845 "\t-del \$(BUILDDIR)*.map\n".
846 "\t-del \$(BUILDDIR)*.idb\n".
847 "\t-del \$(BUILDDIR)debug.log\n";
848 select STDOUT; close OUT;
851 if (defined $makefiles{'vcproj'}) {
852 $dirpfx = &dirpfx($makefiles{'vcproj'}, "\\");
854 ##-- MSVC 6 Workspace and projects
856 # Note: All files created in this section are written in binary
857 # mode, because although MSVC's command-line make can deal with
858 # LF-only line endings, MSVC project files really _need_ to be
859 # CRLF. Hence, in order for mkfiles.pl to generate usable project
860 # files even when run from Unix, I make sure all files are binary
861 # and explicitly write the CRLFs.
863 # Create directories if necessary
864 mkdir $makefiles{'vcproj'}
865 if(! -d $makefiles{'vcproj'});
866 chdir $makefiles{'vcproj'};
867 @deps = &deps("X.obj", "X.res", $dirpfx, "\\", "vcproj");
868 %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
869 # Create the project files
870 # Get names of all Windows projects (GUI and console)
871 my @prognames = &prognames("G:C");
872 foreach $progname (@prognames) {
873 create_vc_project(\%all_object_deps, $progname);
875 # Create the workspace file
876 open OUT, ">$project_name.dsw"; binmode OUT; select OUT;
878 "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
879 "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
881 "###############################################################################\r\n".
884 foreach $progname (@prognames) {
885 ($windows_project, $type) = split ",", $progname;
886 print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n";
898 "###############################################################################\r\n".
910 "###############################################################################\r\n".
912 select STDOUT; close OUT;
915 sub create_vc_project {
916 my ($all_object_deps, $progname) = @_;
917 # Construct program's dependency info
922 %resource_files = ();
923 @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
924 foreach $object_file (@object_files) {
925 next if defined $seen_objects{$object_file};
926 $seen_objects{$object_file} = 1;
927 if($object_file =~ /\.lib$/io) {
928 $lib_files{$object_file} = 1;
931 $object_deps = $all_object_deps{$object_file};
932 foreach $object_dep (@$object_deps) {
933 if($object_dep =~ /\.c$/io) {
934 $source_files{$object_dep} = 1;
937 if($object_dep =~ /\.h$/io) {
938 $header_files{$object_dep} = 1;
941 if($object_dep =~ /\.(rc|ico)$/io) {
942 $resource_files{$object_dep} = 1;
947 $libs = join " ", sort keys %lib_files;
948 @source_files = sort keys %source_files;
949 @header_files = sort keys %header_files;
950 @resources = sort keys %resource_files;
951 ($windows_project, $type) = split ",", $progname;
952 mkdir $windows_project
953 if(! -d $windows_project);
954 chdir $windows_project;
955 $subsys = ($type eq "G") ? "windows" : "console";
956 open OUT, ">$windows_project.dsp"; binmode OUT; select OUT;
958 "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n".
959 "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n".
960 "# ** DO NOT EDIT **\r\n".
962 "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n".
964 "CFG=$windows_project - Win32 Debug\r\n".
965 "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n".
966 "!MESSAGE use the Export Makefile command and run\r\n".
968 "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n".
970 "!MESSAGE You can specify a configuration when running NMAKE\r\n".
971 "!MESSAGE by defining the macro CFG on the command line. For example:\r\n".
973 "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
975 "!MESSAGE Possible choices for configuration are:\r\n".
977 "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n".
978 "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n".
981 "# Begin Project\r\n".
982 "# PROP AllowPerConfigDependencies 0\r\n".
983 "# PROP Scc_ProjName \"\"\r\n".
984 "# PROP Scc_LocalPath \"\"\r\n".
989 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
991 "# PROP BASE Use_MFC 0\r\n".
992 "# PROP BASE Use_Debug_Libraries 0\r\n".
993 "# PROP BASE Output_Dir \"Release\"\r\n".
994 "# PROP BASE Intermediate_Dir \"Release\"\r\n".
995 "# PROP BASE Target_Dir \"\"\r\n".
996 "# PROP Use_MFC 0\r\n".
997 "# PROP Use_Debug_Libraries 0\r\n".
998 "# PROP Output_Dir \"Release\"\r\n".
999 "# PROP Intermediate_Dir \"Release\"\r\n".
1000 "# PROP Ignore_Export_Lib 0\r\n".
1001 "# PROP Target_Dir \"\"\r\n".
1002 "# ADD BASE CPP /nologo /W3 /GX /O2 ".
1003 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
1004 " /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
1005 "# ADD CPP /nologo /W3 /GX /O2 ".
1006 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
1007 " /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
1008 "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
1009 "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
1010 "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n".
1011 "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n".
1012 "BSC32=bscmake.exe\r\n".
1013 "# ADD BASE BSC32 /nologo\r\n".
1014 "# ADD BSC32 /nologo\r\n".
1015 "LINK32=link.exe\r\n".
1016 "# 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".
1017 "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n".
1018 "# SUBTRACT LINK32 /pdb:none\r\n".
1020 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
1022 "# PROP BASE Use_MFC 0\r\n".
1023 "# PROP BASE Use_Debug_Libraries 1\r\n".
1024 "# PROP BASE Output_Dir \"Debug\"\r\n".
1025 "# PROP BASE Intermediate_Dir \"Debug\"\r\n".
1026 "# PROP BASE Target_Dir \"\"\r\n".
1027 "# PROP Use_MFC 0\r\n".
1028 "# PROP Use_Debug_Libraries 1\r\n".
1029 "# PROP Output_Dir \"Debug\"\r\n".
1030 "# PROP Intermediate_Dir \"Debug\"\r\n".
1031 "# PROP Ignore_Export_Lib 0\r\n".
1032 "# PROP Target_Dir \"\"\r\n".
1033 "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od ".
1034 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
1035 " /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
1036 "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od ".
1037 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
1038 " /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
1039 "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
1040 "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
1041 "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n".
1042 "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n".
1043 "BSC32=bscmake.exe\r\n".
1044 "# ADD BASE BSC32 /nologo\r\n".
1045 "# ADD BSC32 /nologo\r\n".
1046 "LINK32=link.exe\r\n".
1047 "# 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".
1048 "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
1049 "# SUBTRACT LINK32 /pdb:none\r\n".
1053 "# Begin Target\r\n".
1055 "# Name \"$windows_project - Win32 Release\"\r\n".
1056 "# Name \"$windows_project - Win32 Debug\"\r\n".
1057 "# Begin Group \"Source Files\"\r\n".
1059 "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
1060 foreach $source_file (@source_files) {
1062 "# Begin Source File\r\n".
1064 "SOURCE=..\\..\\$source_file\r\n";
1065 if($source_file =~ /ssh\.c/io) {
1066 # Disable 'Edit and continue' as Visual Studio can't handle the macros
1069 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
1071 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
1073 "# ADD CPP /Zi\r\n".
1078 print "# End Source File\r\n";
1082 "# Begin Group \"Header Files\"\r\n".
1084 "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
1085 foreach $header_file (@header_files) {
1087 "# Begin Source File\r\n".
1089 "SOURCE=..\\..\\$header_file\r\n".
1090 "# End Source File\r\n";
1094 "# Begin Group \"Resource Files\"\r\n".
1096 "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
1097 foreach $resource_file (@resources) {
1099 "# Begin Source File\r\n".
1101 "SOURCE=..\\..\\$resource_file\r\n".
1102 "# End Source File\r\n";
1107 "# End Project\r\n";
1108 select STDOUT; close OUT;
1113 if (defined $makefiles{'vstudio10'} || defined $makefiles{'vstudio12'}) {
1115 ##-- Visual Studio 2010+ Solution and Projects
1117 if (defined $makefiles{'vstudio10'}) {
1118 create_vs_solution('vstudio10', "2010", "11.00", "v100");
1121 if (defined $makefiles{'vstudio12'}) {
1122 create_vs_solution('vstudio12', "2012", "12.00", "v110");
1125 sub create_vs_solution {
1126 my ($makefilename, $name, $version, $toolsver) = @_;
1128 $dirpfx = &dirpfx($makefiles{$makefilename}, "\\");
1130 @deps = &deps("X.obj", "X.res", $dirpfx, "\\", $makefilename);
1131 %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
1133 my @prognames = &prognames("G:C");
1135 # Create the solution file.
1136 mkdir $makefiles{$makefilename}
1137 if(! -f $makefiles{$makefilename});
1138 chdir $makefiles{$makefilename};
1140 open OUT, ">$project_name.sln"; select OUT;
1143 "Microsoft Visual Studio Solution File, Format Version $version\n" .
1144 "# Visual Studio $name\n";
1147 foreach $progname (@prognames) {
1148 ($windows_project, $type) = split ",", $progname;
1150 $projguids{$windows_project} = $guid =
1151 &invent_guid("project:$progname");
1154 "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"$windows_project\", \"$windows_project\\$windows_project.vcxproj\", \"{$guid}\"\n" .
1160 " GlobalSection(SolutionConfigurationPlatforms) = preSolution\n" .
1161 " Debug|Win32 = Debug|Win32\n" .
1162 " Release|Win32 = Release|Win32\n" .
1163 " EndGlobalSection\n" .
1164 " GlobalSection(ProjectConfigurationPlatforms) = postSolution\n" ;
1166 foreach my $projguid (values %projguids) {
1168 " {$projguid}.Debug|Win32.ActiveCfg = Debug|Win32\n" .
1169 " {$projguid}.Debug|Win32.Build.0 = Debug|Win32\n" .
1170 " {$projguid}.Release|Win32.ActiveCfg = Release|Win32\n" .
1171 " {$projguid}.Release|Win32.Build.0 = Release|Win32\n";
1175 " EndGlobalSection\n" .
1176 " GlobalSection(SolutionProperties) = preSolution\n" .
1177 " HideSolutionNode = FALSE\n" .
1178 " EndGlobalSection\n" .
1181 select STDOUT; close OUT;
1183 foreach $progname (@prognames) {
1184 ($windows_project, $type) = split ",", $progname;
1185 create_vs_project(\%all_object_deps, $windows_project, $type, $projguids{$windows_project}, $toolsver);
1191 sub create_vs_project {
1192 my ($all_object_deps, $windows_project, $type, $projguid, $toolsver) = @_;
1194 # Break down the project's dependency information into the appropriate
1200 %resource_files = ();
1203 @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
1204 foreach $object_file (@object_files) {
1205 next if defined $seen_objects{$object_file};
1206 $seen_objects{$object_file} = 1;
1208 if($object_file =~ /\.lib$/io) {
1209 $lib_files{$object_file} = 1;
1213 $object_deps = $all_object_deps{$object_file};
1214 foreach $object_dep (@$object_deps) {
1215 if($object_dep eq $object_deps->[0]) {
1216 if($object_dep =~ /\.c$/io) {
1217 $source_files{$object_dep} = 1;
1218 } elsif($object_dep =~ /\.rc$/io) {
1219 $resource_files{$object_dep} = 1;
1221 } elsif ($object_dep =~ /\.[ch]$/io) {
1222 $header_files{$object_dep} = 1;
1223 } elsif ($object_dep =~ /\.ico$/io) {
1224 $icon_files{$object_dep} = 1;
1229 $libs = join ";", sort keys %lib_files;
1230 @source_files = sort keys %source_files;
1231 @header_files = sort keys %header_files;
1232 @resources = sort keys %resource_files;
1233 @icons = sort keys %icon_files;
1234 $subsystem = ($type eq "G") ? "Windows" : "Console";
1236 mkdir $windows_project
1237 if(! -d $windows_project);
1238 chdir $windows_project;
1239 open OUT, ">$windows_project.vcxproj"; select OUT;
1240 open FILTERS, ">$windows_project.vcxproj.filters";
1242 # The bulk of the project file is just boilerplate stuff, so we
1243 # can mostly just dump it out here. Note, buried in the ClCompile
1244 # item definition, that we use a debug information format of
1245 # ProgramDatabase, which disables the edit-and-continue support
1246 # that breaks most of the project builds.
1248 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" .
1249 "<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n" .
1250 " <ItemGroup Label=\"ProjectConfigurations\">\n" .
1251 " <ProjectConfiguration Include=\"Debug|Win32\">\n" .
1252 " <Configuration>Debug</Configuration>\n" .
1253 " <Platform>Win32</Platform>\n" .
1254 " </ProjectConfiguration>\n" .
1255 " <ProjectConfiguration Include=\"Release|Win32\">\n" .
1256 " <Configuration>Release</Configuration>\n" .
1257 " <Platform>Win32</Platform>\n" .
1258 " </ProjectConfiguration>\n" .
1260 " <PropertyGroup Label=\"Globals\">\n" .
1261 " <SccProjectName />\n" .
1262 " <SccLocalPath />\n" .
1263 " <ProjectGuid>{$projguid}</ProjectGuid>\n" .
1264 " </PropertyGroup>\n" .
1265 " <Import Project=\"\$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n" .
1266 " <PropertyGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n" .
1267 " <ConfigurationType>Application</ConfigurationType>\n" .
1268 " <UseOfMfc>false</UseOfMfc>\n" .
1269 " <CharacterSet>MultiByte</CharacterSet>\n" .
1270 " <PlatformToolset>$toolsver</PlatformToolset>\n" .
1271 " </PropertyGroup>\n" .
1272 " <PropertyGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n" .
1273 " <ConfigurationType>Application</ConfigurationType>\n" .
1274 " <UseOfMfc>false</UseOfMfc>\n" .
1275 " <CharacterSet>MultiByte</CharacterSet>\n" .
1276 " <PlatformToolset>$toolsver</PlatformToolset>\n" .
1277 " </PropertyGroup>\n" .
1278 " <Import Project=\"\$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n" .
1279 " <ImportGroup Label=\"ExtensionTargets\">\n" .
1280 " </ImportGroup>\n" .
1281 " <ImportGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\" Label=\"PropertySheets\">\n" .
1282 " <Import Project=\"\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props\" Condition=\"exists('\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n" .
1283 " </ImportGroup>\n" .
1284 " <ImportGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Release|Win32'\" Label=\"PropertySheets\">\n" .
1285 " <Import Project=\"\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props\" Condition=\"exists('\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n" .
1286 " </ImportGroup>\n" .
1287 " <PropertyGroup Label=\"UserMacros\" />\n" .
1288 " <PropertyGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Release|Win32'\">\n" .
1289 " <OutDir>.\\Release\\</OutDir>\n" .
1290 " <IntDir>.\\Release\\</IntDir>\n" .
1291 " <LinkIncremental>false</LinkIncremental>\n" .
1292 " </PropertyGroup>\n" .
1293 " <PropertyGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">\n" .
1294 " <OutDir>.\\Debug\\</OutDir>\n" .
1295 " <IntDir>.\\Debug\\</IntDir>\n" .
1296 " <LinkIncremental>true</LinkIncremental>\n" .
1297 " </PropertyGroup>\n" .
1298 " <ItemDefinitionGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Release|Win32'\">\n" .
1300 " <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\n" .
1301 " <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>\n" .
1302 " <StringPooling>true</StringPooling>\n" .
1303 " <FunctionLevelLinking>true</FunctionLevelLinking>\n" .
1304 " <Optimization>MaxSpeed</Optimization>\n" .
1305 " <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1306 " <WarningLevel>Level3</WarningLevel>\n" .
1307 " <AdditionalIncludeDirectories>" . (join ";", map {"..\\..\\$dirpfx$_"} @srcdirs) . ";%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n" .
1308 " <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;POSIX;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1309 " <AssemblerListingLocation>.\\Release\\</AssemblerListingLocation>\n" .
1310 " <PrecompiledHeaderOutputFile>.\\Release\\$windows_project.pch</PrecompiledHeaderOutputFile>\n" .
1311 " <ObjectFileName>.\\Release\\</ObjectFileName>\n" .
1312 " <ProgramDataBaseFileName>.\\Release\\</ProgramDataBaseFileName>\n" .
1315 " <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1316 " <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1317 " <TypeLibraryName>.\\Release\\$windows_project.tlb</TypeLibraryName>\n" .
1318 " <MkTypLibCompatible>true</MkTypLibCompatible>\n" .
1319 " <TargetEnvironment>Win32</TargetEnvironment>\n" .
1321 " <ResourceCompile>\n" .
1322 " <Culture>0x0809</Culture>\n" .
1323 " <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1324 " </ResourceCompile>\n" .
1326 " <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1327 " <OutputFile>.\\Release\\$windows_project.bsc</OutputFile>\n" .
1330 " <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1331 " <SubSystem>$subsystem</SubSystem>\n" .
1332 " <OutputFile>.\\Release\\$windows_project.exe</OutputFile>\n" .
1333 " <AdditionalDependencies>$libs;%(AdditionalDependencies)</AdditionalDependencies>\n" .
1335 " </ItemDefinitionGroup>\n" .
1336 " <ItemDefinitionGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">\n" .
1338 " <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\n" .
1339 " <InlineFunctionExpansion>Default</InlineFunctionExpansion>\n" .
1340 " <FunctionLevelLinking>false</FunctionLevelLinking>\n" .
1341 " <Optimization>Disabled</Optimization>\n" .
1342 " <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1343 " <WarningLevel>Level3</WarningLevel>\n" .
1344 " <MinimalRebuild>true</MinimalRebuild>\n" .
1345 " <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n" .
1346 " <AdditionalIncludeDirectories>" . (join ";", map {"..\\..\\$dirpfx$_"} @srcdirs) . ";%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n" .
1347 " <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;POSIX;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1348 " <AssemblerListingLocation>.\\Debug\\</AssemblerListingLocation>\n" .
1349 " <PrecompiledHeaderOutputFile>.\\Debug\\$windows_project.pch</PrecompiledHeaderOutputFile>\n" .
1350 " <ObjectFileName>.\\Debug\\</ObjectFileName>\n" .
1351 " <ProgramDataBaseFileName>.\\Debug\\</ProgramDataBaseFileName>\n" .
1352 " <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\n" .
1355 " <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1356 " <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1357 " <TypeLibraryName>.\\Debug\\$windows_project.tlb</TypeLibraryName>\n" .
1358 " <MkTypLibCompatible>true</MkTypLibCompatible>\n" .
1359 " <TargetEnvironment>Win32</TargetEnvironment>\n" .
1361 " <ResourceCompile>\n" .
1362 " <Culture>0x0809</Culture>\n" .
1363 " <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1364 " </ResourceCompile>\n" .
1366 " <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1367 " <OutputFile>.\\Debug\\$windows_project.bsc</OutputFile>\n" .
1370 " <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1371 " <GenerateDebugInformation>true</GenerateDebugInformation>\n" .
1372 " <SubSystem>$subsystem</SubSystem>\n" .
1373 " <OutputFile>\$(TargetPath)</OutputFile>\n" .
1374 " <AdditionalDependencies>$libs;%(AdditionalDependencies)</AdditionalDependencies>\n" .
1376 " </ItemDefinitionGroup>\n";
1378 # The VC++ projects don't have physical structure to them, instead
1379 # the files are organized by logical "filters" that are stored in
1380 # a separate file, so different users can organize things differently.
1381 # The filters file contains a copy of the ItemGroup elements from
1382 # the main project file that list the included items, but tack
1383 # on a filter name where needed.
1385 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" .
1386 "<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n";
1388 print " <ItemGroup>\n";
1389 print FILTERS " <ItemGroup>\n";
1390 foreach $icon_file (@icons) {
1391 $icon_file =~ s/..\\windows\\//;
1392 print " <CustomBuild Include=\"..\\..\\$icon_file\" />\n";
1394 " <CustomBuild Include=\"..\\..\\$icon_file\">\n" .
1395 " <Filter>Resource Files</Filter>\n" .
1396 " </CustomBuild>\n";
1398 print FILTERS " </ItemGroup>\n";
1399 print " </ItemGroup>\n";
1401 print " <ItemGroup>\n";
1402 print FILTERS " <ItemGroup>\n";
1403 foreach $resource_file (@resources) {
1404 $resource_file =~ s/..\\windows\\//;
1406 " <ResourceCompile Include=\"..\\..\\$resource_file\">\n" .
1407 " <AdditionalIncludeDirectories Condition=\"'\$(Configuration)|\$(Platform)'=='Release|Win32'\">..\\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n" .
1408 " <AdditionalIncludeDirectories Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">..\\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n" .
1409 " </ResourceCompile>\n";
1411 " <ResourceCompile Include=\"..\\..\\$resource_file\">\n" .
1412 " <Filter>Resource Files</Filter>\n" .
1413 " </ResourceCompile>\n";
1415 print FILTERS " </ItemGroup>\n";
1416 print " </ItemGroup>\n";
1418 print " <ItemGroup>\n";
1419 print FILTERS " <ItemGroup>\n";
1420 foreach $source_file (@source_files) {
1421 $source_file =~ s/..\\windows\\//;
1422 print " <ClCompile Include=\"..\\..\\$source_file\" />\n";
1424 " <ClCompile Include=\"..\\..\\$source_file\">\n" .
1425 " <Filter>Source Files</Filter>\n" .
1428 print FILTERS " </ItemGroup>\n";
1429 print " </ItemGroup>\n";
1431 print " <ItemGroup>\n";
1432 print FILTERS " <ItemGroup>\n";
1433 foreach $header_file (@header_files) {
1434 $header_file =~ s/..\\windows\\//;
1435 print " <ClInclude Include=\"..\\..\\$header_file\" />\n";
1437 " <ClInclude Include=\"..\\..\\$header_file\">\n" .
1438 " <Filter>Header Files</Filter>\n" .
1441 print FILTERS " </ItemGroup>\n";
1442 print " </ItemGroup>\n";
1445 " <Import Project=\"\$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n" .
1450 " <Filter Include=\"Source Files\">\n" .
1451 " <UniqueIdentifier>{" . &invent_guid("sources:$windows_project") . "}</UniqueIdentifier>\n" .
1453 " <Filter Include=\"Header Files\">\n" .
1454 " <UniqueIdentifier>{" . &invent_guid("headers:$windows_project") . "}</UniqueIdentifier>\n" .
1456 " <Filter Include=\"Resource Files\">\n" .
1457 " <UniqueIdentifier>{" . &invent_guid("resources:$windows_project") . "}</UniqueIdentifier>\n" .
1462 select STDOUT; close OUT; close FILTERS;
1467 if (defined $makefiles{'gtk'}) {
1468 $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
1470 ##-- X/GTK/Unix makefile
1471 open OUT, ">$makefiles{'gtk'}"; select OUT;
1473 "# Makefile for $project_name under X/GTK and Unix.\n".
1474 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1475 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1476 # gcc command line option is -D not /D
1477 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
1481 "# You can define this path to point at your tools if you need to\n".
1482 "# TOOLPATH = /opt/gcc/bin\n".
1483 "CC = \$(TOOLPATH)cc\n".
1484 "# If necessary set the path to krb5-config here\n".
1485 "KRB5CONFIG=krb5-config\n".
1486 "# You can manually set this to `gtk-config' or `pkg-config gtk+-1.2'\n".
1487 "# (depending on what works on your system) if you want to enforce\n".
1488 "# building with GTK 1.2, or you can set it to `pkg-config gtk+-2.0 x11'\n".
1489 "# if you want to enforce 2.0. The default is to try 2.0 and fall back\n".
1490 "# to 1.2 if it isn't found.\n".
1491 "GTK_CONFIG = sh -c 'pkg-config gtk+-3.0 x11 \$\$0 2>/dev/null || pkg-config gtk+-2.0 x11 \$\$0 2>/dev/null || gtk-config \$\$0'\n".
1493 "-include Makefile.local\n".
1495 "unexport CFLAGS # work around a weird issue with krb5-config\n".
1497 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1498 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1499 " \$(shell \$(GTK_CONFIG) --cflags)").
1500 " -D _FILE_OFFSET_BITS=64\n".
1501 "XLDFLAGS = \$(LDFLAGS) \$(shell \$(GTK_CONFIG) --libs)\n".
1502 "ULDFLAGS = \$(LDFLAGS)\n".
1503 "ifeq (,\$(findstring NO_GSSAPI,\$(COMPAT)))\n".
1504 "ifeq (,\$(findstring STATIC_GSSAPI,\$(COMPAT)))\n".
1505 "XLDFLAGS+= -ldl\n".
1506 "ULDFLAGS+= -ldl\n".
1508 "CFLAGS+= -DNO_LIBDL \$(shell \$(KRB5CONFIG) --cflags gssapi)\n".
1509 "XLDFLAGS+= \$(shell \$(KRB5CONFIG) --libs gssapi)\n".
1510 "ULDFLAGS+= \$(shell \$(KRB5CONFIG) --libs gssapi)\n".
1513 "INSTALL=install\n".
1514 "INSTALL_PROGRAM=\$(INSTALL)\n".
1515 "INSTALL_DATA=\$(INSTALL)\n".
1516 "prefix=/usr/local\n".
1517 "exec_prefix=\$(prefix)\n".
1518 "bindir=\$(exec_prefix)/bin\n".
1519 "mandir=\$(prefix)/man\n".
1520 "man1dir=\$(mandir)/man1\n".
1522 &def($makefile_extra{'gtk'}->{'vars'}) .
1527 print &splitline("all:" . join "", map { " $_" }
1528 &progrealnames("X:XT:U:UT"));
1530 foreach $p (&prognames("X:XT:U:UT")) {
1531 ($prog, $type) = split ",", $p;
1532 ($ldflags = $type) =~ s/T$//;
1533 $objstr = &objects($p, "X.o", undef, undef);
1534 print &splitline($prog . ": " . $objstr), "\n";
1535 $libstr = &objects($p, undef, undef, "-lX");
1536 print &splitline("\t\$(CC) -o \$@ " .
1537 $objstr . " \$(${ldflags}LDFLAGS) $libstr", 69), "\n\n";
1539 foreach $d (&deps("X.o", undef, $dirpfx, "/", "gtk")) {
1540 if ($forceobj{$d->{obj_orig}}) {
1541 printf("%s: FORCE\n", $d->{obj});
1543 print &splitline(sprintf("%s: %s", $d->{obj},
1544 join " ", @{$d->{deps}})), "\n";
1546 print &splitline("\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c $d->{deps}->[0]\n");
1549 print &def($makefile_extra{'gtk'}->{'end'});
1551 "\trm -f *.o". (join "", map { " $_" } &progrealnames("X:XT:U:UT")) . "\n";
1553 select STDOUT; close OUT;
1556 if (defined $makefiles{'unix'}) {
1557 $dirpfx = &dirpfx($makefiles{'unix'}, "/");
1559 ##-- GTK-free pure-Unix makefile for non-GUI apps only
1560 open OUT, ">$makefiles{'unix'}"; select OUT;
1562 "# Makefile for $project_name under Unix.\n".
1563 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1564 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1565 # gcc command line option is -D not /D
1566 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
1570 "# You can define this path to point at your tools if you need to\n".
1571 "# TOOLPATH = /opt/gcc/bin\n".
1572 "CC = \$(TOOLPATH)cc\n".
1574 "-include Makefile.local\n".
1576 "unexport CFLAGS # work around a weird issue with krb5-config\n".
1578 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1579 (join " ", map {"-I$dirpfx$_"} @srcdirs)).
1580 " -D _FILE_OFFSET_BITS=64\n".
1581 "ULDFLAGS = \$(LDFLAGS)\n".
1582 "INSTALL=install\n".
1583 "INSTALL_PROGRAM=\$(INSTALL)\n".
1584 "INSTALL_DATA=\$(INSTALL)\n".
1585 "prefix=/usr/local\n".
1586 "exec_prefix=\$(prefix)\n".
1587 "bindir=\$(exec_prefix)/bin\n".
1588 "mandir=\$(prefix)/man\n".
1589 "man1dir=\$(mandir)/man1\n".
1591 &def($makefile_extra{'unix'}->{'vars'}) .
1596 print &splitline("all:" . join "", map { " $_" } &progrealnames("U:UT"));
1598 foreach $p (&prognames("U:UT")) {
1599 ($prog, $type) = split ",", $p;
1600 $objstr = &objects($p, "X.o", undef, undef);
1601 print &splitline($prog . ": " . $objstr), "\n";
1602 $libstr = &objects($p, undef, undef, "-lX");
1603 print &splitline("\t\$(CC) -o \$@ " .
1604 $objstr . " \$(${type}LDFLAGS) $libstr", 69), "\n\n";
1606 foreach $d (&deps("X.o", undef, $dirpfx, "/", "unix")) {
1607 if ($forceobj{$d->{obj_orig}}) {
1608 printf("%s: FORCE\n", $d->{obj});
1610 print &splitline(sprintf("%s: %s", $d->{obj},
1611 join " ", @{$d->{deps}})), "\n";
1613 print &splitline("\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c $d->{deps}->[0]\n");
1616 print &def($makefile_extra{'unix'}->{'end'});
1618 "\trm -f *.o". (join "", map { " $_" } &progrealnames("U:UT")) . "\n";
1620 select STDOUT; close OUT;
1623 if (defined $makefiles{'am'}) {
1624 die "Makefile.am in a subdirectory is not supported\n"
1625 if &dirpfx($makefiles{'am'}, "/") ne "";
1627 ##-- Unix/autoconf Makefile.am
1628 open OUT, ">$makefiles{'am'}"; select OUT;
1630 "# Makefile.am for $project_name under Unix with Autoconf/Automake.\n".
1631 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1632 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n\n";
1634 # 2014-02-22: as of automake-1.14 we begin to get complained at if
1635 # we don't use this option
1636 print "AUTOMAKE_OPTIONS = subdir-objects\n\n";
1638 # Complete list of source and header files. Not used by the
1639 # auto-generated parts of this makefile, but Recipe might like to
1640 # have it available as a variable so that mandatory-rebuild things
1641 # (version.o) can conveniently be made to depend on it.
1642 @sources = ("allsources", "=",
1643 sort grep {$_ ne "empty.h"} keys %allsourcefiles);
1644 print &splitline(join " ", @sources), "\n\n";
1646 @cliprogs = ("bin_PROGRAMS", "=");
1647 foreach $p (&prognames("U")) {
1648 ($prog, $type) = split ",", $p;
1649 push @cliprogs, $prog;
1651 @allprogs = @cliprogs;
1652 foreach $p (&prognames("X")) {
1653 ($prog, $type) = split ",", $p;
1654 push @allprogs, $prog;
1656 print "if HAVE_GTK\n";
1657 print &splitline(join " ", @allprogs), "\n";
1659 print &splitline(join " ", @cliprogs), "\n";
1662 @noinstcliprogs = ("noinst_PROGRAMS", "=");
1663 foreach $p (&prognames("XT:UT")) {
1664 ($prog, $type) = split ",", $p;
1665 push @noinstcliprogs, $prog;
1667 print &splitline(join " ", @noinstcliprogs), "\n";
1670 foreach $d (&deps("X", undef, "", "/", "am")) {
1671 $objtosrc{$d->{obj}} = $d->{deps}->[0];
1674 print &splitline(join " ", "AM_CPPFLAGS", "=",
1675 map {"-I\$(srcdir)/$_"} @srcdirs), "\n";
1677 @amcflags = ("\$(COMPAT)", "\$(XFLAGS)", "\$(WARNINGOPTS)");
1678 print "if HAVE_GTK\n";
1679 print &splitline(join " ", "AM_CFLAGS", "=",
1680 "\$(GTK_CFLAGS)", @amcflags), "\n";
1682 print &splitline(join " ", "AM_CFLAGS", "=", @amcflags), "\n";
1685 %amspeciallibs = ();
1686 foreach $obj (sort { $a cmp $b } keys %{$cflags{'am'}}) {
1687 my $flags = $cflags{'am'}->{$obj};
1688 $flags = "" if $flags !~ s/^C//;
1689 print "lib${obj}_a_SOURCES = ", $objtosrc{$obj}, "\n";
1690 print &splitline(join " ", "lib${obj}_a_CFLAGS", "=", @amcflags,
1692 $amspeciallibs{$obj} = "lib${obj}.a";
1694 print &splitline(join " ", "noinst_LIBRARIES", "=",
1695 sort { $a cmp $b } values %amspeciallibs), "\n\n";
1697 foreach $p (&prognames("X:XT:U:UT")) {
1698 ($prog, $type) = split ",", $p;
1699 print "if HAVE_GTK\n" if $type eq "X" || $type eq "XT";
1700 @progsources = ("${prog}_SOURCES", "=");
1703 $objstr = &objects($p, "X", undef, undef);
1704 foreach $obj (split / /,$objstr) {
1705 if ($amspeciallibs{$obj}) {
1706 push @ldadd, $amspeciallibs{$obj};
1708 $sourcefiles{$objtosrc{$obj}} = 1;
1711 push @progsources, sort { $a cmp $b } keys %sourcefiles;
1712 print &splitline(join " ", @progsources), "\n";
1713 if ($type eq "X" || $type eq "XT") {
1714 push @ldadd, "\$(GTK_LIBS)";
1717 print &splitline(join " ", "${prog}_LDADD", "=", @ldadd), "\n";
1719 print "endif\n" if $type eq "X" || $type eq "XT";
1722 print &def($makefile_extra{'am'}->{'end'});
1723 select STDOUT; close OUT;
1726 if (defined $makefiles{'lcc'}) {
1727 $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
1730 open OUT, ">$makefiles{'lcc'}"; select OUT;
1732 "# Makefile for $project_name under lcc.\n".
1733 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1734 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1735 # lcc command line option is -D not /D
1736 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
1740 "# If you rename this file to `Makefile', you should change this line,\n".
1741 "# so that the .rsp files still depend on the correct makefile.\n".
1742 "MAKEFILE = Makefile.lcc\n".
1744 "# C compilation flags\n".
1745 "CFLAGS = -D_WINDOWS " .
1746 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1748 "# Resource compilation flags\n".
1749 "RCFLAGS = ".(join " ", map {"-I$dirpfx$_"} @srcdirs)."\n".
1751 "# Get include directory for resource compiler\n".
1753 &def($makefile_extra{'lcc'}->{'vars'}) .
1755 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
1757 foreach $p (&prognames("G:C")) {
1758 ($prog, $type) = split ",", $p;
1759 $objstr = &objects($p, "X.obj", "X.res", undef);
1760 print &splitline("$prog.exe: " . $objstr ), "\n";
1761 $subsystemtype = '';
1762 if ($type eq "G") { $subsystemtype = "-subsystem windows"; }
1763 my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1764 print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1768 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "lcc")) {
1769 if ($forceobj{$d->{obj_orig}}) {
1770 printf("%s: FORCE\n", $d->{obj});
1772 print &splitline(sprintf("%s: %s", $d->{obj},
1773 join " ", @{$d->{deps}})), "\n";
1775 if ($d->{obj} =~ /\.obj$/) {
1776 print &splitline("\tlcc -O -p6 \$(COMPAT)".
1777 " \$(CFLAGS) \$(XFLAGS) ".$d->{deps}->[0],69)."\n";
1779 print &splitline("\tlrc \$(RCFL) -r \$(RCFLAGS) ".
1780 $d->{deps}->[0],69)."\n";
1784 print &def($makefile_extra{'lcc'}->{'end'});
1792 select STDOUT; close OUT;
1795 if (defined $makefiles{'osx'}) {
1796 $dirpfx = &dirpfx($makefiles{'osx'}, "/");
1798 ##-- Mac OS X makefile
1799 open OUT, ">$makefiles{'osx'}"; select OUT;
1801 "# Makefile for $project_name under Mac OS X.\n".
1802 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1803 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1804 # gcc command line option is -D not /D
1805 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
1808 "CC = \$(TOOLPATH)gcc\n".
1810 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1811 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1812 "MLDFLAGS = -framework Cocoa\n".
1815 &def($makefile_extra{'osx'}->{'vars'}) .
1817 &splitline("all:" . join "", map { " $_" } &progrealnames("MX:U:UT")) .
1819 foreach $p (&prognames("MX")) {
1820 ($prog, $type) = split ",", $p;
1821 $objstr = &objects($p, "X.o", undef, undef);
1822 $icon = &special($p, ".icns");
1823 $infoplist = &special($p, "info.plist");
1824 print "${prog}.app:\n\tmkdir -p \$\@\n";
1825 print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n";
1826 print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1827 $targets = "${prog}.app/Contents/MacOS/$prog";
1828 if (defined $icon) {
1829 print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1830 print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n";
1831 $targets .= " ${prog}.app/Contents/Resources/${prog}.icns";
1833 if (defined $infoplist) {
1834 print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n";
1835 $targets .= " ${prog}.app/Contents/Info.plist";
1837 $targets .= " \$(${prog}_extra)";
1838 print &splitline("${prog}: $targets", 69) . "\n\n";
1839 print &splitline("${prog}.app/Contents/MacOS/$prog: ".
1840 "${prog}.app/Contents/MacOS " . $objstr), "\n";
1841 $libstr = &objects($p, undef, undef, "-lX");
1842 print &splitline("\t\$(CC) \$(MLDFLAGS) -o \$@ " .
1843 $objstr . " $libstr", 69), "\n\n";
1845 foreach $p (&prognames("U:UT")) {
1846 ($prog, $type) = split ",", $p;
1847 $objstr = &objects($p, "X.o", undef, undef);
1848 print &splitline($prog . ": " . $objstr), "\n";
1849 $libstr = &objects($p, undef, undef, "-lX");
1850 print &splitline("\t\$(CC) \$(ULDFLAGS) -o \$@ " .
1851 $objstr . " $libstr", 69), "\n\n";
1853 foreach $d (&deps("X.o", undef, $dirpfx, "/", "osx")) {
1854 if ($forceobj{$d->{obj_orig}}) {
1855 printf("%s: FORCE\n", $d->{obj});
1857 print &splitline(sprintf("%s: %s", $d->{obj},
1858 join " ", @{$d->{deps}})), "\n";
1860 $firstdep = $d->{deps}->[0];
1861 if ($firstdep =~ /\.c$/) {
1862 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS) -c \$<\n";
1863 } elsif ($firstdep =~ /\.m$/) {
1864 print "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS) -c \$<\n";
1867 print "\n".&def($makefile_extra{'osx'}->{'end'});
1869 "\trm -f *.o *.dmg". (join "", map { " $_" } &progrealnames("U:UT")) . "\n".
1873 select STDOUT; close OUT;
1876 if (defined $makefiles{'devcppproj'}) {
1877 $dirpfx = &dirpfx($makefiles{'devcppproj'}, "\\");
1880 ##-- Dev-C++ 5 projects
1882 # Note: All files created in this section are written in binary
1883 # mode to prevent any posibility of misinterpreted line endings.
1884 # I don't know if Dev-C++ is as touchy as MSVC with LF-only line
1885 # endings. But however, CRLF line endings are the common way on
1886 # Win32 machines where Dev-C++ is running.
1887 # Hence, in order for mkfiles.pl to generate CRLF project files
1888 # even when run from Unix, I make sure all files are binary and
1889 # explicitly write the CRLFs.
1891 # Create directories if necessary
1892 mkdir $makefiles{'devcppproj'}
1893 if(! -d $makefiles{'devcppproj'});
1894 chdir $makefiles{'devcppproj'};
1895 @deps = &deps("X.obj", "X.res", $dirpfx, "\\", "devcppproj");
1896 %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
1897 # Make dir names FAT/NTFS compatible
1898 my @srcdirs = @srcdirs;
1899 for ($i=0; $i<@srcdirs; $i++) {
1900 $srcdirs[$i] =~ s/\//\\/g;
1901 $srcdirs[$i] =~ s/\\$//;
1903 # Create the project files
1904 # Get names of all Windows projects (GUI and console)
1905 my @prognames = &prognames("G:C");
1906 foreach $progname (@prognames) {
1907 create_devcpp_project(\%all_object_deps, $progname);
1912 sub create_devcpp_project {
1913 my ($all_object_deps, $progname) = @_;
1914 # Construct program's dependency info (Taken from 'vcproj', seems to work right here, too.)
1919 %resource_files = ();
1920 @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
1921 foreach $object_file (@object_files) {
1922 next if defined $seen_objects{$object_file};
1923 $seen_objects{$object_file} = 1;
1924 if($object_file =~ /\.lib$/io) {
1925 $lib_files{$object_file} = 1;
1928 $object_deps = $all_object_deps{$object_file};
1929 foreach $object_dep (@$object_deps) {
1930 if($object_dep =~ /\.c$/io) {
1931 $source_files{$object_dep} = 1;
1934 if($object_dep =~ /\.h$/io) {
1935 $header_files{$object_dep} = 1;
1938 if($object_dep =~ /\.(rc|ico)$/io) {
1939 $resource_files{$object_dep} = 1;
1944 $libs = join " ", sort keys %lib_files;
1945 @source_files = sort keys %source_files;
1946 @header_files = sort keys %header_files;
1947 @resources = sort keys %resource_files;
1948 ($windows_project, $type) = split ",", $progname;
1949 mkdir $windows_project
1950 if(! -d $windows_project);
1951 chdir $windows_project;
1953 $subsys = ($type eq "G") ? "0" : "1"; # 0 = Win32 GUI, 1 = Win32 Console
1954 open OUT, ">$windows_project.dev"; binmode OUT; select OUT;
1956 "# DEV-C++ 5 Project File - $windows_project.dev\r\n".
1957 "# ** DO NOT EDIT **\r\n".
1959 # No difference between DEBUG and RELEASE here as in 'vcproj', because
1960 # Dev-C++ does not support mutiple compilation profiles in one single project.
1961 # (At least I can say this for Dev-C++ 5 Beta)
1963 "FileName=$windows_project.dev\r\n".
1964 "Name=$windows_project\r\n".
1968 # Multimon is disabled here, as Dev-C++ (Version 5 Beta) does not have multimon.h
1969 "Compiler=-W -D__GNUWIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNO_MULTIMON -D_MBCS_\@\@_\r\n".
1970 "CppCompiler=-W -D__GNUWIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNO_MULTIMON -D_MBCS_\@\@_\r\n".
1971 "Includes=" . (join ";", map {"..\\..\\$dirpfx$_"} @srcdirs) . "\r\n".
1972 "Linker=-ladvapi32 -lcomctl32 -lcomdlg32 -lgdi32 -limm32 -lshell32 -luser32 -lwinmm -lwinspool_\@\@_\r\n".
1974 "UnitCount=" . (@source_files + @header_files + @resources) . "\r\n".
1975 "Folders=\"Header Files\",\"Resource Files\",\"Source Files\"\r\n".
1977 "PrivateResource=${windows_project}_private.rc\r\n".
1978 "ResourceIncludes=..\\..\\..\\WINDOWS\r\n".
1979 "MakeIncludes=\r\n".
1980 "Icon=\r\n". # It's ok to leave this blank.
1982 "ObjectOutput=\r\n".
1983 "OverrideOutput=0\r\n".
1984 "OverrideOutputName=$windows_project.exe\r\n".
1985 "HostApplication=\r\n".
1987 "UseCustomMakefile=0\r\n".
1988 "CustomMakefile=\r\n".
1989 "IncludeVersionInfo=0\r\n".
1990 "SupportXPThemes=0\r\n".
1991 "CompilerSet=0\r\n".
1992 "CompilerSettings=0000000000000000000000\r\n".
1995 foreach $source_file (@source_files) {
1997 "[Unit$unit_count]\r\n".
1998 "FileName=..\\..\\$source_file\r\n".
1999 "Folder=Source Files\r\n".
2003 "Priority=1000\r\n".
2004 "OverrideBuildCmd=0\r\n".
2009 foreach $header_file (@header_files) {
2011 "[Unit$unit_count]\r\n".
2012 "FileName=..\\..\\$header_file\r\n".
2013 "Folder=Header Files\r\n".
2015 "CompileCpp=1\r\n". # Dev-C++ want's to compile all header files with both compilers C and C++. It does not hurt.
2017 "Priority=1000\r\n".
2018 "OverrideBuildCmd=0\r\n".
2023 foreach $resource_file (@resources) {
2024 if ($resource_file =~ /.*\.(ico|cur|bmp|dlg|rc2|rct|bin|rgs|gif|jpg|jpeg|jpe)/io) { # Default filter as in 'vcproj'
2025 $Compile = "0"; # Don't compile images and other binary resource files
2029 $CompileCpp = "1"; # Dev-C++ want's to compile all .rc files with both compilers C and C++. It does not hurt.
2032 "[Unit$unit_count]\r\n".
2033 "FileName=..\\..\\$resource_file\r\n".
2034 "Folder=Resource Files\r\n".
2035 "Compile=$Compile\r\n".
2036 "CompileCpp=$CompileCpp\r\n".
2038 "Priority=1000\r\n".
2039 "OverrideBuildCmd=0\r\n".
2044 #Note: By default, [VersionInfo] is not used.
2046 "[VersionInfo]\r\n".
2051 "LanguageID=1033\r\n".
2052 "CharsetID=1252\r\n".
2054 "FileVersion=0.1\r\n".
2055 "FileDescription=\r\n".
2056 "InternalName=\r\n".
2057 "LegalCopyright=\r\n".
2058 "LegalTrademarks=\r\n".
2059 "OriginalFilename=$windows_project.exe\r\n".
2060 "ProductName=$windows_project\r\n".
2061 "ProductVersion=0.1\r\n".
2062 "AutoIncBuildNr=0\r\n";
2063 select STDOUT; close OUT;
2068 # All done, so do the Unix postprocessing if asked to.
2072 system "./mkauto.sh";
2073 die "mkfiles.pl: mkauto.sh returned $?\n" if $? > 0;
2074 if ($do_unix == 1) {
2075 chdir ($targetdir = "unix")
2076 or die "$targetdir: chdir: $!\n";
2078 system "./configure", @confargs;
2079 die "mkfiles.pl: configure returned $?\n" if $? > 0;
2082 sub invent_guid($) {
2085 # Invent a GUID for use in Visual Studio project files. We need
2086 # a few of these for every executable file we build.
2088 # In order to avoid having to use the non-core Perl module
2089 # Data::GUID, and also arrange for GUIDs to be stable, we generate
2090 # our GUIDs by hashing a pile of fixed (but originally randomly
2091 # generated) data with the filename for which we need an id.
2093 # Hashing _just_ the filenames would clearly be cheating (it's
2094 # quite conceivable that someone might hash the same string for
2095 # another reason and so generate a colliding GUID), but hashing a
2096 # whole SHA-512 data block of random gibberish as well should make
2097 # these GUIDs pseudo-random enough to not collide with anyone
2100 my $randdata = pack "N*",
2101 0xD4AB035F,0x76998BA0,0x2DCCB0BD,0x6D3FA320,0x53638051,0xFE312F35,
2102 0xDE1CECC0,0x784DF852,0x6C9F4589,0x54B7AC23,0x14E7A1C4,0xF9BF04DF,
2103 0x19C08B6D,0x3FB69EF1,0xB2DA9043,0xDB5362F3,0x25718DB6,0x733560DA,
2104 0xFEF871B0,0xFECF7A0C,0x67D19C95,0xB492E911,0xF5D562A3,0xFCE1D478,
2105 0x02C50434,0xF7326B7E,0x93D39872,0xCF0D0269,0x9EF24C0F,0x827689AD,
2106 0x88BD20BC,0x74EA6AFE,0x29223682,0xB9AB9287,0x7EA7CE4F,0xCF81B379,
2107 0x9AE4A954,0x81C7AD97,0x2FF2F031,0xC51DA3C2,0xD311CCE7,0x0A31EB8B,
2108 0x1AB04242,0xAF53B714,0xFC574D40,0x8CB4ED01,0x29FEB16F,0x4904D7ED,
2109 0xF5C5F5E1,0xF138A4C2,0xA9D881CE,0xCEA65187,0x4421BA97,0x0EE8428E,
2110 0x9556E384,0x6D0484C9,0x561BD84B,0xD9516A40,0x6B4FD33F,0xDDFFE4C8,
2111 0x3D5DF8A5,0xFE6B7D99,0x3443371B,0xF4E30A3E,0xE62B9FDA,0x6BAA75DB,
2112 0x9EF3C2C7,0x6815CA42,0xE6536076,0xF851E6E2,0x39D16E69,0xBCDF3BB6,
2113 0x50EFFA41,0x378CDF2A,0xB5EC0D0C,0x1E94C433,0xE818241A,0x2689EB1F,
2114 0xB649CEF9,0xD7344D46,0x59C1BB13,0x27511FDF,0x7DAD1768,0xB355E29E,
2115 0xDFAE550C,0x2433005B,0x09DE10B0,0xAA00BA6B,0xC144ED2D,0x8513D007,
2116 0xB0315232,0x7A10DAB6,0x1D97654E,0xF048214D,0xE3059E75,0x83C225D1,
2117 0xFC7AB177,0x83F2B553,0x79F7A0AF,0x1C94582C,0xF5E4AF4B,0xFB39C865,
2118 0x58ABEB27,0xAAB28058,0x52C15A89,0x0EBE9741,0x343F4D26,0xF941202A,
2119 0xA32FD32F,0xDCC055B8,0x64281BF3,0x468BD7BA,0x0CEE09D3,0xBB5FD2B6,
2120 0xA528D412,0xA6A6967E,0xEAAF5DAE,0xDE7B2FAE,0xCA36887B,0x0DE196EB,
2121 0x74B95EF0,0x9EB8B7C2,0x020BFC83,0x1445086F,0xBF4B61B2,0x89AFACEC,
2122 0x80A5CD69,0xC790F744,0x435A6998,0x8DE7AC48,0x32F31BC9,0x8F760D3D,
2123 0xF02A74CB,0xD7B47E20,0x9EC91035,0x70FDE74D,0x9B531362,0x9D81739A,
2124 0x59ADC2EB,0x511555B5,0xCA84B8D5,0x3EC325FF,0x2E442A4C,0x82AF30D9,
2125 0xBFD3EC87,0x90C59E07,0x1C6DC991,0x2D16B822,0x7EA44EB5,0x3A655A39,
2126 0xAB640886,0x09311821,0x777801D9,0x489DBE61,0xA1FFEC65,0x978B49B1,
2127 0x7DB700CD,0x263CF3D6,0xF977E89F,0xBA0B3D01,0x6C6CED19,0x1BE6F23A,
2128 0x19E0ED98,0x8E71A499,0x70BA3271,0x3FB7EE98,0xABA46848,0x2B797959,
2129 0x72C6DE59,0xE08B795C,0x02936C39,0x02185CCB,0xD6F3CE18,0xD0157A40,
2130 0x833DEC3F,0x319B00C4,0x97B59513,0x900B81FD,0x9A022379,0x16E44E1A,
2131 0x0C4CC540,0xCA98E7F9,0xF9431A26,0x290BCFAC,0x406B82C0,0xBC1C4585,
2132 0x55C54528,0x811EBB77,0xD4EDD4F3,0xA70DC02E,0x8AD5C0D1,0x28D64EF4,
2133 0xBEFF5C69,0x99852C4A,0xB4BBFF7B,0x069230AC,0xA3E141FA,0x4E99FB0E,
2134 0xBC154DAA,0x323C7F15,0x86E0247E,0x2EEA3054,0xC9CA1D32,0x8964A006,
2135 0xC93978AC,0xF9B2C159,0x03F2079E,0xB051D284,0x4A7EA9A9,0xF001DA1F,
2136 0xD47A0DAA,0xCF7B6B73,0xF18293B2,0x84303E34,0xF8BC76C4,0xAFBEE24F,
2137 0xB589CA80,0x77B5BF86,0x21B9FD5B,0x1A5071DF,0xA3863110,0x0E50CA61,
2138 0x939151A5,0xD2A59021,0x83A9CDCE,0xCEC69767,0xC906BB16,0x3EE1FF4D,
2139 0x1321EAE4,0x0BF940D6,0x52471E61,0x8A087056,0x66E54293,0xF84AAB9B,
2140 0x08835EF1,0x8F12B77A,0xD86935A5,0x200281D7,0xCD3C37C9,0x30ABEC05,
2141 0x7067E8A0,0x608C4838,0xC9F51CDE,0xA6D318DE,0x41C05B2A,0x694CCE0E,
2142 0xC7842451,0xA3194393,0xFBDC2C84,0xA6D2B577,0xC91E7924,0x01EDA708,
2143 0x22FBB61E,0x662F9B7B,0xDE3150C3,0x2397058C;
2144 my $digest = sha512_hex($name . "\0" . $randdata);
2145 return sprintf("%s-%s-%04x-%04x-%s",
2146 substr($digest,0,8),
2147 substr($digest,8,4),
2148 0x4000 | (0xFFF & hex(substr($digest,12,4))),
2149 0x8000 | (0x3FFF & hex(substr($digest,16,4))),
2150 substr($digest,20,12));