3 # Cross-platform Makefile generator.
\r
5 # Reads the file `Recipe' to determine the list of generated
\r
6 # executables and their component objects. Then reads the source
\r
7 # files to compute #include dependencies. Finally, writes out the
\r
8 # various target Makefiles.
\r
10 # PuTTY specifics which could still do with removing:
\r
11 # - Mac makefile is not portabilised at all. Include directories
\r
12 # are hardwired, and also the libraries are fixed. This is
\r
13 # mainly because I was too scared to go anywhere near it.
\r
14 # - sbcsgen.pl is still run at startup.
\r
16 # FIXME: no attempt made to handle !forceobj in the project files.
\r
22 open IN, "Recipe" or do {
\r
23 # We want to deal correctly with being run from one of the
\r
24 # subdirs in the source tree. So if we can't find Recipe here,
\r
27 open IN, "Recipe" or die "unable to open Recipe file\n";
\r
30 # HACK: One of the source files in `charset' is auto-generated by
\r
31 # sbcsgen.pl. We need to generate that _now_, before attempting
\r
32 # dependency analysis.
\r
33 eval 'chdir "charset"; require "sbcsgen.pl"; chdir ".."';
\r
37 $divert = undef; # ref to scalar in which text is currently being put
\r
38 $help = ""; # list of newline-free lines of help text
\r
39 $project_name = "project"; # this is a good enough default
\r
40 %makefiles = (); # maps makefile types to output makefile pathnames
\r
41 %makefile_extra = (); # maps makefile types to extra Makefile text
\r
42 %programs = (); # maps prog name + type letter to listref of objects/resources
\r
43 %groups = (); # maps group name to listref of objects/resources
\r
49 # If we're gathering help text, keep doing so.
\r
50 if (defined $divert) {
\r
51 if ((defined $_[0]) && $_[0] eq "!end") {
\r
54 ${$divert} .= "$_\n";
\r
58 # Skip comments and blank lines.
\r
59 next if /^\s*#/ or scalar @_ == 0;
\r
61 if ($_[0] eq "!begin" and $_[1] eq "help") { $divert = \$help; next; }
\r
62 if ($_[0] eq "!end") { $divert = undef; next; }
\r
63 if ($_[0] eq "!name") { $project_name = $_[1]; next; }
\r
64 if ($_[0] eq "!srcdir") { push @srcdirs, $_[1]; next; }
\r
65 if ($_[0] eq "!makefile" and &mfval($_[1])) { $makefiles{$_[1]}=$_[2]; next;}
\r
66 if ($_[0] eq "!specialobj" and &mfval($_[1])) { $specialobj{$_[1]}->{$_[2]} = 1; next;}
\r
67 if ($_[0] eq "!forceobj") { $forceobj{$_[1]} = 1; next; }
\r
68 if ($_[0] eq "!begin") {
\r
69 if (&mfval($_[1])) {
\r
70 $sect = $_[2] ? $_[2] : "end";
\r
71 $divert = \($makefile_extra{$_[1]}->{$sect});
\r
78 # If we're gathering help/verbatim text, keep doing so.
\r
79 if (defined $divert) { ${$divert} .= "$_\n"; next; }
\r
80 # Ignore blank lines.
\r
81 next if scalar @_ == 0;
\r
83 # Now we have an ordinary line. See if it's an = line, a : line
\r
88 $listref = $lastlistref;
\r
90 die "$.: unexpected + line\n" if !defined $lastlistref;
\r
91 } elsif ($_[1] eq "=") {
\r
92 $groups{$_[0]} = [] if !defined $groups{$_[0]};
\r
93 $listref = $groups{$_[0]};
\r
95 shift @objs; # eat the group name
\r
96 } elsif ($_[1] eq ":") {
\r
99 shift @objs; # eat the program name
\r
101 die "$.: unrecognised line type\n";
\r
103 shift @objs; # eat the +, the = or the :
\r
105 while (scalar @objs > 0) {
\r
108 foreach $j (@{$groups{$i}}) { unshift @objs, $j; }
\r
109 } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or
\r
110 $i eq "[X]" or $i eq "[U]" or $i eq "[MX]") and defined $prog) {
\r
111 $type = substr($i,1,(length $i)-2);
\r
113 push @$listref, $i;
\r
116 if ($prog and $type) {
\r
117 die "multiple program entries for $prog [$type]\n"
\r
118 if defined $programs{$prog . "," . $type};
\r
119 $programs{$prog . "," . $type} = $listref;
\r
121 $lastlistref = $listref;
\r
126 # Now retrieve the complete list of objects and resource files, and
\r
127 # construct dependency data for them. While we're here, expand the
\r
128 # object list for each program, and complain if its type isn't set.
\r
129 @prognames = sort keys %programs;
\r
132 foreach $i (@prognames) {
\r
133 ($prog, $type) = split ",", $i;
\r
134 # Strip duplicate object names.
\r
136 @list = grep { $status = ($prev ne $_); $prev=$_; $status }
\r
137 sort @{$programs{$i}};
\r
138 $programs{$i} = [@list];
\r
139 foreach $j (@list) {
\r
140 # Dependencies for "x" start with "x.c" or "x.m" (depending on
\r
141 # which one exists).
\r
142 # Dependencies for "x.res" start with "x.rc".
\r
143 # Dependencies for "x.rsrc" start with "x.r".
\r
144 # Both types of file are pushed on the list of files to scan.
\r
145 # Libraries (.lib) don't have dependencies at all.
\r
146 if ($j =~ /^(.*)\.res$/) {
\r
148 $depends{$j} = [$file];
\r
149 push @scanlist, $file;
\r
150 } elsif ($j =~ /^(.*)\.rsrc$/) {
\r
152 $depends{$j} = [$file];
\r
153 push @scanlist, $file;
\r
154 } elsif ($j !~ /\./) {
\r
156 $file = "$j.m" unless &findfile($file);
\r
157 $depends{$j} = [$file];
\r
158 push @scanlist, $file;
\r
163 # Scan each file on @scanlist and find further inclusions.
\r
164 # Inclusions are given by lines of the form `#include "otherfile"'
\r
165 # (system headers are automatically ignored by this because they'll
\r
166 # be given in angle brackets). Files included by this method are
\r
167 # added back on to @scanlist to be scanned in turn (if not already
\r
170 # Resource scripts (.rc) can also include a file by means of:
\r
171 # - a line # ending `ICON "filename"';
\r
172 # - a line ending `RT_MANIFEST "filename"'.
\r
173 # Files included by this method are not added to @scanlist because
\r
174 # they can never include further files.
\r
176 # In this pass we write out a hash %further which maps a source
\r
177 # file name into a listref containing further source file names.
\r
180 while (scalar @scanlist > 0) {
\r
181 $file = shift @scanlist;
\r
182 next if defined $further{$file}; # skip if we've already done it
\r
183 $further{$file} = [];
\r
184 $dirfile = &findfile($file);
\r
185 open IN, "$dirfile" or die "unable to open source file $file\n";
\r
188 /^\s*#include\s+\"([^\"]+)\"/ and do {
\r
189 push @{$further{$file}}, $1;
\r
190 push @scanlist, $1;
\r
193 /(RT_MANIFEST|ICON)\s+\"([^\"]+)\"\s*$/ and do {
\r
194 push @{$further{$file}}, $2;
\r
201 # Now we're ready to generate the final dependencies section. For
\r
202 # each key in %depends, we must expand the dependencies list by
\r
203 # iteratively adding entries from %further.
\r
204 foreach $i (keys %depends) {
\r
206 @scanlist = @{$depends{$i}};
\r
207 foreach $i (@scanlist) { $dep{$i} = 1; }
\r
208 while (scalar @scanlist > 0) {
\r
209 $file = shift @scanlist;
\r
210 foreach $j (@{$further{$file}}) {
\r
213 push @{$depends{$i}}, $j;
\r
214 push @scanlist, $j;
\r
218 # printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
\r
221 # Validation of input.
\r
225 # Returns true if the argument is a known makefile type. Otherwise,
\r
226 # prints a warning and returns false;
\r
227 if (grep { $type eq $_ }
\r
228 ("vc","vcproj","cygwin","borland","lcc","devcppproj","gtk","unix",
\r
232 warn "$.:unknown makefile type '$type'\n";
\r
236 # Utility routines while writing out the Makefiles.
\r
239 my ($x) = shift @_;
\r
240 return (defined $x) ? $x : "";
\r
244 my ($path) = shift @_;
\r
245 my ($sep) = shift @_;
\r
249 while (($i = index $path, $sep) >= 0 ||
\r
250 ($j = index $path, "/") >= 0) {
\r
251 if ($i >= 0 and ($j < 0 or $i < $j)) {
\r
252 $path = substr $path, ($i + length $sep);
\r
254 $path = substr $path, ($j + 1);
\r
265 my $outdir = undef;
\r
266 unless (defined $findfilecache{$name}) {
\r
268 foreach $dir (@srcdirs) {
\r
269 if (-f "$dir$name") {
\r
272 $outdir =~ s/^\.\///;
\r
275 die "multiple instances of source file $name\n" if $i > 1;
\r
276 $findfilecache{$name} = (defined $outdir ? $outdir . $name : undef);
\r
278 return $findfilecache{$name};
\r
282 my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
\r
285 ($otmpl, $rtmpl, $ltmpl) = map { defined $_ ? $_ : "" } ($otmpl, $rtmpl, $ltmpl);
\r
287 foreach $i (@{$programs{$prog}}) {
\r
289 if ($i =~ /^(.*)\.(res|rsrc)/) {
\r
291 ($x = $rtmpl) =~ s/X/$y/;
\r
292 } elsif ($i =~ /^(.*)\.lib/) {
\r
294 ($x = $ltmpl) =~ s/X/$y/;
\r
295 } elsif ($i !~ /\./) {
\r
296 ($x = $otmpl) =~ s/X/$i/;
\r
298 push @ret, $x if $x ne "";
\r
300 return join " ", @ret;
\r
304 my ($prog, $suffix) = @_;
\r
307 ($otmpl, $rtmpl, $ltmpl) = map { defined $_ ? $_ : "" } ($otmpl, $rtmpl, $ltmpl);
\r
309 foreach $i (@{$programs{$prog}}) {
\r
310 if (substr($i, (length $i) - (length $suffix)) eq $suffix) {
\r
314 return (scalar @ret) ? (join " ", @ret) : undef;
\r
318 my ($line, $width, $splitchar) = @_;
\r
321 $len = (defined $width ? $width : 76);
\r
322 $splitchar = (defined $splitchar ? $splitchar : '\\');
\r
323 while (length $line > $len) {
\r
324 $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
\r
326 $result .= " ${splitchar}\n\t\t" if $2 ne '';
\r
330 return $result . $line;
\r
334 my ($otmpl, $rtmpl, $prefix, $dirsep, $mftyp, $depchar, $splitchar) = @_;
\r
340 foreach $i (sort keys %depends) {
\r
341 next if $specialobj{$mftyp}->{$i};
\r
342 if ($i =~ /^(.*)\.(res|rsrc)/) {
\r
343 next if !defined $rtmpl;
\r
345 ($x = $rtmpl) =~ s/X/$y/;
\r
347 ($x = $otmpl) =~ s/X/$i/;
\r
349 @deps = @{$depends{$i}};
\r
351 $_ = &findfile($_);
\r
355 push @ret, {obj => $x, obj_orig => $i, deps => [@deps]};
\r
362 my ($n, $prog, $type);
\r
365 foreach $n (@prognames) {
\r
366 ($prog, $type) = split ",", $n;
\r
367 push @ret, $n if index(":$types:", ":$type:") >= 0;
\r
372 sub progrealnames {
\r
374 my ($n, $prog, $type);
\r
377 foreach $n (@prognames) {
\r
378 ($prog, $type) = split ",", $n;
\r
379 push @ret, $prog if index(":$types:", ":$type:") >= 0;
\r
385 my ($types,$suffix) = @_;
\r
387 # assume that all UNIX programs have a man page
\r
388 if($suffix eq "1" && $types =~ /:X:/) {
\r
389 return map("$_.1", &progrealnames($types));
\r
394 # Now we're ready to output the actual Makefiles.
\r
396 if (defined $makefiles{'cygwin'}) {
\r
397 $dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
\r
399 ##-- CygWin makefile
\r
400 open OUT, ">$makefiles{'cygwin'}"; select OUT;
\r
402 "# Makefile for $project_name under cygwin.\n".
\r
403 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
\r
404 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
\r
405 # gcc command line option is -D not /D
\r
406 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
\r
410 "# You can define this path to point at your tools if you need to\n".
\r
411 "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
\r
412 "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
\r
413 "CC = \$(TOOLPATH)gcc\n".
\r
414 "RC = \$(TOOLPATH)windres\n".
\r
415 "# Uncomment the following two lines to compile under Winelib\n".
\r
416 "# CC = winegcc\n".
\r
418 "# You may also need to tell windres where to find include files:\n".
\r
419 "# RCINC = --include-dir c:\\cygwin\\include\\\n".
\r
421 &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
\r
422 " -D_NO_OLDNAMES -DNO_MULTIMON -DNO_HTMLHELP " .
\r
423 (join " ", map {"-I$dirpfx$_"} @srcdirs)) .
\r
425 "LDFLAGS = -mno-cygwin -s\n".
\r
426 &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1".
\r
427 " --define WINVER=0x0400")."\n".
\r
429 $makefile_extra{'cygwin'}->{'vars'} .
\r
433 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
\r
435 foreach $p (&prognames("G:C")) {
\r
436 ($prog, $type) = split ",", $p;
\r
437 $objstr = &objects($p, "X.o", "X.res.o", undef);
\r
438 print &splitline($prog . ".exe: " . $objstr), "\n";
\r
439 my $mw = $type eq "G" ? " -mwindows" : "";
\r
440 $libstr = &objects($p, undef, undef, "-lX");
\r
441 print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
\r
442 "-Wl,-Map,$prog.map " .
\r
443 $objstr . " $libstr", 69), "\n\n";
\r
445 foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/", "cygwin")) {
\r
446 if ($forceobj{$d->{obj_orig}}) {
\r
447 printf ("%s: FORCE\n", $d->{obj});
\r
449 print &splitline(sprintf("%s: %s", $d->{obj},
\r
450 join " ", @{$d->{deps}})), "\n";
\r
452 if ($d->{obj} =~ /\.res\.o$/) {
\r
453 print "\t\$(RC) \$(RCFL) \$(RCFLAGS) ".$d->{deps}->[0]." ".$d->{obj}."\n\n";
\r
455 print "\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c ".$d->{deps}->[0]."\n\n";
\r
459 print $makefile_extra{'cygwin'}->{'end'};
\r
460 print "\nclean:\n".
\r
461 "\trm -f *.o *.exe *.res.o *.map\n".
\r
464 select STDOUT; close OUT;
\r
468 ##-- Borland makefile
\r
469 if (defined $makefiles{'borland'}) {
\r
470 $dirpfx = &dirpfx($makefiles{'borland'}, "\\");
\r
472 %stdlibs = ( # Borland provides many Win32 API libraries intrinsically
\r
484 open OUT, ">$makefiles{'borland'}"; select OUT;
\r
486 "# Makefile for $project_name under Borland C.\n".
\r
487 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
\r
488 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
\r
489 # bcc32 command line option is -D not /D
\r
490 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
\r
494 "# If you rename this file to `Makefile', you should change this line,\n".
\r
495 "# so that the .rsp files still depend on the correct makefile.\n".
\r
496 "MAKEFILE = Makefile.bor\n".
\r
498 "# C compilation flags\n".
\r
499 "CFLAGS = -D_WINDOWS -DWINVER=0x0500\n".
\r
500 "# Resource compilation flags\n".
\r
501 "RCFLAGS = -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401\n".
\r
503 "# Get include directory for resource compiler\n".
\r
505 "BCB = \$(MAKEDIR)\\..\n".
\r
508 $makefile_extra{'borland'}->{'vars'} .
\r
511 &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT)".
\r
512 " \$(CFLAGS) \$(XFLAGS) ".
\r
513 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
\r
514 " /c \$*.c",69)."\n".
\r
516 &splitline("\tbrcc32 \$(RCFL) -i \$(BCB)\\include -r".
\r
517 " \$(RCFLAGS) \$*.rc",69)."\n".
\r
519 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
\r
521 foreach $p (&prognames("G:C")) {
\r
522 ($prog, $type) = split ",", $p;
\r
523 $objstr = &objects($p, "X.obj", "X.res", undef);
\r
524 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
\r
525 my $ap = ($type eq "G") ? "-aa" : "-ap";
\r
526 print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n";
\r
528 foreach $p (&prognames("G:C")) {
\r
529 ($prog, $type) = split ",", $p;
\r
530 print $prog, ".rsp: \$(MAKEFILE)\n";
\r
531 $objstr = &objects($p, "X.obj", undef, undef);
\r
532 @objlist = split " ", $objstr;
\r
534 foreach $i (@objlist) {
\r
535 if (length($objlines[$#objlines] . " $i") > 50) {
\r
536 push @objlines, "";
\r
538 $objlines[$#objlines] .= " $i";
\r
540 $c0w = ($type eq "G") ? "c0w32" : "c0x32";
\r
541 print "\techo $c0w + > $prog.rsp\n";
\r
542 for ($i=0; $i<=$#objlines; $i++) {
\r
543 $plus = ($i < $#objlines ? " +" : "");
\r
544 print "\techo$objlines[$i]$plus >> $prog.rsp\n";
\r
546 print "\techo $prog.exe >> $prog.rsp\n";
\r
547 $objstr = &objects($p, "X.obj", "X.res", undef);
\r
548 @libs = split " ", &objects($p, undef, undef, "X");
\r
549 @libs = grep { !$stdlibs{$_} } @libs;
\r
550 unshift @libs, "cw32", "import32";
\r
551 $libstr = join ' ', @libs;
\r
552 print "\techo nul,$libstr, >> $prog.rsp\n";
\r
553 print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n";
\r
556 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "borland")) {
\r
557 if ($forceobj{$d->{obj_orig}}) {
\r
558 printf("%s: FORCE\n", $d->{obj});
\r
560 print &splitline(sprintf("%s: %s", $d->{obj},
\r
561 join " ", @{$d->{deps}})), "\n";
\r
565 print $makefile_extra{'borland'}->{'end'};
\r
566 print "\nclean:\n".
\r
576 "\t-del *.\$\$\$\$\$\$\n".
\r
579 "\t-rem dummy command\n";
\r
580 select STDOUT; close OUT;
\r
583 if (defined $makefiles{'vc'}) {
\r
584 $dirpfx = &dirpfx($makefiles{'vc'}, "\\");
\r
586 ##-- Visual C++ makefile
\r
587 open OUT, ">$makefiles{'vc'}"; select OUT;
\r
589 "# Makefile for $project_name under Visual C.\n".
\r
590 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
\r
591 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
\r
595 "# If you rename this file to `Makefile', you should change this line,\n".
\r
596 "# so that the .rsp files still depend on the correct makefile.\n".
\r
597 "MAKEFILE = Makefile.vc\n".
\r
599 "# C compilation flags\n".
\r
600 "CFLAGS = /nologo /W3 /O1 " .
\r
601 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
\r
602 " /D_WINDOWS /D_WIN32_WINDOWS=0x500 /DWINVER=0x500\n".
\r
603 "LFLAGS = /incremental:no /fixed\n".
\r
604 "RCFLAGS = -DWIN32 -D_WIN32 -DWINVER=0x0400\n".
\r
606 $makefile_extra{'vc'}->{'vars'} .
\r
609 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
\r
611 foreach $p (&prognames("G:C")) {
\r
612 ($prog, $type) = split ",", $p;
\r
613 $objstr = &objects($p, "X.obj", "X.res", undef);
\r
614 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
\r
615 print "\tlink \$(LFLAGS) \$(XLFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
\r
617 foreach $p (&prognames("G:C")) {
\r
618 ($prog, $type) = split ",", $p;
\r
619 print $prog, ".rsp: \$(MAKEFILE)\n";
\r
620 $objstr = &objects($p, "X.obj", "X.res", "X.lib");
\r
621 @objlist = split " ", $objstr;
\r
623 foreach $i (@objlist) {
\r
624 if (length($objlines[$#objlines] . " $i") > 50) {
\r
625 push @objlines, "";
\r
627 $objlines[$#objlines] .= " $i";
\r
629 $subsys = ($type eq "G") ? "windows" : "console";
\r
630 print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
\r
631 for ($i=0; $i<=$#objlines; $i++) {
\r
632 print "\techo$objlines[$i] >> $prog.rsp\n";
\r
636 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "vc")) {
\r
637 $extradeps = $forceobj{$d->{obj_orig}} ? ["*.c","*.h","*.rc"] : [];
\r
638 print &splitline(sprintf("%s: %s", $d->{obj},
\r
639 join " ", @$extradeps, @{$d->{deps}})), "\n";
\r
640 if ($d->{obj} =~ /.obj$/) {
\r
641 print "\tcl \$(COMPAT) \$(CFLAGS) \$(XFLAGS) /c ".$d->{deps}->[0],"\n\n";
\r
643 print "\trc \$(RCFL) -r \$(RCFLAGS) ".$d->{deps}->[0],"\n\n";
\r
647 print $makefile_extra{'vc'}->{'end'};
\r
648 print "\nclean: tidy\n".
\r
649 "\t-del *.exe\n\n".
\r
665 "\t-del debug.log\n";
\r
666 select STDOUT; close OUT;
\r
669 if (defined $makefiles{'vcproj'}) {
\r
670 $dirpfx = &dirpfx($makefiles{'vcproj'}, "\\");
\r
674 ##-- MSVC 6 Workspace and projects
\r
676 # Note: All files created in this section are written in binary
\r
677 # mode, because although MSVC's command-line make can deal with
\r
678 # LF-only line endings, MSVC project files really _need_ to be
\r
679 # CRLF. Hence, in order for mkfiles.pl to generate usable project
\r
680 # files even when run from Unix, I make sure all files are binary
\r
681 # and explicitly write the CRLFs.
\r
683 # Create directories if necessary
\r
684 mkdir $makefiles{'vcproj'}
\r
685 if(! -d $makefiles{'vcproj'});
\r
686 chdir $makefiles{'vcproj'};
\r
687 @deps = &deps("X.obj", "X.res", $dirpfx, "\\", "vcproj");
\r
688 %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
\r
689 # Create the project files
\r
690 # Get names of all Windows projects (GUI and console)
\r
691 my @prognames = &prognames("G:C");
\r
692 foreach $progname (@prognames) {
\r
693 create_vc_project(\%all_object_deps, $progname);
\r
695 # Create the workspace file
\r
696 open OUT, ">$project_name.dsw"; binmode OUT; select OUT;
\r
698 "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
\r
699 "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
\r
701 "###############################################################################\r\n".
\r
704 foreach $progname (@prognames) {
\r
705 ($windows_project, $type) = split ",", $progname;
\r
706 print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n";
\r
718 "###############################################################################\r\n".
\r
730 "###############################################################################\r\n".
\r
732 select STDOUT; close OUT;
\r
735 sub create_vc_project {
\r
736 my ($all_object_deps, $progname) = @_;
\r
737 # Construct program's dependency info
\r
738 %seen_objects = ();
\r
740 %source_files = ();
\r
741 %header_files = ();
\r
742 %resource_files = ();
\r
743 @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
\r
744 foreach $object_file (@object_files) {
\r
745 next if defined $seen_objects{$object_file};
\r
746 $seen_objects{$object_file} = 1;
\r
747 if($object_file =~ /\.lib$/io) {
\r
748 $lib_files{$object_file} = 1;
\r
751 $object_deps = $all_object_deps{$object_file};
\r
752 foreach $object_dep (@$object_deps) {
\r
753 if($object_dep =~ /\.c$/io) {
\r
754 $source_files{$object_dep} = 1;
\r
757 if($object_dep =~ /\.h$/io) {
\r
758 $header_files{$object_dep} = 1;
\r
761 if($object_dep =~ /\.(rc|ico)$/io) {
\r
762 $resource_files{$object_dep} = 1;
\r
767 $libs = join " ", sort keys %lib_files;
\r
768 @source_files = sort keys %source_files;
\r
769 @header_files = sort keys %header_files;
\r
770 @resources = sort keys %resource_files;
\r
771 ($windows_project, $type) = split ",", $progname;
\r
772 mkdir $windows_project
\r
773 if(! -d $windows_project);
\r
774 chdir $windows_project;
\r
775 $subsys = ($type eq "G") ? "windows" : "console";
\r
776 open OUT, ">$windows_project.dsp"; binmode OUT; select OUT;
\r
778 "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n".
\r
779 "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n".
\r
780 "# ** DO NOT EDIT **\r\n".
\r
782 "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n".
\r
784 "CFG=$windows_project - Win32 Debug\r\n".
\r
785 "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n".
\r
786 "!MESSAGE use the Export Makefile command and run\r\n".
\r
788 "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n".
\r
790 "!MESSAGE You can specify a configuration when running NMAKE\r\n".
\r
791 "!MESSAGE by defining the macro CFG on the command line. For example:\r\n".
\r
793 "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
\r
795 "!MESSAGE Possible choices for configuration are:\r\n".
\r
797 "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n".
\r
798 "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n".
\r
801 "# Begin Project\r\n".
\r
802 "# PROP AllowPerConfigDependencies 0\r\n".
\r
803 "# PROP Scc_ProjName \"\"\r\n".
\r
804 "# PROP Scc_LocalPath \"\"\r\n".
\r
806 "MTL=midl.exe\r\n".
\r
809 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
\r
811 "# PROP BASE Use_MFC 0\r\n".
\r
812 "# PROP BASE Use_Debug_Libraries 0\r\n".
\r
813 "# PROP BASE Output_Dir \"Release\"\r\n".
\r
814 "# PROP BASE Intermediate_Dir \"Release\"\r\n".
\r
815 "# PROP BASE Target_Dir \"\"\r\n".
\r
816 "# PROP Use_MFC 0\r\n".
\r
817 "# PROP Use_Debug_Libraries 0\r\n".
\r
818 "# PROP Output_Dir \"Release\"\r\n".
\r
819 "# PROP Intermediate_Dir \"Release\"\r\n".
\r
820 "# PROP Ignore_Export_Lib 0\r\n".
\r
821 "# PROP Target_Dir \"\"\r\n".
\r
822 "# ADD BASE CPP /nologo /W3 /GX /O2 ".
\r
823 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
\r
824 " /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
\r
825 "# ADD CPP /nologo /W3 /GX /O2 ".
\r
826 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
\r
827 " /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
\r
828 "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
\r
829 "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
\r
830 "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n".
\r
831 "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n".
\r
832 "BSC32=bscmake.exe\r\n".
\r
833 "# ADD BASE BSC32 /nologo\r\n".
\r
834 "# ADD BSC32 /nologo\r\n".
\r
835 "LINK32=link.exe\r\n".
\r
836 "# 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".
\r
837 "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n".
\r
838 "# SUBTRACT LINK32 /pdb:none\r\n".
\r
840 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
\r
842 "# PROP BASE Use_MFC 0\r\n".
\r
843 "# PROP BASE Use_Debug_Libraries 1\r\n".
\r
844 "# PROP BASE Output_Dir \"Debug\"\r\n".
\r
845 "# PROP BASE Intermediate_Dir \"Debug\"\r\n".
\r
846 "# PROP BASE Target_Dir \"\"\r\n".
\r
847 "# PROP Use_MFC 0\r\n".
\r
848 "# PROP Use_Debug_Libraries 1\r\n".
\r
849 "# PROP Output_Dir \"Debug\"\r\n".
\r
850 "# PROP Intermediate_Dir \"Debug\"\r\n".
\r
851 "# PROP Ignore_Export_Lib 0\r\n".
\r
852 "# PROP Target_Dir \"\"\r\n".
\r
853 "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od ".
\r
854 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
\r
855 " /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
\r
856 "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od ".
\r
857 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
\r
858 " /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
\r
859 "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
\r
860 "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
\r
861 "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n".
\r
862 "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n".
\r
863 "BSC32=bscmake.exe\r\n".
\r
864 "# ADD BASE BSC32 /nologo\r\n".
\r
865 "# ADD BSC32 /nologo\r\n".
\r
866 "LINK32=link.exe\r\n".
\r
867 "# 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".
\r
868 "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
\r
869 "# SUBTRACT LINK32 /pdb:none\r\n".
\r
873 "# Begin Target\r\n".
\r
875 "# Name \"$windows_project - Win32 Release\"\r\n".
\r
876 "# Name \"$windows_project - Win32 Debug\"\r\n".
\r
877 "# Begin Group \"Source Files\"\r\n".
\r
879 "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
\r
880 foreach $source_file (@source_files) {
\r
882 "# Begin Source File\r\n".
\r
884 "SOURCE=..\\..\\$source_file\r\n";
\r
885 if($source_file =~ /ssh\.c/io) {
\r
886 # Disable 'Edit and continue' as Visual Studio can't handle the macros
\r
889 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
\r
891 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
\r
893 "# ADD CPP /Zi\r\n".
\r
898 print "# End Source File\r\n";
\r
902 "# Begin Group \"Header Files\"\r\n".
\r
904 "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
\r
905 foreach $header_file (@header_files) {
\r
907 "# Begin Source File\r\n".
\r
909 "SOURCE=..\\..\\$header_file\r\n".
\r
910 "# End Source File\r\n";
\r
914 "# Begin Group \"Resource Files\"\r\n".
\r
916 "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
\r
917 foreach $resource_file (@resources) {
\r
919 "# Begin Source File\r\n".
\r
921 "SOURCE=..\\..\\$resource_file\r\n".
\r
922 "# End Source File\r\n";
\r
926 "# End Target\r\n".
\r
927 "# End Project\r\n";
\r
928 select STDOUT; close OUT;
\r
933 if (defined $makefiles{'gtk'}) {
\r
934 $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
\r
936 ##-- X/GTK/Unix makefile
\r
937 open OUT, ">$makefiles{'gtk'}"; select OUT;
\r
939 "# Makefile for $project_name under X/GTK and Unix.\n".
\r
940 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
\r
941 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
\r
942 # gcc command line option is -D not /D
\r
943 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
\r
947 "# You can define this path to point at your tools if you need to\n".
\r
948 "# TOOLPATH = /opt/gcc/bin\n".
\r
949 "CC = \$(TOOLPATH)cc\n".
\r
950 "# If necessary set the path to krb5-config here\n".
\r
951 "KRB5CONFIG=krb5-config\n".
\r
952 "# You can manually set this to `gtk-config' or `pkg-config gtk+-1.2'\n".
\r
953 "# (depending on what works on your system) if you want to enforce\n".
\r
954 "# building with GTK 1.2, or you can set it to `pkg-config gtk+-2.0 x11'\n".
\r
955 "# if you want to enforce 2.0. The default is to try 2.0 and fall back\n".
\r
956 "# to 1.2 if it isn't found.\n".
\r
957 "GTK_CONFIG = sh -c 'pkg-config gtk+-2.0 x11 \$\$0 2>/dev/null || gtk-config \$\$0'\n".
\r
959 "-include Makefile.local\n".
\r
961 "unexport CFLAGS # work around a weird issue with krb5-config\n".
\r
963 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
\r
964 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
\r
965 " \$(shell \$(GTK_CONFIG) --cflags)").
\r
966 " -D _FILE_OFFSET_BITS=64\n".
\r
967 "XLDFLAGS = \$(LDFLAGS) \$(shell \$(GTK_CONFIG) --libs)\n".
\r
968 "ULDFLAGS = \$(LDFLAGS)\n".
\r
969 "ifeq (,\$(findstring NO_GSSAPI,\$(COMPAT)))\n".
\r
970 "ifeq (,\$(findstring STATIC_GSSAPI,\$(COMPAT)))\n".
\r
971 "XLDFLAGS+= -ldl\n".
\r
972 "ULDFLAGS+= -ldl\n".
\r
974 "CFLAGS+= -DNO_LIBDL \$(shell \$(KRB5CONFIG) --cflags gssapi)\n".
\r
975 "XLDFLAGS+= \$(shell \$(KRB5CONFIG) --libs gssapi)\n".
\r
976 "ULDFLAGS+= \$(shell \$(KRB5CONFIG) --libs gssapi)\n".
\r
979 "INSTALL=install\n".
\r
980 "INSTALL_PROGRAM=\$(INSTALL)\n".
\r
981 "INSTALL_DATA=\$(INSTALL)\n".
\r
982 "prefix=/usr/local\n".
\r
983 "exec_prefix=\$(prefix)\n".
\r
984 "bindir=\$(exec_prefix)/bin\n".
\r
985 "mandir=\$(prefix)/man\n".
\r
986 "man1dir=\$(mandir)/man1\n".
\r
988 &def($makefile_extra{'gtk'}->{'vars'}) .
\r
993 print &splitline("all:" . join "", map { " $_" } &progrealnames("X:U"));
\r
995 foreach $p (&prognames("X:U")) {
\r
996 ($prog, $type) = split ",", $p;
\r
997 $objstr = &objects($p, "X.o", undef, undef);
\r
998 print &splitline($prog . ": " . $objstr), "\n";
\r
999 $libstr = &objects($p, undef, undef, "-lX");
\r
1000 print &splitline("\t\$(CC) -o \$@ " .
\r
1001 $objstr . " \$(${type}LDFLAGS) $libstr", 69), "\n\n";
\r
1003 foreach $d (&deps("X.o", undef, $dirpfx, "/", "gtk")) {
\r
1004 if ($forceobj{$d->{obj_orig}}) {
\r
1005 printf("%s: FORCE\n", $d->{obj});
\r
1007 print &splitline(sprintf("%s: %s", $d->{obj},
\r
1008 join " ", @{$d->{deps}})), "\n";
\r
1010 print &splitline("\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c $d->{deps}->[0]\n");
\r
1013 print $makefile_extra{'gtk'}->{'end'};
\r
1014 print "\nclean:\n".
\r
1015 "\trm -f *.o". (join "", map { " $_" } &progrealnames("X:U")) . "\n";
\r
1016 print "\nFORCE:\n";
\r
1017 select STDOUT; close OUT;
\r
1020 if (defined $makefiles{'unix'}) {
\r
1021 $dirpfx = &dirpfx($makefiles{'unix'}, "/");
\r
1023 ##-- GTK-free pure-Unix makefile for non-GUI apps only
\r
1024 open OUT, ">$makefiles{'unix'}"; select OUT;
\r
1026 "# Makefile for $project_name under Unix.\n".
\r
1027 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
\r
1028 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
\r
1029 # gcc command line option is -D not /D
\r
1030 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
\r
1034 "# You can define this path to point at your tools if you need to\n".
\r
1035 "# TOOLPATH = /opt/gcc/bin\n".
\r
1036 "CC = \$(TOOLPATH)cc\n".
\r
1038 "-include Makefile.local\n".
\r
1040 "unexport CFLAGS # work around a weird issue with krb5-config\n".
\r
1042 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
\r
1043 (join " ", map {"-I$dirpfx$_"} @srcdirs)).
\r
1044 " -D _FILE_OFFSET_BITS=64\n".
\r
1045 "ULDFLAGS = \$(LDFLAGS)\n".
\r
1046 "INSTALL=install\n".
\r
1047 "INSTALL_PROGRAM=\$(INSTALL)\n".
\r
1048 "INSTALL_DATA=\$(INSTALL)\n".
\r
1049 "prefix=/usr/local\n".
\r
1050 "exec_prefix=\$(prefix)\n".
\r
1051 "bindir=\$(exec_prefix)/bin\n".
\r
1052 "mandir=\$(prefix)/man\n".
\r
1053 "man1dir=\$(mandir)/man1\n".
\r
1055 &def($makefile_extra{'unix'}->{'vars'}) .
\r
1060 print &splitline("all:" . join "", map { " $_" } &progrealnames("U"));
\r
1062 foreach $p (&prognames("U")) {
\r
1063 ($prog, $type) = split ",", $p;
\r
1064 $objstr = &objects($p, "X.o", undef, undef);
\r
1065 print &splitline($prog . ": " . $objstr), "\n";
\r
1066 $libstr = &objects($p, undef, undef, "-lX");
\r
1067 print &splitline("\t\$(CC) -o \$@ " .
\r
1068 $objstr . " \$(${type}LDFLAGS) $libstr", 69), "\n\n";
\r
1070 foreach $d (&deps("X.o", undef, $dirpfx, "/", "unix")) {
\r
1071 if ($forceobj{$d->{obj_orig}}) {
\r
1072 printf("%s: FORCE\n", $d->{obj});
\r
1074 print &splitline(sprintf("%s: %s", $d->{obj},
\r
1075 join " ", @{$d->{deps}})), "\n";
\r
1077 print &splitline("\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c $d->{deps}->[0]\n");
\r
1080 print &def($makefile_extra{'unix'}->{'end'});
\r
1081 print "\nclean:\n".
\r
1082 "\trm -f *.o". (join "", map { " $_" } &progrealnames("U")) . "\n";
\r
1083 print "\nFORCE:\n";
\r
1084 select STDOUT; close OUT;
\r
1087 if (defined $makefiles{'ac'}) {
\r
1088 $dirpfx = &dirpfx($makefiles{'ac'}, "/");
\r
1090 ##-- Unix/autoconf makefile
\r
1091 open OUT, ">$makefiles{'ac'}"; select OUT;
\r
1093 "# Makefile.in for $project_name under Unix with Autoconf.\n".
\r
1094 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
\r
1095 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
\r
1096 # gcc command line option is -D not /D
\r
1097 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
\r
1103 &splitline("CFLAGS = \@CFLAGS\@ \@PUTTYCFLAGS\@ \@CPPFLAGS\@ " .
\r
1104 "\@DEFS\@ \@GTK_CFLAGS\@ " .
\r
1105 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
\r
1106 "XLDFLAGS = \@LDFLAGS\@ \@LIBS\@ \@GTK_LIBS\@\n".
\r
1107 "ULDFLAGS = \@LDFLAGS\@ \@LIBS\@\n".
\r
1108 "INSTALL=\@INSTALL\@\n".
\r
1109 "INSTALL_PROGRAM=\$(INSTALL)\n".
\r
1110 "INSTALL_DATA=\$(INSTALL)\n".
\r
1111 "prefix=\@prefix\@\n".
\r
1112 "exec_prefix=\@exec_prefix\@\n".
\r
1113 "bindir=\@bindir\@\n".
\r
1114 "datarootdir=\@datarootdir\@\n".
\r
1115 "mandir=\@mandir\@\n".
\r
1116 "man1dir=\$(mandir)/man1\n".
\r
1118 &def($makefile_extra{'gtk'}->{'vars'}) .
\r
1123 "all: \@all_targets\@\n".
\r
1124 &splitline("all-cli:" . join "", map { " $_" } &progrealnames("U"))."\n".
\r
1125 &splitline("all-gtk:" . join "", map { " $_" } &progrealnames("X"))."\n";
\r
1127 foreach $p (&prognames("X:U")) {
\r
1128 ($prog, $type) = split ",", $p;
\r
1129 $objstr = &objects($p, "X.o", undef, undef);
\r
1130 print &splitline($prog . ": " . $objstr), "\n";
\r
1131 $libstr = &objects($p, undef, undef, "-lX");
\r
1132 print &splitline("\t\$(CC) -o \$@ " .
\r
1133 $objstr . " \$(${type}LDFLAGS) $libstr", 69), "\n\n";
\r
1135 foreach $d (&deps("X.o", undef, $dirpfx, "/", "gtk")) {
\r
1136 if ($forceobj{$d->{obj_orig}}) {
\r
1137 printf("%s: FORCE\n", $d->{obj});
\r
1139 print &splitline(sprintf("%s: %s", $d->{obj},
\r
1140 join " ", @{$d->{deps}})), "\n";
\r
1142 print &splitline("\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c $d->{deps}->[0]\n");
\r
1145 print $makefile_extra{'gtk'}->{'end'};
\r
1146 print "\nclean:\n".
\r
1147 "\trm -f *.o". (join "", map { " $_" } &progrealnames("X:U")) . "\n";
\r
1148 print "\ndistclean: clean\n".
\r
1149 "\t". &splitline("rm -f config.status config.cache config.log ".
\r
1150 "configure.lineno config.status.lineno Makefile") . "\n";
\r
1151 print "\nFORCE:\n";
\r
1152 select STDOUT; close OUT;
\r
1155 if (defined $makefiles{'lcc'}) {
\r
1156 $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
\r
1159 open OUT, ">$makefiles{'lcc'}"; select OUT;
\r
1161 "# Makefile for $project_name under lcc.\n".
\r
1162 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
\r
1163 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
\r
1164 # lcc command line option is -D not /D
\r
1165 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
\r
1169 "# If you rename this file to `Makefile', you should change this line,\n".
\r
1170 "# so that the .rsp files still depend on the correct makefile.\n".
\r
1171 "MAKEFILE = Makefile.lcc\n".
\r
1173 "# C compilation flags\n".
\r
1174 "CFLAGS = -D_WINDOWS " .
\r
1175 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
\r
1177 "# Resource compilation flags\n".
\r
1180 "# Get include directory for resource compiler\n".
\r
1182 $makefile_extra{'lcc'}->{'vars'} .
\r
1184 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
\r
1186 foreach $p (&prognames("G:C")) {
\r
1187 ($prog, $type) = split ",", $p;
\r
1188 $objstr = &objects($p, "X.obj", "X.res", undef);
\r
1189 print &splitline("$prog.exe: " . $objstr ), "\n";
\r
1190 $subsystemtype = '';
\r
1191 if ($type eq "G") { $subsystemtype = "-subsystem windows"; }
\r
1192 my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
\r
1193 print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
\r
1197 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "lcc")) {
\r
1198 if ($forceobj{$d->{obj_orig}}) {
\r
1199 printf("%s: FORCE\n", $d->{obj});
\r
1201 print &splitline(sprintf("%s: %s", $d->{obj},
\r
1202 join " ", @{$d->{deps}})), "\n";
\r
1204 if ($d->{obj} =~ /\.obj$/) {
\r
1205 print &splitline("\tlcc -O -p6 \$(COMPAT)".
\r
1206 " \$(CFLAGS) \$(XFLAGS) ".$d->{deps}->[0],69)."\n";
\r
1208 print &splitline("\tlrc \$(RCFL) -r \$(RCFLAGS) ".
\r
1209 $d->{deps}->[0],69)."\n";
\r
1213 print $makefile_extra{'lcc'}->{'end'};
\r
1214 print "\nclean:\n".
\r
1221 select STDOUT; close OUT;
\r
1224 if (defined $makefiles{'osx'}) {
\r
1225 $dirpfx = &dirpfx($makefiles{'osx'}, "/");
\r
1227 ##-- Mac OS X makefile
\r
1228 open OUT, ">$makefiles{'osx'}"; select OUT;
\r
1230 "# Makefile for $project_name under Mac OS X.\n".
\r
1231 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
\r
1232 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
\r
1233 # gcc command line option is -D not /D
\r
1234 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
\r
1237 "CC = \$(TOOLPATH)gcc\n".
\r
1239 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
\r
1240 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
\r
1241 "MLDFLAGS = -framework Cocoa\n".
\r
1244 $makefile_extra{'osx'}->{'vars'} .
\r
1246 &splitline("all:" . join "", map { " $_" } &progrealnames("MX:U")) .
\r
1248 foreach $p (&prognames("MX")) {
\r
1249 ($prog, $type) = split ",", $p;
\r
1250 $objstr = &objects($p, "X.o", undef, undef);
\r
1251 $icon = &special($p, ".icns");
\r
1252 $infoplist = &special($p, "info.plist");
\r
1253 print "${prog}.app:\n\tmkdir -p \$\@\n";
\r
1254 print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n";
\r
1255 print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
\r
1256 $targets = "${prog}.app/Contents/MacOS/$prog";
\r
1257 if (defined $icon) {
\r
1258 print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
\r
1259 print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n";
\r
1260 $targets .= " ${prog}.app/Contents/Resources/${prog}.icns";
\r
1262 if (defined $infoplist) {
\r
1263 print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n";
\r
1264 $targets .= " ${prog}.app/Contents/Info.plist";
\r
1266 $targets .= " \$(${prog}_extra)";
\r
1267 print &splitline("${prog}: $targets", 69) . "\n\n";
\r
1268 print &splitline("${prog}.app/Contents/MacOS/$prog: ".
\r
1269 "${prog}.app/Contents/MacOS " . $objstr), "\n";
\r
1270 $libstr = &objects($p, undef, undef, "-lX");
\r
1271 print &splitline("\t\$(CC) \$(MLDFLAGS) -o \$@ " .
\r
1272 $objstr . " $libstr", 69), "\n\n";
\r
1274 foreach $p (&prognames("U")) {
\r
1275 ($prog, $type) = split ",", $p;
\r
1276 $objstr = &objects($p, "X.o", undef, undef);
\r
1277 print &splitline($prog . ": " . $objstr), "\n";
\r
1278 $libstr = &objects($p, undef, undef, "-lX");
\r
1279 print &splitline("\t\$(CC) \$(ULDFLAGS) -o \$@ " .
\r
1280 $objstr . " $libstr", 69), "\n\n";
\r
1282 foreach $d (&deps("X.o", undef, $dirpfx, "/", "osx")) {
\r
1283 if ($forceobj{$d->{obj_orig}}) {
\r
1284 printf("%s: FORCE\n", $d->{obj});
\r
1286 print &splitline(sprintf("%s: %s", $d->{obj},
\r
1287 join " ", @{$d->{deps}})), "\n";
\r
1289 $firstdep = $d->{deps}->[0];
\r
1290 if ($firstdep =~ /\.c$/) {
\r
1291 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS) -c \$<\n";
\r
1292 } elsif ($firstdep =~ /\.m$/) {
\r
1293 print "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS) -c \$<\n";
\r
1296 print "\n".&def($makefile_extra{'osx'}->{'end'});
\r
1297 print "\nclean:\n".
\r
1298 "\trm -f *.o *.dmg". (join "", map { " $_" } &progrealnames("U")) . "\n".
\r
1299 "\trm -rf *.app\n".
\r
1302 select STDOUT; close OUT;
\r
1305 if (defined $makefiles{'devcppproj'}) {
\r
1306 $dirpfx = &dirpfx($makefiles{'devcppproj'}, "\\");
\r
1309 ##-- Dev-C++ 5 projects
\r
1311 # Note: All files created in this section are written in binary
\r
1312 # mode to prevent any posibility of misinterpreted line endings.
\r
1313 # I don't know if Dev-C++ is as touchy as MSVC with LF-only line
\r
1314 # endings. But however, CRLF line endings are the common way on
\r
1315 # Win32 machines where Dev-C++ is running.
\r
1316 # Hence, in order for mkfiles.pl to generate CRLF project files
\r
1317 # even when run from Unix, I make sure all files are binary and
\r
1318 # explicitly write the CRLFs.
\r
1320 # Create directories if necessary
\r
1321 mkdir $makefiles{'devcppproj'}
\r
1322 if(! -d $makefiles{'devcppproj'});
\r
1323 chdir $makefiles{'devcppproj'};
\r
1324 @deps = &deps("X.obj", "X.res", $dirpfx, "\\", "devcppproj");
\r
1325 %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
\r
1326 # Make dir names FAT/NTFS compatible
\r
1327 my @srcdirs = @srcdirs;
\r
1328 for ($i=0; $i<@srcdirs; $i++) {
\r
1329 $srcdirs[$i] =~ s/\//\\/g;
\r
1330 $srcdirs[$i] =~ s/\\$//;
\r
1332 # Create the project files
\r
1333 # Get names of all Windows projects (GUI and console)
\r
1334 my @prognames = &prognames("G:C");
\r
1335 foreach $progname (@prognames) {
\r
1336 create_devcpp_project(\%all_object_deps, $progname);
\r
1339 sub create_devcpp_project {
\r
1340 my ($all_object_deps, $progname) = @_;
\r
1341 # Construct program's dependency info (Taken from 'vcproj', seems to work right here, too.)
\r
1342 %seen_objects = ();
\r
1344 %source_files = ();
\r
1345 %header_files = ();
\r
1346 %resource_files = ();
\r
1347 @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
\r
1348 foreach $object_file (@object_files) {
\r
1349 next if defined $seen_objects{$object_file};
\r
1350 $seen_objects{$object_file} = 1;
\r
1351 if($object_file =~ /\.lib$/io) {
\r
1352 $lib_files{$object_file} = 1;
\r
1355 $object_deps = $all_object_deps{$object_file};
\r
1356 foreach $object_dep (@$object_deps) {
\r
1357 if($object_dep =~ /\.c$/io) {
\r
1358 $source_files{$object_dep} = 1;
\r
1361 if($object_dep =~ /\.h$/io) {
\r
1362 $header_files{$object_dep} = 1;
\r
1365 if($object_dep =~ /\.(rc|ico)$/io) {
\r
1366 $resource_files{$object_dep} = 1;
\r
1371 $libs = join " ", sort keys %lib_files;
\r
1372 @source_files = sort keys %source_files;
\r
1373 @header_files = sort keys %header_files;
\r
1374 @resources = sort keys %resource_files;
\r
1375 ($windows_project, $type) = split ",", $progname;
\r
1376 mkdir $windows_project
\r
1377 if(! -d $windows_project);
\r
1378 chdir $windows_project;
\r
1380 $subsys = ($type eq "G") ? "0" : "1"; # 0 = Win32 GUI, 1 = Win32 Console
\r
1381 open OUT, ">$windows_project.dev"; binmode OUT; select OUT;
\r
1383 "# DEV-C++ 5 Project File - $windows_project.dev\r\n".
\r
1384 "# ** DO NOT EDIT **\r\n".
\r
1386 # No difference between DEBUG and RELEASE here as in 'vcproj', because
\r
1387 # Dev-C++ does not support mutiple compilation profiles in one single project.
\r
1388 # (At least I can say this for Dev-C++ 5 Beta)
\r
1390 "FileName=$windows_project.dev\r\n".
\r
1391 "Name=$windows_project\r\n".
\r
1394 "Type=$subsys\r\n".
\r
1395 # Multimon is disabled here, as Dev-C++ (Version 5 Beta) does not have multimon.h
\r
1396 "Compiler=-W -D__GNUWIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNO_MULTIMON -D_MBCS_\@\@_\r\n".
\r
1397 "CppCompiler=-W -D__GNUWIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNO_MULTIMON -D_MBCS_\@\@_\r\n".
\r
1398 "Includes=" . (join ";", map {"..\\..\\$dirpfx$_"} @srcdirs) . "\r\n".
\r
1399 "Linker=-ladvapi32 -lcomctl32 -lcomdlg32 -lgdi32 -limm32 -lshell32 -luser32 -lwinmm -lwinspool_\@\@_\r\n".
\r
1401 "UnitCount=" . (@source_files + @header_files + @resources) . "\r\n".
\r
1402 "Folders=\"Header Files\",\"Resource Files\",\"Source Files\"\r\n".
\r
1404 "PrivateResource=${windows_project}_private.rc\r\n".
\r
1405 "ResourceIncludes=..\\..\\..\\WINDOWS\r\n".
\r
1406 "MakeIncludes=\r\n".
\r
1407 "Icon=\r\n". # It's ok to leave this blank.
\r
1409 "ObjectOutput=\r\n".
\r
1410 "OverrideOutput=0\r\n".
\r
1411 "OverrideOutputName=$windows_project.exe\r\n".
\r
1412 "HostApplication=\r\n".
\r
1413 "CommandLine=\r\n".
\r
1414 "UseCustomMakefile=0\r\n".
\r
1415 "CustomMakefile=\r\n".
\r
1416 "IncludeVersionInfo=0\r\n".
\r
1417 "SupportXPThemes=0\r\n".
\r
1418 "CompilerSet=0\r\n".
\r
1419 "CompilerSettings=0000000000000000000000\r\n".
\r
1422 foreach $source_file (@source_files) {
\r
1424 "[Unit$unit_count]\r\n".
\r
1425 "FileName=..\\..\\$source_file\r\n".
\r
1426 "Folder=Source Files\r\n".
\r
1428 "CompileCpp=0\r\n".
\r
1430 "Priority=1000\r\n".
\r
1431 "OverrideBuildCmd=0\r\n".
\r
1436 foreach $header_file (@header_files) {
\r
1438 "[Unit$unit_count]\r\n".
\r
1439 "FileName=..\\..\\$header_file\r\n".
\r
1440 "Folder=Header Files\r\n".
\r
1442 "CompileCpp=1\r\n". # Dev-C++ want's to compile all header files with both compilers C and C++. It does not hurt.
\r
1444 "Priority=1000\r\n".
\r
1445 "OverrideBuildCmd=0\r\n".
\r
1450 foreach $resource_file (@resources) {
\r
1451 if ($resource_file =~ /.*\.(ico|cur|bmp|dlg|rc2|rct|bin|rgs|gif|jpg|jpeg|jpe)/io) { # Default filter as in 'vcproj'
\r
1452 $Compile = "0"; # Don't compile images and other binary resource files
\r
1453 $CompileCpp = "0";
\r
1456 $CompileCpp = "1"; # Dev-C++ want's to compile all .rc files with both compilers C and C++. It does not hurt.
\r
1459 "[Unit$unit_count]\r\n".
\r
1460 "FileName=..\\..\\$resource_file\r\n".
\r
1461 "Folder=Resource Files\r\n".
\r
1462 "Compile=$Compile\r\n".
\r
1463 "CompileCpp=$CompileCpp\r\n".
\r
1465 "Priority=1000\r\n".
\r
1466 "OverrideBuildCmd=0\r\n".
\r
1471 #Note: By default, [VersionInfo] is not used.
\r
1473 "[VersionInfo]\r\n".
\r
1478 "LanguageID=1033\r\n".
\r
1479 "CharsetID=1252\r\n".
\r
1480 "CompanyName=\r\n".
\r
1481 "FileVersion=0.1\r\n".
\r
1482 "FileDescription=\r\n".
\r
1483 "InternalName=\r\n".
\r
1484 "LegalCopyright=\r\n".
\r
1485 "LegalTrademarks=\r\n".
\r
1486 "OriginalFilename=$windows_project.exe\r\n".
\r
1487 "ProductName=$windows_project\r\n".
\r
1488 "ProductVersion=0.1\r\n".
\r
1489 "AutoIncBuildNr=0\r\n";
\r
1490 select STDOUT; close OUT;
\r