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:
156 # - a line # ending `ICON "filename"';
157 # - a line ending `RT_MANIFEST "filename"'.
158 # Files included by this method are not added to @scanlist because
159 # they can never include further files.
161 # In this pass we write out a hash %further which maps a source
162 # file name into a listref containing further source file names.
165 while (scalar @scanlist > 0) {
166 $file = shift @scanlist;
167 next if defined $further{$file}; # skip if we've already done it
168 $resource = ($file =~ /\.rc$/ ? 1 : 0);
169 $further{$file} = [];
170 $dirfile = &findfile($file);
171 open IN, "$dirfile" or die "unable to open source file $file\n";
174 /^\s*#include\s+\"([^\"]+)\"/ and do {
175 push @{$further{$file}}, $1;
179 /(RT_MANIFEST|ICON)\s+\"([^\"]+)\"\s*$/ and do {
180 push @{$further{$file}}, $2;
187 # Now we're ready to generate the final dependencies section. For
188 # each key in %depends, we must expand the dependencies list by
189 # iteratively adding entries from %further.
190 foreach $i (keys %depends) {
192 @scanlist = @{$depends{$i}};
193 foreach $i (@scanlist) { $dep{$i} = 1; }
194 while (scalar @scanlist > 0) {
195 $file = shift @scanlist;
196 foreach $j (@{$further{$file}}) {
199 push @{$depends{$i}}, $j;
204 # printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
207 # Validation of input.
211 # Returns true if the argument is a known makefile type. Otherwise,
212 # prints a warning and returns false;
213 if (grep { $type eq $_ }
214 ("vc","vcproj","cygwin","borland","lcc","gtk","mpw","osx")) {
217 warn "$.:unknown makefile type '$type'\n";
221 # Utility routines while writing out the Makefiles.
224 my ($path) = shift @_;
225 my ($sep) = shift @_;
228 while (($i = index $path, $sep) >= 0 ||
229 ($j = index $path, "/") >= 0) {
230 if ($i >= 0 and ($j < 0 or $i < $j)) {
231 $path = substr $path, ($i + length $sep);
233 $path = substr $path, ($j + 1);
245 unless (defined $findfilecache{$name}) {
247 foreach $dir (@srcdirs) {
248 $outdir = $dir, $i++ if -f "$dir$name";
251 die "multiple instances of source file $name\n" if $i > 1;
252 $findfilecache{$name} = (defined $outdir ? $outdir . $name : undef);
254 return $findfilecache{$name};
258 my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
262 foreach $i (@{$programs{$prog}}) {
264 if ($i =~ /^(.*)\.(res|rsrc)/) {
266 ($x = $rtmpl) =~ s/X/$y/;
267 } elsif ($i =~ /^(.*)\.lib/) {
269 ($x = $ltmpl) =~ s/X/$y/;
270 } elsif ($i !~ /\./) {
271 ($x = $otmpl) =~ s/X/$i/;
273 push @ret, $x if $x ne "";
275 return join " ", @ret;
279 my ($prog, $suffix) = @_;
283 foreach $i (@{$programs{$prog}}) {
284 if (substr($i, (length $i) - (length $suffix)) eq $suffix) {
288 return (scalar @ret) ? (join " ", @ret) : undef;
292 my ($line, $width, $splitchar) = @_;
294 $len = (defined $width ? $width : 76);
295 $splitchar = (defined $splitchar ? $splitchar : '\\');
296 while (length $line > $len) {
297 $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
298 $result .= $1 . " ${splitchar}\n\t\t";
302 return $result . $line;
306 my ($otmpl, $rtmpl, $prefix, $dirsep, $mftyp, $depchar, $splitchar) = @_;
311 foreach $i (sort keys %depends) {
312 next if $specialobj{$mftyp}->{$i};
313 if ($i =~ /^(.*)\.(res|rsrc)/) {
314 next if !defined $rtmpl;
316 ($x = $rtmpl) =~ s/X/$y/;
318 ($x = $otmpl) =~ s/X/$i/;
320 @deps = @{$depends{$i}};
326 push @ret, {obj => $x, deps => [@deps]};
333 my ($n, $prog, $type);
336 foreach $n (@prognames) {
337 ($prog, $type) = split ",", $n;
338 push @ret, $n if index(":$types:", ":$type:") >= 0;
345 my ($n, $prog, $type);
348 foreach $n (@prognames) {
349 ($prog, $type) = split ",", $n;
350 push @ret, $prog if index(":$types:", ":$type:") >= 0;
356 my ($types,$suffix) = @_;
358 # assume that all UNIX programs have a man page
359 if($suffix eq "1" && $types =~ /:X:/) {
360 return map("$_.1", &progrealnames($types));
365 # Now we're ready to output the actual Makefiles.
367 if (defined $makefiles{'cygwin'}) {
368 $dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
371 open OUT, ">$makefiles{'cygwin'}"; select OUT;
373 "# Makefile for $project_name under cygwin.\n".
374 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
375 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
376 # gcc command line option is -D not /D
377 ($_ = $help) =~ s/=\/D/=-D/gs;
381 "# You can define this path to point at your tools if you need to\n".
382 "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
383 "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
384 "CC = \$(TOOLPATH)gcc\n".
385 "RC = \$(TOOLPATH)windres\n".
386 "# Uncomment the following two lines to compile under Winelib\n".
389 "# You may also need to tell windres where to find include files:\n".
390 "# RCINC = --include-dir c:\\cygwin\\include\\\n".
392 &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
393 " -D_NO_OLDNAMES -DNO_MULTIMON " .
394 (join " ", map {"-I$dirpfx$_"} @srcdirs)) .
396 "LDFLAGS = -mno-cygwin -s\n".
397 &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1".
398 " --define WINVER=0x0400 --define MINGW32_FIX=1")."\n".
402 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
404 foreach $p (&prognames("G:C")) {
405 ($prog, $type) = split ",", $p;
406 $objstr = &objects($p, "X.o", "X.res.o", undef);
407 print &splitline($prog . ".exe: " . $objstr), "\n";
408 my $mw = $type eq "G" ? " -mwindows" : "";
409 $libstr = &objects($p, undef, undef, "-lX");
410 print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
411 "-Wl,-Map,$prog.map " .
412 $objstr . " $libstr", 69), "\n\n";
414 foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/", "cygwin")) {
415 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
417 if ($d->{obj} =~ /\.res\.o$/) {
418 print "\t\$(RC) \$(RCFL) \$(RCFLAGS) ".$d->{deps}->[0]." ".$d->{obj}."\n\n";
420 print "\t\$(CC) \$(COMPAT) \$(XFLAGS) \$(CFLAGS) -c ".$d->{deps}->[0]."\n\n";
424 print $makefile_extra{'cygwin'};
426 "\trm -f *.o *.exe *.res.o *.map\n".
428 select STDOUT; close OUT;
432 ##-- Borland makefile
433 if (defined $makefiles{'borland'}) {
434 $dirpfx = &dirpfx($makefiles{'borland'}, "\\");
436 %stdlibs = ( # Borland provides many Win32 API libraries intrinsically
448 open OUT, ">$makefiles{'borland'}"; select OUT;
450 "# Makefile for $project_name under Borland C.\n".
451 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
452 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
453 # bcc32 command line option is -D not /D
454 ($_ = $help) =~ s/=\/D/=-D/gs;
458 "# If you rename this file to `Makefile', you should change this line,\n".
459 "# so that the .rsp files still depend on the correct makefile.\n".
460 "MAKEFILE = Makefile.bor\n".
462 "# C compilation flags\n".
463 "CFLAGS = -D_WINDOWS -DWINVER=0x0401\n".
465 "# Get include directory for resource compiler\n".
467 "BCB = \$(MAKEDIR)\\..\n".
471 &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT)".
472 " \$(XFLAGS) \$(CFLAGS) ".
473 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
474 " /c \$*.c",69)."\n".
476 &splitline("\tbrcc32 \$(RCFL) -i \$(BCB)\\include -r".
477 " -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n".
479 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
481 foreach $p (&prognames("G:C")) {
482 ($prog, $type) = split ",", $p;
483 $objstr = &objects($p, "X.obj", "X.res", undef);
484 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
485 my $ap = ($type eq "G") ? "-aa" : "-ap";
486 print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n";
488 foreach $p (&prognames("G:C")) {
489 ($prog, $type) = split ",", $p;
490 print $prog, ".rsp: \$(MAKEFILE)\n";
491 $objstr = &objects($p, "X.obj", undef, undef);
492 @objlist = split " ", $objstr;
494 foreach $i (@objlist) {
495 if (length($objlines[$#objlines] . " $i") > 50) {
498 $objlines[$#objlines] .= " $i";
500 $c0w = ($type eq "G") ? "c0w32" : "c0x32";
501 print "\techo $c0w + > $prog.rsp\n";
502 for ($i=0; $i<=$#objlines; $i++) {
503 $plus = ($i < $#objlines ? " +" : "");
504 print "\techo$objlines[$i]$plus >> $prog.rsp\n";
506 print "\techo $prog.exe >> $prog.rsp\n";
507 $objstr = &objects($p, "X.obj", "X.res", undef);
508 @libs = split " ", &objects($p, undef, undef, "X");
509 @libs = grep { !$stdlibs{$_} } @libs;
510 unshift @libs, "cw32", "import32";
511 $libstr = join ' ', @libs;
512 print "\techo nul,$libstr, >> $prog.rsp\n";
513 print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n";
516 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "borland")) {
517 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
521 print $makefile_extra{'borland'};
532 "\t-del *.\$\$\$\$\$\$\n";
533 select STDOUT; close OUT;
536 if (defined $makefiles{'vc'}) {
537 $dirpfx = &dirpfx($makefiles{'vc'}, "\\");
539 ##-- Visual C++ makefile
540 open OUT, ">$makefiles{'vc'}"; select OUT;
542 "# Makefile for $project_name under Visual C.\n".
543 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
544 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
548 "# If you rename this file to `Makefile', you should change this line,\n".
549 "# so that the .rsp files still depend on the correct makefile.\n".
550 "MAKEFILE = Makefile.vc\n".
552 "# C compilation flags\n".
553 "CFLAGS = /nologo /W3 /O1 " .
554 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
555 " /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401\n".
556 "LFLAGS = /incremental:no /fixed\n".
559 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
561 foreach $p (&prognames("G:C")) {
562 ($prog, $type) = split ",", $p;
563 $objstr = &objects($p, "X.obj", "X.res", undef);
564 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
565 print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
567 foreach $p (&prognames("G:C")) {
568 ($prog, $type) = split ",", $p;
569 print $prog, ".rsp: \$(MAKEFILE)\n";
570 $objstr = &objects($p, "X.obj", "X.res", "X.lib");
571 @objlist = split " ", $objstr;
573 foreach $i (@objlist) {
574 if (length($objlines[$#objlines] . " $i") > 50) {
577 $objlines[$#objlines] .= " $i";
579 $subsys = ($type eq "G") ? "windows" : "console";
580 print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
581 for ($i=0; $i<=$#objlines; $i++) {
582 print "\techo$objlines[$i] >> $prog.rsp\n";
586 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "vc")) {
587 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
589 if ($d->{obj} =~ /.obj$/) {
590 print "\tcl \$(COMPAT) \$(XFLAGS) \$(CFLAGS) /c ".$d->{deps}->[0],"\n\n";
592 print "\trc \$(RCFL) -r -DWIN32 -D_WIN32 -DWINVER=0x0400 ".$d->{deps}->[0],"\n\n";
596 print $makefile_extra{'vc'};
597 print "\nclean: tidy\n".
614 "\t-del debug.log\n";
615 select STDOUT; close OUT;
618 if (defined $makefiles{'vcproj'}) {
619 $dirpfx = &dirpfx($makefiles{'vcproj'}, "\\");
623 ##-- MSVC 6 Workspace and projects
625 # Note: All files created in this section are written in binary
626 # mode, because although MSVC's command-line make can deal with
627 # LF-only line endings, MSVC project files really _need_ to be
628 # CRLF. Hence, in order for mkfiles.pl to generate usable project
629 # files even when run from Unix, I make sure all files are binary
630 # and explicitly write the CRLFs.
632 # Create directories if necessary
633 mkdir $makefiles{'vcproj'}
634 if(! -d $makefiles{'vcproj'});
635 chdir $makefiles{'vcproj'};
636 @deps = &deps("X.obj", "X.res", $dirpfx, "\\", "vcproj");
637 %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
638 # Create the project files
639 # Get names of all Windows projects (GUI and console)
640 my @prognames = &prognames("G:C");
641 foreach $progname (@prognames) {
642 create_project(\%all_object_deps, $progname);
644 # Create the workspace file
645 open OUT, ">$project_name.dsw"; binmode OUT; select OUT;
647 "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
648 "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
650 "###############################################################################\r\n".
653 foreach $progname (@prognames) {
654 ($windows_project, $type) = split ",", $progname;
655 print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n";
667 "###############################################################################\r\n".
679 "###############################################################################\r\n".
681 select STDOUT; close OUT;
685 my ($all_object_deps, $progname) = @_;
686 # Construct program's dependency info
691 %resource_files = ();
692 @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
693 foreach $object_file (@object_files) {
694 next if defined $seen_objects{$object_file};
695 $seen_objects{$object_file} = 1;
696 if($object_file =~ /\.lib$/io) {
697 $lib_files{$object_file} = 1;
700 $object_deps = $all_object_deps{$object_file};
701 foreach $object_dep (@$object_deps) {
702 if($object_dep =~ /\.c$/io) {
703 $source_files{$object_dep} = 1;
706 if($object_dep =~ /\.h$/io) {
707 $header_files{$object_dep} = 1;
710 if($object_dep =~ /\.(rc|ico)$/io) {
711 $resource_files{$object_dep} = 1;
716 $libs = join " ", sort keys %lib_files;
717 @source_files = sort keys %source_files;
718 @header_files = sort keys %header_files;
719 @resources = sort keys %resource_files;
720 ($windows_project, $type) = split ",", $progname;
721 mkdir $windows_project
722 if(! -d $windows_project);
723 chdir $windows_project;
724 $subsys = ($type eq "G") ? "windows" : "console";
725 open OUT, ">$windows_project.dsp"; binmode OUT; select OUT;
727 "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n".
728 "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n".
729 "# ** DO NOT EDIT **\r\n".
731 "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n".
733 "CFG=$windows_project - Win32 Debug\r\n".
734 "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n".
735 "!MESSAGE use the Export Makefile command and run\r\n".
737 "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n".
739 "!MESSAGE You can specify a configuration when running NMAKE\r\n".
740 "!MESSAGE by defining the macro CFG on the command line. For example:\r\n".
742 "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
744 "!MESSAGE Possible choices for configuration are:\r\n".
746 "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n".
747 "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n".
750 "# Begin Project\r\n".
751 "# PROP AllowPerConfigDependencies 0\r\n".
752 "# PROP Scc_ProjName \"\"\r\n".
753 "# PROP Scc_LocalPath \"\"\r\n".
758 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
760 "# PROP BASE Use_MFC 0\r\n".
761 "# PROP BASE Use_Debug_Libraries 0\r\n".
762 "# PROP BASE Output_Dir \"Release\"\r\n".
763 "# PROP BASE Intermediate_Dir \"Release\"\r\n".
764 "# PROP BASE Target_Dir \"\"\r\n".
765 "# PROP Use_MFC 0\r\n".
766 "# PROP Use_Debug_Libraries 0\r\n".
767 "# PROP Output_Dir \"Release\"\r\n".
768 "# PROP Intermediate_Dir \"Release\"\r\n".
769 "# PROP Ignore_Export_Lib 0\r\n".
770 "# PROP Target_Dir \"\"\r\n".
771 "# ADD BASE CPP /nologo /W3 /GX /O2 ".
772 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
773 " /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
774 "# ADD CPP /nologo /W3 /GX /O2 ".
775 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
776 " /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
777 "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
778 "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
779 "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n".
780 "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n".
781 "BSC32=bscmake.exe\r\n".
782 "# ADD BASE BSC32 /nologo\r\n".
783 "# ADD BSC32 /nologo\r\n".
784 "LINK32=link.exe\r\n".
785 "# 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".
786 "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n".
787 "# SUBTRACT LINK32 /pdb:none\r\n".
789 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
791 "# PROP BASE Use_MFC 0\r\n".
792 "# PROP BASE Use_Debug_Libraries 1\r\n".
793 "# PROP BASE Output_Dir \"Debug\"\r\n".
794 "# PROP BASE Intermediate_Dir \"Debug\"\r\n".
795 "# PROP BASE Target_Dir \"\"\r\n".
796 "# PROP Use_MFC 0\r\n".
797 "# PROP Use_Debug_Libraries 1\r\n".
798 "# PROP Output_Dir \"Debug\"\r\n".
799 "# PROP Intermediate_Dir \"Debug\"\r\n".
800 "# PROP Ignore_Export_Lib 0\r\n".
801 "# PROP Target_Dir \"\"\r\n".
802 "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od ".
803 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
804 " /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
805 "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od ".
806 (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) .
807 " /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
808 "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
809 "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
810 "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n".
811 "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n".
812 "BSC32=bscmake.exe\r\n".
813 "# ADD BASE BSC32 /nologo\r\n".
814 "# ADD BSC32 /nologo\r\n".
815 "LINK32=link.exe\r\n".
816 "# 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".
817 "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
818 "# SUBTRACT LINK32 /pdb:none\r\n".
822 "# Begin Target\r\n".
824 "# Name \"$windows_project - Win32 Release\"\r\n".
825 "# Name \"$windows_project - Win32 Debug\"\r\n".
826 "# Begin Group \"Source Files\"\r\n".
828 "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
829 foreach $source_file (@source_files) {
831 "# Begin Source File\r\n".
833 "SOURCE=..\\..\\$source_file\r\n";
834 if($source_file =~ /ssh\.c/io) {
835 # Disable 'Edit and continue' as Visual Studio can't handle the macros
838 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
840 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
847 print "# End Source File\r\n";
851 "# Begin Group \"Header Files\"\r\n".
853 "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
854 foreach $header_file (@header_files) {
856 "# Begin Source File\r\n".
858 "SOURCE=..\\..\\$header_file\r\n".
859 "# End Source File\r\n";
863 "# Begin Group \"Resource Files\"\r\n".
865 "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
866 foreach $resource_file (@resources) {
868 "# Begin Source File\r\n".
870 "SOURCE=..\\..\\$resource_file\r\n".
871 "# End Source File\r\n";
877 select STDOUT; close OUT;
882 if (defined $makefiles{'gtk'}) {
883 $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
885 ##-- X/GTK/Unix makefile
886 open OUT, ">$makefiles{'gtk'}"; select OUT;
888 "# Makefile for $project_name under X/GTK and Unix.\n".
889 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
890 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
891 # gcc command line option is -D not /D
892 ($_ = $help) =~ s/=\/D/=-D/gs;
896 "# You can define this path to point at your tools if you need to\n".
897 "# TOOLPATH = /opt/gcc/bin\n".
898 "CC = \$(TOOLPATH)cc\n".
900 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
901 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
902 " `gtk-config --cflags`")."\n".
903 "XLDFLAGS = `gtk-config --libs`\n".
906 "INSTALL_PROGRAM=\$(INSTALL)\n",
907 "INSTALL_DATA=\$(INSTALL)\n",
908 "prefix=/usr/local\n",
909 "exec_prefix=\$(prefix)\n",
910 "bindir=\$(exec_prefix)/bin\n",
911 "mandir=\$(prefix)/man\n",
912 "man1dir=\$(mandir)/man1\n",
917 print &splitline("all:" . join "", map { " $_" } &progrealnames("X:U"));
919 foreach $p (&prognames("X:U")) {
920 ($prog, $type) = split ",", $p;
921 $objstr = &objects($p, "X.o", undef, undef);
922 print &splitline($prog . ": " . $objstr), "\n";
923 $libstr = &objects($p, undef, undef, "-lX");
924 print &splitline("\t\$(CC)" . $mw . " \$(${type}LDFLAGS) -o \$@ " .
925 $objstr . " $libstr", 69), "\n\n";
927 foreach $d (&deps("X.o", undef, $dirpfx, "/", "gtk")) {
928 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
930 print &splitline("\t\$(CC) \$(COMPAT) \$(XFLAGS) \$(CFLAGS) -c $d->{deps}->[0]\n");
933 print $makefile_extra{'gtk'};
935 "\trm -f *.o". (join "", map { " $_" } &progrealnames("X:U")) . "\n";
936 select STDOUT; close OUT;
939 if (defined $makefiles{'mpw'}) {
941 open OUT, ">$makefiles{'mpw'}"; select OUT;
943 "# Makefile for $project_name under MPW.\n#\n".
944 "# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
945 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
946 # MPW command line option is -d not /D
947 ($_ = $help) =~ s/=\/D/=-d /gs;
950 "ROptions = `Echo \"{VER}\" | StreamEdit -e \"1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6\"' \xa81 '\xb6\xb6\xb6\xb6\xb6\"'\"`".
955 "C_Carbon = {PPCC}\n".
957 "# -w 35 disables \"unused parameter\" warnings\n".
958 "COptions = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6\n".
960 "COptions_68K = {COptions} -model far -opt time\n".
961 "# Enabling \"-opt space\" for CFM-68K gives me undefined references to\n".
962 "# _\$LDIVT and _\$LMODT.\n".
963 "COptions_CFM68K = {COptions} -model cfmSeg -opt time\n".
964 "COptions_PPC = {COptions} -opt size -traceback\n".
965 "COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON\n".
967 "Link_68K = ILink\n".
968 "Link_CFM68K = ILink\n".
969 "Link_PPC = PPCLink\n".
970 "Link_Carbon = PPCLink\n".
972 "LinkOptions = -c 'pTTY'\n".
973 "LinkOptions_68K = {LinkOptions} -br 68k -model far -compact\n".
974 "LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact\n".
975 "LinkOptions_PPC = {LinkOptions}\n".
976 "LinkOptions_Carbon = -m __appstart -w {LinkOptions}\n".
978 "Libs_68K = \"{CLibraries}StdCLib.far.o\" \xb6\n".
979 " \"{Libraries}MacRuntime.o\" \xb6\n".
980 " \"{Libraries}MathLib.far.o\" \xb6\n".
981 " \"{Libraries}IntEnv.far.o\" \xb6\n".
982 " \"{Libraries}Interface.o\" \xb6\n".
983 " \"{Libraries}Navigation.far.o\" \xb6\n".
984 " \"{Libraries}OpenTransport.o\" \xb6\n".
985 " \"{Libraries}OpenTransportApp.o\" \xb6\n".
986 " \"{Libraries}OpenTptInet.o\" \xb6\n".
987 " \"{Libraries}UnicodeConverterLib.far.o\"\n".
989 "Libs_CFM = \"{SharedLibraries}InterfaceLib\" \xb6\n".
990 " \"{SharedLibraries}StdCLib\" \xb6\n".
991 " \"{SharedLibraries}AppearanceLib\" \xb6\n".
992 " -weaklib AppearanceLib \xb6\n".
993 " \"{SharedLibraries}NavigationLib\" \xb6\n".
994 " -weaklib NavigationLib \xb6\n".
995 " \"{SharedLibraries}TextCommon\" \xb6\n".
996 " -weaklib TextCommon \xb6\n".
997 " \"{SharedLibraries}UnicodeConverter\" \xb6\n".
998 " -weaklib UnicodeConverter\n".
1000 "Libs_CFM68K = {Libs_CFM} \xb6\n".
1001 " \"{CFM68KLibraries}NuMacRuntime.o\"\n".
1003 "Libs_PPC = {Libs_CFM} \xb6\n".
1004 " \"{SharedLibraries}ControlsLib\" \xb6\n".
1005 " -weaklib ControlsLib \xb6\n".
1006 " \"{SharedLibraries}WindowsLib\" \xb6\n".
1007 " -weaklib WindowsLib \xb6\n".
1008 " \"{SharedLibraries}OpenTransportLib\" \xb6\n".
1009 " -weaklib OTClientLib \xb6\n".
1010 " -weaklib OTClientUtilLib \xb6\n".
1011 " \"{SharedLibraries}OpenTptInternetLib\" \xb6\n".
1012 " -weaklib OTInetClientLib \xb6\n".
1013 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1014 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1015 " \"{PPCLibraries}CarbonAccessors.o\" \xb6\n".
1016 " \"{PPCLibraries}OpenTransportAppPPC.o\" \xb6\n".
1017 " \"{PPCLibraries}OpenTptInetPPC.o\"\n".
1019 "Libs_Carbon = \"{PPCLibraries}CarbonStdCLib.o\" \xb6\n".
1020 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1021 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1022 " \"{SharedLibraries}CarbonLib\" \xb6\n".
1023 " \"{SharedLibraries}StdCLib\"\n".
1025 print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6");
1027 foreach $p (&prognames("M")) {
1028 ($prog, $type) = split ",", $p;
1030 print &splitline("$prog \xc4 $prog.68k $prog.ppc $prog.carbon",
1031 undef, "\xb6"), "\n\n";
1033 $rsrc = &objects($p, "", "X.rsrc", undef);
1035 foreach $arch (qw(68K CFM68K PPC Carbon)) {
1036 $objstr = &objects($p, "X.\L$arch\E.o", "", undef);
1037 print &splitline("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6");
1039 print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
1040 print &splitline("\t{Link_$arch} -o {Targ} -fragname $prog " .
1041 "{LinkOptions_$arch} " .
1042 $objstr . " {Libs_$arch}", 69, "\xb6"), "\n";
1043 print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
1047 foreach $d (&deps("", "X.rsrc", "::", ":", "mpw")) {
1048 next unless $d->{obj};
1049 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
1050 undef, "\xb6"), "\n";
1051 print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n";
1053 foreach $arch (qw(68K CFM68K)) {
1054 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":", "mpw")) {
1055 next unless $d->{obj};
1056 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1057 join " ", @{$d->{deps}}),
1058 undef, "\xb6"), "\n";
1059 print "\t{C_$arch} ", $d->{deps}->[0],
1060 " -o {Targ} {COptions_$arch}\n\n";
1063 foreach $arch (qw(PPC Carbon)) {
1064 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":", "mpw")) {
1065 next unless $d->{obj};
1066 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1067 join " ", @{$d->{deps}}),
1068 undef, "\xb6"), "\n";
1069 # The odd stuff here seems to stop afpd getting confused.
1070 print "\techo -n > {Targ}\n";
1071 print "\tsetfile -t XCOF {Targ}\n";
1072 print "\t{C_$arch} ", $d->{deps}->[0],
1073 " -o {Targ} {COptions_$arch}\n\n";
1076 select STDOUT; close OUT;
1079 if (defined $makefiles{'lcc'}) {
1080 $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
1083 open OUT, ">$makefiles{'lcc'}"; select OUT;
1085 "# Makefile for $project_name under lcc.\n".
1086 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1087 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1088 # lcc command line option is -D not /D
1089 ($_ = $help) =~ s/=\/D/=-D/gs;
1093 "# If you rename this file to `Makefile', you should change this line,\n".
1094 "# so that the .rsp files still depend on the correct makefile.\n".
1095 "MAKEFILE = Makefile.lcc\n".
1097 "# C compilation flags\n".
1098 "CFLAGS = -D_WINDOWS " .
1099 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1102 "# Get include directory for resource compiler\n".
1104 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
1106 foreach $p (&prognames("G:C")) {
1107 ($prog, $type) = split ",", $p;
1108 $objstr = &objects($p, "X.obj", "X.res", undef);
1109 print &splitline("$prog.exe: " . $objstr ), "\n";
1110 $subsystemtype = undef;
1111 if ($type eq "G") { $subsystemtype = "-subsystem windows"; }
1112 my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1113 print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1117 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "lcc")) {
1118 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1120 if ($d->{obj} =~ /\.obj$/) {
1121 print &splitline("\tlcc -O -p6 \$(COMPAT)".
1122 " \$(XFLAGS) \$(CFLAGS) ".$d->{deps}->[0],69)."\n";
1124 print &splitline("\tlrc \$(RCFL) -r ".$d->{deps}->[0],69)."\n";
1128 print $makefile_extra{'lcc'};
1134 select STDOUT; close OUT;
1137 if (defined $makefiles{'osx'}) {
1138 $dirpfx = &dirpfx($makefiles{'osx'}, "/");
1140 ##-- Mac OS X makefile
1141 open OUT, ">$makefiles{'osx'}"; select OUT;
1143 "# Makefile for $project_name under Mac OS X.\n".
1144 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1145 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1146 # gcc command line option is -D not /D
1147 ($_ = $help) =~ s/=\/D/=-D/gs;
1150 "CC = \$(TOOLPATH)gcc\n".
1152 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1153 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1154 "MLDFLAGS = -framework Cocoa\n".
1156 &splitline("all:" . join "", map { " $_" } &progrealnames("MX:U")) .
1158 $makefile_extra{'osx'} .
1160 foreach $p (&prognames("MX")) {
1161 ($prog, $type) = split ",", $p;
1162 $objstr = &objects($p, "X.o", undef, undef);
1163 $icon = &special($p, ".icns");
1164 $infoplist = &special($p, "info.plist");
1165 print "${prog}.app:\n\tmkdir -p \$\@\n";
1166 print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n";
1167 print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1168 $targets = "${prog}.app/Contents/MacOS/$prog";
1169 if (defined $icon) {
1170 print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1171 print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n";
1172 $targets .= " ${prog}.app/Contents/Resources/${prog}.icns";
1174 if (defined $infoplist) {
1175 print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n";
1176 $targets .= " ${prog}.app/Contents/Info.plist";
1178 $targets .= " \$(${prog}_extra)";
1179 print &splitline("${prog}: $targets", 69) . "\n\n";
1180 print &splitline("${prog}.app/Contents/MacOS/$prog: ".
1181 "${prog}.app/Contents/MacOS " . $objstr), "\n";
1182 $libstr = &objects($p, undef, undef, "-lX");
1183 print &splitline("\t\$(CC)" . $mw . " \$(MLDFLAGS) -o \$@ " .
1184 $objstr . " $libstr", 69), "\n\n";
1186 foreach $p (&prognames("U")) {
1187 ($prog, $type) = split ",", $p;
1188 $objstr = &objects($p, "X.o", undef, undef);
1189 print &splitline($prog . ": " . $objstr), "\n";
1190 $libstr = &objects($p, undef, undef, "-lX");
1191 print &splitline("\t\$(CC)" . $mw . " \$(ULDFLAGS) -o \$@ " .
1192 $objstr . " $libstr", 69), "\n\n";
1194 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1195 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1197 $firstdep = $d->{deps}->[0];
1198 if ($firstdep =~ /\.c$/) {
1199 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n";
1200 } elsif ($firstdep =~ /\.m$/) {
1201 print "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n";
1205 "\trm -f *.o *.dmg". (join "", map { " $_" } &progrealnames("U")) . "\n";
1207 select STDOUT; close OUT;