chiark / gitweb /
b805dbe0d1f3a9709ae1fbc3c885627c31c5c0f2
[sgt-puzzles.git] / mkfiles.pl
1 #!/usr/bin/env perl
2 #
3 # Cross-platform Makefile generator.
4 #
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.
9
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.
15
16 use FileHandle;
17 use Cwd;
18
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,
22     # try one level up.
23     chdir "..";
24     open IN, "Recipe" or die "unable to open Recipe file\n";
25 };
26
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 ".."';
31
32 @srcdirs = ("./");
33
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
41
42 while (<IN>) {
43   # Skip comments (unless the comments belong, for example because
44   # they're part of a diversion).
45   next if /^\s*#/ and !defined $divert;
46
47   chomp;
48   split;
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") {
56       if (&mfval($_[1])) {
57           $divert = \$makefile_extra{$_[1]};
58       } else {
59           $divert = \$dummy;
60       }
61       next;
62   }
63   # If we're gathering help text, keep doing so.
64   if (defined $divert) { ${$divert} .= "$_\n"; next; }
65   # Ignore blank lines.
66   next if scalar @_ == 0;
67
68   # Now we have an ordinary line. See if it's an = line, a : line
69   # or a + line.
70   @objs = @_;
71
72   if ($_[0] eq "+") {
73     $listref = $lastlistref;
74     $prog = undef;
75     die "$.: unexpected + line\n" if !defined $lastlistref;
76   } elsif ($_[1] eq "=") {
77     $groups{$_[0]} = [] if !defined $groups{$_[0]};
78     $listref = $groups{$_[0]};
79     $prog = undef;
80     shift @objs; # eat the group name
81   } elsif ($_[1] eq ":") {
82     $listref = [];
83     $prog = $_[0];
84     shift @objs; # eat the program name
85   } else {
86     die "$.: unrecognised line type\n";
87   }
88   shift @objs; # eat the +, the = or the :
89
90   while (scalar @objs > 0) {
91     $i = shift @objs;
92     if ($groups{$i}) {
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);
97     } else {
98       push @$listref, $i;
99     }
100   }
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;
105   }
106   $lastlistref = $listref;
107 }
108
109 close IN;
110
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;
115 %depends = ();
116 @scanlist = ();
117 foreach $i (@prognames) {
118   ($prog, $type) = split ",", $i;
119   # Strip duplicate object names.
120   $prev = undef;
121   @list = grep { $status = ($prev ne $_); $prev=$_; $status }
122           sort @{$programs{$i}};
123   $programs{$i} = [@list];
124   foreach $j (@list) {
125     # Dependencies for "x" start with "x.c" or "x.m" (depending on
126     # which one exists).
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$/) {
132       $file = "$1.rc";
133       $depends{$j} = [$file];
134       push @scanlist, $file;
135     } elsif ($j =~ /^(.*)\.rsrc$/) {
136       $file = "$1.r";
137       $depends{$j} = [$file];
138       push @scanlist, $file;
139     } elsif ($j !~ /\./) {
140       $file = "$j.c";
141       $file = "$j.m" unless &findfile($file);
142       $depends{$j} = [$file];
143       push @scanlist, $file;
144     }
145   }
146 }
147
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
153 # done).
154 #
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.
158 #
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.
161
162 %further = ();
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";
170   while (<IN>) {
171     chomp;
172     /^\s*#include\s+\"([^\"]+)\"/ and do {
173       push @{$further{$file}}, $1;
174       push @scanlist, $1;
175       next;
176     };
177     /ICON\s+\"([^\"]+)\"\s*$/ and do {
178       push @{$further{$file}}, $1;
179       next;
180     }
181   }
182   close IN;
183 }
184
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) {
189   %dep = ();
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}}) {
195       if ($dep{$j} != 1) {
196         $dep{$j} = 1;
197         push @{$depends{$i}}, $j;
198         push @scanlist, $j;
199       }
200     }
201   }
202 #  printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
203 }
204
205 # Validation of input.
206
207 sub mfval($) {
208     my ($type) = @_;
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")) {
213             return 1;
214         }
215     warn "$.:unknown makefile type '$type'\n";
216     return 0;
217 }
218
219 # Utility routines while writing out the Makefiles.
220
221 sub dirpfx {
222     my ($path) = shift @_;
223     my ($sep) = shift @_;
224     my $ret = "", $i;
225     while (($i = index $path, $sep) >= 0) {
226         $path = substr $path, ($i + length $sep);
227         $ret .= "..$sep";
228     }
229     return $ret;
230 }
231
232 sub findfile {
233   my ($name) = @_;
234   my $dir;
235   my $i;
236   my $outdir = undef;
237   unless (defined $findfilecache{$name}) {
238     $i = 0;
239     foreach $dir (@srcdirs) {
240       $outdir = $dir, $i++ if -f "$dir$name";
241     }
242     die "multiple instances of source file $name\n" if $i > 1;
243     $findfilecache{$name} = (defined $outdir ? $outdir . $name : undef);
244   }
245   return $findfilecache{$name};
246 }
247
248 sub objects {
249   my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
250   my @ret;
251   my ($i, $x, $y);
252   @ret = ();
253   foreach $i (@{$programs{$prog}}) {
254     $x = "";
255     if ($i =~ /^(.*)\.(res|rsrc)/) {
256       $y = $1;
257       ($x = $rtmpl) =~ s/X/$y/;
258     } elsif ($i =~ /^(.*)\.lib/) {
259       $y = $1;
260       ($x = $ltmpl) =~ s/X/$y/;
261     } elsif ($i !~ /\./) {
262       ($x = $otmpl) =~ s/X/$i/;
263     }
264     push @ret, $x if $x ne "";
265   }
266   return join " ", @ret;
267 }
268
269 sub special {
270   my ($prog, $suffix) = @_;
271   my @ret;
272   my ($i, $x, $y);
273   @ret = ();
274   foreach $i (@{$programs{$prog}}) {
275     if (substr($i, (length $i) - (length $suffix)) eq $suffix) {
276       push @ret, $i;
277     }
278   }
279   return join " ", @ret;
280 }
281
282 sub splitline {
283   my ($line, $width, $splitchar) = @_;
284   my ($result, $len);
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";
290     $line = $2;
291     $len = 60;
292   }
293   return $result . $line;
294 }
295
296 sub deps {
297   my ($otmpl, $rtmpl, $prefix, $dirsep, $depchar, $splitchar) = @_;
298   my ($i, $x, $y);
299   my @deps, @ret;
300   @ret = ();
301   $depchar ||= ':';
302   foreach $i (sort keys %depends) {
303     next if $specialobj{$mftyp}->{$i};
304     if ($i =~ /^(.*)\.(res|rsrc)/) {
305       next if !defined $rtmpl;
306       $y = $1;
307       ($x = $rtmpl) =~ s/X/$y/;
308     } else {
309       ($x = $otmpl) =~ s/X/$i/;
310     }
311     @deps = @{$depends{$i}};
312     @deps = map {
313       $_ = &findfile($_);
314       s/\//$dirsep/g;
315       $_ = $prefix . $_;
316     } @deps;
317     push @ret, {obj => $x, deps => [@deps]};
318   }
319   return @ret;
320 }
321
322 sub prognames {
323   my ($types) = @_;
324   my ($n, $prog, $type);
325   my @ret;
326   @ret = ();
327   foreach $n (@prognames) {
328     ($prog, $type) = split ",", $n;
329     push @ret, $n if index(":$types:", ":$type:") >= 0;
330   }
331   return @ret;
332 }
333
334 sub progrealnames {
335   my ($types) = @_;
336   my ($n, $prog, $type);
337   my @ret;
338   @ret = ();
339   foreach $n (@prognames) {
340     ($prog, $type) = split ",", $n;
341     push @ret, $prog if index(":$types:", ":$type:") >= 0;
342   }
343   return @ret;
344 }
345
346 sub manpages {
347   my ($types,$suffix) = @_;
348
349   # assume that all UNIX programs have a man page
350   if($suffix eq "1" && $types =~ /:X:/) {
351     return map("$_.1", &progrealnames($types));
352   }
353   return ();
354 }
355
356 # Now we're ready to output the actual Makefiles.
357
358 if (defined $makefiles{'cygwin'}) {
359     $dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
360
361     ##-- CygWin makefile
362     open OUT, ">$makefiles{'cygwin'}"; select OUT;
363     print
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;
369     print $_;
370     print
371     "\n".
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".
378     "# CC = winegcc\n".
379     "# RC = wrc\n".
380     "# You may also need to tell windres where to find include files:\n".
381     "# RCINC = --include-dir c:\\cygwin\\include\\\n".
382     "\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)) .
386                "\n".
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".
390     "\n".
391     ".SUFFIXES:\n".
392     "\n".
393     "%.o: %.c\n".
394     "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
395     "\n".
396     "%.res.o: %.rc\n".
397     "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n".
398     "\n";
399     print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
400     print "\n\n";
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";
410     }
411     foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/")) {
412       print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
413         "\n";
414     }
415     print "\n";
416     print $makefile_extra{'cygwin'};
417     print "\nclean:\n".
418     "\trm -f *.o *.exe *.res.o *.map\n".
419     "\n";
420     select STDOUT; close OUT;
421
422 }
423
424 ##-- Borland makefile
425 if (defined $makefiles{'borland'}) {
426     $dirpfx = &dirpfx($makefiles{'borland'}, "\\");
427
428     %stdlibs = (  # Borland provides many Win32 API libraries intrinsically
429       "advapi32" => 1,
430       "comctl32" => 1,
431       "comdlg32" => 1,
432       "gdi32" => 1,
433       "imm32" => 1,
434       "shell32" => 1,
435       "user32" => 1,
436       "winmm" => 1,
437       "winspool" => 1,
438       "wsock32" => 1,
439     );
440     open OUT, ">$makefiles{'borland'}"; select OUT;
441     print
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;
447     print $_;
448     print
449     "\n".
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".
453     "\n".
454     "# C compilation flags\n".
455     "CFLAGS = -D_WINDOWS -DWINVER=0x0401\n".
456     "\n".
457     "# Get include directory for resource compiler\n".
458     "!if !\$d(BCB)\n".
459     "BCB = \$(MAKEDIR)\\..\n".
460     "!endif\n".
461     "\n".
462     ".c.obj:\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".
467     ".rc.res:\n".
468     &splitline("\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include -r".
469       " -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n".
470     "\n";
471     print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
472     print "\n\n";
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";
479     }
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;
485       @objlines = ("");
486       foreach $i (@objlist) {
487         if (length($objlines[$#objlines] . " $i") > 50) {
488           push @objlines, "";
489         }
490         $objlines[$#objlines] .= " $i";
491       }
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";
497       }
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";
506       print "\n";
507     }
508     foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
509       print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
510         "\n";
511     }
512     print "\n";
513     print $makefile_extra{'borland'};
514     print "\nclean:\n".
515     "\t-del *.obj\n".
516     "\t-del *.exe\n".
517     "\t-del *.res\n".
518     "\t-del *.pch\n".
519     "\t-del *.aps\n".
520     "\t-del *.il*\n".
521     "\t-del *.pdb\n".
522     "\t-del *.rsp\n".
523     "\t-del *.tds\n".
524     "\t-del *.\$\$\$\$\$\$\n";
525     select STDOUT; close OUT;
526 }
527
528 if (defined $makefiles{'vc'}) {
529     $dirpfx = &dirpfx($makefiles{'vc'}, "\\");
530
531     ##-- Visual C++ makefile
532     open OUT, ">$makefiles{'vc'}"; select OUT;
533     print
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";
537     print $help;
538     print
539       "\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".
543       "\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".
547       "\n".
548       ".c.obj:\n".
549       "\tcl \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) /c \$*.c\n".
550       ".rc.res:\n".
551       "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 -DWINVER=0x0400 \$*.rc\n".
552       "\n";
553     print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
554     print "\n\n";
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";
560     }
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;
566         @objlines = ("");
567         foreach $i (@objlist) {
568             if (length($objlines[$#objlines] . " $i") > 50) {
569                 push @objlines, "";
570             }
571             $objlines[$#objlines] .= " $i";
572         }
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";
577         }
578         print "\n";
579     }
580     foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
581         print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
582           "\n";
583     }
584     print "\n";
585     print $makefile_extra{'vc'};
586     print "\nclean: tidy\n".
587       "\t-del *.exe\n\n".
588       "tidy:\n".
589       "\t-del *.obj\n".
590       "\t-del *.res\n".
591       "\t-del *.pch\n".
592       "\t-del *.aps\n".
593       "\t-del *.ilk\n".
594       "\t-del *.pdb\n".
595       "\t-del *.rsp\n".
596       "\t-del *.dsp\n".
597       "\t-del *.dsw\n".
598       "\t-del *.ncb\n".
599       "\t-del *.opt\n".
600       "\t-del *.plg\n".
601       "\t-del *.map\n".
602       "\t-del *.idb\n".
603       "\t-del debug.log\n";
604     select STDOUT; close OUT;
605 }
606
607 if (defined $makefiles{'vcproj'}) {
608
609     $orig_dir = cwd;
610
611     ##-- MSVC 6 Workspace and projects
612     #
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.
619     #
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);
631     }
632     # Create the workspace file
633     open OUT, ">$project_name.dsw"; binmode OUT; select OUT;
634     print
635     "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
636     "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
637     "\r\n".
638     "###############################################################################\r\n".
639     "\r\n";
640     # List projects
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";
644     }
645     print
646     "\r\n".
647     "Package=<5>\r\n".
648     "{{{\r\n".
649     "}}}\r\n".
650     "\r\n".
651     "Package=<4>\r\n".
652     "{{{\r\n".
653     "}}}\r\n".
654     "\r\n".
655     "###############################################################################\r\n".
656     "\r\n".
657     "Global:\r\n".
658     "\r\n".
659     "Package=<5>\r\n".
660     "{{{\r\n".
661     "}}}\r\n".
662     "\r\n".
663     "Package=<3>\r\n".
664     "{{{\r\n".
665     "}}}\r\n".
666     "\r\n".
667     "###############################################################################\r\n".
668     "\r\n";
669     select STDOUT; close OUT;
670     chdir $orig_dir;
671
672     sub create_project {
673         my ($all_object_deps, $progname) = @_;
674         # Construct program's dependency info
675         %seen_objects = ();
676         %lib_files = ();
677         %source_files = ();
678         %header_files = ();
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;
686                 next;
687             }
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;
692                     next;
693                 }
694                 if($object_dep =~ /\.h$/io) {
695                     $header_files{$object_dep} = 1;
696                     next;
697                 }
698                 if($object_dep =~ /\.(rc|ico)$/io) {
699                     $resource_files{$object_dep} = 1;
700                     next;
701                 }
702             }
703         }
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;
714         print
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".
718         "\r\n".
719         "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n".
720         "\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".
724         "!MESSAGE \r\n".
725         "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n".
726         "!MESSAGE \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".
729         "!MESSAGE \r\n".
730         "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
731         "!MESSAGE \r\n".
732         "!MESSAGE Possible choices for configuration are:\r\n".
733         "!MESSAGE \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".
736         "!MESSAGE \r\n".
737         "\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".
742         "CPP=cl.exe\r\n".
743         "MTL=midl.exe\r\n".
744         "RSC=rc.exe\r\n".
745         "\r\n".
746         "!IF  \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
747         "\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".
772         "\r\n".
773         "!ELSEIF  \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
774         "\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".
799         "\r\n".
800         "!ENDIF \r\n".
801         "\r\n".
802         "# Begin Target\r\n".
803         "\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".
807         "\r\n".
808         "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
809         foreach $source_file (@source_files) {
810             print
811               "# Begin Source File\r\n".
812               "\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
816                 print
817                   "\r\n".
818                   "!IF  \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
819                   "\r\n".
820                   "!ELSEIF  \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
821                   "\r\n".
822                   "# ADD CPP /Zi\r\n".
823                   "\r\n".
824                   "!ENDIF \r\n".
825                   "\r\n";
826             }
827             print "# End Source File\r\n";
828         }
829         print
830         "# End Group\r\n".
831         "# Begin Group \"Header Files\"\r\n".
832         "\r\n".
833         "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
834         foreach $header_file (@header_files) {
835             print
836               "# Begin Source File\r\n".
837               "\r\n".
838               "SOURCE=..\\..\\$header_file\r\n".
839               "# End Source File\r\n";
840         }
841         print
842         "# End Group\r\n".
843         "# Begin Group \"Resource Files\"\r\n".
844         "\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) {
847             print
848               "# Begin Source File\r\n".
849               "\r\n".
850               "SOURCE=..\\..\\$resource_file\r\n".
851               "# End Source File\r\n";
852         }
853         print
854         "# End Group\r\n".
855         "# End Target\r\n".
856         "# End Project\r\n";
857         select STDOUT; close OUT;
858         chdir "..";
859     }
860 }
861
862 if (defined $makefiles{'gtk'}) {
863     $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
864
865     ##-- X/GTK/Unix makefile
866     open OUT, ">$makefiles{'gtk'}"; select OUT;
867     print
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;
873     print $_;
874     print
875     "\n".
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".
885     "\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".
890     "ULDFLAGS =#\n".
891     "INSTALL=install\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     "mandir=\$(prefix)/man\n",
898     "man1dir=\$(mandir)/man1\n",
899     "\n".
900     ".SUFFIXES:\n".
901     "\n".
902     "%.o:\n".
903     "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
904     "\n";
905     print &splitline("all:" . join "", map { " $_" } &progrealnames("X:U"));
906     print "\n\n";
907     foreach $p (&prognames("X:U")) {
908       ($prog, $type) = split ",", $p;
909       $objstr = &objects($p, "X.o", undef, undef);
910       print &splitline($prog . ": " . $objstr), "\n";
911       $libstr = &objects($p, undef, undef, "-lX");
912       print &splitline("\t\$(CC)" . $mw . " \$(${type}LDFLAGS) -o \$@ " .
913                        $objstr . " $libstr", 69), "\n\n";
914     }
915     foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
916       print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
917           "\n";
918     }
919     print "\n";
920     print $makefile_extra{'gtk'};
921     print "\nclean:\n".
922     "\trm -f *.o". (join "", map { " $_" } &progrealnames("X:U")) . "\n";
923     select STDOUT; close OUT;
924 }
925
926 if (defined $makefiles{'mpw'}) {
927     ##-- MPW Makefile
928     open OUT, ">$makefiles{'mpw'}"; select OUT;
929     print
930     "# Makefile for $project_name under MPW.\n#\n".
931     "# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
932     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
933     # MPW command line option is -d not /D
934     ($_ = $help) =~ s/=\/D/=-d /gs;
935     print $_;
936     print "\n\n".
937     "ROptions     = `Echo \"{VER}\" | StreamEdit -e \"1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6\"' \xa81 '\xb6\xb6\xb6\xb6\xb6\"'\"`".
938     "\n".
939     "C_68K = {C}\n".
940     "C_CFM68K = {C}\n".
941     "C_PPC = {PPCC}\n".
942     "C_Carbon = {PPCC}\n".
943     "\n".
944     "# -w 35 disables \"unused parameter\" warnings\n".
945     "COptions     = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6\n".
946     "          -notOnce\n".
947     "COptions_68K = {COptions} -model far -opt time\n".
948     "# Enabling \"-opt space\" for CFM-68K gives me undefined references to\n".
949     "# _\$LDIVT and _\$LMODT.\n".
950     "COptions_CFM68K = {COptions} -model cfmSeg -opt time\n".
951     "COptions_PPC = {COptions} -opt size -traceback\n".
952     "COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON\n".
953     "\n".
954     "Link_68K = ILink\n".
955     "Link_CFM68K = ILink\n".
956     "Link_PPC = PPCLink\n".
957     "Link_Carbon = PPCLink\n".
958     "\n".
959     "LinkOptions = -c 'pTTY'\n".
960     "LinkOptions_68K = {LinkOptions} -br 68k -model far -compact\n".
961     "LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact\n".
962     "LinkOptions_PPC = {LinkOptions}\n".
963     "LinkOptions_Carbon = -m __appstart -w {LinkOptions}\n".
964     "\n".
965     "Libs_68K = \"{CLibraries}StdCLib.far.o\" \xb6\n".
966     "           \"{Libraries}MacRuntime.o\" \xb6\n".
967     "           \"{Libraries}MathLib.far.o\" \xb6\n".
968     "           \"{Libraries}IntEnv.far.o\" \xb6\n".
969     "           \"{Libraries}Interface.o\" \xb6\n".
970     "           \"{Libraries}Navigation.far.o\" \xb6\n".
971     "           \"{Libraries}OpenTransport.o\" \xb6\n".
972     "           \"{Libraries}OpenTransportApp.o\" \xb6\n".
973     "           \"{Libraries}OpenTptInet.o\" \xb6\n".
974     "           \"{Libraries}UnicodeConverterLib.far.o\"\n".
975     "\n".
976     "Libs_CFM = \"{SharedLibraries}InterfaceLib\" \xb6\n".
977     "           \"{SharedLibraries}StdCLib\" \xb6\n".
978     "           \"{SharedLibraries}AppearanceLib\" \xb6\n".
979     "                   -weaklib AppearanceLib \xb6\n".
980     "           \"{SharedLibraries}NavigationLib\" \xb6\n".
981     "                   -weaklib NavigationLib \xb6\n".
982     "           \"{SharedLibraries}TextCommon\" \xb6\n".
983     "                   -weaklib TextCommon \xb6\n".
984     "           \"{SharedLibraries}UnicodeConverter\" \xb6\n".
985     "                   -weaklib UnicodeConverter\n".
986     "\n".
987     "Libs_CFM68K =      {Libs_CFM} \xb6\n".
988     "           \"{CFM68KLibraries}NuMacRuntime.o\"\n".
989     "\n".
990     "Libs_PPC = {Libs_CFM} \xb6\n".
991     "           \"{SharedLibraries}ControlsLib\" \xb6\n".
992     "                   -weaklib ControlsLib \xb6\n".
993     "           \"{SharedLibraries}WindowsLib\" \xb6\n".
994     "                   -weaklib WindowsLib \xb6\n".
995     "           \"{SharedLibraries}OpenTransportLib\" \xb6\n".
996     "                   -weaklib OTClientLib \xb6\n".
997     "                   -weaklib OTClientUtilLib \xb6\n".
998     "           \"{SharedLibraries}OpenTptInternetLib\" \xb6\n".
999     "                   -weaklib OTInetClientLib \xb6\n".
1000     "           \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1001     "           \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1002     "           \"{PPCLibraries}CarbonAccessors.o\" \xb6\n".
1003     "           \"{PPCLibraries}OpenTransportAppPPC.o\" \xb6\n".
1004     "           \"{PPCLibraries}OpenTptInetPPC.o\"\n".
1005     "\n".
1006     "Libs_Carbon =      \"{PPCLibraries}CarbonStdCLib.o\" \xb6\n".
1007     "           \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1008     "           \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1009     "           \"{SharedLibraries}CarbonLib\" \xb6\n".
1010     "           \"{SharedLibraries}StdCLib\"\n".
1011     "\n";
1012     print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6");
1013     print "\n\n";
1014     foreach $p (&prognames("M")) {
1015       ($prog, $type) = split ",", $p;
1016
1017       print &splitline("$prog \xc4 $prog.68k $prog.ppc $prog.carbon",
1018                    undef, "\xb6"), "\n\n";
1019
1020       $rsrc = &objects($p, "", "X.rsrc", undef);
1021
1022       foreach $arch (qw(68K CFM68K PPC Carbon)) {
1023           $objstr = &objects($p, "X.\L$arch\E.o", "", undef);
1024           print &splitline("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6");
1025           print "\n";
1026           print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
1027           print &splitline("\t{Link_$arch} -o {Targ} -fragname $prog " .
1028                        "{LinkOptions_$arch} " .
1029                        $objstr . " {Libs_$arch}", 69, "\xb6"), "\n";
1030           print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
1031       }
1032
1033     }
1034     foreach $d (&deps("", "X.rsrc", "::", ":")) {
1035       next unless $d->{obj};
1036       print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
1037                    undef, "\xb6"), "\n";
1038       print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n";
1039     }
1040     foreach $arch (qw(68K CFM68K)) {
1041         foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1042          next unless $d->{obj};
1043         print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1044                                  join " ", @{$d->{deps}}),
1045                          undef, "\xb6"), "\n";
1046          print "\t{C_$arch} ", $d->{deps}->[0],
1047                " -o {Targ} {COptions_$arch}\n\n";
1048          }
1049     }
1050     foreach $arch (qw(PPC Carbon)) {
1051         foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1052          next unless $d->{obj};
1053         print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1054                                  join " ", @{$d->{deps}}),
1055                          undef, "\xb6"), "\n";
1056          # The odd stuff here seems to stop afpd getting confused.
1057          print "\techo -n > {Targ}\n";
1058          print "\tsetfile -t XCOF {Targ}\n";
1059          print "\t{C_$arch} ", $d->{deps}->[0],
1060                " -o {Targ} {COptions_$arch}\n\n";
1061          }
1062     }
1063     select STDOUT; close OUT;
1064 }
1065
1066 if (defined $makefiles{'lcc'}) {
1067     $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
1068
1069     ##-- lcc makefile
1070     open OUT, ">$makefiles{'lcc'}"; select OUT;
1071     print
1072     "# Makefile for $project_name under lcc.\n".
1073     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1074     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1075     # lcc command line option is -D not /D
1076     ($_ = $help) =~ s/=\/D/=-D/gs;
1077     print $_;
1078     print
1079     "\n".
1080     "# If you rename this file to `Makefile', you should change this line,\n".
1081     "# so that the .rsp files still depend on the correct makefile.\n".
1082     "MAKEFILE = Makefile.lcc\n".
1083     "\n".
1084     "# C compilation flags\n".
1085     "CFLAGS = -D_WINDOWS " .
1086       (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1087       "\n".
1088     "\n".
1089     "# Get include directory for resource compiler\n".
1090     "\n".
1091     ".c.obj:\n".
1092     &splitline("\tlcc -O -p6 \$(COMPAT) \$(FWHACK)".
1093       " \$(XFLAGS) \$(CFLAGS)  \$*.c",69)."\n".
1094     ".rc.res:\n".
1095     &splitline("\tlrc \$(FWHACK) \$(RCFL) -r \$*.rc",69)."\n".
1096     "\n";
1097     print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
1098     print "\n\n";
1099     foreach $p (&prognames("G:C")) {
1100       ($prog, $type) = split ",", $p;
1101       $objstr = &objects($p, "X.obj", "X.res", undef);
1102       print &splitline("$prog.exe: " . $objstr ), "\n";
1103       $subsystemtype = undef;
1104       if ($type eq "G") { $subsystemtype = "-subsystem  windows"; }
1105       my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1106       print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1107       print "\n\n";
1108     }
1109
1110     foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
1111       print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1112         "\n";
1113     }
1114     print "\n";
1115     print $makefile_extra{'lcc'};
1116     print "\nclean:\n".
1117     "\t-del *.obj\n".
1118     "\t-del *.exe\n".
1119     "\t-del *.res\n";
1120
1121     select STDOUT; close OUT;
1122 }
1123
1124 if (defined $makefiles{'osx'}) {
1125     $dirpfx = &dirpfx($makefiles{'osx'}, "/");
1126
1127     ##-- Mac OS X makefile
1128     open OUT, ">$makefiles{'osx'}"; select OUT;
1129     print
1130     "# Makefile for $project_name under Mac OS X.\n".
1131     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1132     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1133     # gcc command line option is -D not /D
1134     ($_ = $help) =~ s/=\/D/=-D/gs;
1135     print $_;
1136     print
1137     "CC = \$(TOOLPATH)gcc\n".
1138     "\n".
1139     &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1140                (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1141     "LDFLAGS = -framework Cocoa\n".
1142     &splitline("all:" . join "", map { " $_" } &progrealnames("MX")) .
1143     "\n" .
1144     $makefile_extra{'osx'} .
1145     "\n".
1146     ".SUFFIXES: .o .c .m\n".
1147     "\n".
1148     ".c.o:\n".
1149     "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
1150     ".m.o:\n".
1151     "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
1152     "\n";
1153     print "\n\n";
1154     foreach $p (&prognames("MX")) {
1155       ($prog, $type) = split ",", $p;
1156       $objstr = &objects($p, "X.o", undef, undef);
1157       $icon = &special($p, ".icns");
1158       $infoplist = &special($p, "info.plist");
1159       print "${prog}.app:\n\tmkdir -p \$\@\n";
1160       print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n";
1161       print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1162       $targets = "${prog}.app/Contents/MacOS/$prog";
1163       if (defined $icon) {
1164         print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1165         print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n";
1166         $targets .= " ${prog}.app/Contents/Resources/${prog}.icns";
1167       }
1168       if (defined $infoplist) {
1169         print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n";
1170         $targets .= " ${prog}.app/Contents/Info.plist";
1171       }
1172       $targets .= " \$(${prog}_extra)";
1173       print &splitline("${prog}: $targets", 69) . "\n\n";
1174       print &splitline("${prog}.app/Contents/MacOS/$prog: ".
1175                        "${prog}.app/Contents/MacOS " . $objstr), "\n";
1176       $libstr = &objects($p, undef, undef, "-lX");
1177       print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
1178                        $objstr . " $libstr", 69), "\n\n";
1179     }
1180     foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1181       print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1182           "\n";
1183     }
1184     print "\nclean:\n".
1185     "\trm -f *.o *.dmg\n".
1186     "\trm -rf *.app\n";
1187     select STDOUT; close OUT;
1188 }