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 "!begin") {
56 $divert = \$makefile_extra{$_[1]};
62 # If we're gathering help text, keep doing so.
63 if (defined $divert) { ${$divert} .= "$_\n"; next; }
65 next if scalar @_ == 0;
67 # Now we have an ordinary line. See if it's an = line, a : line
72 $listref = $lastlistref;
74 die "$.: unexpected + line\n" if !defined $lastlistref;
75 } elsif ($_[1] eq "=") {
76 $groups{$_[0]} = [] if !defined $groups{$_[0]};
77 $listref = $groups{$_[0]};
79 shift @objs; # eat the group name
80 } elsif ($_[1] eq ":") {
83 shift @objs; # eat the program name
85 die "$.: unrecognised line type\n";
87 shift @objs; # eat the +, the = or the :
89 while (scalar @objs > 0) {
92 foreach $j (@{$groups{$i}}) { unshift @objs, $j; }
93 } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or
94 $i eq "[X]" or $i eq "[U]") and defined $prog) {
95 $type = substr($i,1,1);
100 if ($prog and $type) {
101 die "multiple program entries for $prog [$type]\n"
102 if defined $programs{$prog . "," . $type};
103 $programs{$prog . "," . $type} = $listref;
105 $lastlistref = $listref;
110 # Now retrieve the complete list of objects and resource files, and
111 # construct dependency data for them. While we're here, expand the
112 # object list for each program, and complain if its type isn't set.
113 @prognames = sort keys %programs;
116 foreach $i (@prognames) {
117 ($prog, $type) = split ",", $i;
118 # Strip duplicate object names.
120 @list = grep { $status = ($prev ne $_); $prev=$_; $status }
121 sort @{$programs{$i}};
122 $programs{$i} = [@list];
124 # Dependencies for "x" start with "x.c".
125 # Dependencies for "x.res" start with "x.rc".
126 # Dependencies for "x.rsrc" start with "x.r".
127 # Both types of file are pushed on the list of files to scan.
128 # Libraries (.lib) don't have dependencies at all.
129 if ($j =~ /^(.*)\.res$/) {
131 $depends{$j} = [$file];
132 push @scanlist, $file;
133 } elsif ($j =~ /^(.*)\.rsrc$/) {
135 $depends{$j} = [$file];
136 push @scanlist, $file;
137 } elsif ($j =~ /\.lib$/) {
138 # libraries don't have dependencies
141 $depends{$j} = [$file];
142 push @scanlist, $file;
147 # Scan each file on @scanlist and find further inclusions.
148 # Inclusions are given by lines of the form `#include "otherfile"'
149 # (system headers are automatically ignored by this because they'll
150 # be given in angle brackets). Files included by this method are
151 # added back on to @scanlist to be scanned in turn (if not already
154 # Resource scripts (.rc) can also include a file by means of a line
155 # ending `ICON "filename"'. Files included by this method are not
156 # added to @scanlist because they can never include further files.
158 # In this pass we write out a hash %further which maps a source
159 # file name into a listref containing further source file names.
162 while (scalar @scanlist > 0) {
163 $file = shift @scanlist;
164 next if defined $further{$file}; # skip if we've already done it
165 $resource = ($file =~ /\.rc$/ ? 1 : 0);
166 $further{$file} = [];
167 $dirfile = &findfile($file);
168 open IN, "$dirfile" or die "unable to open source file $file\n";
171 /^\s*#include\s+\"([^\"]+)\"/ and do {
172 push @{$further{$file}}, $1;
176 /ICON\s+\"([^\"]+)\"\s*$/ and do {
177 push @{$further{$file}}, $1;
184 # Now we're ready to generate the final dependencies section. For
185 # each key in %depends, we must expand the dependencies list by
186 # iteratively adding entries from %further.
187 foreach $i (keys %depends) {
189 @scanlist = @{$depends{$i}};
190 foreach $i (@scanlist) { $dep{$i} = 1; }
191 while (scalar @scanlist > 0) {
192 $file = shift @scanlist;
193 foreach $j (@{$further{$file}}) {
196 push @{$depends{$i}}, $j;
201 # printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
204 # Validation of input.
208 # Returns true if the argument is a known makefile type. Otherwise,
209 # prints a warning and returns false;
210 if (grep { $type eq $_ }
211 ("vc","vcproj","cygwin","borland","lcc","gtk","mpw")) {
214 warn "$.:unknown makefile type '$type'\n";
218 # Utility routines while writing out the Makefiles.
221 my ($path) = shift @_;
222 my ($sep) = shift @_;
224 while (($i = index $path, $sep) >= 0) {
225 $path = substr $path, ($i + length $sep);
233 my $dir, $i, $outdir = "";
234 unless (defined $findfilecache{$name}) {
236 foreach $dir (@srcdirs) {
237 $outdir = $dir, $i++ if -f "$dir$name";
239 die "multiple instances of source file $name\n" if $i > 1;
240 $findfilecache{$name} = $outdir . $name;
242 return $findfilecache{$name};
246 my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
250 foreach $i (@{$programs{$prog}}) {
252 if ($i =~ /^(.*)\.(res|rsrc)/) {
254 ($x = $rtmpl) =~ s/X/$y/;
255 } elsif ($i =~ /^(.*)\.lib/) {
257 ($x = $ltmpl) =~ s/X/$y/;
259 ($x = $otmpl) =~ s/X/$i/;
261 push @ret, $x if $x ne "";
263 return join " ", @ret;
267 my ($line, $width, $splitchar) = @_;
269 $len = (defined $width ? $width : 76);
270 $splitchar = (defined $splitchar ? $splitchar : '\\');
271 while (length $line > $len) {
272 $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
273 $result .= $1 . " ${splitchar}\n\t\t";
277 return $result . $line;
281 my ($otmpl, $rtmpl, $prefix, $dirsep, $depchar, $splitchar) = @_;
286 foreach $i (sort keys %depends) {
287 if ($i =~ /^(.*)\.(res|rsrc)/) {
288 next if !defined $rtmpl;
290 ($x = $rtmpl) =~ s/X/$y/;
292 ($x = $otmpl) =~ s/X/$i/;
294 @deps = @{$depends{$i}};
300 push @ret, {obj => $x, deps => [@deps]};
307 my ($n, $prog, $type);
310 foreach $n (@prognames) {
311 ($prog, $type) = split ",", $n;
312 push @ret, $n if index($types, $type) >= 0;
319 my ($n, $prog, $type);
322 foreach $n (@prognames) {
323 ($prog, $type) = split ",", $n;
324 push @ret, $prog if index($types, $type) >= 0;
330 my ($types,$suffix) = @_;
332 # assume that all UNIX programs have a man page
333 if($suffix eq "1" && $types =~ /X/) {
334 return map("$_.1", &progrealnames($types));
339 # Now we're ready to output the actual Makefiles.
341 if (defined $makefiles{'cygwin'}) {
342 $dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
345 open OUT, ">$makefiles{'cygwin'}"; select OUT;
347 "# Makefile for $project_name under cygwin.\n".
348 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
349 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
350 # gcc command line option is -D not /D
351 ($_ = $help) =~ s/=\/D/=-D/gs;
355 "# You can define this path to point at your tools if you need to\n".
356 "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
357 "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
358 "CC = \$(TOOLPATH)gcc\n".
359 "RC = \$(TOOLPATH)windres\n".
360 "# Uncomment the following two lines to compile under Winelib\n".
363 "# You may also need to tell windres where to find include files:\n".
364 "# RCINC = --include-dir c:\\cygwin\\include\\\n".
366 &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
367 " -D_NO_OLDNAMES -DNO_MULTIMON " .
368 (join " ", map {"-I$dirpfx$_"} @srcdirs)) .
370 "LDFLAGS = -mno-cygwin -s\n".
371 &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1".
372 " --define WINVER=0x0400 --define MINGW32_FIX=1")."\n".
377 "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
380 "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n".
382 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
384 foreach $p (&prognames("GC")) {
385 ($prog, $type) = split ",", $p;
386 $objstr = &objects($p, "X.o", "X.res.o", undef);
387 print &splitline($prog . ".exe: " . $objstr), "\n";
388 my $mw = $type eq "G" ? " -mwindows" : "";
389 $libstr = &objects($p, undef, undef, "-lX");
390 print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
391 "-Wl,-Map,$prog.map " .
392 $objstr . " $libstr", 69), "\n\n";
394 foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/")) {
395 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
399 print $makefile_extra{'cygwin'};
401 "\trm -f *.o *.exe *.res.o *.map\n".
403 select STDOUT; close OUT;
407 ##-- Borland makefile
408 if (defined $makefiles{'borland'}) {
409 $dirpfx = &dirpfx($makefiles{'borland'}, "\\");
411 %stdlibs = ( # Borland provides many Win32 API libraries intrinsically
423 open OUT, ">$makefiles{'borland'}"; select OUT;
425 "# Makefile for $project_name under Borland C.\n".
426 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
427 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
428 # bcc32 command line option is -D not /D
429 ($_ = $help) =~ s/=\/D/=-D/gs;
433 "# If you rename this file to `Makefile', you should change this line,\n".
434 "# so that the .rsp files still depend on the correct makefile.\n".
435 "MAKEFILE = Makefile.bor\n".
437 "# C compilation flags\n".
438 "CFLAGS = -D_WINDOWS -DWINVER=0x0401\n".
440 "# Get include directory for resource compiler\n".
442 "BCB = \$(MAKEDIR)\\..\n".
446 &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT) \$(FWHACK)".
447 " \$(XFLAGS) \$(CFLAGS) ".
448 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
449 " /c \$*.c",69)."\n".
451 &splitline("\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include -r".
452 " -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n".
454 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
456 foreach $p (&prognames("GC")) {
457 ($prog, $type) = split ",", $p;
458 $objstr = &objects($p, "X.obj", "X.res", undef);
459 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
460 my $ap = ($type eq "G") ? "-aa" : "-ap";
461 print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n";
463 foreach $p (&prognames("GC")) {
464 ($prog, $type) = split ",", $p;
465 print $prog, ".rsp: \$(MAKEFILE)\n";
466 $objstr = &objects($p, "X.obj", undef, undef);
467 @objlist = split " ", $objstr;
469 foreach $i (@objlist) {
470 if (length($objlines[$#objlines] . " $i") > 50) {
473 $objlines[$#objlines] .= " $i";
475 $c0w = ($type eq "G") ? "c0w32" : "c0x32";
476 print "\techo $c0w + > $prog.rsp\n";
477 for ($i=0; $i<=$#objlines; $i++) {
478 $plus = ($i < $#objlines ? " +" : "");
479 print "\techo$objlines[$i]$plus >> $prog.rsp\n";
481 print "\techo $prog.exe >> $prog.rsp\n";
482 $objstr = &objects($p, "X.obj", "X.res", undef);
483 @libs = split " ", &objects($p, undef, undef, "X");
484 @libs = grep { !$stdlibs{$_} } @libs;
485 unshift @libs, "cw32", "import32";
486 $libstr = join ' ', @libs;
487 print "\techo nul,$libstr, >> $prog.rsp\n";
488 print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n";
491 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
492 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
496 print $makefile_extra{'borland'};
507 "\t-del *.\$\$\$\$\$\$\n";
508 select STDOUT; close OUT;
511 if (defined $makefiles{'vc'}) {
512 $dirpfx = &dirpfx($makefiles{'vc'}, "\\");
514 ##-- Visual C++ makefile
515 open OUT, ">$makefiles{'vc'}"; select OUT;
517 "# Makefile for $project_name under Visual C.\n".
518 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
519 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
523 "# If you rename this file to `Makefile', you should change this line,\n".
524 "# so that the .rsp files still depend on the correct makefile.\n".
525 "MAKEFILE = Makefile.vc\n".
527 "# C compilation flags\n".
528 "CFLAGS = /nologo /W3 /O1 /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401\n".
529 "LFLAGS = /incremental:no /fixed\n".
532 "\tcl \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) /c \$*.c\n".
534 "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 -DWINVER=0x0400 \$*.rc\n".
536 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
538 foreach $p (&prognames("GC")) {
539 ($prog, $type) = split ",", $p;
540 $objstr = &objects($p, "X.obj", "X.res", undef);
541 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
542 print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
544 foreach $p (&prognames("GC")) {
545 ($prog, $type) = split ",", $p;
546 print $prog, ".rsp: \$(MAKEFILE)\n";
547 $objstr = &objects($p, "X.obj", "X.res", "X.lib");
548 @objlist = split " ", $objstr;
550 foreach $i (@objlist) {
551 if (length($objlines[$#objlines] . " $i") > 50) {
554 $objlines[$#objlines] .= " $i";
556 $subsys = ($type eq "G") ? "windows" : "console";
557 print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
558 for ($i=0; $i<=$#objlines; $i++) {
559 print "\techo$objlines[$i] >> $prog.rsp\n";
563 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
564 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
568 print $makefile_extra{'vc'};
569 print "\nclean: tidy\n".
586 "\t-del debug.log\n";
587 select STDOUT; close OUT;
590 if (defined $makefiles{'vcproj'}) {
594 ##-- MSVC 6 Workspace and projects
596 # Note: All files created in this section are written in binary
597 # mode, because although MSVC's command-line make can deal with
598 # LF-only line endings, MSVC project files really _need_ to be
599 # CRLF. Hence, in order for mkfiles.pl to generate usable project
600 # files even when run from Unix, I make sure all files are binary
601 # and explicitly write the CRLFs.
603 # Create directories if necessary
604 mkdir $makefiles{'vcproj'}
605 if(! -d $makefiles{'vcproj'});
606 chdir $makefiles{'vcproj'};
607 @deps = &deps("X.obj", "X.res", "", "\\");
608 %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
609 # Create the project files
610 # Get names of all Windows projects (GUI and console)
611 my @prognames = &prognames("GC");
612 foreach $progname (@prognames) {
613 create_project(\%all_object_deps, $progname);
615 # Create the workspace file
616 open OUT, ">$project_name.dsw"; binmode OUT; select OUT;
618 "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
619 "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
621 "###############################################################################\r\n".
624 foreach $progname (@prognames) {
625 ($windows_project, $type) = split ",", $progname;
626 print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n";
638 "###############################################################################\r\n".
650 "###############################################################################\r\n".
652 select STDOUT; close OUT;
656 my ($all_object_deps, $progname) = @_;
657 # Construct program's dependency info
662 %resource_files = ();
663 @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
664 foreach $object_file (@object_files) {
665 next if defined $seen_objects{$object_file};
666 $seen_objects{$object_file} = 1;
667 if($object_file =~ /\.lib$/io) {
668 $lib_files{$object_file} = 1;
671 $object_deps = $all_object_deps{$object_file};
672 foreach $object_dep (@$object_deps) {
673 if($object_dep =~ /\.c$/io) {
674 $source_files{$object_dep} = 1;
677 if($object_dep =~ /\.h$/io) {
678 $header_files{$object_dep} = 1;
681 if($object_dep =~ /\.(rc|ico)$/io) {
682 $resource_files{$object_dep} = 1;
687 $libs = join " ", sort keys %lib_files;
688 @source_files = sort keys %source_files;
689 @header_files = sort keys %header_files;
690 @resources = sort keys %resource_files;
691 ($windows_project, $type) = split ",", $progname;
692 mkdir $windows_project
693 if(! -d $windows_project);
694 chdir $windows_project;
695 $subsys = ($type eq "G") ? "windows" : "console";
696 open OUT, ">$windows_project.dsp"; binmode OUT; select OUT;
698 "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n".
699 "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n".
700 "# ** DO NOT EDIT **\r\n".
702 "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n".
704 "CFG=$windows_project - Win32 Debug\r\n".
705 "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n".
706 "!MESSAGE use the Export Makefile command and run\r\n".
708 "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n".
710 "!MESSAGE You can specify a configuration when running NMAKE\r\n".
711 "!MESSAGE by defining the macro CFG on the command line. For example:\r\n".
713 "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
715 "!MESSAGE Possible choices for configuration are:\r\n".
717 "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n".
718 "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n".
721 "# Begin Project\r\n".
722 "# PROP AllowPerConfigDependencies 0\r\n".
723 "# PROP Scc_ProjName \"\"\r\n".
724 "# PROP Scc_LocalPath \"\"\r\n".
729 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
731 "# PROP BASE Use_MFC 0\r\n".
732 "# PROP BASE Use_Debug_Libraries 0\r\n".
733 "# PROP BASE Output_Dir \"Release\"\r\n".
734 "# PROP BASE Intermediate_Dir \"Release\"\r\n".
735 "# PROP BASE Target_Dir \"\"\r\n".
736 "# PROP Use_MFC 0\r\n".
737 "# PROP Use_Debug_Libraries 0\r\n".
738 "# PROP Output_Dir \"Release\"\r\n".
739 "# PROP Intermediate_Dir \"Release\"\r\n".
740 "# PROP Ignore_Export_Lib 0\r\n".
741 "# PROP Target_Dir \"\"\r\n".
742 "# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
743 "# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
744 "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
745 "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
746 "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n".
747 "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n".
748 "BSC32=bscmake.exe\r\n".
749 "# ADD BASE BSC32 /nologo\r\n".
750 "# ADD BSC32 /nologo\r\n".
751 "LINK32=link.exe\r\n".
752 "# 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".
753 "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n".
754 "# SUBTRACT LINK32 /pdb:none\r\n".
756 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
758 "# PROP BASE Use_MFC 0\r\n".
759 "# PROP BASE Use_Debug_Libraries 1\r\n".
760 "# PROP BASE Output_Dir \"Debug\"\r\n".
761 "# PROP BASE Intermediate_Dir \"Debug\"\r\n".
762 "# PROP BASE Target_Dir \"\"\r\n".
763 "# PROP Use_MFC 0\r\n".
764 "# PROP Use_Debug_Libraries 1\r\n".
765 "# PROP Output_Dir \"Debug\"\r\n".
766 "# PROP Intermediate_Dir \"Debug\"\r\n".
767 "# PROP Ignore_Export_Lib 0\r\n".
768 "# PROP Target_Dir \"\"\r\n".
769 "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
770 "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
771 "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
772 "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
773 "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n".
774 "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n".
775 "BSC32=bscmake.exe\r\n".
776 "# ADD BASE BSC32 /nologo\r\n".
777 "# ADD BSC32 /nologo\r\n".
778 "LINK32=link.exe\r\n".
779 "# 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".
780 "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
781 "# SUBTRACT LINK32 /pdb:none\r\n".
785 "# Begin Target\r\n".
787 "# Name \"$windows_project - Win32 Release\"\r\n".
788 "# Name \"$windows_project - Win32 Debug\"\r\n".
789 "# Begin Group \"Source Files\"\r\n".
791 "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
792 foreach $source_file (@source_files) {
794 "# Begin Source File\r\n".
796 "SOURCE=..\\..\\$source_file\r\n";
797 if($source_file =~ /ssh\.c/io) {
798 # Disable 'Edit and continue' as Visual Studio can't handle the macros
801 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
803 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
810 print "# End Source File\r\n";
814 "# Begin Group \"Header Files\"\r\n".
816 "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
817 foreach $header_file (@header_files) {
819 "# Begin Source File\r\n".
821 "SOURCE=..\\..\\$header_file\r\n".
822 "# End Source File\r\n";
826 "# Begin Group \"Resource Files\"\r\n".
828 "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
829 foreach $resource_file (@resources) {
831 "# Begin Source File\r\n".
833 "SOURCE=..\\..\\$resource_file\r\n".
834 "# End Source File\r\n";
840 select STDOUT; close OUT;
845 if (defined $makefiles{'gtk'}) {
846 $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
848 ##-- X/GTK/Unix makefile
849 open OUT, ">$makefiles{'gtk'}"; select OUT;
851 "# Makefile for $project_name under X/GTK and Unix.\n".
852 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
853 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
854 # gcc command line option is -D not /D
855 ($_ = $help) =~ s/=\/D/=-D/gs;
859 "# You can define this path to point at your tools if you need to\n".
860 "# TOOLPATH = /opt/gcc/bin\n".
861 "CC = \$(TOOLPATH)cc\n".
863 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
864 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
865 " `gtk-config --cflags`")."\n".
866 "XLDFLAGS = `gtk-config --libs`\n".
869 "INSTALL_PROGRAM=\$(INSTALL)\n",
870 "INSTALL_DATA=\$(INSTALL)\n",
871 "prefix=/usr/local\n",
872 "exec_prefix=\$(prefix)\n",
873 "bindir=\$(exec_prefix)/bin\n",
874 "mandir=\$(prefix)/man\n",
875 "man1dir=\$(mandir)/man1\n",
880 "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
882 print &splitline("all:" . join "", map { " $_" } &progrealnames("XU"));
884 foreach $p (&prognames("XU")) {
885 ($prog, $type) = split ",", $p;
886 $objstr = &objects($p, "X.o", undef, undef);
887 print &splitline($prog . ": " . $objstr), "\n";
888 $libstr = &objects($p, undef, undef, "-lX");
889 print &splitline("\t\$(CC)" . $mw . " \$(${type}LDFLAGS) -o \$@ " .
890 $objstr . " $libstr", 69), "\n\n";
892 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
893 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
897 print $makefile_extra{'gtk'};
899 "\trm -f *.o". (join "", map { " $_" } &progrealnames("XU")) . "\n";
900 select STDOUT; close OUT;
903 if (defined $makefiles{'mpw'}) {
905 open OUT, ">$makefiles{'mpw'}"; select OUT;
907 "# Makefile for $project_name under MPW.\n#\n".
908 "# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
909 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
910 # MPW command line option is -d not /D
911 ($_ = $help) =~ s/=\/D/=-d /gs;
914 "ROptions = `Echo \"{VER}\" | StreamEdit -e \"1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6\"' \xa81 '\xb6\xb6\xb6\xb6\xb6\"'\"`".
919 "C_Carbon = {PPCC}\n".
921 "# -w 35 disables \"unused parameter\" warnings\n".
922 "COptions = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6\n".
924 "COptions_68K = {COptions} -model far -opt time\n".
925 "# Enabling \"-opt space\" for CFM-68K gives me undefined references to\n".
926 "# _\$LDIVT and _\$LMODT.\n".
927 "COptions_CFM68K = {COptions} -model cfmSeg -opt time\n".
928 "COptions_PPC = {COptions} -opt size -traceback\n".
929 "COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON\n".
931 "Link_68K = ILink\n".
932 "Link_CFM68K = ILink\n".
933 "Link_PPC = PPCLink\n".
934 "Link_Carbon = PPCLink\n".
936 "LinkOptions = -c 'pTTY'\n".
937 "LinkOptions_68K = {LinkOptions} -br 68k -model far -compact\n".
938 "LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact\n".
939 "LinkOptions_PPC = {LinkOptions}\n".
940 "LinkOptions_Carbon = -m __appstart -w {LinkOptions}\n".
942 "Libs_68K = \"{CLibraries}StdCLib.far.o\" \xb6\n".
943 " \"{Libraries}MacRuntime.o\" \xb6\n".
944 " \"{Libraries}MathLib.far.o\" \xb6\n".
945 " \"{Libraries}IntEnv.far.o\" \xb6\n".
946 " \"{Libraries}Interface.o\" \xb6\n".
947 " \"{Libraries}Navigation.far.o\" \xb6\n".
948 " \"{Libraries}OpenTransport.o\" \xb6\n".
949 " \"{Libraries}OpenTransportApp.o\" \xb6\n".
950 " \"{Libraries}OpenTptInet.o\" \xb6\n".
951 " \"{Libraries}UnicodeConverterLib.far.o\"\n".
953 "Libs_CFM = \"{SharedLibraries}InterfaceLib\" \xb6\n".
954 " \"{SharedLibraries}StdCLib\" \xb6\n".
955 " \"{SharedLibraries}AppearanceLib\" \xb6\n".
956 " -weaklib AppearanceLib \xb6\n".
957 " \"{SharedLibraries}NavigationLib\" \xb6\n".
958 " -weaklib NavigationLib \xb6\n".
959 " \"{SharedLibraries}TextCommon\" \xb6\n".
960 " -weaklib TextCommon \xb6\n".
961 " \"{SharedLibraries}UnicodeConverter\" \xb6\n".
962 " -weaklib UnicodeConverter\n".
964 "Libs_CFM68K = {Libs_CFM} \xb6\n".
965 " \"{CFM68KLibraries}NuMacRuntime.o\"\n".
967 "Libs_PPC = {Libs_CFM} \xb6\n".
968 " \"{SharedLibraries}ControlsLib\" \xb6\n".
969 " -weaklib ControlsLib \xb6\n".
970 " \"{SharedLibraries}WindowsLib\" \xb6\n".
971 " -weaklib WindowsLib \xb6\n".
972 " \"{SharedLibraries}OpenTransportLib\" \xb6\n".
973 " -weaklib OTClientLib \xb6\n".
974 " -weaklib OTClientUtilLib \xb6\n".
975 " \"{SharedLibraries}OpenTptInternetLib\" \xb6\n".
976 " -weaklib OTInetClientLib \xb6\n".
977 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
978 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
979 " \"{PPCLibraries}CarbonAccessors.o\" \xb6\n".
980 " \"{PPCLibraries}OpenTransportAppPPC.o\" \xb6\n".
981 " \"{PPCLibraries}OpenTptInetPPC.o\"\n".
983 "Libs_Carbon = \"{PPCLibraries}CarbonStdCLib.o\" \xb6\n".
984 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
985 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
986 " \"{SharedLibraries}CarbonLib\" \xb6\n".
987 " \"{SharedLibraries}StdCLib\"\n".
989 print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6");
991 foreach $p (&prognames("M")) {
992 ($prog, $type) = split ",", $p;
994 print &splitline("$prog \xc4 $prog.68k $prog.ppc $prog.carbon",
995 undef, "\xb6"), "\n\n";
997 $rsrc = &objects($p, "", "X.rsrc", undef);
999 foreach $arch (qw(68K CFM68K PPC Carbon)) {
1000 $objstr = &objects($p, "X.\L$arch\E.o", "", undef);
1001 print &splitline("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6");
1003 print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
1004 print &splitline("\t{Link_$arch} -o {Targ} -fragname $prog " .
1005 "{LinkOptions_$arch} " .
1006 $objstr . " {Libs_$arch}", 69, "\xb6"), "\n";
1007 print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
1011 foreach $d (&deps("", "X.rsrc", "::", ":")) {
1012 next unless $d->{obj};
1013 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
1014 undef, "\xb6"), "\n";
1015 print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n";
1017 foreach $arch (qw(68K CFM68K)) {
1018 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1019 next unless $d->{obj};
1020 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1021 join " ", @{$d->{deps}}),
1022 undef, "\xb6"), "\n";
1023 print "\t{C_$arch} ", $d->{deps}->[0],
1024 " -o {Targ} {COptions_$arch}\n\n";
1027 foreach $arch (qw(PPC Carbon)) {
1028 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1029 next unless $d->{obj};
1030 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1031 join " ", @{$d->{deps}}),
1032 undef, "\xb6"), "\n";
1033 # The odd stuff here seems to stop afpd getting confused.
1034 print "\techo -n > {Targ}\n";
1035 print "\tsetfile -t XCOF {Targ}\n";
1036 print "\t{C_$arch} ", $d->{deps}->[0],
1037 " -o {Targ} {COptions_$arch}\n\n";
1040 select STDOUT; close OUT;
1043 if (defined $makefiles{'lcc'}) {
1044 $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
1047 open OUT, ">$makefiles{'lcc'}"; select OUT;
1049 "# Makefile for $project_name under lcc.\n".
1050 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1051 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1052 # lcc command line option is -D not /D
1053 ($_ = $help) =~ s/=\/D/=-D/gs;
1057 "# If you rename this file to `Makefile', you should change this line,\n".
1058 "# so that the .rsp files still depend on the correct makefile.\n".
1059 "MAKEFILE = Makefile.lcc\n".
1061 "# C compilation flags\n".
1062 "CFLAGS = -D_WINDOWS " .
1063 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1066 "# Get include directory for resource compiler\n".
1069 &splitline("\tlcc -O -p6 \$(COMPAT) \$(FWHACK)".
1070 " \$(XFLAGS) \$(CFLAGS) \$*.c",69)."\n".
1072 &splitline("\tlrc \$(FWHACK) \$(RCFL) -r \$*.rc",69)."\n".
1074 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
1076 foreach $p (&prognames("GC")) {
1077 ($prog, $type) = split ",", $p;
1078 $objstr = &objects($p, "X.obj", "X.res", undef);
1079 print &splitline("$prog.exe: " . $objstr ), "\n";
1080 $subsystemtype = undef;
1081 if ($type eq "G") { $subsystemtype = "-subsystem windows"; }
1082 my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1083 print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1087 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
1088 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1092 print $makefile_extra{'lcc'};
1098 select STDOUT; close OUT;