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