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
87 $rest = 1 if $rest eq "";
88 $cflags{$_[1]}->{$_[2]} = $rest;
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});
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;
109 # Now we have an ordinary line. See if it's an = line, a : line
114 $listref = $lastlistref;
116 die "$.: unexpected + line\n" if !defined $lastlistref;
117 } elsif ($_[1] eq "=") {
118 $groups{$_[0]} = [] if !defined $groups{$_[0]};
119 $listref = $groups{$_[0]};
121 shift @objs; # eat the group name
122 } elsif ($_[1] eq ":") {
125 shift @objs; # eat the program name
127 die "$.: unrecognised line type\n";
129 shift @objs; # eat the +, the = or the :
131 while (scalar @objs > 0) {
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 UT);
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;
148 $lastlistref = $listref;
153 foreach $aux (sort keys %auxfiles) {
155 print AUX $auxfiles{$aux};
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;
165 foreach $i (@prognames) {
166 ($prog, $type) = split ",", $i;
167 # Strip duplicate object names.
169 @list = grep { $status = ($prev ne $_); $prev=$_; $status }
170 sort @{$programs{$i}};
171 $programs{$i} = [@list];
173 # Dependencies for "x" start with "x.c" or "x.m" (depending on
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$/) {
181 $depends{$j} = [$file];
182 push @scanlist, $file;
183 } elsif ($j =~ /^(.*)\.rsrc$/) {
185 $depends{$j} = [$file];
186 push @scanlist, $file;
187 } elsif ($j !~ /\./) {
189 $file = "$j.m" unless &findfile($file);
190 $depends{$j} = [$file];
191 push @scanlist, $file;
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
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.
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.
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";
223 /^\s*#include\s+\"([^\"]+)\"/ and do {
224 push @{$further{$file}}, $1;
228 /(RT_MANIFEST|ICON)\s+\"([^\"]+)\"\s*$/ and do {
229 push @{$further{$file}}, $2;
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) {
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}}) {
248 push @{$depends{$i}}, $j;
253 # printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
256 # Validation of input.
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")) {
267 warn "$.:unknown makefile type '$type'\n";
271 # Utility routines while writing out the Makefiles.
275 return (defined $x) ? $x : "";
279 my ($path) = shift @_;
280 my ($sep) = shift @_;
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);
289 $path = substr $path, ($j + 1);
301 unless (defined $findfilecache{$name}) {
303 foreach $dir (@srcdirs) {
304 if (-f "$dir$name") {
307 $outdir =~ s/^\.\///;
310 die "multiple instances of source file $name\n" if $i > 1;
311 $findfilecache{$name} = (defined $outdir ? $outdir . $name : undef);
313 return $findfilecache{$name};
317 my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
320 ($otmpl, $rtmpl, $ltmpl) = map { defined $_ ? $_ : "" } ($otmpl, $rtmpl, $ltmpl);
322 foreach $i (@{$programs{$prog}}) {
324 if ($i =~ /^(.*)\.(res|rsrc)/) {
326 ($x = $rtmpl) =~ s/X/$y/;
327 } elsif ($i =~ /^(.*)\.lib/) {
329 ($x = $ltmpl) =~ s/X/$y/;
330 } elsif ($i !~ /\./) {
331 ($x = $otmpl) =~ s/X/$i/;
333 push @ret, $x if $x ne "";
335 return join " ", @ret;
339 my ($prog, $suffix) = @_;
342 ($otmpl, $rtmpl, $ltmpl) = map { defined $_ ? $_ : "" } ($otmpl, $rtmpl, $ltmpl);
344 foreach $i (@{$programs{$prog}}) {
345 if (substr($i, (length $i) - (length $suffix)) eq $suffix) {
349 return (scalar @ret) ? (join " ", @ret) : undef;
353 my ($line, $width, $splitchar) = @_;
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(.*)$/;
361 $result .= " ${splitchar}\n\t\t" if $2 ne '';
365 return $result . $line;
369 my ($otmpl, $rtmpl, $prefix, $dirsep, $mftyp, $depchar, $splitchar) = @_;
375 foreach $i (sort keys %depends) {
376 next if $specialobj{$mftyp}->{$i};
377 if ($i =~ /^(.*)\.(res|rsrc)/) {
378 next if !defined $rtmpl;
380 ($x = $rtmpl) =~ s/X/$y/;
382 ($x = $otmpl) =~ s/X/$i/;
384 @deps = @{$depends{$i}};
390 push @ret, {obj => $x, obj_orig => $i, deps => [@deps]};
397 my ($n, $prog, $type);
400 foreach $n (@prognames) {
401 ($prog, $type) = split ",", $n;
402 push @ret, $n if index(":$types:", ":$type:") >= 0;
409 my ($n, $prog, $type);
412 foreach $n (@prognames) {
413 ($prog, $type) = split ",", $n;
414 push @ret, $prog if index(":$types:", ":$type:") >= 0;
420 my ($types,$suffix) = @_;
422 # assume that all UNIX programs have a man page
423 if($suffix eq "1" && $types =~ /:X:/) {
424 return map("$_.1", &progrealnames($types));
431 # Now we're ready to output the actual Makefiles.
433 if (defined $makefiles{'cygwin'}) {
434 $dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
437 open OUT, ">$makefiles{'cygwin'}"; select OUT;
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;
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".
455 "# You may also need to tell windres where to find include files:\n".
456 "# RCINC = --include-dir c:\\cygwin\\include\\\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)) .
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".
466 &def($makefile_extra{'cygwin'}->{'vars'}) .
470 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
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";
482 foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/", "cygwin")) {
483 if ($forceobj{$d->{obj_orig}}) {
484 printf ("%s: FORCE\n", $d->{obj});
486 print &splitline(sprintf("%s: %s", $d->{obj},
487 join " ", @{$d->{deps}})), "\n";
489 if ($d->{obj} =~ /\.res\.o$/) {
490 print "\t\$(RC) \$(RCFL) \$(RCFLAGS) ".$d->{deps}->[0]." -o ".$d->{obj}."\n\n";
492 print "\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c ".$d->{deps}->[0]."\n\n";
496 print &def($makefile_extra{'cygwin'}->{'end'});
498 "\trm -f *.o *.exe *.res.o *.so *.map\n".
501 select STDOUT; close OUT;
505 ##-- Borland makefile
506 if (defined $makefiles{'borland'}) {
507 $dirpfx = &dirpfx($makefiles{'borland'}, "\\");
509 %stdlibs = ( # Borland provides many Win32 API libraries intrinsically
521 open OUT, ">$makefiles{'borland'}"; select OUT;
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;
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".
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".
540 "# Get include directory for resource compiler\n".
542 "BCB = \$(MAKEDIR)\\..\n".
545 &def($makefile_extra{'borland'}->{'vars'}) .
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".
553 &splitline("\tbrcc32 \$(RCFL) -i \$(BCB)\\include -r".
554 " \$(RCFLAGS) \$*.rc",69)."\n".
556 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
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";
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;
571 foreach $i (@objlist) {
572 if (length($objlines[$#objlines] . " $i") > 50) {
575 $objlines[$#objlines] .= " $i";
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";
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";
593 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "borland")) {
594 if ($forceobj{$d->{obj_orig}}) {
595 printf("%s: FORCE\n", $d->{obj});
597 print &splitline(sprintf("%s: %s", $d->{obj},
598 join " ", @{$d->{deps}})), "\n";
602 print &def($makefile_extra{'borland'}->{'end'});
613 "\t-del *.\$\$\$\$\$\$\n".
616 "\t-rem dummy command\n";
617 select STDOUT; close OUT;
620 if (defined $makefiles{'vc'}) {
621 $dirpfx = &dirpfx($makefiles{'vc'}, "\\");
623 ##-- Visual C++ makefile
624 open OUT, ">$makefiles{'vc'}"; select OUT;
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";
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".
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".
644 &def($makefile_extra{'vc'}->{'vars'}) .
647 print &splitline("all:" . join "", map { " \$(BUILDDIR)$_.exe" } &progrealnames("G:C"));
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";
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;
660 foreach $i (@objlist) {
661 if (length($objlines[$#objlines] . " $i") > 72) {
664 $objlines[$#objlines] .= " $i";
666 for ($i=0; $i<=$#objlines; $i++) {
667 print "$objlines[$i]\n";
670 print "\tlink \$(LFLAGS) \$(XLFLAGS) -out:\$(BUILDDIR)$prog.exe -map:\$(BUILDDIR)$prog.map -nologo -subsystem:$subsys \@$inlinefilename\n\n";
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";
681 foreach $real_srcdir ("", @srcdirs) {
682 $srcdir = $real_srcdir;
685 $srcdir = $dirpfx . $srcdir;
686 $srcdir =~ s!\\\.\\!\\!;
687 $srcdir = "{$srcdir}";
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
696 print "${srcdir}.c.obj::\n\tcl /Fo\$(BUILDDIR) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) /c \$<\n\n";
698 print &def($makefile_extra{'vc'}->{'end'});
699 print "\nclean: tidy\n".
700 "\t-del \$(BUILDDIR)*.exe\n\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;
720 if (defined $makefiles{'vcproj'}) {
721 $dirpfx = &dirpfx($makefiles{'vcproj'}, "\\");
723 ##-- MSVC 6 Workspace and projects
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.
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);
744 # Create the workspace file
745 open OUT, ">$project_name.dsw"; binmode OUT; select OUT;
747 "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
748 "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
750 "###############################################################################\r\n".
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";
767 "###############################################################################\r\n".
779 "###############################################################################\r\n".
781 select STDOUT; close OUT;
784 sub create_vc_project {
785 my ($all_object_deps, $progname) = @_;
786 # Construct program's dependency info
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;
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;
806 if($object_dep =~ /\.h$/io) {
807 $header_files{$object_dep} = 1;
810 if($object_dep =~ /\.(rc|ico)$/io) {
811 $resource_files{$object_dep} = 1;
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;
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".
831 "# TARGTYPE \"Win32 (x86) Application\" 0x0101\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".
837 "!MESSAGE NMAKE /f \"$windows_project.mak\".\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".
842 "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
844 "!MESSAGE Possible choices for configuration are:\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".
850 "# Begin Project\r\n".
851 "# PROP AllowPerConfigDependencies 0\r\n".
852 "# PROP Scc_ProjName \"\"\r\n".
853 "# PROP Scc_LocalPath \"\"\r\n".
858 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\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".
889 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\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".
922 "# Begin Target\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".
928 "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
929 foreach $source_file (@source_files) {
931 "# Begin Source File\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
938 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
940 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
947 print "# End Source File\r\n";
951 "# Begin Group \"Header Files\"\r\n".
953 "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
954 foreach $header_file (@header_files) {
956 "# Begin Source File\r\n".
958 "SOURCE=..\\..\\$header_file\r\n".
959 "# End Source File\r\n";
963 "# Begin Group \"Resource Files\"\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) {
968 "# Begin Source File\r\n".
970 "SOURCE=..\\..\\$resource_file\r\n".
971 "# End Source File\r\n";
977 select STDOUT; close OUT;
982 if (defined $makefiles{'vstudio10'} || defined $makefiles{'vstudio12'}) {
984 ##-- Visual Studio 2010+ Solution and Projects
986 if (defined $makefiles{'vstudio10'}) {
987 create_vs_solution('vstudio10', "2010", "11.00", "v100");
990 if (defined $makefiles{'vstudio12'}) {
991 create_vs_solution('vstudio12', "2012", "12.00", "v110");
994 sub create_vs_solution {
995 my ($makefilename, $name, $version, $toolsver) = @_;
997 $dirpfx = &dirpfx($makefiles{$makefilename}, "\\");
999 @deps = &deps("X.obj", "X.res", $dirpfx, "\\", $makefilename);
1000 %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
1002 my @prognames = &prognames("G:C");
1004 # Create the solution file.
1005 mkdir $makefiles{$makefilename}
1006 if(! -f $makefiles{$makefilename});
1007 chdir $makefiles{$makefilename};
1009 open OUT, ">$project_name.sln"; select OUT;
1012 "Microsoft Visual Studio Solution File, Format Version $version\n" .
1013 "# Visual Studio $name\n";
1016 foreach $progname (@prognames) {
1017 ($windows_project, $type) = split ",", $progname;
1019 $projguids{$windows_project} = $guid =
1020 &invent_guid("project:$progname");
1023 "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"$windows_project\", \"$windows_project\\$windows_project.vcxproj\", \"{$guid}\"\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" ;
1035 foreach my $projguid (values %projguids) {
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";
1044 " EndGlobalSection\n" .
1045 " GlobalSection(SolutionProperties) = preSolution\n" .
1046 " HideSolutionNode = FALSE\n" .
1047 " EndGlobalSection\n" .
1050 select STDOUT; close OUT;
1052 foreach $progname (@prognames) {
1053 ($windows_project, $type) = split ",", $progname;
1054 create_vs_project(\%all_object_deps, $windows_project, $type, $projguids{$windows_project}, $toolsver);
1060 sub create_vs_project {
1061 my ($all_object_deps, $windows_project, $type, $projguid, $toolsver) = @_;
1063 # Break down the project's dependency information into the appropriate
1069 %resource_files = ();
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;
1077 if($object_file =~ /\.lib$/io) {
1078 $lib_files{$object_file} = 1;
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;
1090 } elsif ($object_dep =~ /\.[ch]$/io) {
1091 $header_files{$object_dep} = 1;
1092 } elsif ($object_dep =~ /\.ico$/io) {
1093 $icon_files{$object_dep} = 1;
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";
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";
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.
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" .
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" .
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" .
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" .
1190 " <ResourceCompile>\n" .
1191 " <Culture>0x0809</Culture>\n" .
1192 " <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1193 " </ResourceCompile>\n" .
1195 " <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1196 " <OutputFile>.\\Release\\$windows_project.bsc</OutputFile>\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" .
1204 " </ItemDefinitionGroup>\n" .
1205 " <ItemDefinitionGroup Condition=\"'\$(Configuration)|\$(Platform)'=='Debug|Win32'\">\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" .
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" .
1230 " <ResourceCompile>\n" .
1231 " <Culture>0x0809</Culture>\n" .
1232 " <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" .
1233 " </ResourceCompile>\n" .
1235 " <SuppressStartupBanner>true</SuppressStartupBanner>\n" .
1236 " <OutputFile>.\\Debug\\$windows_project.bsc</OutputFile>\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" .
1245 " </ItemDefinitionGroup>\n";
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.
1254 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" .
1255 "<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n";
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";
1263 " <CustomBuild Include=\"..\\..\\$icon_file\">\n" .
1264 " <Filter>Resource Files</Filter>\n" .
1265 " </CustomBuild>\n";
1267 print FILTERS " </ItemGroup>\n";
1268 print " </ItemGroup>\n";
1270 print " <ItemGroup>\n";
1271 print FILTERS " <ItemGroup>\n";
1272 foreach $resource_file (@resources) {
1273 $resource_file =~ s/..\\windows\\//;
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";
1280 " <ResourceCompile Include=\"..\\..\\$resource_file\">\n" .
1281 " <Filter>Resource Files</Filter>\n" .
1282 " </ResourceCompile>\n";
1284 print FILTERS " </ItemGroup>\n";
1285 print " </ItemGroup>\n";
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";
1293 " <ClCompile Include=\"..\\..\\$source_file\">\n" .
1294 " <Filter>Source Files</Filter>\n" .
1297 print FILTERS " </ItemGroup>\n";
1298 print " </ItemGroup>\n";
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";
1306 " <ClInclude Include=\"..\\..\\$header_file\">\n" .
1307 " <Filter>Header Files</Filter>\n" .
1310 print FILTERS " </ItemGroup>\n";
1311 print " </ItemGroup>\n";
1314 " <Import Project=\"\$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n" .
1319 " <Filter Include=\"Source Files\">\n" .
1320 " <UniqueIdentifier>{" . &invent_guid("sources:$windows_project") . "}</UniqueIdentifier>\n" .
1322 " <Filter Include=\"Header Files\">\n" .
1323 " <UniqueIdentifier>{" . &invent_guid("headers:$windows_project") . "}</UniqueIdentifier>\n" .
1325 " <Filter Include=\"Resource Files\">\n" .
1326 " <UniqueIdentifier>{" . &invent_guid("resources:$windows_project") . "}</UniqueIdentifier>\n" .
1331 select STDOUT; close OUT; close FILTERS;
1336 if (defined $makefiles{'gtk'}) {
1337 $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
1339 ##-- X/GTK/Unix makefile
1340 open OUT, ">$makefiles{'gtk'}"; select OUT;
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;
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".
1362 "-include Makefile.local\n".
1364 "unexport CFLAGS # work around a weird issue with krb5-config\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".
1377 "CFLAGS+= -DNO_LIBDL \$(shell \$(KRB5CONFIG) --cflags gssapi)\n".
1378 "XLDFLAGS+= \$(shell \$(KRB5CONFIG) --libs gssapi)\n".
1379 "ULDFLAGS+= \$(shell \$(KRB5CONFIG) --libs gssapi)\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".
1391 &def($makefile_extra{'gtk'}->{'vars'}) .
1396 print &splitline("all:" . join "", map { " $_" } &progrealnames("X:U:UT"));
1398 foreach $p (&prognames("X:U:UT")) {
1399 ($prog, $type) = split ",", $p;
1400 $objstr = &objects($p, "X.o", undef, undef);
1401 print &splitline($prog . ": " . $objstr), "\n";
1402 $libstr = &objects($p, undef, undef, "-lX");
1403 print &splitline("\t\$(CC) -o \$@ " .
1404 $objstr . " \$(${type}LDFLAGS) $libstr", 69), "\n\n";
1406 foreach $d (&deps("X.o", undef, $dirpfx, "/", "gtk")) {
1407 if ($forceobj{$d->{obj_orig}}) {
1408 printf("%s: FORCE\n", $d->{obj});
1410 print &splitline(sprintf("%s: %s", $d->{obj},
1411 join " ", @{$d->{deps}})), "\n";
1413 print &splitline("\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c $d->{deps}->[0]\n");
1416 print &def($makefile_extra{'gtk'}->{'end'});
1418 "\trm -f *.o". (join "", map { " $_" } &progrealnames("X:U:UT")) . "\n";
1420 select STDOUT; close OUT;
1423 if (defined $makefiles{'unix'}) {
1424 $dirpfx = &dirpfx($makefiles{'unix'}, "/");
1426 ##-- GTK-free pure-Unix makefile for non-GUI apps only
1427 open OUT, ">$makefiles{'unix'}"; select OUT;
1429 "# Makefile for $project_name under Unix.\n".
1430 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1431 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1432 # gcc command line option is -D not /D
1433 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
1437 "# You can define this path to point at your tools if you need to\n".
1438 "# TOOLPATH = /opt/gcc/bin\n".
1439 "CC = \$(TOOLPATH)cc\n".
1441 "-include Makefile.local\n".
1443 "unexport CFLAGS # work around a weird issue with krb5-config\n".
1445 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1446 (join " ", map {"-I$dirpfx$_"} @srcdirs)).
1447 " -D _FILE_OFFSET_BITS=64\n".
1448 "ULDFLAGS = \$(LDFLAGS)\n".
1449 "INSTALL=install\n".
1450 "INSTALL_PROGRAM=\$(INSTALL)\n".
1451 "INSTALL_DATA=\$(INSTALL)\n".
1452 "prefix=/usr/local\n".
1453 "exec_prefix=\$(prefix)\n".
1454 "bindir=\$(exec_prefix)/bin\n".
1455 "mandir=\$(prefix)/man\n".
1456 "man1dir=\$(mandir)/man1\n".
1458 &def($makefile_extra{'unix'}->{'vars'}) .
1463 print &splitline("all:" . join "", map { " $_" } &progrealnames("U:UT"));
1465 foreach $p (&prognames("U:UT")) {
1466 ($prog, $type) = split ",", $p;
1467 $objstr = &objects($p, "X.o", undef, undef);
1468 print &splitline($prog . ": " . $objstr), "\n";
1469 $libstr = &objects($p, undef, undef, "-lX");
1470 print &splitline("\t\$(CC) -o \$@ " .
1471 $objstr . " \$(${type}LDFLAGS) $libstr", 69), "\n\n";
1473 foreach $d (&deps("X.o", undef, $dirpfx, "/", "unix")) {
1474 if ($forceobj{$d->{obj_orig}}) {
1475 printf("%s: FORCE\n", $d->{obj});
1477 print &splitline(sprintf("%s: %s", $d->{obj},
1478 join " ", @{$d->{deps}})), "\n";
1480 print &splitline("\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c $d->{deps}->[0]\n");
1483 print &def($makefile_extra{'unix'}->{'end'});
1485 "\trm -f *.o". (join "", map { " $_" } &progrealnames("U:UT")) . "\n";
1487 select STDOUT; close OUT;
1490 if (defined $makefiles{'am'}) {
1491 die "Makefile.am in a subdirectory is not supported\n"
1492 if &dirpfx($makefiles{'am'}, "/") ne "";
1494 ##-- Unix/autoconf Makefile.am
1495 open OUT, ">$makefiles{'am'}"; select OUT;
1497 "# Makefile.am for $project_name under Unix with Autoconf/Automake.\n".
1498 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1499 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n\n";
1501 # 2014-02-22: as of automake-1.14 we begin to get complained at if
1502 # we don't use this option
1503 print "AUTOMAKE_OPTIONS = subdir-objects\n\n";
1505 # Complete list of source and header files. Not used by the
1506 # auto-generated parts of this makefile, but Recipe might like to
1507 # have it available as a variable so that mandatory-rebuild things
1508 # (version.o) can conveniently be made to depend on it.
1509 @sources = ("allsources", "=", sort keys %allsourcefiles);
1510 print &splitline(join " ", @sources), "\n\n";
1512 @cliprogs = ("bin_PROGRAMS", "=");
1513 foreach $p (&prognames("U")) {
1514 ($prog, $type) = split ",", $p;
1515 push @cliprogs, $prog;
1517 @allprogs = @cliprogs;
1518 foreach $p (&prognames("X")) {
1519 ($prog, $type) = split ",", $p;
1520 push @allprogs, $prog;
1522 print "if HAVE_GTK\n";
1523 print &splitline(join " ", @allprogs), "\n";
1525 print &splitline(join " ", @cliprogs), "\n";
1528 @noinstcliprogs = ("noinst_PROGRAMS", "=");
1529 foreach $p (&prognames("UT")) {
1530 ($prog, $type) = split ",", $p;
1531 push @noinstcliprogs, $prog;
1533 print &splitline(join " ", @noinstcliprogs), "\n";
1536 foreach $d (&deps("X", undef, "", "/", "am")) {
1537 $objtosrc{$d->{obj}} = $d->{deps}->[0];
1540 print &splitline(join " ", "AM_CPPFLAGS", "=",
1541 map {"-I\$(srcdir)/$_"} @srcdirs), "\n";
1543 @amcflags = ("\$(COMPAT)", "\$(XFLAGS)", "\$(WARNINGOPTS)");
1544 print "if HAVE_GTK\n";
1545 print &splitline(join " ", "AM_CFLAGS", "=",
1546 "\$(GTK_CFLAGS)", @amcflags), "\n";
1548 print &splitline(join " ", "AM_CFLAGS", "=", @amcflags), "\n";
1551 %amspeciallibs = ();
1552 foreach $obj (sort { $a cmp $b } keys %{$cflags{'am'}}) {
1553 print "lib${obj}_a_SOURCES = ", $objtosrc{$obj}, "\n";
1554 print &splitline(join " ", "lib${obj}_a_CFLAGS", "=", @amcflags,
1555 $cflags{'am'}->{$obj}), "\n";
1556 $amspeciallibs{$obj} = "lib${obj}.a";
1558 print &splitline(join " ", "noinst_LIBRARIES", "=",
1559 sort { $a cmp $b } values %amspeciallibs), "\n\n";
1561 foreach $p (&prognames("X:U:UT")) {
1562 ($prog, $type) = split ",", $p;
1563 print "if HAVE_GTK\n" if $type eq "X";
1564 @progsources = ("${prog}_SOURCES", "=");
1567 $objstr = &objects($p, "X", undef, undef);
1568 foreach $obj (split / /,$objstr) {
1569 if ($amspeciallibs{$obj}) {
1570 push @ldadd, $amspeciallibs{$obj};
1572 $sourcefiles{$objtosrc{$obj}} = 1;
1575 push @progsources, sort { $a cmp $b } keys %sourcefiles;
1576 print &splitline(join " ", @progsources), "\n";
1578 push @ldadd, "\$(GTK_LIBS)";
1581 print &splitline(join " ", "${prog}_LDADD", "=", @ldadd), "\n";
1583 print "endif\n" if $type eq "X";
1586 print &def($makefile_extra{'am'}->{'end'});
1587 select STDOUT; close OUT;
1590 if (defined $makefiles{'lcc'}) {
1591 $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
1594 open OUT, ">$makefiles{'lcc'}"; select OUT;
1596 "# Makefile for $project_name under lcc.\n".
1597 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1598 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1599 # lcc command line option is -D not /D
1600 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
1604 "# If you rename this file to `Makefile', you should change this line,\n".
1605 "# so that the .rsp files still depend on the correct makefile.\n".
1606 "MAKEFILE = Makefile.lcc\n".
1608 "# C compilation flags\n".
1609 "CFLAGS = -D_WINDOWS " .
1610 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1612 "# Resource compilation flags\n".
1613 "RCFLAGS = ".(join " ", map {"-I$dirpfx$_"} @srcdirs)."\n".
1615 "# Get include directory for resource compiler\n".
1617 &def($makefile_extra{'lcc'}->{'vars'}) .
1619 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
1621 foreach $p (&prognames("G:C")) {
1622 ($prog, $type) = split ",", $p;
1623 $objstr = &objects($p, "X.obj", "X.res", undef);
1624 print &splitline("$prog.exe: " . $objstr ), "\n";
1625 $subsystemtype = '';
1626 if ($type eq "G") { $subsystemtype = "-subsystem windows"; }
1627 my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1628 print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1632 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "lcc")) {
1633 if ($forceobj{$d->{obj_orig}}) {
1634 printf("%s: FORCE\n", $d->{obj});
1636 print &splitline(sprintf("%s: %s", $d->{obj},
1637 join " ", @{$d->{deps}})), "\n";
1639 if ($d->{obj} =~ /\.obj$/) {
1640 print &splitline("\tlcc -O -p6 \$(COMPAT)".
1641 " \$(CFLAGS) \$(XFLAGS) ".$d->{deps}->[0],69)."\n";
1643 print &splitline("\tlrc \$(RCFL) -r \$(RCFLAGS) ".
1644 $d->{deps}->[0],69)."\n";
1648 print &def($makefile_extra{'lcc'}->{'end'});
1656 select STDOUT; close OUT;
1659 if (defined $makefiles{'osx'}) {
1660 $dirpfx = &dirpfx($makefiles{'osx'}, "/");
1662 ##-- Mac OS X makefile
1663 open OUT, ">$makefiles{'osx'}"; select OUT;
1665 "# Makefile for $project_name under Mac OS X.\n".
1666 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1667 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1668 # gcc command line option is -D not /D
1669 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
1672 "CC = \$(TOOLPATH)gcc\n".
1674 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1675 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1676 "MLDFLAGS = -framework Cocoa\n".
1679 &def($makefile_extra{'osx'}->{'vars'}) .
1681 &splitline("all:" . join "", map { " $_" } &progrealnames("MX:U:UT")) .
1683 foreach $p (&prognames("MX")) {
1684 ($prog, $type) = split ",", $p;
1685 $objstr = &objects($p, "X.o", undef, undef);
1686 $icon = &special($p, ".icns");
1687 $infoplist = &special($p, "info.plist");
1688 print "${prog}.app:\n\tmkdir -p \$\@\n";
1689 print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n";
1690 print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1691 $targets = "${prog}.app/Contents/MacOS/$prog";
1692 if (defined $icon) {
1693 print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1694 print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n";
1695 $targets .= " ${prog}.app/Contents/Resources/${prog}.icns";
1697 if (defined $infoplist) {
1698 print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n";
1699 $targets .= " ${prog}.app/Contents/Info.plist";
1701 $targets .= " \$(${prog}_extra)";
1702 print &splitline("${prog}: $targets", 69) . "\n\n";
1703 print &splitline("${prog}.app/Contents/MacOS/$prog: ".
1704 "${prog}.app/Contents/MacOS " . $objstr), "\n";
1705 $libstr = &objects($p, undef, undef, "-lX");
1706 print &splitline("\t\$(CC) \$(MLDFLAGS) -o \$@ " .
1707 $objstr . " $libstr", 69), "\n\n";
1709 foreach $p (&prognames("U:UT")) {
1710 ($prog, $type) = split ",", $p;
1711 $objstr = &objects($p, "X.o", undef, undef);
1712 print &splitline($prog . ": " . $objstr), "\n";
1713 $libstr = &objects($p, undef, undef, "-lX");
1714 print &splitline("\t\$(CC) \$(ULDFLAGS) -o \$@ " .
1715 $objstr . " $libstr", 69), "\n\n";
1717 foreach $d (&deps("X.o", undef, $dirpfx, "/", "osx")) {
1718 if ($forceobj{$d->{obj_orig}}) {
1719 printf("%s: FORCE\n", $d->{obj});
1721 print &splitline(sprintf("%s: %s", $d->{obj},
1722 join " ", @{$d->{deps}})), "\n";
1724 $firstdep = $d->{deps}->[0];
1725 if ($firstdep =~ /\.c$/) {
1726 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS) -c \$<\n";
1727 } elsif ($firstdep =~ /\.m$/) {
1728 print "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS) -c \$<\n";
1731 print "\n".&def($makefile_extra{'osx'}->{'end'});
1733 "\trm -f *.o *.dmg". (join "", map { " $_" } &progrealnames("U:UT")) . "\n".
1737 select STDOUT; close OUT;
1740 if (defined $makefiles{'devcppproj'}) {
1741 $dirpfx = &dirpfx($makefiles{'devcppproj'}, "\\");
1744 ##-- Dev-C++ 5 projects
1746 # Note: All files created in this section are written in binary
1747 # mode to prevent any posibility of misinterpreted line endings.
1748 # I don't know if Dev-C++ is as touchy as MSVC with LF-only line
1749 # endings. But however, CRLF line endings are the common way on
1750 # Win32 machines where Dev-C++ is running.
1751 # Hence, in order for mkfiles.pl to generate CRLF project files
1752 # even when run from Unix, I make sure all files are binary and
1753 # explicitly write the CRLFs.
1755 # Create directories if necessary
1756 mkdir $makefiles{'devcppproj'}
1757 if(! -d $makefiles{'devcppproj'});
1758 chdir $makefiles{'devcppproj'};
1759 @deps = &deps("X.obj", "X.res", $dirpfx, "\\", "devcppproj");
1760 %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
1761 # Make dir names FAT/NTFS compatible
1762 my @srcdirs = @srcdirs;
1763 for ($i=0; $i<@srcdirs; $i++) {
1764 $srcdirs[$i] =~ s/\//\\/g;
1765 $srcdirs[$i] =~ s/\\$//;
1767 # Create the project files
1768 # Get names of all Windows projects (GUI and console)
1769 my @prognames = &prognames("G:C");
1770 foreach $progname (@prognames) {
1771 create_devcpp_project(\%all_object_deps, $progname);
1776 sub create_devcpp_project {
1777 my ($all_object_deps, $progname) = @_;
1778 # Construct program's dependency info (Taken from 'vcproj', seems to work right here, too.)
1783 %resource_files = ();
1784 @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
1785 foreach $object_file (@object_files) {
1786 next if defined $seen_objects{$object_file};
1787 $seen_objects{$object_file} = 1;
1788 if($object_file =~ /\.lib$/io) {
1789 $lib_files{$object_file} = 1;
1792 $object_deps = $all_object_deps{$object_file};
1793 foreach $object_dep (@$object_deps) {
1794 if($object_dep =~ /\.c$/io) {
1795 $source_files{$object_dep} = 1;
1798 if($object_dep =~ /\.h$/io) {
1799 $header_files{$object_dep} = 1;
1802 if($object_dep =~ /\.(rc|ico)$/io) {
1803 $resource_files{$object_dep} = 1;
1808 $libs = join " ", sort keys %lib_files;
1809 @source_files = sort keys %source_files;
1810 @header_files = sort keys %header_files;
1811 @resources = sort keys %resource_files;
1812 ($windows_project, $type) = split ",", $progname;
1813 mkdir $windows_project
1814 if(! -d $windows_project);
1815 chdir $windows_project;
1817 $subsys = ($type eq "G") ? "0" : "1"; # 0 = Win32 GUI, 1 = Win32 Console
1818 open OUT, ">$windows_project.dev"; binmode OUT; select OUT;
1820 "# DEV-C++ 5 Project File - $windows_project.dev\r\n".
1821 "# ** DO NOT EDIT **\r\n".
1823 # No difference between DEBUG and RELEASE here as in 'vcproj', because
1824 # Dev-C++ does not support mutiple compilation profiles in one single project.
1825 # (At least I can say this for Dev-C++ 5 Beta)
1827 "FileName=$windows_project.dev\r\n".
1828 "Name=$windows_project\r\n".
1832 # Multimon is disabled here, as Dev-C++ (Version 5 Beta) does not have multimon.h
1833 "Compiler=-W -D__GNUWIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNO_MULTIMON -D_MBCS_\@\@_\r\n".
1834 "CppCompiler=-W -D__GNUWIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNO_MULTIMON -D_MBCS_\@\@_\r\n".
1835 "Includes=" . (join ";", map {"..\\..\\$dirpfx$_"} @srcdirs) . "\r\n".
1836 "Linker=-ladvapi32 -lcomctl32 -lcomdlg32 -lgdi32 -limm32 -lshell32 -luser32 -lwinmm -lwinspool_\@\@_\r\n".
1838 "UnitCount=" . (@source_files + @header_files + @resources) . "\r\n".
1839 "Folders=\"Header Files\",\"Resource Files\",\"Source Files\"\r\n".
1841 "PrivateResource=${windows_project}_private.rc\r\n".
1842 "ResourceIncludes=..\\..\\..\\WINDOWS\r\n".
1843 "MakeIncludes=\r\n".
1844 "Icon=\r\n". # It's ok to leave this blank.
1846 "ObjectOutput=\r\n".
1847 "OverrideOutput=0\r\n".
1848 "OverrideOutputName=$windows_project.exe\r\n".
1849 "HostApplication=\r\n".
1851 "UseCustomMakefile=0\r\n".
1852 "CustomMakefile=\r\n".
1853 "IncludeVersionInfo=0\r\n".
1854 "SupportXPThemes=0\r\n".
1855 "CompilerSet=0\r\n".
1856 "CompilerSettings=0000000000000000000000\r\n".
1859 foreach $source_file (@source_files) {
1861 "[Unit$unit_count]\r\n".
1862 "FileName=..\\..\\$source_file\r\n".
1863 "Folder=Source Files\r\n".
1867 "Priority=1000\r\n".
1868 "OverrideBuildCmd=0\r\n".
1873 foreach $header_file (@header_files) {
1875 "[Unit$unit_count]\r\n".
1876 "FileName=..\\..\\$header_file\r\n".
1877 "Folder=Header Files\r\n".
1879 "CompileCpp=1\r\n". # Dev-C++ want's to compile all header files with both compilers C and C++. It does not hurt.
1881 "Priority=1000\r\n".
1882 "OverrideBuildCmd=0\r\n".
1887 foreach $resource_file (@resources) {
1888 if ($resource_file =~ /.*\.(ico|cur|bmp|dlg|rc2|rct|bin|rgs|gif|jpg|jpeg|jpe)/io) { # Default filter as in 'vcproj'
1889 $Compile = "0"; # Don't compile images and other binary resource files
1893 $CompileCpp = "1"; # Dev-C++ want's to compile all .rc files with both compilers C and C++. It does not hurt.
1896 "[Unit$unit_count]\r\n".
1897 "FileName=..\\..\\$resource_file\r\n".
1898 "Folder=Resource Files\r\n".
1899 "Compile=$Compile\r\n".
1900 "CompileCpp=$CompileCpp\r\n".
1902 "Priority=1000\r\n".
1903 "OverrideBuildCmd=0\r\n".
1908 #Note: By default, [VersionInfo] is not used.
1910 "[VersionInfo]\r\n".
1915 "LanguageID=1033\r\n".
1916 "CharsetID=1252\r\n".
1918 "FileVersion=0.1\r\n".
1919 "FileDescription=\r\n".
1920 "InternalName=\r\n".
1921 "LegalCopyright=\r\n".
1922 "LegalTrademarks=\r\n".
1923 "OriginalFilename=$windows_project.exe\r\n".
1924 "ProductName=$windows_project\r\n".
1925 "ProductVersion=0.1\r\n".
1926 "AutoIncBuildNr=0\r\n";
1927 select STDOUT; close OUT;
1932 # All done, so do the Unix postprocessing if asked to.
1936 system "./mkauto.sh";
1937 die "mkfiles.pl: mkauto.sh returned $?\n" if $? > 0;
1938 if ($do_unix == 1) {
1939 chdir ($targetdir = "unix")
1940 or die "$targetdir: chdir: $!\n";
1942 system "./configure", @confargs;
1943 die "mkfiles.pl: configure returned $?\n" if $? > 0;
1946 sub invent_guid($) {
1949 # Invent a GUID for use in Visual Studio project files. We need
1950 # a few of these for every executable file we build.
1952 # In order to avoid having to use the non-core Perl module
1953 # Data::GUID, and also arrange for GUIDs to be stable, we generate
1954 # our GUIDs by hashing a pile of fixed (but originally randomly
1955 # generated) data with the filename for which we need an id.
1957 # Hashing _just_ the filenames would clearly be cheating (it's
1958 # quite conceivable that someone might hash the same string for
1959 # another reason and so generate a colliding GUID), but hashing a
1960 # whole SHA-512 data block of random gibberish as well should make
1961 # these GUIDs pseudo-random enough to not collide with anyone
1964 my $randdata = pack "N*",
1965 0xD4AB035F,0x76998BA0,0x2DCCB0BD,0x6D3FA320,0x53638051,0xFE312F35,
1966 0xDE1CECC0,0x784DF852,0x6C9F4589,0x54B7AC23,0x14E7A1C4,0xF9BF04DF,
1967 0x19C08B6D,0x3FB69EF1,0xB2DA9043,0xDB5362F3,0x25718DB6,0x733560DA,
1968 0xFEF871B0,0xFECF7A0C,0x67D19C95,0xB492E911,0xF5D562A3,0xFCE1D478,
1969 0x02C50434,0xF7326B7E,0x93D39872,0xCF0D0269,0x9EF24C0F,0x827689AD,
1970 0x88BD20BC,0x74EA6AFE,0x29223682,0xB9AB9287,0x7EA7CE4F,0xCF81B379,
1971 0x9AE4A954,0x81C7AD97,0x2FF2F031,0xC51DA3C2,0xD311CCE7,0x0A31EB8B,
1972 0x1AB04242,0xAF53B714,0xFC574D40,0x8CB4ED01,0x29FEB16F,0x4904D7ED,
1973 0xF5C5F5E1,0xF138A4C2,0xA9D881CE,0xCEA65187,0x4421BA97,0x0EE8428E,
1974 0x9556E384,0x6D0484C9,0x561BD84B,0xD9516A40,0x6B4FD33F,0xDDFFE4C8,
1975 0x3D5DF8A5,0xFE6B7D99,0x3443371B,0xF4E30A3E,0xE62B9FDA,0x6BAA75DB,
1976 0x9EF3C2C7,0x6815CA42,0xE6536076,0xF851E6E2,0x39D16E69,0xBCDF3BB6,
1977 0x50EFFA41,0x378CDF2A,0xB5EC0D0C,0x1E94C433,0xE818241A,0x2689EB1F,
1978 0xB649CEF9,0xD7344D46,0x59C1BB13,0x27511FDF,0x7DAD1768,0xB355E29E,
1979 0xDFAE550C,0x2433005B,0x09DE10B0,0xAA00BA6B,0xC144ED2D,0x8513D007,
1980 0xB0315232,0x7A10DAB6,0x1D97654E,0xF048214D,0xE3059E75,0x83C225D1,
1981 0xFC7AB177,0x83F2B553,0x79F7A0AF,0x1C94582C,0xF5E4AF4B,0xFB39C865,
1982 0x58ABEB27,0xAAB28058,0x52C15A89,0x0EBE9741,0x343F4D26,0xF941202A,
1983 0xA32FD32F,0xDCC055B8,0x64281BF3,0x468BD7BA,0x0CEE09D3,0xBB5FD2B6,
1984 0xA528D412,0xA6A6967E,0xEAAF5DAE,0xDE7B2FAE,0xCA36887B,0x0DE196EB,
1985 0x74B95EF0,0x9EB8B7C2,0x020BFC83,0x1445086F,0xBF4B61B2,0x89AFACEC,
1986 0x80A5CD69,0xC790F744,0x435A6998,0x8DE7AC48,0x32F31BC9,0x8F760D3D,
1987 0xF02A74CB,0xD7B47E20,0x9EC91035,0x70FDE74D,0x9B531362,0x9D81739A,
1988 0x59ADC2EB,0x511555B5,0xCA84B8D5,0x3EC325FF,0x2E442A4C,0x82AF30D9,
1989 0xBFD3EC87,0x90C59E07,0x1C6DC991,0x2D16B822,0x7EA44EB5,0x3A655A39,
1990 0xAB640886,0x09311821,0x777801D9,0x489DBE61,0xA1FFEC65,0x978B49B1,
1991 0x7DB700CD,0x263CF3D6,0xF977E89F,0xBA0B3D01,0x6C6CED19,0x1BE6F23A,
1992 0x19E0ED98,0x8E71A499,0x70BA3271,0x3FB7EE98,0xABA46848,0x2B797959,
1993 0x72C6DE59,0xE08B795C,0x02936C39,0x02185CCB,0xD6F3CE18,0xD0157A40,
1994 0x833DEC3F,0x319B00C4,0x97B59513,0x900B81FD,0x9A022379,0x16E44E1A,
1995 0x0C4CC540,0xCA98E7F9,0xF9431A26,0x290BCFAC,0x406B82C0,0xBC1C4585,
1996 0x55C54528,0x811EBB77,0xD4EDD4F3,0xA70DC02E,0x8AD5C0D1,0x28D64EF4,
1997 0xBEFF5C69,0x99852C4A,0xB4BBFF7B,0x069230AC,0xA3E141FA,0x4E99FB0E,
1998 0xBC154DAA,0x323C7F15,0x86E0247E,0x2EEA3054,0xC9CA1D32,0x8964A006,
1999 0xC93978AC,0xF9B2C159,0x03F2079E,0xB051D284,0x4A7EA9A9,0xF001DA1F,
2000 0xD47A0DAA,0xCF7B6B73,0xF18293B2,0x84303E34,0xF8BC76C4,0xAFBEE24F,
2001 0xB589CA80,0x77B5BF86,0x21B9FD5B,0x1A5071DF,0xA3863110,0x0E50CA61,
2002 0x939151A5,0xD2A59021,0x83A9CDCE,0xCEC69767,0xC906BB16,0x3EE1FF4D,
2003 0x1321EAE4,0x0BF940D6,0x52471E61,0x8A087056,0x66E54293,0xF84AAB9B,
2004 0x08835EF1,0x8F12B77A,0xD86935A5,0x200281D7,0xCD3C37C9,0x30ABEC05,
2005 0x7067E8A0,0x608C4838,0xC9F51CDE,0xA6D318DE,0x41C05B2A,0x694CCE0E,
2006 0xC7842451,0xA3194393,0xFBDC2C84,0xA6D2B577,0xC91E7924,0x01EDA708,
2007 0x22FBB61E,0x662F9B7B,0xDE3150C3,0x2397058C;
2008 my $digest = sha512_hex($name . "\0" . $randdata);
2009 return sprintf("%s-%s-%04x-%04x-%s",
2010 substr($digest,0,8),
2011 substr($digest,8,4),
2012 0x4000 | (0xFFF & hex(substr($digest,12,4))),
2013 0x8000 | (0x3FFF & hex(substr($digest,16,4))),
2014 substr($digest,20,12));