3 # Cross-platform Makefile generator.
5 # Reads the file `Recipe' to determine the list of generated
6 # executables and their component objects. Then reads the source
7 # files to compute #include dependencies. Finally, writes out the
8 # various target Makefiles.
10 # PuTTY specifics which could still do with removing:
11 # - Mac makefile is not portabilised at all. Include directories
12 # are hardwired, and also the libraries are fixed. This is
13 # mainly because I was too scared to go anywhere near it.
14 # - sbcsgen.pl is still run at startup.
19 open IN, "Recipe" or do {
20 # We want to deal correctly with being run from one of the
21 # subdirs in the source tree. So if we can't find Recipe here,
24 open IN, "Recipe" or die "unable to open Recipe file\n";
27 # HACK: One of the source files in `charset' is auto-generated by
28 # sbcsgen.pl. We need to generate that _now_, before attempting
29 # dependency analysis.
30 eval 'chdir "charset"; require "sbcsgen.pl"; chdir ".."';
34 $divert = undef; # ref to scalar in which text is currently being put
35 $help = ""; # list of newline-free lines of help text
36 $project_name = "project"; # this is a good enough default
37 %makefiles = (); # maps makefile types to output makefile pathnames
38 %makefile_extra = (); # maps makefile types to extra Makefile text
39 %programs = (); # maps prog name + type letter to listref of objects/resources
40 %groups = (); # maps group name to listref of objects/resources
43 # Skip comments (unless the comments belong, for example because
44 # they're part of a diversion).
45 next if /^\s*#/ and !defined $divert;
49 if ($_[0] eq "!begin" and $_[1] eq "help") { $divert = \$help; next; }
50 if ($_[0] eq "!end") { $divert = undef; next; }
51 if ($_[0] eq "!name") { $project_name = $_[1]; next; }
52 if ($_[0] eq "!srcdir") { push @srcdirs, $_[1]; next; }
53 if ($_[0] eq "!makefile" and &mfval($_[1])) { $makefiles{$_[1]}=$_[2]; next;}
54 if ($_[0] eq "!specialobj" and &mfval($_[1])) { $specialobj{$_[1]}->{$_[2]} = 1; next;}
55 if ($_[0] eq "!begin") {
57 $divert = \$makefile_extra{$_[1]};
63 # If we're gathering help text, keep doing so.
64 if (defined $divert) { ${$divert} .= "$_\n"; next; }
66 next if scalar @_ == 0;
68 # Now we have an ordinary line. See if it's an = line, a : line
73 $listref = $lastlistref;
75 die "$.: unexpected + line\n" if !defined $lastlistref;
76 } elsif ($_[1] eq "=") {
77 $groups{$_[0]} = [] if !defined $groups{$_[0]};
78 $listref = $groups{$_[0]};
80 shift @objs; # eat the group name
81 } elsif ($_[1] eq ":") {
84 shift @objs; # eat the program name
86 die "$.: unrecognised line type\n";
88 shift @objs; # eat the +, the = or the :
90 while (scalar @objs > 0) {
93 foreach $j (@{$groups{$i}}) { unshift @objs, $j; }
94 } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or
95 $i eq "[X]" or $i eq "[U]") and defined $prog) {
96 $type = substr($i,1,1);
101 if ($prog and $type) {
102 die "multiple program entries for $prog [$type]\n"
103 if defined $programs{$prog . "," . $type};
104 $programs{$prog . "," . $type} = $listref;
106 $lastlistref = $listref;
111 # Now retrieve the complete list of objects and resource files, and
112 # construct dependency data for them. While we're here, expand the
113 # object list for each program, and complain if its type isn't set.
114 @prognames = sort keys %programs;
117 foreach $i (@prognames) {
118 ($prog, $type) = split ",", $i;
119 # Strip duplicate object names.
121 @list = grep { $status = ($prev ne $_); $prev=$_; $status }
122 sort @{$programs{$i}};
123 $programs{$i} = [@list];
125 # Dependencies for "x" start with "x.c".
126 # Dependencies for "x.res" start with "x.rc".
127 # Dependencies for "x.rsrc" start with "x.r".
128 # Both types of file are pushed on the list of files to scan.
129 # Libraries (.lib) don't have dependencies at all.
130 if ($j =~ /^(.*)\.res$/) {
132 $depends{$j} = [$file];
133 push @scanlist, $file;
134 } elsif ($j =~ /^(.*)\.rsrc$/) {
136 $depends{$j} = [$file];
137 push @scanlist, $file;
138 } elsif ($j =~ /\.lib$/) {
139 # libraries don't have dependencies
142 $depends{$j} = [$file];
143 push @scanlist, $file;
148 # Scan each file on @scanlist and find further inclusions.
149 # Inclusions are given by lines of the form `#include "otherfile"'
150 # (system headers are automatically ignored by this because they'll
151 # be given in angle brackets). Files included by this method are
152 # added back on to @scanlist to be scanned in turn (if not already
155 # Resource scripts (.rc) can also include a file by means of a line
156 # ending `ICON "filename"'. Files included by this method are not
157 # added to @scanlist because they can never include further files.
159 # In this pass we write out a hash %further which maps a source
160 # file name into a listref containing further source file names.
163 while (scalar @scanlist > 0) {
164 $file = shift @scanlist;
165 next if defined $further{$file}; # skip if we've already done it
166 $resource = ($file =~ /\.rc$/ ? 1 : 0);
167 $further{$file} = [];
168 $dirfile = &findfile($file);
169 open IN, "$dirfile" or die "unable to open source file $file\n";
172 /^\s*#include\s+\"([^\"]+)\"/ and do {
173 push @{$further{$file}}, $1;
177 /ICON\s+\"([^\"]+)\"\s*$/ and do {
178 push @{$further{$file}}, $1;
185 # Now we're ready to generate the final dependencies section. For
186 # each key in %depends, we must expand the dependencies list by
187 # iteratively adding entries from %further.
188 foreach $i (keys %depends) {
190 @scanlist = @{$depends{$i}};
191 foreach $i (@scanlist) { $dep{$i} = 1; }
192 while (scalar @scanlist > 0) {
193 $file = shift @scanlist;
194 foreach $j (@{$further{$file}}) {
197 push @{$depends{$i}}, $j;
202 # printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
205 # Validation of input.
209 # Returns true if the argument is a known makefile type. Otherwise,
210 # prints a warning and returns false;
211 if (grep { $type eq $_ }
212 ("vc","vcproj","cygwin","borland","lcc","gtk","mpw")) {
215 warn "$.:unknown makefile type '$type'\n";
219 # Utility routines while writing out the Makefiles.
222 my ($path) = shift @_;
223 my ($sep) = shift @_;
226 while (($i = index $path, $sep) >= 0 ||
227 ($j = index $path, "/") >= 0) {
228 if ($i >= 0 and ($j < 0 or $i < $j)) {
229 $path = substr $path, ($i + length $sep);
231 $path = substr $path, ($j + 1);
240 my $dir, $i, $outdir = "";
241 unless (defined $findfilecache{$name}) {
243 foreach $dir (@srcdirs) {
244 $outdir = $dir, $i++ if -f "$dir$name";
246 die "multiple instances of source file $name\n" if $i > 1;
247 $findfilecache{$name} = $outdir . $name;
249 return $findfilecache{$name};
253 my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
257 foreach $i (@{$programs{$prog}}) {
259 if ($i =~ /^(.*)\.(res|rsrc)/) {
261 ($x = $rtmpl) =~ s/X/$y/;
262 } elsif ($i =~ /^(.*)\.lib/) {
264 ($x = $ltmpl) =~ s/X/$y/;
266 ($x = $otmpl) =~ s/X/$i/;
268 push @ret, $x if $x ne "";
270 return join " ", @ret;
274 my ($line, $width, $splitchar) = @_;
276 $len = (defined $width ? $width : 76);
277 $splitchar = (defined $splitchar ? $splitchar : '\\');
278 while (length $line > $len) {
279 $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
280 $result .= $1 . " ${splitchar}\n\t\t";
284 return $result . $line;
288 my ($otmpl, $rtmpl, $prefix, $dirsep, $mftyp, $depchar, $splitchar) = @_;
293 foreach $i (sort keys %depends) {
294 next if $specialobj{$mftyp}->{$i};
295 if ($i =~ /^(.*)\.(res|rsrc)/) {
296 next if !defined $rtmpl;
298 ($x = $rtmpl) =~ s/X/$y/;
300 ($x = $otmpl) =~ s/X/$i/;
302 @deps = @{$depends{$i}};
308 push @ret, {obj => $x, deps => [@deps]};
315 my ($n, $prog, $type);
318 foreach $n (@prognames) {
319 ($prog, $type) = split ",", $n;
320 push @ret, $n if index($types, $type) >= 0;
327 my ($n, $prog, $type);
330 foreach $n (@prognames) {
331 ($prog, $type) = split ",", $n;
332 push @ret, $prog if index($types, $type) >= 0;
338 my ($types,$suffix) = @_;
340 # assume that all UNIX programs have a man page
341 if($suffix eq "1" && $types =~ /X/) {
342 return map("$_.1", &progrealnames($types));
347 # Now we're ready to output the actual Makefiles.
349 if (defined $makefiles{'cygwin'}) {
350 $dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
353 open OUT, ">$makefiles{'cygwin'}"; select OUT;
355 "# Makefile for $project_name under cygwin.\n".
356 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
357 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
358 # gcc command line option is -D not /D
359 ($_ = $help) =~ s/=\/D/=-D/gs;
363 "# You can define this path to point at your tools if you need to\n".
364 "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
365 "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
366 "CC = \$(TOOLPATH)gcc\n".
367 "RC = \$(TOOLPATH)windres\n".
368 "# Uncomment the following two lines to compile under Winelib\n".
371 "# You may also need to tell windres where to find include files:\n".
372 "# RCINC = --include-dir c:\\cygwin\\include\\\n".
374 &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
375 " -D_NO_OLDNAMES -DNO_MULTIMON " .
376 (join " ", map {"-I$dirpfx$_"} @srcdirs)) .
378 "LDFLAGS = -mno-cygwin -s\n".
379 &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1".
380 " --define WINVER=0x0400 --define MINGW32_FIX=1")."\n".
384 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
386 foreach $p (&prognames("GC")) {
387 ($prog, $type) = split ",", $p;
388 $objstr = &objects($p, "X.o", "X.res.o", undef);
389 print &splitline($prog . ".exe: " . $objstr), "\n";
390 my $mw = $type eq "G" ? " -mwindows" : "";
391 $libstr = &objects($p, undef, undef, "-lX");
392 print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
393 "-Wl,-Map,$prog.map " .
394 $objstr . " $libstr", 69), "\n\n";
396 foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/", "cygwin")) {
397 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
399 if ($d->{obj} =~ /\.res\.o$/) {
400 print "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) ".$d->{deps}->[0]." ".$d->{obj}."\n\n";
402 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c ".$d->{deps}->[0]."\n\n";
406 print $makefile_extra{'cygwin'};
408 "\trm -f *.o *.exe *.res.o *.map\n".
410 select STDOUT; close OUT;
414 ##-- Borland makefile
415 if (defined $makefiles{'borland'}) {
416 $dirpfx = &dirpfx($makefiles{'borland'}, "\\");
418 %stdlibs = ( # Borland provides many Win32 API libraries intrinsically
430 open OUT, ">$makefiles{'borland'}"; select OUT;
432 "# Makefile for $project_name under Borland C.\n".
433 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
434 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
435 # bcc32 command line option is -D not /D
436 ($_ = $help) =~ s/=\/D/=-D/gs;
440 "# If you rename this file to `Makefile', you should change this line,\n".
441 "# so that the .rsp files still depend on the correct makefile.\n".
442 "MAKEFILE = Makefile.bor\n".
444 "# C compilation flags\n".
445 "CFLAGS = -D_WINDOWS -DWINVER=0x0401\n".
447 "# Get include directory for resource compiler\n".
449 "BCB = \$(MAKEDIR)\\..\n".
453 &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT) \$(FWHACK)".
454 " \$(XFLAGS) \$(CFLAGS) ".
455 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
456 " /c \$*.c",69)."\n".
458 &splitline("\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include -r".
459 " -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n".
461 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
463 foreach $p (&prognames("GC")) {
464 ($prog, $type) = split ",", $p;
465 $objstr = &objects($p, "X.obj", "X.res", undef);
466 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
467 my $ap = ($type eq "G") ? "-aa" : "-ap";
468 print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n";
470 foreach $p (&prognames("GC")) {
471 ($prog, $type) = split ",", $p;
472 print $prog, ".rsp: \$(MAKEFILE)\n";
473 $objstr = &objects($p, "X.obj", undef, undef);
474 @objlist = split " ", $objstr;
476 foreach $i (@objlist) {
477 if (length($objlines[$#objlines] . " $i") > 50) {
480 $objlines[$#objlines] .= " $i";
482 $c0w = ($type eq "G") ? "c0w32" : "c0x32";
483 print "\techo $c0w + > $prog.rsp\n";
484 for ($i=0; $i<=$#objlines; $i++) {
485 $plus = ($i < $#objlines ? " +" : "");
486 print "\techo$objlines[$i]$plus >> $prog.rsp\n";
488 print "\techo $prog.exe >> $prog.rsp\n";
489 $objstr = &objects($p, "X.obj", "X.res", undef);
490 @libs = split " ", &objects($p, undef, undef, "X");
491 @libs = grep { !$stdlibs{$_} } @libs;
492 unshift @libs, "cw32", "import32";
493 $libstr = join ' ', @libs;
494 print "\techo nul,$libstr, >> $prog.rsp\n";
495 print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n";
498 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "borland")) {
499 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
503 print $makefile_extra{'borland'};
514 "\t-del *.\$\$\$\$\$\$\n";
515 select STDOUT; close OUT;
518 if (defined $makefiles{'vc'}) {
519 $dirpfx = &dirpfx($makefiles{'vc'}, "\\");
521 ##-- Visual C++ makefile
522 open OUT, ">$makefiles{'vc'}"; select OUT;
524 "# Makefile for $project_name under Visual C.\n".
525 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
526 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
530 "# If you rename this file to `Makefile', you should change this line,\n".
531 "# so that the .rsp files still depend on the correct makefile.\n".
532 "MAKEFILE = Makefile.vc\n".
534 "# C compilation flags\n".
535 "CFLAGS = /nologo /W3 /O1 " .
536 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
537 " /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401\n".
538 "LFLAGS = /incremental:no /fixed\n".
541 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
543 foreach $p (&prognames("GC")) {
544 ($prog, $type) = split ",", $p;
545 $objstr = &objects($p, "X.obj", "X.res", undef);
546 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
547 print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
549 foreach $p (&prognames("GC")) {
550 ($prog, $type) = split ",", $p;
551 print $prog, ".rsp: \$(MAKEFILE)\n";
552 $objstr = &objects($p, "X.obj", "X.res", "X.lib");
553 @objlist = split " ", $objstr;
555 foreach $i (@objlist) {
556 if (length($objlines[$#objlines] . " $i") > 50) {
559 $objlines[$#objlines] .= " $i";
561 $subsys = ($type eq "G") ? "windows" : "console";
562 print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
563 for ($i=0; $i<=$#objlines; $i++) {
564 print "\techo$objlines[$i] >> $prog.rsp\n";
568 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "vc")) {
569 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
571 if ($d->{obj} =~ /.obj$/) {
572 print "\tcl \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) /c ".$d->{deps}->[0],"\n\n";
574 print "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 -DWINVER=0x0400 ".$d->{deps}->[0],"\n\n";
578 print $makefile_extra{'vc'};
579 print "\nclean: tidy\n".
596 "\t-del debug.log\n";
597 select STDOUT; close OUT;
600 if (defined $makefiles{'vcproj'}) {
601 $dirpfx = &dirpfx($makefiles{'vcproj'}, "\\");
605 ##-- MSVC 6 Workspace and projects
607 # Note: All files created in this section are written in binary
608 # mode, because although MSVC's command-line make can deal with
609 # LF-only line endings, MSVC project files really _need_ to be
610 # CRLF. Hence, in order for mkfiles.pl to generate usable project
611 # files even when run from Unix, I make sure all files are binary
612 # and explicitly write the CRLFs.
614 # Create directories if necessary
615 mkdir $makefiles{'vcproj'}
616 if(! -d $makefiles{'vcproj'});
617 chdir $makefiles{'vcproj'};
618 @deps = &deps("X.obj", "X.res", $dirpfx, "\\", "vcproj");
619 %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
620 # Create the project files
621 # Get names of all Windows projects (GUI and console)
622 my @prognames = &prognames("GC");
623 foreach $progname (@prognames) {
624 create_project(\%all_object_deps, $progname);
626 # Create the workspace file
627 open OUT, ">$project_name.dsw"; binmode OUT; select OUT;
629 "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
630 "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
632 "###############################################################################\r\n".
635 foreach $progname (@prognames) {
636 ($windows_project, $type) = split ",", $progname;
637 print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n";
649 "###############################################################################\r\n".
661 "###############################################################################\r\n".
663 select STDOUT; close OUT;
667 my ($all_object_deps, $progname) = @_;
668 # Construct program's dependency info
673 %resource_files = ();
674 @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
675 foreach $object_file (@object_files) {
676 next if defined $seen_objects{$object_file};
677 $seen_objects{$object_file} = 1;
678 if($object_file =~ /\.lib$/io) {
679 $lib_files{$object_file} = 1;
682 $object_deps = $all_object_deps{$object_file};
683 foreach $object_dep (@$object_deps) {
684 if($object_dep =~ /\.c$/io) {
685 $source_files{$object_dep} = 1;
688 if($object_dep =~ /\.h$/io) {
689 $header_files{$object_dep} = 1;
692 if($object_dep =~ /\.(rc|ico)$/io) {
693 $resource_files{$object_dep} = 1;
698 $libs = join " ", sort keys %lib_files;
699 @source_files = sort keys %source_files;
700 @header_files = sort keys %header_files;
701 @resources = sort keys %resource_files;
702 ($windows_project, $type) = split ",", $progname;
703 mkdir $windows_project
704 if(! -d $windows_project);
705 chdir $windows_project;
706 $subsys = ($type eq "G") ? "windows" : "console";
707 open OUT, ">$windows_project.dsp"; binmode OUT; select OUT;
709 "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n".
710 "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n".
711 "# ** DO NOT EDIT **\r\n".
713 "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n".
715 "CFG=$windows_project - Win32 Debug\r\n".
716 "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n".
717 "!MESSAGE use the Export Makefile command and run\r\n".
719 "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n".
721 "!MESSAGE You can specify a configuration when running NMAKE\r\n".
722 "!MESSAGE by defining the macro CFG on the command line. For example:\r\n".
724 "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
726 "!MESSAGE Possible choices for configuration are:\r\n".
728 "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n".
729 "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n".
732 "# Begin Project\r\n".
733 "# PROP AllowPerConfigDependencies 0\r\n".
734 "# PROP Scc_ProjName \"\"\r\n".
735 "# PROP Scc_LocalPath \"\"\r\n".
740 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
742 "# PROP BASE Use_MFC 0\r\n".
743 "# PROP BASE Use_Debug_Libraries 0\r\n".
744 "# PROP BASE Output_Dir \"Release\"\r\n".
745 "# PROP BASE Intermediate_Dir \"Release\"\r\n".
746 "# PROP BASE Target_Dir \"\"\r\n".
747 "# PROP Use_MFC 0\r\n".
748 "# PROP Use_Debug_Libraries 0\r\n".
749 "# PROP Output_Dir \"Release\"\r\n".
750 "# PROP Intermediate_Dir \"Release\"\r\n".
751 "# PROP Ignore_Export_Lib 0\r\n".
752 "# PROP Target_Dir \"\"\r\n".
753 "# ADD BASE CPP /nologo /W3 /GX /O2 ".
754 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
755 " /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
756 "# ADD CPP /nologo /W3 /GX /O2 ".
757 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
758 " /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
759 "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
760 "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
761 "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n".
762 "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n".
763 "BSC32=bscmake.exe\r\n".
764 "# ADD BASE BSC32 /nologo\r\n".
765 "# ADD BSC32 /nologo\r\n".
766 "LINK32=link.exe\r\n".
767 "# 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".
768 "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n".
769 "# SUBTRACT LINK32 /pdb:none\r\n".
771 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
773 "# PROP BASE Use_MFC 0\r\n".
774 "# PROP BASE Use_Debug_Libraries 1\r\n".
775 "# PROP BASE Output_Dir \"Debug\"\r\n".
776 "# PROP BASE Intermediate_Dir \"Debug\"\r\n".
777 "# PROP BASE Target_Dir \"\"\r\n".
778 "# PROP Use_MFC 0\r\n".
779 "# PROP Use_Debug_Libraries 1\r\n".
780 "# PROP Output_Dir \"Debug\"\r\n".
781 "# PROP Intermediate_Dir \"Debug\"\r\n".
782 "# PROP Ignore_Export_Lib 0\r\n".
783 "# PROP Target_Dir \"\"\r\n".
784 "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od ".
785 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
786 " /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
787 "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od ".
788 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
789 " /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
790 "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
791 "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
792 "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n".
793 "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n".
794 "BSC32=bscmake.exe\r\n".
795 "# ADD BASE BSC32 /nologo\r\n".
796 "# ADD BSC32 /nologo\r\n".
797 "LINK32=link.exe\r\n".
798 "# 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".
799 "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
800 "# SUBTRACT LINK32 /pdb:none\r\n".
804 "# Begin Target\r\n".
806 "# Name \"$windows_project - Win32 Release\"\r\n".
807 "# Name \"$windows_project - Win32 Debug\"\r\n".
808 "# Begin Group \"Source Files\"\r\n".
810 "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
811 foreach $source_file (@source_files) {
813 "# Begin Source File\r\n".
815 "SOURCE=..\\..\\$source_file\r\n";
816 if($source_file =~ /ssh\.c/io) {
817 # Disable 'Edit and continue' as Visual Studio can't handle the macros
820 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
822 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
829 print "# End Source File\r\n";
833 "# Begin Group \"Header Files\"\r\n".
835 "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
836 foreach $header_file (@header_files) {
838 "# Begin Source File\r\n".
840 "SOURCE=..\\..\\$header_file\r\n".
841 "# End Source File\r\n";
845 "# Begin Group \"Resource Files\"\r\n".
847 "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
848 foreach $resource_file (@resources) {
850 "# Begin Source File\r\n".
852 "SOURCE=..\\..\\$resource_file\r\n".
853 "# End Source File\r\n";
859 select STDOUT; close OUT;
864 if (defined $makefiles{'gtk'}) {
865 $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
867 ##-- X/GTK/Unix makefile
868 open OUT, ">$makefiles{'gtk'}"; select OUT;
870 "# Makefile for $project_name under X/GTK and Unix.\n".
871 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
872 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
873 # gcc command line option is -D not /D
874 ($_ = $help) =~ s/=\/D/=-D/gs;
878 "# You can define this path to point at your tools if you need to\n".
879 "# TOOLPATH = /opt/gcc/bin\n".
880 "CC = \$(TOOLPATH)cc\n".
882 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
883 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
884 " `gtk-config --cflags`")."\n".
885 "XLDFLAGS = `gtk-config --libs`\n".
888 "INSTALL_PROGRAM=\$(INSTALL)\n",
889 "INSTALL_DATA=\$(INSTALL)\n",
890 "prefix=/usr/local\n",
891 "exec_prefix=\$(prefix)\n",
892 "bindir=\$(exec_prefix)/bin\n",
893 "mandir=\$(prefix)/man\n",
894 "man1dir=\$(mandir)/man1\n",
899 "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
901 print &splitline("all:" . join "", map { " $_" } &progrealnames("XU"));
903 foreach $p (&prognames("XU")) {
904 ($prog, $type) = split ",", $p;
905 $objstr = &objects($p, "X.o", undef, undef);
906 print &splitline($prog . ": " . $objstr), "\n";
907 $libstr = &objects($p, undef, undef, "-lX");
908 print &splitline("\t\$(CC)" . $mw . " \$(${type}LDFLAGS) -o \$@ " .
909 $objstr . " $libstr", 69), "\n\n";
911 foreach $d (&deps("X.o", undef, $dirpfx, "/", "gtk")) {
912 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
916 print $makefile_extra{'gtk'};
918 "\trm -f *.o". (join "", map { " $_" } &progrealnames("XU")) . "\n";
919 select STDOUT; close OUT;
922 if (defined $makefiles{'mpw'}) {
924 open OUT, ">$makefiles{'mpw'}"; select OUT;
926 "# Makefile for $project_name under MPW.\n#\n".
927 "# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
928 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
929 # MPW command line option is -d not /D
930 ($_ = $help) =~ s/=\/D/=-d /gs;
933 "ROptions = `Echo \"{VER}\" | StreamEdit -e \"1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6\"' \xa81 '\xb6\xb6\xb6\xb6\xb6\"'\"`".
938 "C_Carbon = {PPCC}\n".
940 "# -w 35 disables \"unused parameter\" warnings\n".
941 "COptions = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6\n".
943 "COptions_68K = {COptions} -model far -opt time\n".
944 "# Enabling \"-opt space\" for CFM-68K gives me undefined references to\n".
945 "# _\$LDIVT and _\$LMODT.\n".
946 "COptions_CFM68K = {COptions} -model cfmSeg -opt time\n".
947 "COptions_PPC = {COptions} -opt size -traceback\n".
948 "COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON\n".
950 "Link_68K = ILink\n".
951 "Link_CFM68K = ILink\n".
952 "Link_PPC = PPCLink\n".
953 "Link_Carbon = PPCLink\n".
955 "LinkOptions = -c 'pTTY'\n".
956 "LinkOptions_68K = {LinkOptions} -br 68k -model far -compact\n".
957 "LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact\n".
958 "LinkOptions_PPC = {LinkOptions}\n".
959 "LinkOptions_Carbon = -m __appstart -w {LinkOptions}\n".
961 "Libs_68K = \"{CLibraries}StdCLib.far.o\" \xb6\n".
962 " \"{Libraries}MacRuntime.o\" \xb6\n".
963 " \"{Libraries}MathLib.far.o\" \xb6\n".
964 " \"{Libraries}IntEnv.far.o\" \xb6\n".
965 " \"{Libraries}Interface.o\" \xb6\n".
966 " \"{Libraries}Navigation.far.o\" \xb6\n".
967 " \"{Libraries}OpenTransport.o\" \xb6\n".
968 " \"{Libraries}OpenTransportApp.o\" \xb6\n".
969 " \"{Libraries}OpenTptInet.o\" \xb6\n".
970 " \"{Libraries}UnicodeConverterLib.far.o\"\n".
972 "Libs_CFM = \"{SharedLibraries}InterfaceLib\" \xb6\n".
973 " \"{SharedLibraries}StdCLib\" \xb6\n".
974 " \"{SharedLibraries}AppearanceLib\" \xb6\n".
975 " -weaklib AppearanceLib \xb6\n".
976 " \"{SharedLibraries}NavigationLib\" \xb6\n".
977 " -weaklib NavigationLib \xb6\n".
978 " \"{SharedLibraries}TextCommon\" \xb6\n".
979 " -weaklib TextCommon \xb6\n".
980 " \"{SharedLibraries}UnicodeConverter\" \xb6\n".
981 " -weaklib UnicodeConverter\n".
983 "Libs_CFM68K = {Libs_CFM} \xb6\n".
984 " \"{CFM68KLibraries}NuMacRuntime.o\"\n".
986 "Libs_PPC = {Libs_CFM} \xb6\n".
987 " \"{SharedLibraries}ControlsLib\" \xb6\n".
988 " -weaklib ControlsLib \xb6\n".
989 " \"{SharedLibraries}WindowsLib\" \xb6\n".
990 " -weaklib WindowsLib \xb6\n".
991 " \"{SharedLibraries}OpenTransportLib\" \xb6\n".
992 " -weaklib OTClientLib \xb6\n".
993 " -weaklib OTClientUtilLib \xb6\n".
994 " \"{SharedLibraries}OpenTptInternetLib\" \xb6\n".
995 " -weaklib OTInetClientLib \xb6\n".
996 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
997 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
998 " \"{PPCLibraries}CarbonAccessors.o\" \xb6\n".
999 " \"{PPCLibraries}OpenTransportAppPPC.o\" \xb6\n".
1000 " \"{PPCLibraries}OpenTptInetPPC.o\"\n".
1002 "Libs_Carbon = \"{PPCLibraries}CarbonStdCLib.o\" \xb6\n".
1003 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1004 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1005 " \"{SharedLibraries}CarbonLib\" \xb6\n".
1006 " \"{SharedLibraries}StdCLib\"\n".
1008 print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6");
1010 foreach $p (&prognames("M")) {
1011 ($prog, $type) = split ",", $p;
1013 print &splitline("$prog \xc4 $prog.68k $prog.ppc $prog.carbon",
1014 undef, "\xb6"), "\n\n";
1016 $rsrc = &objects($p, "", "X.rsrc", undef);
1018 foreach $arch (qw(68K CFM68K PPC Carbon)) {
1019 $objstr = &objects($p, "X.\L$arch\E.o", "", undef);
1020 print &splitline("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6");
1022 print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
1023 print &splitline("\t{Link_$arch} -o {Targ} -fragname $prog " .
1024 "{LinkOptions_$arch} " .
1025 $objstr . " {Libs_$arch}", 69, "\xb6"), "\n";
1026 print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
1030 foreach $d (&deps("", "X.rsrc", "::", ":", "mpw")) {
1031 next unless $d->{obj};
1032 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
1033 undef, "\xb6"), "\n";
1034 print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n";
1036 foreach $arch (qw(68K CFM68K)) {
1037 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":", "mpw")) {
1038 next unless $d->{obj};
1039 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1040 join " ", @{$d->{deps}}),
1041 undef, "\xb6"), "\n";
1042 print "\t{C_$arch} ", $d->{deps}->[0],
1043 " -o {Targ} {COptions_$arch}\n\n";
1046 foreach $arch (qw(PPC Carbon)) {
1047 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":", "mpw")) {
1048 next unless $d->{obj};
1049 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1050 join " ", @{$d->{deps}}),
1051 undef, "\xb6"), "\n";
1052 # The odd stuff here seems to stop afpd getting confused.
1053 print "\techo -n > {Targ}\n";
1054 print "\tsetfile -t XCOF {Targ}\n";
1055 print "\t{C_$arch} ", $d->{deps}->[0],
1056 " -o {Targ} {COptions_$arch}\n\n";
1059 select STDOUT; close OUT;
1062 if (defined $makefiles{'lcc'}) {
1063 $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
1066 open OUT, ">$makefiles{'lcc'}"; select OUT;
1068 "# Makefile for $project_name under lcc.\n".
1069 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1070 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1071 # lcc command line option is -D not /D
1072 ($_ = $help) =~ s/=\/D/=-D/gs;
1076 "# If you rename this file to `Makefile', you should change this line,\n".
1077 "# so that the .rsp files still depend on the correct makefile.\n".
1078 "MAKEFILE = Makefile.lcc\n".
1080 "# C compilation flags\n".
1081 "CFLAGS = -D_WINDOWS " .
1082 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1085 "# Get include directory for resource compiler\n".
1087 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
1089 foreach $p (&prognames("GC")) {
1090 ($prog, $type) = split ",", $p;
1091 $objstr = &objects($p, "X.obj", "X.res", undef);
1092 print &splitline("$prog.exe: " . $objstr ), "\n";
1093 $subsystemtype = undef;
1094 if ($type eq "G") { $subsystemtype = "-subsystem windows"; }
1095 my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1096 print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1100 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "lcc")) {
1101 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1103 if ($d->{obj} =~ /\.obj$/) {
1104 print &splitline("\tlcc -O -p6 \$(COMPAT) \$(FWHACK)".
1105 " \$(XFLAGS) \$(CFLAGS) ".$d->{deps}->[0],69)."\n";
1107 print &splitline("\tlrc \$(FWHACK) \$(RCFL) -r ".$d->{deps}->[0],69)."\n";
1111 print $makefile_extra{'lcc'};
1117 select STDOUT; close OUT;