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]" or $i eq "[MX]") and defined $prog) {
96 $type = substr($i,1,(length $i)-2);
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" or "x.m" (depending on
127 # Dependencies for "x.res" start with "x.rc".
128 # Dependencies for "x.rsrc" start with "x.r".
129 # Both types of file are pushed on the list of files to scan.
130 # Libraries (.lib) don't have dependencies at all.
131 if ($j =~ /^(.*)\.res$/) {
133 $depends{$j} = [$file];
134 push @scanlist, $file;
135 } elsif ($j =~ /^(.*)\.rsrc$/) {
137 $depends{$j} = [$file];
138 push @scanlist, $file;
139 } elsif ($j !~ /\./) {
141 $file = "$j.m" unless &findfile($file);
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","osx")) {
215 warn "$.:unknown makefile type '$type'\n";
219 # Utility routines while writing out the Makefiles.
222 my ($path) = shift @_;
223 my ($sep) = shift @_;
225 while (($i = index $path, $sep) >= 0) {
226 $path = substr $path, ($i + length $sep);
237 unless (defined $findfilecache{$name}) {
239 foreach $dir (@srcdirs) {
240 $outdir = $dir, $i++ if -f "$dir$name";
242 die "multiple instances of source file $name\n" if $i > 1;
243 $findfilecache{$name} = (defined $outdir ? $outdir . $name : undef);
245 return $findfilecache{$name};
249 my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
253 foreach $i (@{$programs{$prog}}) {
255 if ($i =~ /^(.*)\.(res|rsrc)/) {
257 ($x = $rtmpl) =~ s/X/$y/;
258 } elsif ($i =~ /^(.*)\.lib/) {
260 ($x = $ltmpl) =~ s/X/$y/;
261 } elsif ($i !~ /\./) {
262 ($x = $otmpl) =~ s/X/$i/;
264 push @ret, $x if $x ne "";
266 return join " ", @ret;
270 my ($prog, $suffix) = @_;
274 foreach $i (@{$programs{$prog}}) {
275 if (substr($i, (length $i) - (length $suffix)) eq $suffix) {
279 return join " ", @ret;
283 my ($line, $width, $splitchar) = @_;
285 $len = (defined $width ? $width : 76);
286 $splitchar = (defined $splitchar ? $splitchar : '\\');
287 while (length $line > $len) {
288 $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
289 $result .= $1 . " ${splitchar}\n\t\t";
293 return $result . $line;
297 my ($otmpl, $rtmpl, $prefix, $dirsep, $depchar, $splitchar) = @_;
302 foreach $i (sort keys %depends) {
303 next if $specialobj{$mftyp}->{$i};
304 if ($i =~ /^(.*)\.(res|rsrc)/) {
305 next if !defined $rtmpl;
307 ($x = $rtmpl) =~ s/X/$y/;
309 ($x = $otmpl) =~ s/X/$i/;
311 @deps = @{$depends{$i}};
317 push @ret, {obj => $x, deps => [@deps]};
324 my ($n, $prog, $type);
327 foreach $n (@prognames) {
328 ($prog, $type) = split ",", $n;
329 push @ret, $n if index(":$types:", ":$type:") >= 0;
336 my ($n, $prog, $type);
339 foreach $n (@prognames) {
340 ($prog, $type) = split ",", $n;
341 push @ret, $prog if index(":$types:", ":$type:") >= 0;
347 my ($types,$suffix) = @_;
349 # assume that all UNIX programs have a man page
350 if($suffix eq "1" && $types =~ /:X:/) {
351 return map("$_.1", &progrealnames($types));
356 # Now we're ready to output the actual Makefiles.
358 if (defined $makefiles{'cygwin'}) {
359 $dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
362 open OUT, ">$makefiles{'cygwin'}"; select OUT;
364 "# Makefile for $project_name under cygwin.\n".
365 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
366 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
367 # gcc command line option is -D not /D
368 ($_ = $help) =~ s/=\/D/=-D/gs;
372 "# You can define this path to point at your tools if you need to\n".
373 "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
374 "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
375 "CC = \$(TOOLPATH)gcc\n".
376 "RC = \$(TOOLPATH)windres\n".
377 "# Uncomment the following two lines to compile under Winelib\n".
380 "# You may also need to tell windres where to find include files:\n".
381 "# RCINC = --include-dir c:\\cygwin\\include\\\n".
383 &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
384 " -D_NO_OLDNAMES -DNO_MULTIMON " .
385 (join " ", map {"-I$dirpfx$_"} @srcdirs)) .
387 "LDFLAGS = -mno-cygwin -s\n".
388 &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1".
389 " --define WINVER=0x0400 --define MINGW32_FIX=1")."\n".
394 "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
397 "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n".
399 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
401 foreach $p (&prognames("G:C")) {
402 ($prog, $type) = split ",", $p;
403 $objstr = &objects($p, "X.o", "X.res.o", undef);
404 print &splitline($prog . ".exe: " . $objstr), "\n";
405 my $mw = $type eq "G" ? " -mwindows" : "";
406 $libstr = &objects($p, undef, undef, "-lX");
407 print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
408 "-Wl,-Map,$prog.map " .
409 $objstr . " $libstr", 69), "\n\n";
411 foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/")) {
412 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
416 print $makefile_extra{'cygwin'};
418 "\trm -f *.o *.exe *.res.o *.map\n".
420 select STDOUT; close OUT;
424 ##-- Borland makefile
425 if (defined $makefiles{'borland'}) {
426 $dirpfx = &dirpfx($makefiles{'borland'}, "\\");
428 %stdlibs = ( # Borland provides many Win32 API libraries intrinsically
440 open OUT, ">$makefiles{'borland'}"; select OUT;
442 "# Makefile for $project_name under Borland C.\n".
443 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
444 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
445 # bcc32 command line option is -D not /D
446 ($_ = $help) =~ s/=\/D/=-D/gs;
450 "# If you rename this file to `Makefile', you should change this line,\n".
451 "# so that the .rsp files still depend on the correct makefile.\n".
452 "MAKEFILE = Makefile.bor\n".
454 "# C compilation flags\n".
455 "CFLAGS = -D_WINDOWS -DWINVER=0x0401\n".
457 "# Get include directory for resource compiler\n".
459 "BCB = \$(MAKEDIR)\\..\n".
463 &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT) \$(FWHACK)".
464 " \$(XFLAGS) \$(CFLAGS) ".
465 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
466 " /c \$*.c",69)."\n".
468 &splitline("\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include -r".
469 " -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n".
471 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
473 foreach $p (&prognames("G:C")) {
474 ($prog, $type) = split ",", $p;
475 $objstr = &objects($p, "X.obj", "X.res", undef);
476 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
477 my $ap = ($type eq "G") ? "-aa" : "-ap";
478 print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n";
480 foreach $p (&prognames("G:C")) {
481 ($prog, $type) = split ",", $p;
482 print $prog, ".rsp: \$(MAKEFILE)\n";
483 $objstr = &objects($p, "X.obj", undef, undef);
484 @objlist = split " ", $objstr;
486 foreach $i (@objlist) {
487 if (length($objlines[$#objlines] . " $i") > 50) {
490 $objlines[$#objlines] .= " $i";
492 $c0w = ($type eq "G") ? "c0w32" : "c0x32";
493 print "\techo $c0w + > $prog.rsp\n";
494 for ($i=0; $i<=$#objlines; $i++) {
495 $plus = ($i < $#objlines ? " +" : "");
496 print "\techo$objlines[$i]$plus >> $prog.rsp\n";
498 print "\techo $prog.exe >> $prog.rsp\n";
499 $objstr = &objects($p, "X.obj", "X.res", undef);
500 @libs = split " ", &objects($p, undef, undef, "X");
501 @libs = grep { !$stdlibs{$_} } @libs;
502 unshift @libs, "cw32", "import32";
503 $libstr = join ' ', @libs;
504 print "\techo nul,$libstr, >> $prog.rsp\n";
505 print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n";
508 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
509 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
513 print $makefile_extra{'borland'};
524 "\t-del *.\$\$\$\$\$\$\n";
525 select STDOUT; close OUT;
528 if (defined $makefiles{'vc'}) {
529 $dirpfx = &dirpfx($makefiles{'vc'}, "\\");
531 ##-- Visual C++ makefile
532 open OUT, ">$makefiles{'vc'}"; select OUT;
534 "# Makefile for $project_name under Visual C.\n".
535 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
536 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
540 "# If you rename this file to `Makefile', you should change this line,\n".
541 "# so that the .rsp files still depend on the correct makefile.\n".
542 "MAKEFILE = Makefile.vc\n".
544 "# C compilation flags\n".
545 "CFLAGS = /nologo /W3 /O1 /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401\n".
546 "LFLAGS = /incremental:no /fixed\n".
549 "\tcl \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) /c \$*.c\n".
551 "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 -DWINVER=0x0400 \$*.rc\n".
553 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
555 foreach $p (&prognames("G:C")) {
556 ($prog, $type) = split ",", $p;
557 $objstr = &objects($p, "X.obj", "X.res", undef);
558 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
559 print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
561 foreach $p (&prognames("G:C")) {
562 ($prog, $type) = split ",", $p;
563 print $prog, ".rsp: \$(MAKEFILE)\n";
564 $objstr = &objects($p, "X.obj", "X.res", "X.lib");
565 @objlist = split " ", $objstr;
567 foreach $i (@objlist) {
568 if (length($objlines[$#objlines] . " $i") > 50) {
571 $objlines[$#objlines] .= " $i";
573 $subsys = ($type eq "G") ? "windows" : "console";
574 print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
575 for ($i=0; $i<=$#objlines; $i++) {
576 print "\techo$objlines[$i] >> $prog.rsp\n";
580 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
581 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
585 print $makefile_extra{'vc'};
586 print "\nclean: tidy\n".
603 "\t-del debug.log\n";
604 select STDOUT; close OUT;
607 if (defined $makefiles{'vcproj'}) {
611 ##-- MSVC 6 Workspace and projects
613 # Note: All files created in this section are written in binary
614 # mode, because although MSVC's command-line make can deal with
615 # LF-only line endings, MSVC project files really _need_ to be
616 # CRLF. Hence, in order for mkfiles.pl to generate usable project
617 # files even when run from Unix, I make sure all files are binary
618 # and explicitly write the CRLFs.
620 # Create directories if necessary
621 mkdir $makefiles{'vcproj'}
622 if(! -d $makefiles{'vcproj'});
623 chdir $makefiles{'vcproj'};
624 @deps = &deps("X.obj", "X.res", "", "\\");
625 %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
626 # Create the project files
627 # Get names of all Windows projects (GUI and console)
628 my @prognames = &prognames("G:C");
629 foreach $progname (@prognames) {
630 create_project(\%all_object_deps, $progname);
632 # Create the workspace file
633 open OUT, ">$project_name.dsw"; binmode OUT; select OUT;
635 "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
636 "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
638 "###############################################################################\r\n".
641 foreach $progname (@prognames) {
642 ($windows_project, $type) = split ",", $progname;
643 print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n";
655 "###############################################################################\r\n".
667 "###############################################################################\r\n".
669 select STDOUT; close OUT;
673 my ($all_object_deps, $progname) = @_;
674 # Construct program's dependency info
679 %resource_files = ();
680 @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
681 foreach $object_file (@object_files) {
682 next if defined $seen_objects{$object_file};
683 $seen_objects{$object_file} = 1;
684 if($object_file =~ /\.lib$/io) {
685 $lib_files{$object_file} = 1;
688 $object_deps = $all_object_deps{$object_file};
689 foreach $object_dep (@$object_deps) {
690 if($object_dep =~ /\.c$/io) {
691 $source_files{$object_dep} = 1;
694 if($object_dep =~ /\.h$/io) {
695 $header_files{$object_dep} = 1;
698 if($object_dep =~ /\.(rc|ico)$/io) {
699 $resource_files{$object_dep} = 1;
704 $libs = join " ", sort keys %lib_files;
705 @source_files = sort keys %source_files;
706 @header_files = sort keys %header_files;
707 @resources = sort keys %resource_files;
708 ($windows_project, $type) = split ",", $progname;
709 mkdir $windows_project
710 if(! -d $windows_project);
711 chdir $windows_project;
712 $subsys = ($type eq "G") ? "windows" : "console";
713 open OUT, ">$windows_project.dsp"; binmode OUT; select OUT;
715 "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n".
716 "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n".
717 "# ** DO NOT EDIT **\r\n".
719 "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n".
721 "CFG=$windows_project - Win32 Debug\r\n".
722 "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n".
723 "!MESSAGE use the Export Makefile command and run\r\n".
725 "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n".
727 "!MESSAGE You can specify a configuration when running NMAKE\r\n".
728 "!MESSAGE by defining the macro CFG on the command line. For example:\r\n".
730 "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
732 "!MESSAGE Possible choices for configuration are:\r\n".
734 "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n".
735 "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n".
738 "# Begin Project\r\n".
739 "# PROP AllowPerConfigDependencies 0\r\n".
740 "# PROP Scc_ProjName \"\"\r\n".
741 "# PROP Scc_LocalPath \"\"\r\n".
746 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
748 "# PROP BASE Use_MFC 0\r\n".
749 "# PROP BASE Use_Debug_Libraries 0\r\n".
750 "# PROP BASE Output_Dir \"Release\"\r\n".
751 "# PROP BASE Intermediate_Dir \"Release\"\r\n".
752 "# PROP BASE Target_Dir \"\"\r\n".
753 "# PROP Use_MFC 0\r\n".
754 "# PROP Use_Debug_Libraries 0\r\n".
755 "# PROP Output_Dir \"Release\"\r\n".
756 "# PROP Intermediate_Dir \"Release\"\r\n".
757 "# PROP Ignore_Export_Lib 0\r\n".
758 "# PROP Target_Dir \"\"\r\n".
759 "# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
760 "# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
761 "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
762 "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
763 "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n".
764 "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n".
765 "BSC32=bscmake.exe\r\n".
766 "# ADD BASE BSC32 /nologo\r\n".
767 "# ADD BSC32 /nologo\r\n".
768 "LINK32=link.exe\r\n".
769 "# 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".
770 "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n".
771 "# SUBTRACT LINK32 /pdb:none\r\n".
773 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
775 "# PROP BASE Use_MFC 0\r\n".
776 "# PROP BASE Use_Debug_Libraries 1\r\n".
777 "# PROP BASE Output_Dir \"Debug\"\r\n".
778 "# PROP BASE Intermediate_Dir \"Debug\"\r\n".
779 "# PROP BASE Target_Dir \"\"\r\n".
780 "# PROP Use_MFC 0\r\n".
781 "# PROP Use_Debug_Libraries 1\r\n".
782 "# PROP Output_Dir \"Debug\"\r\n".
783 "# PROP Intermediate_Dir \"Debug\"\r\n".
784 "# PROP Ignore_Export_Lib 0\r\n".
785 "# PROP Target_Dir \"\"\r\n".
786 "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
787 "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
788 "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
789 "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
790 "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n".
791 "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n".
792 "BSC32=bscmake.exe\r\n".
793 "# ADD BASE BSC32 /nologo\r\n".
794 "# ADD BSC32 /nologo\r\n".
795 "LINK32=link.exe\r\n".
796 "# 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".
797 "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
798 "# SUBTRACT LINK32 /pdb:none\r\n".
802 "# Begin Target\r\n".
804 "# Name \"$windows_project - Win32 Release\"\r\n".
805 "# Name \"$windows_project - Win32 Debug\"\r\n".
806 "# Begin Group \"Source Files\"\r\n".
808 "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
809 foreach $source_file (@source_files) {
811 "# Begin Source File\r\n".
813 "SOURCE=..\\..\\$source_file\r\n";
814 if($source_file =~ /ssh\.c/io) {
815 # Disable 'Edit and continue' as Visual Studio can't handle the macros
818 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
820 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
827 print "# End Source File\r\n";
831 "# Begin Group \"Header Files\"\r\n".
833 "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
834 foreach $header_file (@header_files) {
836 "# Begin Source File\r\n".
838 "SOURCE=..\\..\\$header_file\r\n".
839 "# End Source File\r\n";
843 "# Begin Group \"Resource Files\"\r\n".
845 "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
846 foreach $resource_file (@resources) {
848 "# Begin Source File\r\n".
850 "SOURCE=..\\..\\$resource_file\r\n".
851 "# End Source File\r\n";
857 select STDOUT; close OUT;
862 if (defined $makefiles{'gtk'}) {
863 $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
865 ##-- X/GTK/Unix makefile
866 open OUT, ">$makefiles{'gtk'}"; select OUT;
868 "# Makefile for $project_name under X/GTK and Unix.\n".
869 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
870 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
871 # gcc command line option is -D not /D
872 ($_ = $help) =~ s/=\/D/=-D/gs;
876 "# You can define this path to point at your tools if you need to\n".
877 "# TOOLPATH = /opt/gcc/bin\n".
878 "CC = \$(TOOLPATH)cc\n".
879 "# You can manually set this to `gtk-config' or `pkg-config gtk+-1.2'\n".
880 "# (depending on what works on your system) if you want to enforce\n".
881 "# building with GTK 1.2, or you can set it to `pkg-config gtk+-2.0'\n".
882 "# if you want to enforce 2.0. The default is to try 2.0 and fall back\n".
883 "# to 1.2 if it isn't found.\n".
884 "GTK_CONFIG = sh -c 'pkg-config gtk+-2.0 \$\$0 2>/dev/null || gtk-config \$\$0'\n".
886 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
887 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
888 " `\$(GTK_CONFIG) --cflags`")."\n".
889 "XLDFLAGS = `\$(GTK_CONFIG) --libs`\n".
892 "INSTALL_PROGRAM=\$(INSTALL)\n",
893 "INSTALL_DATA=\$(INSTALL)\n",
894 "prefix=/usr/local\n",
895 "exec_prefix=\$(prefix)\n",
896 "bindir=\$(exec_prefix)/bin\n",
897 "gamesdir=\$(exec_prefix)/games\n",
898 "mandir=\$(prefix)/man\n",
899 "man1dir=\$(mandir)/man1\n",
904 "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
906 print &splitline("all:" . join "", map { " $_" } &progrealnames("X:U"));
908 foreach $p (&prognames("X:U")) {
909 ($prog, $type) = split ",", $p;
910 $objstr = &objects($p, "X.o", undef, undef);
911 print &splitline($prog . ": " . $objstr), "\n";
912 $libstr = &objects($p, undef, undef, "-lX");
913 print &splitline("\t\$(CC)" . $mw . " \$(${type}LDFLAGS) -o \$@ " .
914 $objstr . " $libstr", 69), "\n\n";
916 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
917 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
921 print $makefile_extra{'gtk'};
923 "\trm -f *.o". (join "", map { " $_" } &progrealnames("X:U")) . "\n";
924 select STDOUT; close OUT;
927 if (defined $makefiles{'mpw'}) {
929 open OUT, ">$makefiles{'mpw'}"; select OUT;
931 "# Makefile for $project_name under MPW.\n#\n".
932 "# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
933 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
934 # MPW command line option is -d not /D
935 ($_ = $help) =~ s/=\/D/=-d /gs;
938 "ROptions = `Echo \"{VER}\" | StreamEdit -e \"1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6\"' \xa81 '\xb6\xb6\xb6\xb6\xb6\"'\"`".
943 "C_Carbon = {PPCC}\n".
945 "# -w 35 disables \"unused parameter\" warnings\n".
946 "COptions = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6\n".
948 "COptions_68K = {COptions} -model far -opt time\n".
949 "# Enabling \"-opt space\" for CFM-68K gives me undefined references to\n".
950 "# _\$LDIVT and _\$LMODT.\n".
951 "COptions_CFM68K = {COptions} -model cfmSeg -opt time\n".
952 "COptions_PPC = {COptions} -opt size -traceback\n".
953 "COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON\n".
955 "Link_68K = ILink\n".
956 "Link_CFM68K = ILink\n".
957 "Link_PPC = PPCLink\n".
958 "Link_Carbon = PPCLink\n".
960 "LinkOptions = -c 'pTTY'\n".
961 "LinkOptions_68K = {LinkOptions} -br 68k -model far -compact\n".
962 "LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact\n".
963 "LinkOptions_PPC = {LinkOptions}\n".
964 "LinkOptions_Carbon = -m __appstart -w {LinkOptions}\n".
966 "Libs_68K = \"{CLibraries}StdCLib.far.o\" \xb6\n".
967 " \"{Libraries}MacRuntime.o\" \xb6\n".
968 " \"{Libraries}MathLib.far.o\" \xb6\n".
969 " \"{Libraries}IntEnv.far.o\" \xb6\n".
970 " \"{Libraries}Interface.o\" \xb6\n".
971 " \"{Libraries}Navigation.far.o\" \xb6\n".
972 " \"{Libraries}OpenTransport.o\" \xb6\n".
973 " \"{Libraries}OpenTransportApp.o\" \xb6\n".
974 " \"{Libraries}OpenTptInet.o\" \xb6\n".
975 " \"{Libraries}UnicodeConverterLib.far.o\"\n".
977 "Libs_CFM = \"{SharedLibraries}InterfaceLib\" \xb6\n".
978 " \"{SharedLibraries}StdCLib\" \xb6\n".
979 " \"{SharedLibraries}AppearanceLib\" \xb6\n".
980 " -weaklib AppearanceLib \xb6\n".
981 " \"{SharedLibraries}NavigationLib\" \xb6\n".
982 " -weaklib NavigationLib \xb6\n".
983 " \"{SharedLibraries}TextCommon\" \xb6\n".
984 " -weaklib TextCommon \xb6\n".
985 " \"{SharedLibraries}UnicodeConverter\" \xb6\n".
986 " -weaklib UnicodeConverter\n".
988 "Libs_CFM68K = {Libs_CFM} \xb6\n".
989 " \"{CFM68KLibraries}NuMacRuntime.o\"\n".
991 "Libs_PPC = {Libs_CFM} \xb6\n".
992 " \"{SharedLibraries}ControlsLib\" \xb6\n".
993 " -weaklib ControlsLib \xb6\n".
994 " \"{SharedLibraries}WindowsLib\" \xb6\n".
995 " -weaklib WindowsLib \xb6\n".
996 " \"{SharedLibraries}OpenTransportLib\" \xb6\n".
997 " -weaklib OTClientLib \xb6\n".
998 " -weaklib OTClientUtilLib \xb6\n".
999 " \"{SharedLibraries}OpenTptInternetLib\" \xb6\n".
1000 " -weaklib OTInetClientLib \xb6\n".
1001 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1002 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1003 " \"{PPCLibraries}CarbonAccessors.o\" \xb6\n".
1004 " \"{PPCLibraries}OpenTransportAppPPC.o\" \xb6\n".
1005 " \"{PPCLibraries}OpenTptInetPPC.o\"\n".
1007 "Libs_Carbon = \"{PPCLibraries}CarbonStdCLib.o\" \xb6\n".
1008 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1009 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1010 " \"{SharedLibraries}CarbonLib\" \xb6\n".
1011 " \"{SharedLibraries}StdCLib\"\n".
1013 print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6");
1015 foreach $p (&prognames("M")) {
1016 ($prog, $type) = split ",", $p;
1018 print &splitline("$prog \xc4 $prog.68k $prog.ppc $prog.carbon",
1019 undef, "\xb6"), "\n\n";
1021 $rsrc = &objects($p, "", "X.rsrc", undef);
1023 foreach $arch (qw(68K CFM68K PPC Carbon)) {
1024 $objstr = &objects($p, "X.\L$arch\E.o", "", undef);
1025 print &splitline("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6");
1027 print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
1028 print &splitline("\t{Link_$arch} -o {Targ} -fragname $prog " .
1029 "{LinkOptions_$arch} " .
1030 $objstr . " {Libs_$arch}", 69, "\xb6"), "\n";
1031 print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
1035 foreach $d (&deps("", "X.rsrc", "::", ":")) {
1036 next unless $d->{obj};
1037 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
1038 undef, "\xb6"), "\n";
1039 print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n";
1041 foreach $arch (qw(68K CFM68K)) {
1042 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1043 next unless $d->{obj};
1044 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1045 join " ", @{$d->{deps}}),
1046 undef, "\xb6"), "\n";
1047 print "\t{C_$arch} ", $d->{deps}->[0],
1048 " -o {Targ} {COptions_$arch}\n\n";
1051 foreach $arch (qw(PPC Carbon)) {
1052 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1053 next unless $d->{obj};
1054 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1055 join " ", @{$d->{deps}}),
1056 undef, "\xb6"), "\n";
1057 # The odd stuff here seems to stop afpd getting confused.
1058 print "\techo -n > {Targ}\n";
1059 print "\tsetfile -t XCOF {Targ}\n";
1060 print "\t{C_$arch} ", $d->{deps}->[0],
1061 " -o {Targ} {COptions_$arch}\n\n";
1064 select STDOUT; close OUT;
1067 if (defined $makefiles{'lcc'}) {
1068 $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
1071 open OUT, ">$makefiles{'lcc'}"; select OUT;
1073 "# Makefile for $project_name under lcc.\n".
1074 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1075 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1076 # lcc command line option is -D not /D
1077 ($_ = $help) =~ s/=\/D/=-D/gs;
1081 "# If you rename this file to `Makefile', you should change this line,\n".
1082 "# so that the .rsp files still depend on the correct makefile.\n".
1083 "MAKEFILE = Makefile.lcc\n".
1085 "# C compilation flags\n".
1086 "CFLAGS = -D_WINDOWS " .
1087 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1090 "# Get include directory for resource compiler\n".
1093 &splitline("\tlcc -O -p6 \$(COMPAT) \$(FWHACK)".
1094 " \$(XFLAGS) \$(CFLAGS) \$*.c",69)."\n".
1096 &splitline("\tlrc \$(FWHACK) \$(RCFL) -r \$*.rc",69)."\n".
1098 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
1100 foreach $p (&prognames("G:C")) {
1101 ($prog, $type) = split ",", $p;
1102 $objstr = &objects($p, "X.obj", "X.res", undef);
1103 print &splitline("$prog.exe: " . $objstr ), "\n";
1104 $subsystemtype = undef;
1105 if ($type eq "G") { $subsystemtype = "-subsystem windows"; }
1106 my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1107 print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1111 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
1112 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1116 print $makefile_extra{'lcc'};
1122 select STDOUT; close OUT;
1125 if (defined $makefiles{'osx'}) {
1126 $dirpfx = &dirpfx($makefiles{'osx'}, "/");
1128 ##-- Mac OS X makefile
1129 open OUT, ">$makefiles{'osx'}"; select OUT;
1131 "# Makefile for $project_name under Mac OS X.\n".
1132 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1133 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1134 # gcc command line option is -D not /D
1135 ($_ = $help) =~ s/=\/D/=-D/gs;
1138 "CC = \$(TOOLPATH)gcc\n".
1140 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1141 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1142 "LDFLAGS = -framework Cocoa\n".
1143 &splitline("all:" . join "", map { " $_" } &progrealnames("MX")) .
1145 $makefile_extra{'osx'} .
1147 ".SUFFIXES: .o .c .m\n".
1150 "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
1152 "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
1155 foreach $p (&prognames("MX")) {
1156 ($prog, $type) = split ",", $p;
1157 $objstr = &objects($p, "X.o", undef, undef);
1158 $icon = &special($p, ".icns");
1159 $infoplist = &special($p, "info.plist");
1160 print "${prog}.app:\n\tmkdir -p \$\@\n";
1161 print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n";
1162 print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1163 $targets = "${prog}.app/Contents/MacOS/$prog";
1164 if (defined $icon) {
1165 print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1166 print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n";
1167 $targets .= " ${prog}.app/Contents/Resources/${prog}.icns";
1169 if (defined $infoplist) {
1170 print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n";
1171 $targets .= " ${prog}.app/Contents/Info.plist";
1173 $targets .= " \$(${prog}_extra)";
1174 print &splitline("${prog}: $targets", 69) . "\n\n";
1175 print &splitline("${prog}.app/Contents/MacOS/$prog: ".
1176 "${prog}.app/Contents/MacOS " . $objstr), "\n";
1177 $libstr = &objects($p, undef, undef, "-lX");
1178 print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
1179 $objstr . " $libstr", 69), "\n\n";
1181 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1182 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1186 "\trm -f *.o *.dmg\n".
1188 select STDOUT; close OUT;