Cancelling a remote port forwarding that had been refused by the server caused
[u/mdw/putty] / mkfiles.pl
CommitLineData
52a1ed22 1#!/usr/bin/env perl
3d541627 2#
e35fb54b 3# Cross-platform Makefile generator.
7603011f 4#
5# Reads the file `Recipe' to determine the list of generated
6# executables and their component objects. Then reads the source
7# files to compute #include dependencies. Finally, writes out the
8# various target Makefiles.
9
cdd310bb 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.
976374cd 15#
16# FIXME: no attempt made to handle !forceobj in the project files.
cdd310bb 17
52a1ed22 18use warnings;
f7f27309 19use FileHandle;
e35fb54b 20use Cwd;
f7f27309 21
e3109730 22open IN, "Recipe" or do {
23 # We want to deal correctly with being run from one of the
24 # subdirs in the source tree. So if we can't find Recipe here,
25 # try one level up.
26 chdir "..";
27 open IN, "Recipe" or die "unable to open Recipe file\n";
28};
7603011f 29
2dc6356a 30# HACK: One of the source files in `charset' is auto-generated by
31# sbcsgen.pl. We need to generate that _now_, before attempting
32# dependency analysis.
33eval 'chdir "charset"; require "sbcsgen.pl"; chdir ".."';
34
cdd310bb 35@srcdirs = ("./");
f7f27309 36
e35fb54b 37$divert = undef; # ref to scalar in which text is currently being put
7603011f 38$help = ""; # list of newline-free lines of help text
e35fb54b 39$project_name = "project"; # this is a good enough default
40%makefiles = (); # maps makefile types to output makefile pathnames
41%makefile_extra = (); # maps makefile types to extra Makefile text
c282cde3 42%programs = (); # maps prog name + type letter to listref of objects/resources
7603011f 43%groups = (); # maps group name to listref of objects/resources
3d541627 44
3d541627 45while (<IN>) {
46 chomp;
4877ec8d 47 @_ = split;
48
49 # If we're gathering help text, keep doing so.
50 if (defined $divert) {
51 if ((defined $_[0]) && $_[0] eq "!end") {
52 $divert = undef;
53 } else {
54 ${$divert} .= "$_\n";
55 }
56 next;
57 }
58 # Skip comments and blank lines.
59 next if /^\s*#/ or scalar @_ == 0;
60
e35fb54b 61 if ($_[0] eq "!begin" and $_[1] eq "help") { $divert = \$help; next; }
62 if ($_[0] eq "!end") { $divert = undef; next; }
63 if ($_[0] eq "!name") { $project_name = $_[1]; next; }
cdd310bb 64 if ($_[0] eq "!srcdir") { push @srcdirs, $_[1]; next; }
e35fb54b 65 if ($_[0] eq "!makefile" and &mfval($_[1])) { $makefiles{$_[1]}=$_[2]; next;}
6da41155 66 if ($_[0] eq "!specialobj" and &mfval($_[1])) { $specialobj{$_[1]}->{$_[2]} = 1; next;}
976374cd 67 if ($_[0] eq "!forceobj") { $forceobj{$_[1]} = 1; next; }
e35fb54b 68 if ($_[0] eq "!begin") {
69 if (&mfval($_[1])) {
77603464 70 $sect = $_[2] ? $_[2] : "end";
71 $divert = \($makefile_extra{$_[1]}->{$sect});
e35fb54b 72 } else {
4877ec8d 73 $dummy = '';
e35fb54b 74 $divert = \$dummy;
75 }
76 next;
77 }
77603464 78 # If we're gathering help/verbatim text, keep doing so.
e35fb54b 79 if (defined $divert) { ${$divert} .= "$_\n"; next; }
7603011f 80 # Ignore blank lines.
81 next if scalar @_ == 0;
82
83 # Now we have an ordinary line. See if it's an = line, a : line
84 # or a + line.
85 @objs = @_;
86
87 if ($_[0] eq "+") {
88 $listref = $lastlistref;
89 $prog = undef;
90 die "$.: unexpected + line\n" if !defined $lastlistref;
91 } elsif ($_[1] eq "=") {
92 $groups{$_[0]} = [] if !defined $groups{$_[0]};
93 $listref = $groups{$_[0]};
94 $prog = undef;
95 shift @objs; # eat the group name
96 } elsif ($_[1] eq ":") {
c282cde3 97 $listref = [];
7603011f 98 $prog = $_[0];
99 shift @objs; # eat the program name
3d541627 100 } else {
7603011f 101 die "$.: unrecognised line type\n";
3d541627 102 }
7603011f 103 shift @objs; # eat the +, the = or the :
104
105 while (scalar @objs > 0) {
106 $i = shift @objs;
107 if ($groups{$i}) {
108 foreach $j (@{$groups{$i}}) { unshift @objs, $j; }
a86a2725 109 } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or
1ddda1ca 110 $i eq "[X]" or $i eq "[U]" or $i eq "[MX]") and defined $prog) {
111 $type = substr($i,1,(length $i)-2);
7603011f 112 } else {
113 push @$listref, $i;
114 }
115 }
c282cde3 116 if ($prog and $type) {
117 die "multiple program entries for $prog [$type]\n"
e35fb54b 118 if defined $programs{$prog . "," . $type};
c282cde3 119 $programs{$prog . "," . $type} = $listref;
120 }
7603011f 121 $lastlistref = $listref;
3d541627 122}
7603011f 123
3d541627 124close IN;
7603011f 125
126# Now retrieve the complete list of objects and resource files, and
127# construct dependency data for them. While we're here, expand the
128# object list for each program, and complain if its type isn't set.
129@prognames = sort keys %programs;
130%depends = ();
131@scanlist = ();
132foreach $i (@prognames) {
c282cde3 133 ($prog, $type) = split ",", $i;
7603011f 134 # Strip duplicate object names.
4877ec8d 135 $prev = '';
7603011f 136 @list = grep { $status = ($prev ne $_); $prev=$_; $status }
137 sort @{$programs{$i}};
138 $programs{$i} = [@list];
139 foreach $j (@list) {
1ddda1ca 140 # Dependencies for "x" start with "x.c" or "x.m" (depending on
141 # which one exists).
7603011f 142 # Dependencies for "x.res" start with "x.rc".
c88dc003 143 # Dependencies for "x.rsrc" start with "x.r".
7603011f 144 # Both types of file are pushed on the list of files to scan.
145 # Libraries (.lib) don't have dependencies at all.
146 if ($j =~ /^(.*)\.res$/) {
147 $file = "$1.rc";
148 $depends{$j} = [$file];
149 push @scanlist, $file;
c88dc003 150 } elsif ($j =~ /^(.*)\.rsrc$/) {
151 $file = "$1.r";
152 $depends{$j} = [$file];
153 push @scanlist, $file;
1ddda1ca 154 } elsif ($j !~ /\./) {
7603011f 155 $file = "$j.c";
1ddda1ca 156 $file = "$j.m" unless &findfile($file);
7603011f 157 $depends{$j} = [$file];
158 push @scanlist, $file;
159 }
160 }
161}
162
163# Scan each file on @scanlist and find further inclusions.
164# Inclusions are given by lines of the form `#include "otherfile"'
165# (system headers are automatically ignored by this because they'll
166# be given in angle brackets). Files included by this method are
167# added back on to @scanlist to be scanned in turn (if not already
168# done).
169#
0f2ab471 170# Resource scripts (.rc) can also include a file by means of:
171# - a line # ending `ICON "filename"';
172# - a line ending `RT_MANIFEST "filename"'.
173# Files included by this method are not added to @scanlist because
174# they can never include further files.
7603011f 175#
176# In this pass we write out a hash %further which maps a source
177# file name into a listref containing further source file names.
178
179%further = ();
180while (scalar @scanlist > 0) {
181 $file = shift @scanlist;
182 next if defined $further{$file}; # skip if we've already done it
7603011f 183 $further{$file} = [];
f7f27309 184 $dirfile = &findfile($file);
185 open IN, "$dirfile" or die "unable to open source file $file\n";
7603011f 186 while (<IN>) {
187 chomp;
188 /^\s*#include\s+\"([^\"]+)\"/ and do {
189 push @{$further{$file}}, $1;
190 push @scanlist, $1;
191 next;
192 };
0f2ab471 193 /(RT_MANIFEST|ICON)\s+\"([^\"]+)\"\s*$/ and do {
194 push @{$further{$file}}, $2;
7603011f 195 next;
196 }
197 }
198 close IN;
3d541627 199}
200
7603011f 201# Now we're ready to generate the final dependencies section. For
202# each key in %depends, we must expand the dependencies list by
203# iteratively adding entries from %further.
204foreach $i (keys %depends) {
205 %dep = ();
206 @scanlist = @{$depends{$i}};
207 foreach $i (@scanlist) { $dep{$i} = 1; }
208 while (scalar @scanlist > 0) {
209 $file = shift @scanlist;
210 foreach $j (@{$further{$file}}) {
4877ec8d 211 if (!$dep{$j}) {
7603011f 212 $dep{$j} = 1;
e35fb54b 213 push @{$depends{$i}}, $j;
214 push @scanlist, $j;
7603011f 215 }
216 }
217 }
218# printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
3d541627 219}
220
e35fb54b 221# Validation of input.
222
223sub mfval($) {
224 my ($type) = @_;
225 # Returns true if the argument is a known makefile type. Otherwise,
226 # prints a warning and returns false;
227 if (grep { $type eq $_ }
b89e7e07 228 ("vc","vcproj","cygwin","borland","lcc","devcppproj","gtk","unix",
229 "ac","mpw","osx",)) {
e35fb54b 230 return 1;
231 }
232 warn "$.:unknown makefile type '$type'\n";
233 return 0;
234}
235
7603011f 236# Utility routines while writing out the Makefiles.
237
4877ec8d 238sub def {
239 my ($x) = shift @_;
240 return (defined $x) ? $x : "";
241}
242
cdd310bb 243sub dirpfx {
244 my ($path) = shift @_;
245 my ($sep) = shift @_;
4877ec8d 246 my $ret = "";
247 my $i;
6da41155 248
249 while (($i = index $path, $sep) >= 0 ||
250 ($j = index $path, "/") >= 0) {
251 if ($i >= 0 and ($j < 0 or $i < $j)) {
252 $path = substr $path, ($i + length $sep);
253 } else {
254 $path = substr $path, ($j + 1);
255 }
cdd310bb 256 $ret .= "..$sep";
257 }
258 return $ret;
259}
260
f7f27309 261sub findfile {
262 my ($name) = @_;
4877ec8d 263 my $dir = '';
1ddda1ca 264 my $i;
265 my $outdir = undef;
b6b40d9b 266 unless (defined $findfilecache{$name}) {
267 $i = 0;
cdd310bb 268 foreach $dir (@srcdirs) {
4877ec8d 269 if (-f "$dir$name") {
270 $outdir = $dir;
271 $i++;
272 $outdir =~ s/^\.\///;
273 }
b6b40d9b 274 }
275 die "multiple instances of source file $name\n" if $i > 1;
1ddda1ca 276 $findfilecache{$name} = (defined $outdir ? $outdir . $name : undef);
f7f27309 277 }
b6b40d9b 278 return $findfilecache{$name};
f7f27309 279}
280
7603011f 281sub objects {
f7f27309 282 my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
7603011f 283 my @ret;
284 my ($i, $x, $y);
4877ec8d 285 ($otmpl, $rtmpl, $ltmpl) = map { defined $_ ? $_ : "" } ($otmpl, $rtmpl, $ltmpl);
7603011f 286 @ret = ();
287 foreach $i (@{$programs{$prog}}) {
f7f27309 288 $x = "";
c88dc003 289 if ($i =~ /^(.*)\.(res|rsrc)/) {
7603011f 290 $y = $1;
291 ($x = $rtmpl) =~ s/X/$y/;
7603011f 292 } elsif ($i =~ /^(.*)\.lib/) {
293 $y = $1;
294 ($x = $ltmpl) =~ s/X/$y/;
1ddda1ca 295 } elsif ($i !~ /\./) {
7603011f 296 ($x = $otmpl) =~ s/X/$i/;
7603011f 297 }
f7f27309 298 push @ret, $x if $x ne "";
7603011f 299 }
300 return join " ", @ret;
3d541627 301}
302
1ddda1ca 303sub special {
304 my ($prog, $suffix) = @_;
305 my @ret;
306 my ($i, $x, $y);
4877ec8d 307 ($otmpl, $rtmpl, $ltmpl) = map { defined $_ ? $_ : "" } ($otmpl, $rtmpl, $ltmpl);
1ddda1ca 308 @ret = ();
309 foreach $i (@{$programs{$prog}}) {
310 if (substr($i, (length $i) - (length $suffix)) eq $suffix) {
311 push @ret, $i;
312 }
313 }
314 return (scalar @ret) ? (join " ", @ret) : undef;
315}
316
7603011f 317sub splitline {
a86a2725 318 my ($line, $width, $splitchar) = @_;
4877ec8d 319 my $result = "";
320 my $len;
7603011f 321 $len = (defined $width ? $width : 76);
a86a2725 322 $splitchar = (defined $splitchar ? $splitchar : '\\');
7603011f 323 while (length $line > $len) {
324 $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
b76d219a 325 $result .= $1;
326 $result .= " ${splitchar}\n\t\t" if $2 ne '';
7603011f 327 $line = $2;
328 $len = 60;
329 }
330 return $result . $line;
331}
332
333sub deps {
6da41155 334 my ($otmpl, $rtmpl, $prefix, $dirsep, $mftyp, $depchar, $splitchar) = @_;
7603011f 335 my ($i, $x, $y);
4877ec8d 336 my @deps;
337 my @ret;
a86a2725 338 @ret = ();
339 $depchar ||= ':';
7603011f 340 foreach $i (sort keys %depends) {
6da41155 341 next if $specialobj{$mftyp}->{$i};
c88dc003 342 if ($i =~ /^(.*)\.(res|rsrc)/) {
f7f27309 343 next if !defined $rtmpl;
7603011f 344 $y = $1;
345 ($x = $rtmpl) =~ s/X/$y/;
346 } else {
347 ($x = $otmpl) =~ s/X/$i/;
348 }
f7f27309 349 @deps = @{$depends{$i}};
350 @deps = map {
351 $_ = &findfile($_);
352 s/\//$dirsep/g;
353 $_ = $prefix . $_;
354 } @deps;
976374cd 355 push @ret, {obj => $x, obj_orig => $i, deps => [@deps]};
7603011f 356 }
a86a2725 357 return @ret;
3d541627 358}
359
f7f27309 360sub prognames {
361 my ($types) = @_;
c282cde3 362 my ($n, $prog, $type);
363 my @ret;
364 @ret = ();
365 foreach $n (@prognames) {
366 ($prog, $type) = split ",", $n;
1ddda1ca 367 push @ret, $n if index(":$types:", ":$type:") >= 0;
c282cde3 368 }
369 return @ret;
370}
371
372sub progrealnames {
373 my ($types) = @_;
374 my ($n, $prog, $type);
f7f27309 375 my @ret;
376 @ret = ();
377 foreach $n (@prognames) {
c282cde3 378 ($prog, $type) = split ",", $n;
1ddda1ca 379 push @ret, $prog if index(":$types:", ":$type:") >= 0;
f7f27309 380 }
381 return @ret;
382}
383
c76d309d 384sub manpages {
385 my ($types,$suffix) = @_;
386
387 # assume that all UNIX programs have a man page
1ddda1ca 388 if($suffix eq "1" && $types =~ /:X:/) {
c76d309d 389 return map("$_.1", &progrealnames($types));
390 }
391 return ();
392}
393
7603011f 394# Now we're ready to output the actual Makefiles.
395
e35fb54b 396if (defined $makefiles{'cygwin'}) {
cdd310bb 397 $dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
3d541627 398
e35fb54b 399 ##-- CygWin makefile
400 open OUT, ">$makefiles{'cygwin'}"; select OUT;
401 print
402 "# Makefile for $project_name under cygwin.\n".
403 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
404 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
405 # gcc command line option is -D not /D
4877ec8d 406 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
e35fb54b 407 print $_;
408 print
409 "\n".
410 "# You can define this path to point at your tools if you need to\n".
411 "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
412 "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
413 "CC = \$(TOOLPATH)gcc\n".
414 "RC = \$(TOOLPATH)windres\n".
415 "# Uncomment the following two lines to compile under Winelib\n".
416 "# CC = winegcc\n".
417 "# RC = wrc\n".
418 "# You may also need to tell windres where to find include files:\n".
419 "# RCINC = --include-dir c:\\cygwin\\include\\\n".
420 "\n".
421 &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
db6452be 422 " -D_NO_OLDNAMES -DNO_MULTIMON -DNO_HTMLHELP " .
cdd310bb 423 (join " ", map {"-I$dirpfx$_"} @srcdirs)) .
424 "\n".
e35fb54b 425 "LDFLAGS = -mno-cygwin -s\n".
426 &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1".
33205978 427 " --define WINVER=0x0400")."\n".
e35fb54b 428 "\n".
77603464 429 $makefile_extra{'cygwin'}->{'vars'} .
430 "\n".
e35fb54b 431 ".SUFFIXES:\n".
e35fb54b 432 "\n";
1ddda1ca 433 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
e35fb54b 434 print "\n\n";
1ddda1ca 435 foreach $p (&prognames("G:C")) {
e35fb54b 436 ($prog, $type) = split ",", $p;
437 $objstr = &objects($p, "X.o", "X.res.o", undef);
438 print &splitline($prog . ".exe: " . $objstr), "\n";
439 my $mw = $type eq "G" ? " -mwindows" : "";
440 $libstr = &objects($p, undef, undef, "-lX");
441 print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
442 "-Wl,-Map,$prog.map " .
443 $objstr . " $libstr", 69), "\n\n";
7603011f 444 }
6da41155 445 foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/", "cygwin")) {
976374cd 446 if ($forceobj{$d->{obj_orig}}) {
447 printf ("%s: FORCE\n", $d->{obj});
448 } else {
449 print &splitline(sprintf("%s: %s", $d->{obj},
450 join " ", @{$d->{deps}})), "\n";
451 }
6da41155 452 if ($d->{obj} =~ /\.res\.o$/) {
d8284c29 453 print "\t\$(RC) \$(RCFL) \$(RCFLAGS) ".$d->{deps}->[0]." ".$d->{obj}."\n\n";
6da41155 454 } else {
a77c6ed3 455 print "\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c ".$d->{deps}->[0]."\n\n";
6da41155 456 }
e35fb54b 457 }
458 print "\n";
77603464 459 print $makefile_extra{'cygwin'}->{'end'};
e35fb54b 460 print "\nclean:\n".
461 "\trm -f *.o *.exe *.res.o *.map\n".
976374cd 462 "\n".
463 "FORCE:\n";
e35fb54b 464 select STDOUT; close OUT;
7603011f 465
7603011f 466}
e35fb54b 467
468##-- Borland makefile
469if (defined $makefiles{'borland'}) {
cdd310bb 470 $dirpfx = &dirpfx($makefiles{'borland'}, "\\");
471
e35fb54b 472 %stdlibs = ( # Borland provides many Win32 API libraries intrinsically
473 "advapi32" => 1,
474 "comctl32" => 1,
475 "comdlg32" => 1,
476 "gdi32" => 1,
477 "imm32" => 1,
478 "shell32" => 1,
479 "user32" => 1,
480 "winmm" => 1,
481 "winspool" => 1,
482 "wsock32" => 1,
483 );
484 open OUT, ">$makefiles{'borland'}"; select OUT;
485 print
486 "# Makefile for $project_name under Borland C.\n".
487 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
488 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
489 # bcc32 command line option is -D not /D
4877ec8d 490 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
e35fb54b 491 print $_;
492 print
493 "\n".
494 "# If you rename this file to `Makefile', you should change this line,\n".
495 "# so that the .rsp files still depend on the correct makefile.\n".
496 "MAKEFILE = Makefile.bor\n".
497 "\n".
498 "# C compilation flags\n".
06c3eadd 499 "CFLAGS = -D_WINDOWS -DWINVER=0x0500\n".
976374cd 500 "# Resource compilation flags\n".
501 "RCFLAGS = -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401\n".
e35fb54b 502 "\n".
503 "# Get include directory for resource compiler\n".
504 "!if !\$d(BCB)\n".
505 "BCB = \$(MAKEDIR)\\..\n".
506 "!endif\n".
507 "\n".
77603464 508 $makefile_extra{'borland'}->{'vars'} .
509 "\n".
e35fb54b 510 ".c.obj:\n".
d8284c29 511 &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT)".
a77c6ed3 512 " \$(CFLAGS) \$(XFLAGS) ".
cdd310bb 513 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
ba58fbaa 514 " /c \$*.c",69)."\n".
e35fb54b 515 ".rc.res:\n".
d8284c29 516 &splitline("\tbrcc32 \$(RCFL) -i \$(BCB)\\include -r".
976374cd 517 " \$(RCFLAGS) \$*.rc",69)."\n".
e35fb54b 518 "\n";
1ddda1ca 519 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
e35fb54b 520 print "\n\n";
1ddda1ca 521 foreach $p (&prognames("G:C")) {
e35fb54b 522 ($prog, $type) = split ",", $p;
4877ec8d 523 $objstr = &objects($p, "X.obj", "X.res", undef);
e35fb54b 524 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
525 my $ap = ($type eq "G") ? "-aa" : "-ap";
526 print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n";
7603011f 527 }
1ddda1ca 528 foreach $p (&prognames("G:C")) {
e35fb54b 529 ($prog, $type) = split ",", $p;
530 print $prog, ".rsp: \$(MAKEFILE)\n";
531 $objstr = &objects($p, "X.obj", undef, undef);
532 @objlist = split " ", $objstr;
533 @objlines = ("");
534 foreach $i (@objlist) {
535 if (length($objlines[$#objlines] . " $i") > 50) {
536 push @objlines, "";
537 }
538 $objlines[$#objlines] .= " $i";
539 }
540 $c0w = ($type eq "G") ? "c0w32" : "c0x32";
541 print "\techo $c0w + > $prog.rsp\n";
542 for ($i=0; $i<=$#objlines; $i++) {
543 $plus = ($i < $#objlines ? " +" : "");
544 print "\techo$objlines[$i]$plus >> $prog.rsp\n";
545 }
546 print "\techo $prog.exe >> $prog.rsp\n";
547 $objstr = &objects($p, "X.obj", "X.res", undef);
548 @libs = split " ", &objects($p, undef, undef, "X");
549 @libs = grep { !$stdlibs{$_} } @libs;
550 unshift @libs, "cw32", "import32";
551 $libstr = join ' ', @libs;
552 print "\techo nul,$libstr, >> $prog.rsp\n";
553 print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n";
554 print "\n";
555 }
6da41155 556 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "borland")) {
976374cd 557 if ($forceobj{$d->{obj_orig}}) {
558 printf("%s: FORCE\n", $d->{obj});
559 } else {
560 print &splitline(sprintf("%s: %s", $d->{obj},
561 join " ", @{$d->{deps}})), "\n";
562 }
e35fb54b 563 }
564 print "\n";
77603464 565 print $makefile_extra{'borland'}->{'end'};
e35fb54b 566 print "\nclean:\n".
567 "\t-del *.obj\n".
568 "\t-del *.exe\n".
569 "\t-del *.res\n".
570 "\t-del *.pch\n".
571 "\t-del *.aps\n".
572 "\t-del *.il*\n".
573 "\t-del *.pdb\n".
574 "\t-del *.rsp\n".
575 "\t-del *.tds\n".
976374cd 576 "\t-del *.\$\$\$\$\$\$\n".
577 "\n".
578 "FORCE:\n".
579 "\t-rem dummy command\n";
e35fb54b 580 select STDOUT; close OUT;
7603011f 581}
e35fb54b 582
583if (defined $makefiles{'vc'}) {
cdd310bb 584 $dirpfx = &dirpfx($makefiles{'vc'}, "\\");
585
e35fb54b 586 ##-- Visual C++ makefile
587 open OUT, ">$makefiles{'vc'}"; select OUT;
588 print
589 "# Makefile for $project_name under Visual C.\n".
590 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
591 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
592 print $help;
593 print
594 "\n".
595 "# If you rename this file to `Makefile', you should change this line,\n".
596 "# so that the .rsp files still depend on the correct makefile.\n".
597 "MAKEFILE = Makefile.vc\n".
598 "\n".
599 "# C compilation flags\n".
6da41155 600 "CFLAGS = /nologo /W3 /O1 " .
601 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
06c3eadd 602 " /D_WINDOWS /D_WIN32_WINDOWS=0x500 /DWINVER=0x500\n".
e35fb54b 603 "LFLAGS = /incremental:no /fixed\n".
976374cd 604 "RCFLAGS = -DWIN32 -D_WIN32 -DWINVER=0x0400\n".
e35fb54b 605 "\n".
77603464 606 $makefile_extra{'vc'}->{'vars'} .
607 "\n".
a86a2725 608 "\n";
1ddda1ca 609 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
e35fb54b 610 print "\n\n";
1ddda1ca 611 foreach $p (&prognames("G:C")) {
e35fb54b 612 ($prog, $type) = split ",", $p;
613 $objstr = &objects($p, "X.obj", "X.res", undef);
614 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
615 print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
616 }
1ddda1ca 617 foreach $p (&prognames("G:C")) {
e35fb54b 618 ($prog, $type) = split ",", $p;
619 print $prog, ".rsp: \$(MAKEFILE)\n";
620 $objstr = &objects($p, "X.obj", "X.res", "X.lib");
621 @objlist = split " ", $objstr;
622 @objlines = ("");
623 foreach $i (@objlist) {
624 if (length($objlines[$#objlines] . " $i") > 50) {
625 push @objlines, "";
626 }
627 $objlines[$#objlines] .= " $i";
628 }
629 $subsys = ($type eq "G") ? "windows" : "console";
630 print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
631 for ($i=0; $i<=$#objlines; $i++) {
632 print "\techo$objlines[$i] >> $prog.rsp\n";
633 }
634 print "\n";
635 }
6da41155 636 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "vc")) {
976374cd 637 $extradeps = $forceobj{$d->{obj_orig}} ? ["*.c","*.h","*.rc"] : [];
638 print &splitline(sprintf("%s: %s", $d->{obj},
639 join " ", @$extradeps, @{$d->{deps}})), "\n";
6da41155 640 if ($d->{obj} =~ /.obj$/) {
a77c6ed3 641 print "\tcl \$(COMPAT) \$(CFLAGS) \$(XFLAGS) /c ".$d->{deps}->[0],"\n\n";
6da41155 642 } else {
976374cd 643 print "\trc \$(RCFL) -r \$(RCFLAGS) ".$d->{deps}->[0],"\n\n";
6da41155 644 }
e35fb54b 645 }
646 print "\n";
77603464 647 print $makefile_extra{'vc'}->{'end'};
e35fb54b 648 print "\nclean: tidy\n".
649 "\t-del *.exe\n\n".
650 "tidy:\n".
651 "\t-del *.obj\n".
652 "\t-del *.res\n".
653 "\t-del *.pch\n".
654 "\t-del *.aps\n".
655 "\t-del *.ilk\n".
656 "\t-del *.pdb\n".
657 "\t-del *.rsp\n".
658 "\t-del *.dsp\n".
659 "\t-del *.dsw\n".
660 "\t-del *.ncb\n".
661 "\t-del *.opt\n".
662 "\t-del *.plg\n".
663 "\t-del *.map\n".
664 "\t-del *.idb\n".
665 "\t-del debug.log\n";
666 select STDOUT; close OUT;
a86a2725 667}
f7f27309 668
e35fb54b 669if (defined $makefiles{'vcproj'}) {
6da41155 670 $dirpfx = &dirpfx($makefiles{'vcproj'}, "\\");
58de2f3c 671
e35fb54b 672 $orig_dir = cwd;
673
674 ##-- MSVC 6 Workspace and projects
675 #
676 # Note: All files created in this section are written in binary
677 # mode, because although MSVC's command-line make can deal with
678 # LF-only line endings, MSVC project files really _need_ to be
679 # CRLF. Hence, in order for mkfiles.pl to generate usable project
680 # files even when run from Unix, I make sure all files are binary
681 # and explicitly write the CRLFs.
682 #
683 # Create directories if necessary
684 mkdir $makefiles{'vcproj'}
685 if(! -d $makefiles{'vcproj'});
686 chdir $makefiles{'vcproj'};
6da41155 687 @deps = &deps("X.obj", "X.res", $dirpfx, "\\", "vcproj");
e35fb54b 688 %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
689 # Create the project files
690 # Get names of all Windows projects (GUI and console)
1ddda1ca 691 my @prognames = &prognames("G:C");
e35fb54b 692 foreach $progname (@prognames) {
985b6440 693 create_vc_project(\%all_object_deps, $progname);
e35fb54b 694 }
695 # Create the workspace file
696 open OUT, ">$project_name.dsw"; binmode OUT; select OUT;
697 print
698 "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
699 "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
700 "\r\n".
701 "###############################################################################\r\n".
702 "\r\n";
703 # List projects
704 foreach $progname (@prognames) {
705 ($windows_project, $type) = split ",", $progname;
706 print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n";
707 }
708 print
709 "\r\n".
710 "Package=<5>\r\n".
711 "{{{\r\n".
712 "}}}\r\n".
713 "\r\n".
714 "Package=<4>\r\n".
715 "{{{\r\n".
716 "}}}\r\n".
717 "\r\n".
718 "###############################################################################\r\n".
719 "\r\n".
720 "Global:\r\n".
721 "\r\n".
722 "Package=<5>\r\n".
723 "{{{\r\n".
724 "}}}\r\n".
725 "\r\n".
726 "Package=<3>\r\n".
727 "{{{\r\n".
728 "}}}\r\n".
729 "\r\n".
730 "###############################################################################\r\n".
731 "\r\n";
732 select STDOUT; close OUT;
733 chdir $orig_dir;
734
985b6440 735 sub create_vc_project {
e35fb54b 736 my ($all_object_deps, $progname) = @_;
737 # Construct program's dependency info
738 %seen_objects = ();
739 %lib_files = ();
740 %source_files = ();
741 %header_files = ();
742 %resource_files = ();
743 @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
744 foreach $object_file (@object_files) {
745 next if defined $seen_objects{$object_file};
746 $seen_objects{$object_file} = 1;
747 if($object_file =~ /\.lib$/io) {
748 $lib_files{$object_file} = 1;
749 next;
750 }
751 $object_deps = $all_object_deps{$object_file};
752 foreach $object_dep (@$object_deps) {
753 if($object_dep =~ /\.c$/io) {
754 $source_files{$object_dep} = 1;
755 next;
58de2f3c 756 }
e35fb54b 757 if($object_dep =~ /\.h$/io) {
758 $header_files{$object_dep} = 1;
759 next;
58de2f3c 760 }
e35fb54b 761 if($object_dep =~ /\.(rc|ico)$/io) {
762 $resource_files{$object_dep} = 1;
763 next;
58de2f3c 764 }
e35fb54b 765 }
766 }
767 $libs = join " ", sort keys %lib_files;
768 @source_files = sort keys %source_files;
769 @header_files = sort keys %header_files;
770 @resources = sort keys %resource_files;
771 ($windows_project, $type) = split ",", $progname;
772 mkdir $windows_project
773 if(! -d $windows_project);
774 chdir $windows_project;
775 $subsys = ($type eq "G") ? "windows" : "console";
776 open OUT, ">$windows_project.dsp"; binmode OUT; select OUT;
777 print
778 "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n".
779 "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n".
780 "# ** DO NOT EDIT **\r\n".
781 "\r\n".
782 "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n".
783 "\r\n".
784 "CFG=$windows_project - Win32 Debug\r\n".
785 "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n".
786 "!MESSAGE use the Export Makefile command and run\r\n".
787 "!MESSAGE \r\n".
788 "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n".
789 "!MESSAGE \r\n".
790 "!MESSAGE You can specify a configuration when running NMAKE\r\n".
791 "!MESSAGE by defining the macro CFG on the command line. For example:\r\n".
792 "!MESSAGE \r\n".
793 "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
794 "!MESSAGE \r\n".
795 "!MESSAGE Possible choices for configuration are:\r\n".
796 "!MESSAGE \r\n".
797 "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n".
798 "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n".
799 "!MESSAGE \r\n".
800 "\r\n".
801 "# Begin Project\r\n".
802 "# PROP AllowPerConfigDependencies 0\r\n".
803 "# PROP Scc_ProjName \"\"\r\n".
804 "# PROP Scc_LocalPath \"\"\r\n".
805 "CPP=cl.exe\r\n".
806 "MTL=midl.exe\r\n".
807 "RSC=rc.exe\r\n".
808 "\r\n".
809 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
810 "\r\n".
811 "# PROP BASE Use_MFC 0\r\n".
812 "# PROP BASE Use_Debug_Libraries 0\r\n".
813 "# PROP BASE Output_Dir \"Release\"\r\n".
814 "# PROP BASE Intermediate_Dir \"Release\"\r\n".
815 "# PROP BASE Target_Dir \"\"\r\n".
816 "# PROP Use_MFC 0\r\n".
817 "# PROP Use_Debug_Libraries 0\r\n".
818 "# PROP Output_Dir \"Release\"\r\n".
819 "# PROP Intermediate_Dir \"Release\"\r\n".
820 "# PROP Ignore_Export_Lib 0\r\n".
821 "# PROP Target_Dir \"\"\r\n".
6da41155 822 "# ADD BASE CPP /nologo /W3 /GX /O2 ".
823 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
824 " /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
825 "# ADD CPP /nologo /W3 /GX /O2 ".
826 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
827 " /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
e35fb54b 828 "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
829 "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
830 "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n".
831 "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n".
832 "BSC32=bscmake.exe\r\n".
833 "# ADD BASE BSC32 /nologo\r\n".
834 "# ADD BSC32 /nologo\r\n".
835 "LINK32=link.exe\r\n".
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".
837 "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n".
838 "# SUBTRACT LINK32 /pdb:none\r\n".
839 "\r\n".
840 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
841 "\r\n".
842 "# PROP BASE Use_MFC 0\r\n".
843 "# PROP BASE Use_Debug_Libraries 1\r\n".
844 "# PROP BASE Output_Dir \"Debug\"\r\n".
845 "# PROP BASE Intermediate_Dir \"Debug\"\r\n".
846 "# PROP BASE Target_Dir \"\"\r\n".
847 "# PROP Use_MFC 0\r\n".
848 "# PROP Use_Debug_Libraries 1\r\n".
849 "# PROP Output_Dir \"Debug\"\r\n".
850 "# PROP Intermediate_Dir \"Debug\"\r\n".
851 "# PROP Ignore_Export_Lib 0\r\n".
852 "# PROP Target_Dir \"\"\r\n".
6da41155 853 "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od ".
854 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
855 " /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
856 "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od ".
857 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
858 " /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
e35fb54b 859 "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
860 "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
861 "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n".
862 "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n".
863 "BSC32=bscmake.exe\r\n".
864 "# ADD BASE BSC32 /nologo\r\n".
865 "# ADD BSC32 /nologo\r\n".
866 "LINK32=link.exe\r\n".
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".
868 "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
869 "# SUBTRACT LINK32 /pdb:none\r\n".
870 "\r\n".
871 "!ENDIF \r\n".
872 "\r\n".
873 "# Begin Target\r\n".
874 "\r\n".
875 "# Name \"$windows_project - Win32 Release\"\r\n".
876 "# Name \"$windows_project - Win32 Debug\"\r\n".
877 "# Begin Group \"Source Files\"\r\n".
878 "\r\n".
879 "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
880 foreach $source_file (@source_files) {
881 print
882 "# Begin Source File\r\n".
883 "\r\n".
884 "SOURCE=..\\..\\$source_file\r\n";
885 if($source_file =~ /ssh\.c/io) {
886 # Disable 'Edit and continue' as Visual Studio can't handle the macros
58de2f3c 887 print
e35fb54b 888 "\r\n".
889 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
890 "\r\n".
891 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
892 "\r\n".
893 "# ADD CPP /Zi\r\n".
894 "\r\n".
895 "!ENDIF \r\n".
896 "\r\n";
897 }
898 print "# End Source File\r\n";
899 }
900 print
901 "# End Group\r\n".
902 "# Begin Group \"Header Files\"\r\n".
903 "\r\n".
904 "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
905 foreach $header_file (@header_files) {
906 print
907 "# Begin Source File\r\n".
908 "\r\n".
909 "SOURCE=..\\..\\$header_file\r\n".
910 "# End Source File\r\n";
58de2f3c 911 }
e35fb54b 912 print
913 "# End Group\r\n".
914 "# Begin Group \"Resource Files\"\r\n".
915 "\r\n".
916 "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
917 foreach $resource_file (@resources) {
918 print
919 "# Begin Source File\r\n".
920 "\r\n".
921 "SOURCE=..\\..\\$resource_file\r\n".
922 "# End Source File\r\n";
923 }
924 print
925 "# End Group\r\n".
926 "# End Target\r\n".
927 "# End Project\r\n";
928 select STDOUT; close OUT;
929 chdir "..";
930 }
a86a2725 931}
a86a2725 932
e35fb54b 933if (defined $makefiles{'gtk'}) {
cdd310bb 934 $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
d37a507a 935
e35fb54b 936 ##-- X/GTK/Unix makefile
937 open OUT, ">$makefiles{'gtk'}"; select OUT;
938 print
939 "# Makefile for $project_name under X/GTK and Unix.\n".
940 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
941 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
942 # gcc command line option is -D not /D
4877ec8d 943 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
e35fb54b 944 print $_;
945 print
946 "\n".
947 "# You can define this path to point at your tools if you need to\n".
948 "# TOOLPATH = /opt/gcc/bin\n".
949 "CC = \$(TOOLPATH)cc\n".
42af6a67 950 "# If necessary set the path to krb5-config here\n".
951 "KRB5CONFIG=krb5-config\n".
f160b7b8 952 "# You can manually set this to `gtk-config' or `pkg-config gtk+-1.2'\n".
953 "# (depending on what works on your system) if you want to enforce\n".
c349ffb1 954 "# building with GTK 1.2, or you can set it to `pkg-config gtk+-2.0 x11'\n".
f160b7b8 955 "# if you want to enforce 2.0. The default is to try 2.0 and fall back\n".
956 "# to 1.2 if it isn't found.\n".
c349ffb1 957 "GTK_CONFIG = sh -c 'pkg-config gtk+-2.0 x11 \$\$0 2>/dev/null || gtk-config \$\$0'\n".
e35fb54b 958 "\n".
3290cec9 959 "-include Makefile.local\n".
960 "\n".
9ac18d71 961 "unexport CFLAGS # work around a weird issue with krb5-config\n".
962 "\n".
cdd310bb 963 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
964 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
c407e146 965 " \$(shell \$(GTK_CONFIG) --cflags)").
0ac1920c 966 " -D _FILE_OFFSET_BITS=64\n".
c407e146 967 "XLDFLAGS = \$(LDFLAGS) \$(shell \$(GTK_CONFIG) --libs)\n".
0dbe2956 968 "ULDFLAGS = \$(LDFLAGS)\n".
42af6a67 969 "ifeq (,\$(findstring NO_GSSAPI,\$(COMPAT)))\n".
b3d375b2 970 "ifeq (,\$(findstring STATIC_GSSAPI,\$(COMPAT)))\n".
971 "XLDFLAGS+= -ldl\n".
972 "ULDFLAGS+= -ldl\n".
973 "else\n".
974 "CFLAGS+= -DNO_LIBDL \$(shell \$(KRB5CONFIG) --cflags gssapi)\n".
c407e146 975 "XLDFLAGS+= \$(shell \$(KRB5CONFIG) --libs gssapi)\n".
b3d375b2 976 "ULDFLAGS+= \$(shell \$(KRB5CONFIG) --libs gssapi)\n".
977 "endif\n".
666b0d2a 978 "endif\n".
979 "INSTALL=install\n".
980 "INSTALL_PROGRAM=\$(INSTALL)\n".
981 "INSTALL_DATA=\$(INSTALL)\n".
982 "prefix=/usr/local\n".
983 "exec_prefix=\$(prefix)\n".
984 "bindir=\$(exec_prefix)/bin\n".
985 "mandir=\$(prefix)/man\n".
986 "man1dir=\$(mandir)/man1\n".
e35fb54b 987 "\n".
4877ec8d 988 &def($makefile_extra{'gtk'}->{'vars'}) .
77603464 989 "\n".
e35fb54b 990 ".SUFFIXES:\n".
991 "\n".
e35fb54b 992 "\n";
1ddda1ca 993 print &splitline("all:" . join "", map { " $_" } &progrealnames("X:U"));
e35fb54b 994 print "\n\n";
1ddda1ca 995 foreach $p (&prognames("X:U")) {
e35fb54b 996 ($prog, $type) = split ",", $p;
997 $objstr = &objects($p, "X.o", undef, undef);
998 print &splitline($prog . ": " . $objstr), "\n";
999 $libstr = &objects($p, undef, undef, "-lX");
4877ec8d 1000 print &splitline("\t\$(CC) -o \$@ " .
0dbe2956 1001 $objstr . " \$(${type}LDFLAGS) $libstr", 69), "\n\n";
e35fb54b 1002 }
6da41155 1003 foreach $d (&deps("X.o", undef, $dirpfx, "/", "gtk")) {
976374cd 1004 if ($forceobj{$d->{obj_orig}}) {
1005 printf("%s: FORCE\n", $d->{obj});
1006 } else {
1007 print &splitline(sprintf("%s: %s", $d->{obj},
1008 join " ", @{$d->{deps}})), "\n";
1009 }
a77c6ed3 1010 print &splitline("\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c $d->{deps}->[0]\n");
76d3a838 1011 }
1012 print "\n";
1013 print $makefile_extra{'gtk'}->{'end'};
1014 print "\nclean:\n".
1015 "\trm -f *.o". (join "", map { " $_" } &progrealnames("X:U")) . "\n";
976374cd 1016 print "\nFORCE:\n";
76d3a838 1017 select STDOUT; close OUT;
1018}
1019
b89e7e07 1020if (defined $makefiles{'unix'}) {
1021 $dirpfx = &dirpfx($makefiles{'unix'}, "/");
1022
1023 ##-- GTK-free pure-Unix makefile for non-GUI apps only
1024 open OUT, ">$makefiles{'unix'}"; select OUT;
1025 print
1026 "# Makefile for $project_name under Unix.\n".
1027 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1028 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1029 # gcc command line option is -D not /D
4877ec8d 1030 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
b89e7e07 1031 print $_;
1032 print
1033 "\n".
1034 "# You can define this path to point at your tools if you need to\n".
1035 "# TOOLPATH = /opt/gcc/bin\n".
1036 "CC = \$(TOOLPATH)cc\n".
b89e7e07 1037 "\n".
1038 "-include Makefile.local\n".
1039 "\n".
1040 "unexport CFLAGS # work around a weird issue with krb5-config\n".
1041 "\n".
1042 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1043 (join " ", map {"-I$dirpfx$_"} @srcdirs)).
1044 " -D _FILE_OFFSET_BITS=64\n".
1045 "ULDFLAGS = \$(LDFLAGS)\n".
b89e7e07 1046 "INSTALL=install\n".
1047 "INSTALL_PROGRAM=\$(INSTALL)\n".
1048 "INSTALL_DATA=\$(INSTALL)\n".
1049 "prefix=/usr/local\n".
1050 "exec_prefix=\$(prefix)\n".
1051 "bindir=\$(exec_prefix)/bin\n".
1052 "mandir=\$(prefix)/man\n".
1053 "man1dir=\$(mandir)/man1\n".
1054 "\n".
4877ec8d 1055 &def($makefile_extra{'unix'}->{'vars'}) .
b89e7e07 1056 "\n".
1057 ".SUFFIXES:\n".
1058 "\n".
1059 "\n";
1060 print &splitline("all:" . join "", map { " $_" } &progrealnames("U"));
1061 print "\n\n";
1062 foreach $p (&prognames("U")) {
1063 ($prog, $type) = split ",", $p;
1064 $objstr = &objects($p, "X.o", undef, undef);
1065 print &splitline($prog . ": " . $objstr), "\n";
1066 $libstr = &objects($p, undef, undef, "-lX");
4877ec8d 1067 print &splitline("\t\$(CC) -o \$@ " .
b89e7e07 1068 $objstr . " \$(${type}LDFLAGS) $libstr", 69), "\n\n";
1069 }
1070 foreach $d (&deps("X.o", undef, $dirpfx, "/", "unix")) {
1071 if ($forceobj{$d->{obj_orig}}) {
1072 printf("%s: FORCE\n", $d->{obj});
1073 } else {
1074 print &splitline(sprintf("%s: %s", $d->{obj},
1075 join " ", @{$d->{deps}})), "\n";
1076 }
1077 print &splitline("\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c $d->{deps}->[0]\n");
1078 }
1079 print "\n";
4877ec8d 1080 print &def($makefile_extra{'unix'}->{'end'});
b89e7e07 1081 print "\nclean:\n".
1082 "\trm -f *.o". (join "", map { " $_" } &progrealnames("U")) . "\n";
1083 print "\nFORCE:\n";
1084 select STDOUT; close OUT;
1085}
1086
76d3a838 1087if (defined $makefiles{'ac'}) {
1088 $dirpfx = &dirpfx($makefiles{'ac'}, "/");
1089
1090 ##-- Unix/autoconf makefile
1091 open OUT, ">$makefiles{'ac'}"; select OUT;
1092 print
1093 "# Makefile.in for $project_name under Unix with Autoconf.\n".
1094 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1095 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1096 # gcc command line option is -D not /D
4877ec8d 1097 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
76d3a838 1098 print $_;
1099 print
1100 "\n".
1101 "CC = \@CC\@\n".
1102 "\n".
16707d1c 1103 &splitline("CFLAGS = \@CFLAGS\@ \@PUTTYCFLAGS\@ \@CPPFLAGS\@ " .
1104 "\@DEFS\@ \@GTK_CFLAGS\@ " .
76d3a838 1105 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1106 "XLDFLAGS = \@LDFLAGS\@ \@LIBS\@ \@GTK_LIBS\@\n".
1107 "ULDFLAGS = \@LDFLAGS\@ \@LIBS\@\n".
666b0d2a 1108 "INSTALL=\@INSTALL\@\n".
1109 "INSTALL_PROGRAM=\$(INSTALL)\n".
1110 "INSTALL_DATA=\$(INSTALL)\n".
1111 "prefix=\@prefix\@\n".
1112 "exec_prefix=\@exec_prefix\@\n".
1113 "bindir=\@bindir\@\n".
403941c0 1114 "datarootdir=\@datarootdir\@\n".
666b0d2a 1115 "mandir=\@mandir\@\n".
1116 "man1dir=\$(mandir)/man1\n".
76d3a838 1117 "\n".
4877ec8d 1118 &def($makefile_extra{'gtk'}->{'vars'}) .
76d3a838 1119 "\n".
1120 ".SUFFIXES:\n".
1121 "\n".
1122 "\n".
1123 "all: \@all_targets\@\n".
1124 &splitline("all-cli:" . join "", map { " $_" } &progrealnames("U"))."\n".
1125 &splitline("all-gtk:" . join "", map { " $_" } &progrealnames("X"))."\n";
1126 print "\n";
1127 foreach $p (&prognames("X:U")) {
1128 ($prog, $type) = split ",", $p;
1129 $objstr = &objects($p, "X.o", undef, undef);
1130 print &splitline($prog . ": " . $objstr), "\n";
1131 $libstr = &objects($p, undef, undef, "-lX");
4877ec8d 1132 print &splitline("\t\$(CC) -o \$@ " .
0dbe2956 1133 $objstr . " \$(${type}LDFLAGS) $libstr", 69), "\n\n";
76d3a838 1134 }
1135 foreach $d (&deps("X.o", undef, $dirpfx, "/", "gtk")) {
976374cd 1136 if ($forceobj{$d->{obj_orig}}) {
1137 printf("%s: FORCE\n", $d->{obj});
1138 } else {
1139 print &splitline(sprintf("%s: %s", $d->{obj},
1140 join " ", @{$d->{deps}})), "\n";
1141 }
a77c6ed3 1142 print &splitline("\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c $d->{deps}->[0]\n");
e35fb54b 1143 }
1144 print "\n";
77603464 1145 print $makefile_extra{'gtk'}->{'end'};
e35fb54b 1146 print "\nclean:\n".
1ddda1ca 1147 "\trm -f *.o". (join "", map { " $_" } &progrealnames("X:U")) . "\n";
64b7adb9 1148 print "\ndistclean: clean\n".
1149 "\t". &splitline("rm -f config.status config.cache config.log ".
1150 "configure.lineno config.status.lineno Makefile") . "\n";
976374cd 1151 print "\nFORCE:\n";
e35fb54b 1152 select STDOUT; close OUT;
1153}
f8422c0b 1154
e35fb54b 1155if (defined $makefiles{'mpw'}) {
1156 ##-- MPW Makefile
1157 open OUT, ">$makefiles{'mpw'}"; select OUT;
1158 print
1159 "# Makefile for $project_name under MPW.\n#\n".
1160 "# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1161 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
976374cd 1162 # MPW command line option is -d not /D (FIXME further massaging?)
4877ec8d 1163 ($_ = $help) =~ s/([=" ])\/D/$1-d /gs;
e35fb54b 1164 print $_;
1165 print "\n\n".
1166 "ROptions = `Echo \"{VER}\" | StreamEdit -e \"1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6\"' \xa81 '\xb6\xb6\xb6\xb6\xb6\"'\"`".
1167 "\n".
1168 "C_68K = {C}\n".
1169 "C_CFM68K = {C}\n".
1170 "C_PPC = {PPCC}\n".
1171 "C_Carbon = {PPCC}\n".
1172 "\n".
1173 "# -w 35 disables \"unused parameter\" warnings\n".
1174 "COptions = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6\n".
1175 " -notOnce\n".
1176 "COptions_68K = {COptions} -model far -opt time\n".
1177 "# Enabling \"-opt space\" for CFM-68K gives me undefined references to\n".
1178 "# _\$LDIVT and _\$LMODT.\n".
1179 "COptions_CFM68K = {COptions} -model cfmSeg -opt time\n".
1180 "COptions_PPC = {COptions} -opt size -traceback\n".
1181 "COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON\n".
1182 "\n".
1183 "Link_68K = ILink\n".
1184 "Link_CFM68K = ILink\n".
1185 "Link_PPC = PPCLink\n".
1186 "Link_Carbon = PPCLink\n".
1187 "\n".
1188 "LinkOptions = -c 'pTTY'\n".
1189 "LinkOptions_68K = {LinkOptions} -br 68k -model far -compact\n".
1190 "LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact\n".
1191 "LinkOptions_PPC = {LinkOptions}\n".
1192 "LinkOptions_Carbon = -m __appstart -w {LinkOptions}\n".
1193 "\n".
1194 "Libs_68K = \"{CLibraries}StdCLib.far.o\" \xb6\n".
1195 " \"{Libraries}MacRuntime.o\" \xb6\n".
1196 " \"{Libraries}MathLib.far.o\" \xb6\n".
1197 " \"{Libraries}IntEnv.far.o\" \xb6\n".
1198 " \"{Libraries}Interface.o\" \xb6\n".
1199 " \"{Libraries}Navigation.far.o\" \xb6\n".
1200 " \"{Libraries}OpenTransport.o\" \xb6\n".
1201 " \"{Libraries}OpenTransportApp.o\" \xb6\n".
1202 " \"{Libraries}OpenTptInet.o\" \xb6\n".
1203 " \"{Libraries}UnicodeConverterLib.far.o\"\n".
1204 "\n".
1205 "Libs_CFM = \"{SharedLibraries}InterfaceLib\" \xb6\n".
1206 " \"{SharedLibraries}StdCLib\" \xb6\n".
1207 " \"{SharedLibraries}AppearanceLib\" \xb6\n".
1208 " -weaklib AppearanceLib \xb6\n".
1209 " \"{SharedLibraries}NavigationLib\" \xb6\n".
1210 " -weaklib NavigationLib \xb6\n".
1211 " \"{SharedLibraries}TextCommon\" \xb6\n".
1212 " -weaklib TextCommon \xb6\n".
1213 " \"{SharedLibraries}UnicodeConverter\" \xb6\n".
1214 " -weaklib UnicodeConverter\n".
1215 "\n".
1216 "Libs_CFM68K = {Libs_CFM} \xb6\n".
1217 " \"{CFM68KLibraries}NuMacRuntime.o\"\n".
1218 "\n".
1219 "Libs_PPC = {Libs_CFM} \xb6\n".
1220 " \"{SharedLibraries}ControlsLib\" \xb6\n".
1221 " -weaklib ControlsLib \xb6\n".
1222 " \"{SharedLibraries}WindowsLib\" \xb6\n".
1223 " -weaklib WindowsLib \xb6\n".
1224 " \"{SharedLibraries}OpenTransportLib\" \xb6\n".
1225 " -weaklib OTClientLib \xb6\n".
1226 " -weaklib OTClientUtilLib \xb6\n".
1227 " \"{SharedLibraries}OpenTptInternetLib\" \xb6\n".
1228 " -weaklib OTInetClientLib \xb6\n".
1229 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1230 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1231 " \"{PPCLibraries}CarbonAccessors.o\" \xb6\n".
1232 " \"{PPCLibraries}OpenTransportAppPPC.o\" \xb6\n".
1233 " \"{PPCLibraries}OpenTptInetPPC.o\"\n".
1234 "\n".
1235 "Libs_Carbon = \"{PPCLibraries}CarbonStdCLib.o\" \xb6\n".
1236 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1237 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1238 " \"{SharedLibraries}CarbonLib\" \xb6\n".
1239 " \"{SharedLibraries}StdCLib\"\n".
1240 "\n";
1241 print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6");
1242 print "\n\n";
1243 foreach $p (&prognames("M")) {
1244 ($prog, $type) = split ",", $p;
f8422c0b 1245
e35fb54b 1246 print &splitline("$prog \xc4 $prog.68k $prog.ppc $prog.carbon",
1247 undef, "\xb6"), "\n\n";
c88dc003 1248
e35fb54b 1249 $rsrc = &objects($p, "", "X.rsrc", undef);
b941ca10 1250
e35fb54b 1251 foreach $arch (qw(68K CFM68K PPC Carbon)) {
1252 $objstr = &objects($p, "X.\L$arch\E.o", "", undef);
1253 print &splitline("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6");
1254 print "\n";
1255 print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
1256 print &splitline("\t{Link_$arch} -o {Targ} -fragname $prog " .
1257 "{LinkOptions_$arch} " .
1258 $objstr . " {Libs_$arch}", 69, "\xb6"), "\n";
1259 print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
1260 }
4e95095a 1261
e35fb54b 1262 }
6da41155 1263 foreach $d (&deps("", "X.rsrc", "::", ":", "mpw")) {
e35fb54b 1264 next unless $d->{obj};
1265 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
1266 undef, "\xb6"), "\n";
1267 print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n";
1268 }
1269 foreach $arch (qw(68K CFM68K)) {
6da41155 1270 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":", "mpw")) {
e35fb54b 1271 next unless $d->{obj};
1272 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1273 join " ", @{$d->{deps}}),
1274 undef, "\xb6"), "\n";
1275 print "\t{C_$arch} ", $d->{deps}->[0],
1276 " -o {Targ} {COptions_$arch}\n\n";
1277 }
1278 }
1279 foreach $arch (qw(PPC Carbon)) {
6da41155 1280 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":", "mpw")) {
e35fb54b 1281 next unless $d->{obj};
1282 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1283 join " ", @{$d->{deps}}),
1284 undef, "\xb6"), "\n";
1285 # The odd stuff here seems to stop afpd getting confused.
1286 print "\techo -n > {Targ}\n";
1287 print "\tsetfile -t XCOF {Targ}\n";
1288 print "\t{C_$arch} ", $d->{deps}->[0],
1289 " -o {Targ} {COptions_$arch}\n\n";
1290 }
1291 }
1292 select STDOUT; close OUT;
4e95095a 1293}
1294
e35fb54b 1295if (defined $makefiles{'lcc'}) {
cdd310bb 1296 $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
1297
e35fb54b 1298 ##-- lcc makefile
1299 open OUT, ">$makefiles{'lcc'}"; select OUT;
1300 print
1301 "# Makefile for $project_name under lcc.\n".
1302 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1303 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1304 # lcc command line option is -D not /D
4877ec8d 1305 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
e35fb54b 1306 print $_;
1307 print
1308 "\n".
1309 "# If you rename this file to `Makefile', you should change this line,\n".
1310 "# so that the .rsp files still depend on the correct makefile.\n".
1311 "MAKEFILE = Makefile.lcc\n".
1312 "\n".
1313 "# C compilation flags\n".
cdd310bb 1314 "CFLAGS = -D_WINDOWS " .
1315 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1316 "\n".
976374cd 1317 "# Resource compilation flags\n".
1318 "RCFLAGS = \n".
e35fb54b 1319 "\n".
1320 "# Get include directory for resource compiler\n".
77603464 1321 "\n".
1322 $makefile_extra{'lcc'}->{'vars'} .
4e95095a 1323 "\n";
1ddda1ca 1324 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
e35fb54b 1325 print "\n\n";
1ddda1ca 1326 foreach $p (&prognames("G:C")) {
e35fb54b 1327 ($prog, $type) = split ",", $p;
1328 $objstr = &objects($p, "X.obj", "X.res", undef);
1329 print &splitline("$prog.exe: " . $objstr ), "\n";
4877ec8d 1330 $subsystemtype = '';
e35fb54b 1331 if ($type eq "G") { $subsystemtype = "-subsystem windows"; }
1332 my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1333 print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1334 print "\n\n";
1335 }
4e95095a 1336
6da41155 1337 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "lcc")) {
976374cd 1338 if ($forceobj{$d->{obj_orig}}) {
1339 printf("%s: FORCE\n", $d->{obj});
1340 } else {
1341 print &splitline(sprintf("%s: %s", $d->{obj},
1342 join " ", @{$d->{deps}})), "\n";
1343 }
6da41155 1344 if ($d->{obj} =~ /\.obj$/) {
d8284c29 1345 print &splitline("\tlcc -O -p6 \$(COMPAT)".
a77c6ed3 1346 " \$(CFLAGS) \$(XFLAGS) ".$d->{deps}->[0],69)."\n";
6da41155 1347 } else {
976374cd 1348 print &splitline("\tlrc \$(RCFL) -r \$(RCFLAGS) ".
1349 $d->{deps}->[0],69)."\n";
6da41155 1350 }
e35fb54b 1351 }
1352 print "\n";
77603464 1353 print $makefile_extra{'lcc'}->{'end'};
e35fb54b 1354 print "\nclean:\n".
1355 "\t-del *.obj\n".
1356 "\t-del *.exe\n".
976374cd 1357 "\t-del *.res\n".
1358 "\n".
1359 "FORCE:\n";
4e95095a 1360
e35fb54b 1361 select STDOUT; close OUT;
1362}
1ddda1ca 1363
1364if (defined $makefiles{'osx'}) {
1365 $dirpfx = &dirpfx($makefiles{'osx'}, "/");
1366
1367 ##-- Mac OS X makefile
1368 open OUT, ">$makefiles{'osx'}"; select OUT;
1369 print
1370 "# Makefile for $project_name under Mac OS X.\n".
1371 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1372 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1373 # gcc command line option is -D not /D
4877ec8d 1374 ($_ = $help) =~ s/([=" ])\/D/$1-D/gs;
1ddda1ca 1375 print $_;
1376 print
1377 "CC = \$(TOOLPATH)gcc\n".
1378 "\n".
1379 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1380 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1381 "MLDFLAGS = -framework Cocoa\n".
1382 "ULDFLAGS =\n".
1ddda1ca 1383 "\n" .
77603464 1384 $makefile_extra{'osx'}->{'vars'} .
1385 "\n" .
1386 &splitline("all:" . join "", map { " $_" } &progrealnames("MX:U")) .
1ddda1ca 1387 "\n";
1388 foreach $p (&prognames("MX")) {
1389 ($prog, $type) = split ",", $p;
1390 $objstr = &objects($p, "X.o", undef, undef);
1391 $icon = &special($p, ".icns");
1392 $infoplist = &special($p, "info.plist");
1393 print "${prog}.app:\n\tmkdir -p \$\@\n";
1394 print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n";
1395 print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1396 $targets = "${prog}.app/Contents/MacOS/$prog";
1397 if (defined $icon) {
1398 print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1399 print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n";
1400 $targets .= " ${prog}.app/Contents/Resources/${prog}.icns";
1401 }
1402 if (defined $infoplist) {
1403 print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n";
1404 $targets .= " ${prog}.app/Contents/Info.plist";
1405 }
1406 $targets .= " \$(${prog}_extra)";
1407 print &splitline("${prog}: $targets", 69) . "\n\n";
1408 print &splitline("${prog}.app/Contents/MacOS/$prog: ".
1409 "${prog}.app/Contents/MacOS " . $objstr), "\n";
1410 $libstr = &objects($p, undef, undef, "-lX");
4877ec8d 1411 print &splitline("\t\$(CC) \$(MLDFLAGS) -o \$@ " .
1ddda1ca 1412 $objstr . " $libstr", 69), "\n\n";
1413 }
1414 foreach $p (&prognames("U")) {
1415 ($prog, $type) = split ",", $p;
1416 $objstr = &objects($p, "X.o", undef, undef);
1417 print &splitline($prog . ": " . $objstr), "\n";
1418 $libstr = &objects($p, undef, undef, "-lX");
4877ec8d 1419 print &splitline("\t\$(CC) \$(ULDFLAGS) -o \$@ " .
1ddda1ca 1420 $objstr . " $libstr", 69), "\n\n";
1421 }
4877ec8d 1422 foreach $d (&deps("X.o", undef, $dirpfx, "/", "osx")) {
976374cd 1423 if ($forceobj{$d->{obj_orig}}) {
1424 printf("%s: FORCE\n", $d->{obj});
1425 } else {
1426 print &splitline(sprintf("%s: %s", $d->{obj},
1427 join " ", @{$d->{deps}})), "\n";
1428 }
1ddda1ca 1429 $firstdep = $d->{deps}->[0];
1430 if ($firstdep =~ /\.c$/) {
a77c6ed3 1431 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS) -c \$<\n";
1ddda1ca 1432 } elsif ($firstdep =~ /\.m$/) {
a77c6ed3 1433 print "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS) -c \$<\n";
1ddda1ca 1434 }
1435 }
4877ec8d 1436 print "\n".&def($makefile_extra{'osx'}->{'end'});
1ddda1ca 1437 print "\nclean:\n".
976374cd 1438 "\trm -f *.o *.dmg". (join "", map { " $_" } &progrealnames("U")) . "\n".
4877ec8d 1439 "\trm -rf *.app\n".
976374cd 1440 "\n".
1441 "FORCE:\n";
1ddda1ca 1442 select STDOUT; close OUT;
1443}
985b6440 1444
1445if (defined $makefiles{'devcppproj'}) {
1446 $dirpfx = &dirpfx($makefiles{'devcppproj'}, "\\");
1447 $orig_dir = cwd;
1448
1449 ##-- Dev-C++ 5 projects
1450 #
1451 # Note: All files created in this section are written in binary
1452 # mode to prevent any posibility of misinterpreted line endings.
1453 # I don't know if Dev-C++ is as touchy as MSVC with LF-only line
1454 # endings. But however, CRLF line endings are the common way on
1455 # Win32 machines where Dev-C++ is running.
1456 # Hence, in order for mkfiles.pl to generate CRLF project files
1457 # even when run from Unix, I make sure all files are binary and
1458 # explicitly write the CRLFs.
1459 #
1460 # Create directories if necessary
1461 mkdir $makefiles{'devcppproj'}
1462 if(! -d $makefiles{'devcppproj'});
1463 chdir $makefiles{'devcppproj'};
1464 @deps = &deps("X.obj", "X.res", $dirpfx, "\\", "devcppproj");
1465 %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
1466 # Make dir names FAT/NTFS compatible
1467 my @srcdirs = @srcdirs;
1468 for ($i=0; $i<@srcdirs; $i++) {
1469 $srcdirs[$i] =~ s/\//\\/g;
1470 $srcdirs[$i] =~ s/\\$//;
1471 }
1472 # Create the project files
1473 # Get names of all Windows projects (GUI and console)
1474 my @prognames = &prognames("G:C");
1475 foreach $progname (@prognames) {
1476 create_devcpp_project(\%all_object_deps, $progname);
1477 }
1478
1479 sub create_devcpp_project {
1480 my ($all_object_deps, $progname) = @_;
1481 # Construct program's dependency info (Taken from 'vcproj', seems to work right here, too.)
1482 %seen_objects = ();
1483 %lib_files = ();
1484 %source_files = ();
1485 %header_files = ();
1486 %resource_files = ();
1487 @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
1488 foreach $object_file (@object_files) {
1489 next if defined $seen_objects{$object_file};
1490 $seen_objects{$object_file} = 1;
1491 if($object_file =~ /\.lib$/io) {
1492 $lib_files{$object_file} = 1;
1493 next;
1494 }
1495 $object_deps = $all_object_deps{$object_file};
1496 foreach $object_dep (@$object_deps) {
1497 if($object_dep =~ /\.c$/io) {
1498 $source_files{$object_dep} = 1;
1499 next;
1500 }
1501 if($object_dep =~ /\.h$/io) {
1502 $header_files{$object_dep} = 1;
1503 next;
1504 }
1505 if($object_dep =~ /\.(rc|ico)$/io) {
1506 $resource_files{$object_dep} = 1;
1507 next;
1508 }
1509 }
1510 }
1511 $libs = join " ", sort keys %lib_files;
1512 @source_files = sort keys %source_files;
1513 @header_files = sort keys %header_files;
1514 @resources = sort keys %resource_files;
1515 ($windows_project, $type) = split ",", $progname;
1516 mkdir $windows_project
1517 if(! -d $windows_project);
1518 chdir $windows_project;
1519
1520 $subsys = ($type eq "G") ? "0" : "1"; # 0 = Win32 GUI, 1 = Win32 Console
1521 open OUT, ">$windows_project.dev"; binmode OUT; select OUT;
1522 print
1523 "# DEV-C++ 5 Project File - $windows_project.dev\r\n".
1524 "# ** DO NOT EDIT **\r\n".
1525 "\r\n".
1526 # No difference between DEBUG and RELEASE here as in 'vcproj', because
1527 # Dev-C++ does not support mutiple compilation profiles in one single project.
1528 # (At least I can say this for Dev-C++ 5 Beta)
1529 "[Project]\r\n".
1530 "FileName=$windows_project.dev\r\n".
1531 "Name=$windows_project\r\n".
1532 "Ver=1\r\n".
1533 "IsCpp=1\r\n".
1534 "Type=$subsys\r\n".
1535 # Multimon is disabled here, as Dev-C++ (Version 5 Beta) does not have multimon.h
1536 "Compiler=-W -D__GNUWIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNO_MULTIMON -D_MBCS_\@\@_\r\n".
1537 "CppCompiler=-W -D__GNUWIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNO_MULTIMON -D_MBCS_\@\@_\r\n".
1538 "Includes=" . (join ";", map {"..\\..\\$dirpfx$_"} @srcdirs) . "\r\n".
1539 "Linker=-ladvapi32 -lcomctl32 -lcomdlg32 -lgdi32 -limm32 -lshell32 -luser32 -lwinmm -lwinspool_\@\@_\r\n".
1540 "Libs=\r\n".
1541 "UnitCount=" . (@source_files + @header_files + @resources) . "\r\n".
1542 "Folders=\"Header Files\",\"Resource Files\",\"Source Files\"\r\n".
1543 "ObjFiles=\r\n".
1544 "PrivateResource=${windows_project}_private.rc\r\n".
1545 "ResourceIncludes=..\\..\\..\\WINDOWS\r\n".
1546 "MakeIncludes=\r\n".
1547 "Icon=\r\n". # It's ok to leave this blank.
1548 "ExeOutput=\r\n".
1549 "ObjectOutput=\r\n".
1550 "OverrideOutput=0\r\n".
1551 "OverrideOutputName=$windows_project.exe\r\n".
1552 "HostApplication=\r\n".
1553 "CommandLine=\r\n".
1554 "UseCustomMakefile=0\r\n".
1555 "CustomMakefile=\r\n".
1556 "IncludeVersionInfo=0\r\n".
1557 "SupportXPThemes=0\r\n".
1558 "CompilerSet=0\r\n".
1559 "CompilerSettings=0000000000000000000000\r\n".
1560 "\r\n";
1561 $unit_count = 1;
1562 foreach $source_file (@source_files) {
1563 print
1564 "[Unit$unit_count]\r\n".
1565 "FileName=..\\..\\$source_file\r\n".
1566 "Folder=Source Files\r\n".
1567 "Compile=1\r\n".
1568 "CompileCpp=0\r\n".
1569 "Link=1\r\n".
1570 "Priority=1000\r\n".
1571 "OverrideBuildCmd=0\r\n".
1572 "BuildCmd=\r\n".
1573 "\r\n";
1574 $unit_count++;
1575 }
1576 foreach $header_file (@header_files) {
1577 print
1578 "[Unit$unit_count]\r\n".
1579 "FileName=..\\..\\$header_file\r\n".
1580 "Folder=Header Files\r\n".
1581 "Compile=1\r\n".
1582 "CompileCpp=1\r\n". # Dev-C++ want's to compile all header files with both compilers C and C++. It does not hurt.
1583 "Link=1\r\n".
1584 "Priority=1000\r\n".
1585 "OverrideBuildCmd=0\r\n".
1586 "BuildCmd=\r\n".
1587 "\r\n";
1588 $unit_count++;
1589 }
1590 foreach $resource_file (@resources) {
1591 if ($resource_file =~ /.*\.(ico|cur|bmp|dlg|rc2|rct|bin|rgs|gif|jpg|jpeg|jpe)/io) { # Default filter as in 'vcproj'
1592 $Compile = "0"; # Don't compile images and other binary resource files
1593 $CompileCpp = "0";
1594 } else {
1595 $Compile = "1";
1596 $CompileCpp = "1"; # Dev-C++ want's to compile all .rc files with both compilers C and C++. It does not hurt.
1597 }
1598 print
1599 "[Unit$unit_count]\r\n".
1600 "FileName=..\\..\\$resource_file\r\n".
1601 "Folder=Resource Files\r\n".
1602 "Compile=$Compile\r\n".
1603 "CompileCpp=$CompileCpp\r\n".
1604 "Link=0\r\n".
1605 "Priority=1000\r\n".
1606 "OverrideBuildCmd=0\r\n".
1607 "BuildCmd=\r\n".
1608 "\r\n";
1609 $unit_count++;
1610 }
1611 #Note: By default, [VersionInfo] is not used.
1612 print
1613 "[VersionInfo]\r\n".
1614 "Major=0\r\n".
1615 "Minor=0\r\n".
1616 "Release=1\r\n".
1617 "Build=1\r\n".
1618 "LanguageID=1033\r\n".
1619 "CharsetID=1252\r\n".
1620 "CompanyName=\r\n".
1621 "FileVersion=0.1\r\n".
1622 "FileDescription=\r\n".
1623 "InternalName=\r\n".
1624 "LegalCopyright=\r\n".
1625 "LegalTrademarks=\r\n".
1626 "OriginalFilename=$windows_project.exe\r\n".
1627 "ProductName=$windows_project\r\n".
1628 "ProductVersion=0.1\r\n".
1629 "AutoIncBuildNr=0\r\n";
1630 select STDOUT; close OUT;
1631 chdir "..";
1632 }
1633}