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]" or $i eq "[MX]") and defined $prog) {
95 $type = substr($i,1,(length $i)-2);
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" or "x.m" (depending on
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 $file = "$j.m" unless &findfile
($file);
143 $depends{$j} = [$file];
144 push @scanlist, $file;
149 # Scan each file on @scanlist and find further inclusions.
150 # Inclusions are given by lines of the form `#include "otherfile"'
151 # (system headers are automatically ignored by this because they'll
152 # be given in angle brackets). Files included by this method are
153 # added back on to @scanlist to be scanned in turn (if not already
156 # Resource scripts (.rc) can also include a file by means of a line
157 # ending `ICON "filename"'. Files included by this method are not
158 # added to @scanlist because they can never include further files.
160 # In this pass we write out a hash %further which maps a source
161 # file name into a listref containing further source file names.
164 while (scalar @scanlist > 0) {
165 $file = shift @scanlist;
166 next if defined $further{$file}; # skip if we've already done it
167 $resource = ($file =~ /\.rc$/ ?
1 : 0);
168 $further{$file} = [];
169 $dirfile = &findfile
($file);
170 open IN
, "$dirfile" or die "unable to open source file $file\n";
173 /^\s*#include\s+\"([^\"]+)\"/ and do {
174 push @
{$further{$file}}, $1;
178 /ICON\s+\"([^\"]+)\"\s*$/ and do {
179 push @
{$further{$file}}, $1;
186 # Now we're ready to generate the final dependencies section. For
187 # each key in %depends, we must expand the dependencies list by
188 # iteratively adding entries from %further.
189 foreach $i (keys %depends) {
191 @scanlist = @
{$depends{$i}};
192 foreach $i (@scanlist) { $dep{$i} = 1; }
193 while (scalar @scanlist > 0) {
194 $file = shift @scanlist;
195 foreach $j (@
{$further{$file}}) {
198 push @
{$depends{$i}}, $j;
203 # printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
206 # Validation of input.
210 # Returns true if the argument is a known makefile type. Otherwise,
211 # prints a warning and returns false;
212 if (grep { $type eq $_ }
213 ("vc","vcproj","cygwin","borland","lcc","gtk","mpw","osx")) {
216 warn "$.:unknown makefile type '$type'\n";
220 # Utility routines while writing out the Makefiles.
223 my ($path) = shift @_;
224 my ($sep) = shift @_;
226 while (($i = index $path, $sep) >= 0) {
227 $path = substr $path, ($i + length $sep);
238 unless (defined $findfilecache{$name}) {
240 foreach $dir (@srcdirs) {
241 $outdir = $dir, $i++ if -f
"$dir$name";
243 die "multiple instances of source file $name\n" if $i > 1;
244 $findfilecache{$name} = (defined $outdir ?
$outdir . $name : undef);
246 return $findfilecache{$name};
250 my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
254 foreach $i (@
{$programs{$prog}}) {
256 if ($i =~ /^(.*)\.(res|rsrc)/) {
258 ($x = $rtmpl) =~ s/X/$y/;
259 } elsif ($i =~ /^(.*)\.lib/) {
261 ($x = $ltmpl) =~ s/X/$y/;
263 ($x = $otmpl) =~ s/X/$i/;
265 push @ret, $x if $x ne "";
267 return join " ", @ret;
271 my ($line, $width, $splitchar) = @_;
273 $len = (defined $width ?
$width : 76);
274 $splitchar = (defined $splitchar ?
$splitchar : '\\');
275 while (length $line > $len) {
276 $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
277 $result .= $1 . " ${splitchar}\n\t\t";
281 return $result . $line;
285 my ($otmpl, $rtmpl, $prefix, $dirsep, $depchar, $splitchar) = @_;
290 foreach $i (sort keys %depends) {
291 if ($i =~ /^(.*)\.(res|rsrc)/) {
292 next if !defined $rtmpl;
294 ($x = $rtmpl) =~ s/X/$y/;
296 ($x = $otmpl) =~ s/X/$i/;
298 @deps = @
{$depends{$i}};
304 push @ret, {obj
=> $x, deps
=> [@deps]};
311 my ($n, $prog, $type);
314 foreach $n (@prognames) {
315 ($prog, $type) = split ",", $n;
316 push @ret, $n if index(":$types:", ":$type:") >= 0;
323 my ($n, $prog, $type);
326 foreach $n (@prognames) {
327 ($prog, $type) = split ",", $n;
328 push @ret, $prog if index(":$types:", ":$type:") >= 0;
334 my ($types,$suffix) = @_;
336 # assume that all UNIX programs have a man page
337 if($suffix eq "1" && $types =~ /:X:/) {
338 return map("$_.1", &progrealnames
($types));
343 # Now we're ready to output the actual Makefiles.
345 if (defined $makefiles{'cygwin'}) {
346 $dirpfx = &dirpfx
($makefiles{'cygwin'}, "/");
349 open OUT
, ">$makefiles{'cygwin'}"; select OUT
;
351 "# Makefile for $project_name under cygwin.\n".
352 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
353 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
354 # gcc command line option is -D not /D
355 ($_ = $help) =~ s/=\/D/=-D
/gs
;
359 "# You can define this path to point at your tools if you need to\n".
360 "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
361 "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
362 "CC = \$(TOOLPATH)gcc\n".
363 "RC = \$(TOOLPATH)windres\n".
364 "# Uncomment the following two lines to compile under Winelib\n".
367 "# You may also need to tell windres where to find include files:\n".
368 "# RCINC = --include-dir c:\\cygwin\\include\\\n".
370 &splitline
("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
371 " -D_NO_OLDNAMES -DNO_MULTIMON " .
372 (join " ", map {"-I$dirpfx$_"} @srcdirs)) .
374 "LDFLAGS = -mno-cygwin -s\n".
375 &splitline
("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1".
376 " --define WINVER=0x0400 --define MINGW32_FIX=1")."\n".
381 "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
384 "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n".
386 print &splitline
("all:" . join "", map { " $_.exe" } &progrealnames
("G:C"));
388 foreach $p (&prognames
("G:C")) {
389 ($prog, $type) = split ",", $p;
390 $objstr = &objects
($p, "X.o", "X.res.o", undef);
391 print &splitline
($prog . ".exe: " . $objstr), "\n";
392 my $mw = $type eq "G" ?
" -mwindows" : "";
393 $libstr = &objects
($p, undef, undef, "-lX");
394 print &splitline
("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
395 "-Wl,-Map,$prog.map " .
396 $objstr . " $libstr", 69), "\n\n";
398 foreach $d (&deps
("X.o", "X.res.o", $dirpfx, "/")) {
399 print &splitline
(sprintf("%s: %s", $d->{obj
}, join " ", @
{$d->{deps
}})),
403 print $makefile_extra{'cygwin'};
405 "\trm -f *.o *.exe *.res.o *.map\n".
407 select STDOUT
; close OUT
;
411 ##-- Borland makefile
412 if (defined $makefiles{'borland'}) {
413 $dirpfx = &dirpfx
($makefiles{'borland'}, "\\");
415 %stdlibs = ( # Borland provides many Win32 API libraries intrinsically
427 open OUT
, ">$makefiles{'borland'}"; select OUT
;
429 "# Makefile for $project_name under Borland C.\n".
430 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
431 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
432 # bcc32 command line option is -D not /D
433 ($_ = $help) =~ s/=\/D/=-D
/gs
;
437 "# If you rename this file to `Makefile', you should change this line,\n".
438 "# so that the .rsp files still depend on the correct makefile.\n".
439 "MAKEFILE = Makefile.bor\n".
441 "# C compilation flags\n".
442 "CFLAGS = -D_WINDOWS -DWINVER=0x0401\n".
444 "# Get include directory for resource compiler\n".
446 "BCB = \$(MAKEDIR)\\..\n".
450 &splitline
("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT) \$(FWHACK)".
451 " \$(XFLAGS) \$(CFLAGS) ".
452 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
453 " /c \$*.c",69)."\n".
455 &splitline
("\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include -r".
456 " -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n".
458 print &splitline
("all:" . join "", map { " $_.exe" } &progrealnames
("G:C"));
460 foreach $p (&prognames
("G:C")) {
461 ($prog, $type) = split ",", $p;
462 $objstr = &objects
($p, "X.obj", "X.res", undef);
463 print &splitline
("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
464 my $ap = ($type eq "G") ?
"-aa" : "-ap";
465 print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n";
467 foreach $p (&prognames
("G:C")) {
468 ($prog, $type) = split ",", $p;
469 print $prog, ".rsp: \$(MAKEFILE)\n";
470 $objstr = &objects
($p, "X.obj", undef, undef);
471 @objlist = split " ", $objstr;
473 foreach $i (@objlist) {
474 if (length($objlines[$#objlines] . " $i") > 50) {
477 $objlines[$#objlines] .= " $i";
479 $c0w = ($type eq "G") ?
"c0w32" : "c0x32";
480 print "\techo $c0w + > $prog.rsp\n";
481 for ($i=0; $i<=$#objlines; $i++) {
482 $plus = ($i < $#objlines ?
" +" : "");
483 print "\techo$objlines[$i]$plus >> $prog.rsp\n";
485 print "\techo $prog.exe >> $prog.rsp\n";
486 $objstr = &objects
($p, "X.obj", "X.res", undef);
487 @libs = split " ", &objects
($p, undef, undef, "X");
488 @libs = grep { !$stdlibs{$_} } @libs;
489 unshift @libs, "cw32", "import32";
490 $libstr = join ' ', @libs;
491 print "\techo nul,$libstr, >> $prog.rsp\n";
492 print "\techo " . &objects
($p, undef, "X.res", undef) . " >> $prog.rsp\n";
495 foreach $d (&deps
("X.obj", "X.res", $dirpfx, "\\")) {
496 print &splitline
(sprintf("%s: %s", $d->{obj
}, join " ", @
{$d->{deps
}})),
500 print $makefile_extra{'borland'};
511 "\t-del *.\$\$\$\$\$\$\n";
512 select STDOUT
; close OUT
;
515 if (defined $makefiles{'vc'}) {
516 $dirpfx = &dirpfx
($makefiles{'vc'}, "\\");
518 ##-- Visual C++ makefile
519 open OUT
, ">$makefiles{'vc'}"; select OUT
;
521 "# Makefile for $project_name under Visual C.\n".
522 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
523 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
527 "# If you rename this file to `Makefile', you should change this line,\n".
528 "# so that the .rsp files still depend on the correct makefile.\n".
529 "MAKEFILE = Makefile.vc\n".
531 "# C compilation flags\n".
532 "CFLAGS = /nologo /W3 /O1 /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401\n".
533 "LFLAGS = /incremental:no /fixed\n".
536 "\tcl \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) /c \$*.c\n".
538 "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 -DWINVER=0x0400 \$*.rc\n".
540 print &splitline
("all:" . join "", map { " $_.exe" } &progrealnames
("G:C"));
542 foreach $p (&prognames
("G:C")) {
543 ($prog, $type) = split ",", $p;
544 $objstr = &objects
($p, "X.obj", "X.res", undef);
545 print &splitline
("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
546 print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
548 foreach $p (&prognames
("G:C")) {
549 ($prog, $type) = split ",", $p;
550 print $prog, ".rsp: \$(MAKEFILE)\n";
551 $objstr = &objects
($p, "X.obj", "X.res", "X.lib");
552 @objlist = split " ", $objstr;
554 foreach $i (@objlist) {
555 if (length($objlines[$#objlines] . " $i") > 50) {
558 $objlines[$#objlines] .= " $i";
560 $subsys = ($type eq "G") ?
"windows" : "console";
561 print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
562 for ($i=0; $i<=$#objlines; $i++) {
563 print "\techo$objlines[$i] >> $prog.rsp\n";
567 foreach $d (&deps
("X.obj", "X.res", $dirpfx, "\\")) {
568 print &splitline
(sprintf("%s: %s", $d->{obj
}, join " ", @
{$d->{deps
}})),
572 print $makefile_extra{'vc'};
573 print "\nclean: tidy\n".
590 "\t-del debug.log\n";
591 select STDOUT
; close OUT
;
594 if (defined $makefiles{'vcproj'}) {
598 ##-- MSVC 6 Workspace and projects
600 # Note: All files created in this section are written in binary
601 # mode, because although MSVC's command-line make can deal with
602 # LF-only line endings, MSVC project files really _need_ to be
603 # CRLF. Hence, in order for mkfiles.pl to generate usable project
604 # files even when run from Unix, I make sure all files are binary
605 # and explicitly write the CRLFs.
607 # Create directories if necessary
608 mkdir $makefiles{'vcproj'}
609 if(! -d
$makefiles{'vcproj'});
610 chdir $makefiles{'vcproj'};
611 @deps = &deps
("X.obj", "X.res", "", "\\");
612 %all_object_deps = map {$_->{obj
} => $_->{deps
}} @deps;
613 # Create the project files
614 # Get names of all Windows projects (GUI and console)
615 my @prognames = &prognames
("G:C");
616 foreach $progname (@prognames) {
617 create_project
(\
%all_object_deps, $progname);
619 # Create the workspace file
620 open OUT
, ">$project_name.dsw"; binmode OUT
; select OUT
;
622 "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
623 "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
625 "###############################################################################\r\n".
628 foreach $progname (@prognames) {
629 ($windows_project, $type) = split ",", $progname;
630 print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n";
642 "###############################################################################\r\n".
654 "###############################################################################\r\n".
656 select STDOUT
; close OUT
;
660 my ($all_object_deps, $progname) = @_;
661 # Construct program's dependency info
666 %resource_files = ();
667 @object_files = split " ", &objects
($progname, "X.obj", "X.res", "X.lib");
668 foreach $object_file (@object_files) {
669 next if defined $seen_objects{$object_file};
670 $seen_objects{$object_file} = 1;
671 if($object_file =~ /\.lib$/io) {
672 $lib_files{$object_file} = 1;
675 $object_deps = $all_object_deps{$object_file};
676 foreach $object_dep (@
$object_deps) {
677 if($object_dep =~ /\.c$/io) {
678 $source_files{$object_dep} = 1;
681 if($object_dep =~ /\.h$/io) {
682 $header_files{$object_dep} = 1;
685 if($object_dep =~ /\.(rc|ico)$/io) {
686 $resource_files{$object_dep} = 1;
691 $libs = join " ", sort keys %lib_files;
692 @source_files = sort keys %source_files;
693 @header_files = sort keys %header_files;
694 @resources = sort keys %resource_files;
695 ($windows_project, $type) = split ",", $progname;
696 mkdir $windows_project
697 if(! -d
$windows_project);
698 chdir $windows_project;
699 $subsys = ($type eq "G") ?
"windows" : "console";
700 open OUT
, ">$windows_project.dsp"; binmode OUT
; select OUT
;
702 "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n".
703 "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n".
704 "# ** DO NOT EDIT **\r\n".
706 "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n".
708 "CFG=$windows_project - Win32 Debug\r\n".
709 "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n".
710 "!MESSAGE use the Export Makefile command and run\r\n".
712 "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n".
714 "!MESSAGE You can specify a configuration when running NMAKE\r\n".
715 "!MESSAGE by defining the macro CFG on the command line. For example:\r\n".
717 "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
719 "!MESSAGE Possible choices for configuration are:\r\n".
721 "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n".
722 "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n".
725 "# Begin Project\r\n".
726 "# PROP AllowPerConfigDependencies 0\r\n".
727 "# PROP Scc_ProjName \"\"\r\n".
728 "# PROP Scc_LocalPath \"\"\r\n".
733 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
735 "# PROP BASE Use_MFC 0\r\n".
736 "# PROP BASE Use_Debug_Libraries 0\r\n".
737 "# PROP BASE Output_Dir \"Release\"\r\n".
738 "# PROP BASE Intermediate_Dir \"Release\"\r\n".
739 "# PROP BASE Target_Dir \"\"\r\n".
740 "# PROP Use_MFC 0\r\n".
741 "# PROP Use_Debug_Libraries 0\r\n".
742 "# PROP Output_Dir \"Release\"\r\n".
743 "# PROP Intermediate_Dir \"Release\"\r\n".
744 "# PROP Ignore_Export_Lib 0\r\n".
745 "# PROP Target_Dir \"\"\r\n".
746 "# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
747 "# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
748 "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
749 "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
750 "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n".
751 "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n".
752 "BSC32=bscmake.exe\r\n".
753 "# ADD BASE BSC32 /nologo\r\n".
754 "# ADD BSC32 /nologo\r\n".
755 "LINK32=link.exe\r\n".
756 "# 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".
757 "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n".
758 "# SUBTRACT LINK32 /pdb:none\r\n".
760 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
762 "# PROP BASE Use_MFC 0\r\n".
763 "# PROP BASE Use_Debug_Libraries 1\r\n".
764 "# PROP BASE Output_Dir \"Debug\"\r\n".
765 "# PROP BASE Intermediate_Dir \"Debug\"\r\n".
766 "# PROP BASE Target_Dir \"\"\r\n".
767 "# PROP Use_MFC 0\r\n".
768 "# PROP Use_Debug_Libraries 1\r\n".
769 "# PROP Output_Dir \"Debug\"\r\n".
770 "# PROP Intermediate_Dir \"Debug\"\r\n".
771 "# PROP Ignore_Export_Lib 0\r\n".
772 "# PROP Target_Dir \"\"\r\n".
773 "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
774 "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
775 "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
776 "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
777 "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n".
778 "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n".
779 "BSC32=bscmake.exe\r\n".
780 "# ADD BASE BSC32 /nologo\r\n".
781 "# ADD BSC32 /nologo\r\n".
782 "LINK32=link.exe\r\n".
783 "# 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".
784 "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
785 "# SUBTRACT LINK32 /pdb:none\r\n".
789 "# Begin Target\r\n".
791 "# Name \"$windows_project - Win32 Release\"\r\n".
792 "# Name \"$windows_project - Win32 Debug\"\r\n".
793 "# Begin Group \"Source Files\"\r\n".
795 "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
796 foreach $source_file (@source_files) {
798 "# Begin Source File\r\n".
800 "SOURCE=..\\..\\$source_file\r\n";
801 if($source_file =~ /ssh\.c/io) {
802 # Disable 'Edit and continue' as Visual Studio can't handle the macros
805 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
807 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
814 print "# End Source File\r\n";
818 "# Begin Group \"Header Files\"\r\n".
820 "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
821 foreach $header_file (@header_files) {
823 "# Begin Source File\r\n".
825 "SOURCE=..\\..\\$header_file\r\n".
826 "# End Source File\r\n";
830 "# Begin Group \"Resource Files\"\r\n".
832 "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
833 foreach $resource_file (@resources) {
835 "# Begin Source File\r\n".
837 "SOURCE=..\\..\\$resource_file\r\n".
838 "# End Source File\r\n";
844 select STDOUT
; close OUT
;
849 if (defined $makefiles{'gtk'}) {
850 $dirpfx = &dirpfx
($makefiles{'gtk'}, "/");
852 ##-- X/GTK/Unix makefile
853 open OUT
, ">$makefiles{'gtk'}"; select OUT
;
855 "# Makefile for $project_name under X/GTK and Unix.\n".
856 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
857 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
858 # gcc command line option is -D not /D
859 ($_ = $help) =~ s/=\/D/=-D
/gs
;
863 "# You can define this path to point at your tools if you need to\n".
864 "# TOOLPATH = /opt/gcc/bin\n".
865 "CC = \$(TOOLPATH)cc\n".
867 &splitline
("CFLAGS = -O2 -Wall -Werror -g " .
868 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
869 " `gtk-config --cflags`")."\n".
870 "XLDFLAGS = `gtk-config --libs`\n".
873 "INSTALL_PROGRAM=\$(INSTALL)\n",
874 "INSTALL_DATA=\$(INSTALL)\n",
875 "prefix=/usr/local\n",
876 "exec_prefix=\$(prefix)\n",
877 "bindir=\$(exec_prefix)/bin\n",
878 "mandir=\$(prefix)/man\n",
879 "man1dir=\$(mandir)/man1\n",
884 "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
886 print &splitline
("all:" . join "", map { " $_" } &progrealnames
("X:U"));
888 foreach $p (&prognames
("X:U")) {
889 ($prog, $type) = split ",", $p;
890 $objstr = &objects
($p, "X.o", undef, undef);
891 print &splitline
($prog . ": " . $objstr), "\n";
892 $libstr = &objects
($p, undef, undef, "-lX");
893 print &splitline
("\t\$(CC)" . $mw . " \$(${type}LDFLAGS) -o \$@ " .
894 $objstr . " $libstr", 69), "\n\n";
896 foreach $d (&deps
("X.o", undef, $dirpfx, "/")) {
897 print &splitline
(sprintf("%s: %s", $d->{obj
}, join " ", @
{$d->{deps
}})),
901 print $makefile_extra{'gtk'};
903 "\trm -f *.o". (join "", map { " $_" } &progrealnames
("X:U")) . "\n";
904 select STDOUT
; close OUT
;
907 if (defined $makefiles{'mpw'}) {
909 open OUT
, ">$makefiles{'mpw'}"; select OUT
;
911 "# Makefile for $project_name under MPW.\n#\n".
912 "# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
913 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
914 # MPW command line option is -d not /D
915 ($_ = $help) =~ s/=\/D/=-d
/gs
;
918 "ROptions = `Echo \"{VER}\" | StreamEdit -e \"1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6\"' \xa81 '\xb6\xb6\xb6\xb6\xb6\"'\"`".
923 "C_Carbon = {PPCC}\n".
925 "# -w 35 disables \"unused parameter\" warnings\n".
926 "COptions = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6\n".
928 "COptions_68K = {COptions} -model far -opt time\n".
929 "# Enabling \"-opt space\" for CFM-68K gives me undefined references to\n".
930 "# _\$LDIVT and _\$LMODT.\n".
931 "COptions_CFM68K = {COptions} -model cfmSeg -opt time\n".
932 "COptions_PPC = {COptions} -opt size -traceback\n".
933 "COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON\n".
935 "Link_68K = ILink\n".
936 "Link_CFM68K = ILink\n".
937 "Link_PPC = PPCLink\n".
938 "Link_Carbon = PPCLink\n".
940 "LinkOptions = -c 'pTTY'\n".
941 "LinkOptions_68K = {LinkOptions} -br 68k -model far -compact\n".
942 "LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact\n".
943 "LinkOptions_PPC = {LinkOptions}\n".
944 "LinkOptions_Carbon = -m __appstart -w {LinkOptions}\n".
946 "Libs_68K = \"{CLibraries}StdCLib.far.o\" \xb6\n".
947 " \"{Libraries}MacRuntime.o\" \xb6\n".
948 " \"{Libraries}MathLib.far.o\" \xb6\n".
949 " \"{Libraries}IntEnv.far.o\" \xb6\n".
950 " \"{Libraries}Interface.o\" \xb6\n".
951 " \"{Libraries}Navigation.far.o\" \xb6\n".
952 " \"{Libraries}OpenTransport.o\" \xb6\n".
953 " \"{Libraries}OpenTransportApp.o\" \xb6\n".
954 " \"{Libraries}OpenTptInet.o\" \xb6\n".
955 " \"{Libraries}UnicodeConverterLib.far.o\"\n".
957 "Libs_CFM = \"{SharedLibraries}InterfaceLib\" \xb6\n".
958 " \"{SharedLibraries}StdCLib\" \xb6\n".
959 " \"{SharedLibraries}AppearanceLib\" \xb6\n".
960 " -weaklib AppearanceLib \xb6\n".
961 " \"{SharedLibraries}NavigationLib\" \xb6\n".
962 " -weaklib NavigationLib \xb6\n".
963 " \"{SharedLibraries}TextCommon\" \xb6\n".
964 " -weaklib TextCommon \xb6\n".
965 " \"{SharedLibraries}UnicodeConverter\" \xb6\n".
966 " -weaklib UnicodeConverter\n".
968 "Libs_CFM68K = {Libs_CFM} \xb6\n".
969 " \"{CFM68KLibraries}NuMacRuntime.o\"\n".
971 "Libs_PPC = {Libs_CFM} \xb6\n".
972 " \"{SharedLibraries}ControlsLib\" \xb6\n".
973 " -weaklib ControlsLib \xb6\n".
974 " \"{SharedLibraries}WindowsLib\" \xb6\n".
975 " -weaklib WindowsLib \xb6\n".
976 " \"{SharedLibraries}OpenTransportLib\" \xb6\n".
977 " -weaklib OTClientLib \xb6\n".
978 " -weaklib OTClientUtilLib \xb6\n".
979 " \"{SharedLibraries}OpenTptInternetLib\" \xb6\n".
980 " -weaklib OTInetClientLib \xb6\n".
981 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
982 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
983 " \"{PPCLibraries}CarbonAccessors.o\" \xb6\n".
984 " \"{PPCLibraries}OpenTransportAppPPC.o\" \xb6\n".
985 " \"{PPCLibraries}OpenTptInetPPC.o\"\n".
987 "Libs_Carbon = \"{PPCLibraries}CarbonStdCLib.o\" \xb6\n".
988 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
989 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
990 " \"{SharedLibraries}CarbonLib\" \xb6\n".
991 " \"{SharedLibraries}StdCLib\"\n".
993 print &splitline
("all \xc4 " . join(" ", &progrealnames
("M")), undef, "\xb6");
995 foreach $p (&prognames
("M")) {
996 ($prog, $type) = split ",", $p;
998 print &splitline
("$prog \xc4 $prog.68k $prog.ppc $prog.carbon",
999 undef, "\xb6"), "\n\n";
1001 $rsrc = &objects
($p, "", "X.rsrc", undef);
1003 foreach $arch (qw(68K CFM68K PPC Carbon
)) {
1004 $objstr = &objects
($p, "X.\L$arch\E.o", "", undef);
1005 print &splitline
("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6");
1007 print &splitline
("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
1008 print &splitline
("\t{Link_$arch} -o {Targ} -fragname $prog " .
1009 "{LinkOptions_$arch} " .
1010 $objstr . " {Libs_$arch}", 69, "\xb6"), "\n";
1011 print &splitline
("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
1015 foreach $d (&deps
("", "X.rsrc", "::", ":")) {
1016 next unless $d->{obj
};
1017 print &splitline
(sprintf("%s \xc4 %s", $d->{obj
}, join " ", @
{$d->{deps
}}),
1018 undef, "\xb6"), "\n";
1019 print "\tRez ", $d->{deps
}->[0], " -o {Targ} {ROptions}\n\n";
1021 foreach $arch (qw(68K CFM68K
)) {
1022 foreach $d (&deps
("X.\L$arch\E.o", "", "::", ":")) {
1023 next unless $d->{obj
};
1024 print &splitline
(sprintf("%s \xc4 %s", $d->{obj
},
1025 join " ", @
{$d->{deps
}}),
1026 undef, "\xb6"), "\n";
1027 print "\t{C_$arch} ", $d->{deps
}->[0],
1028 " -o {Targ} {COptions_$arch}\n\n";
1031 foreach $arch (qw(PPC Carbon
)) {
1032 foreach $d (&deps
("X.\L$arch\E.o", "", "::", ":")) {
1033 next unless $d->{obj
};
1034 print &splitline
(sprintf("%s \xc4 %s", $d->{obj
},
1035 join " ", @
{$d->{deps
}}),
1036 undef, "\xb6"), "\n";
1037 # The odd stuff here seems to stop afpd getting confused.
1038 print "\techo -n > {Targ}\n";
1039 print "\tsetfile -t XCOF {Targ}\n";
1040 print "\t{C_$arch} ", $d->{deps
}->[0],
1041 " -o {Targ} {COptions_$arch}\n\n";
1044 select STDOUT
; close OUT
;
1047 if (defined $makefiles{'lcc'}) {
1048 $dirpfx = &dirpfx
($makefiles{'lcc'}, "\\");
1051 open OUT
, ">$makefiles{'lcc'}"; select OUT
;
1053 "# Makefile for $project_name under lcc.\n".
1054 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1055 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1056 # lcc command line option is -D not /D
1057 ($_ = $help) =~ s/=\/D/=-D
/gs
;
1061 "# If you rename this file to `Makefile', you should change this line,\n".
1062 "# so that the .rsp files still depend on the correct makefile.\n".
1063 "MAKEFILE = Makefile.lcc\n".
1065 "# C compilation flags\n".
1066 "CFLAGS = -D_WINDOWS " .
1067 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1070 "# Get include directory for resource compiler\n".
1073 &splitline
("\tlcc -O -p6 \$(COMPAT) \$(FWHACK)".
1074 " \$(XFLAGS) \$(CFLAGS) \$*.c",69)."\n".
1076 &splitline
("\tlrc \$(FWHACK) \$(RCFL) -r \$*.rc",69)."\n".
1078 print &splitline
("all:" . join "", map { " $_.exe" } &progrealnames
("G:C"));
1080 foreach $p (&prognames
("G:C")) {
1081 ($prog, $type) = split ",", $p;
1082 $objstr = &objects
($p, "X.obj", "X.res", undef);
1083 print &splitline
("$prog.exe: " . $objstr ), "\n";
1084 $subsystemtype = undef;
1085 if ($type eq "G") { $subsystemtype = "-subsystem windows"; }
1086 my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1087 print &splitline
("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1091 foreach $d (&deps
("X.obj", "X.res", $dirpfx, "\\")) {
1092 print &splitline
(sprintf("%s: %s", $d->{obj
}, join " ", @
{$d->{deps
}})),
1096 print $makefile_extra{'lcc'};
1102 select STDOUT
; close OUT
;
1105 if (defined $makefiles{'osx'}) {
1106 $dirpfx = &dirpfx
($makefiles{'osx'}, "/");
1108 ##-- Mac OS X makefile
1109 open OUT
, ">$makefiles{'osx'}"; select OUT
;
1111 "# Makefile for $project_name under Mac OS X.\n".
1112 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1113 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1114 # gcc command line option is -D not /D
1115 ($_ = $help) =~ s/=\/D/=-D
/gs
;
1118 "CC = \$(TOOLPATH)gcc\n".
1120 &splitline
("CFLAGS = -O2 -Wall -Werror -g -DMAC_OS_X " .
1121 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1122 "LDFLAGS = -framework Cocoa\n".
1124 ".SUFFIXES: .o .c .m\n".
1127 "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
1129 "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
1131 print &splitline
("all:" . join "", map { " $_" } &progrealnames
("MX"));
1133 foreach $p (&prognames
("MX")) {
1134 ($prog, $type) = split ",", $p;
1135 $objstr = &objects
($p, "X.o", undef, undef);
1136 print "${prog}: ${prog}.app/Contents/MacOS/$prog\n\n";
1137 print "${prog}.app:\n\tmkdir \$\@\n";
1138 print "${prog}.app/Contents: ${prog}.app\n\tmkdir \$\@\n";
1139 print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir \$\@\n";
1140 print &splitline
("${prog}.app/Contents/MacOS/$prog: ".
1141 "${prog}.app/Contents/MacOS " . $objstr), "\n";
1142 $libstr = &objects
($p, undef, undef, "-lX");
1143 print &splitline
("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
1144 $objstr . " $libstr", 69), "\n\n";
1146 foreach $d (&deps
("X.o", undef, $dirpfx, "/")) {
1147 print &splitline
(sprintf("%s: %s", $d->{obj
}, join " ", @
{$d->{deps
}})),
1151 print $makefile_extra{'osx'};
1155 select STDOUT
; close OUT
;