~ubuntu-branches/ubuntu/wily/sgt-puzzles/wily

« back to all changes in this revision

Viewing changes to .pc/301_fix-install-dirs.diff/mkfiles.pl

  • Committer: Package Import Robot
  • Author(s): Ben Hutchings
  • Date: 2014-10-01 22:10:50 UTC
  • mfrom: (1.2.14)
  • Revision ID: package-import@ubuntu.com-20141001221050-a83g6j14c9dal6ek
Tags: 20140928.r10274-1
* New upstream version
  - Version scheme is now date-based
  - Fix a failure to warn about non-unique rows/columns in non-square Unruly
    grids (Closes: #718354)
* Add Debian menu entries for Range and Signpost
* debian/watch: Delete, as new versions are date-based and there is
  currently no obvious way to find the last date changed
* Disable 304_combine-binaries.diff which no longer applies
* Build using autotools
  - Drop patches 301_fix-install-dirs.diff, 305_no-werror.diff
* Exclude puzzles.chm from orig tarball because it requires non-free tools
  to regenerate from source
* Update policy version to 3.9.6; no changes required

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
# Other things undone:
17
 
#  - special-define objects (foo.o[PREPROCSYMBOL]) are not
18
 
#    supported in the mac or vcproj makefiles.
19
 
 
20
 
use warnings;
21
 
use IO::Handle;
22
 
use Cwd;
23
 
 
24
 
@filestack = ();
25
 
$in = new IO::Handle;
26
 
open $in, "Recipe" or do {
27
 
    # We want to deal correctly with being run from one of the
28
 
    # subdirs in the source tree. So if we can't find Recipe here,
29
 
    # try one level up.
30
 
    chdir "..";
31
 
    open $in, "Recipe" or die "unable to open Recipe file\n";
32
 
};
33
 
push @filestack, $in;
34
 
 
35
 
# HACK: One of the source files in `charset' is auto-generated by
36
 
# sbcsgen.pl. We need to generate that _now_, before attempting
37
 
# dependency analysis.
38
 
eval 'chdir "charset"; require "sbcsgen.pl"; chdir ".."';
39
 
 
40
 
@srcdirs = ("./");
41
 
 
42
 
$divert = undef; # ref to scalar in which text is currently being put
43
 
$help = ""; # list of newline-free lines of help text
44
 
$project_name = "project"; # this is a good enough default
45
 
%makefiles = (); # maps makefile types to output makefile pathnames
46
 
%makefile_extra = (); # maps makefile types to extra Makefile text
47
 
%programs = (); # maps prog name + type letter to listref of objects/resources
48
 
%groups = (); # maps group name to listref of objects/resources
49
 
 
50
 
@allobjs = (); # all object file names
51
 
 
52
 
readinput: while (1) {
53
 
  $in = $filestack[$#filestack];
54
 
  while (not defined ($_ = <$in>)) {
55
 
    close $filestack[$#filestack];
56
 
    pop @filestack;
57
 
    last readinput if 0 == scalar @filestack;
58
 
    $in = $filestack[$#filestack];
59
 
  }
60
 
  chomp;
61
 
  @_ = split;
62
 
 
63
 
  # If we're gathering help text, keep doing so.
64
 
  if (defined $divert) {
65
 
      if ((defined $_[0]) && $_[0] eq "!end") {
66
 
          $divert = undef;
67
 
      } else {
68
 
          ${$divert} .= "$_\n";
69
 
      }
70
 
      next;
71
 
  }
72
 
  # Skip comments and blank lines.
73
 
  next if /^\s*#/ or scalar @_ == 0;
74
 
 
75
 
  if ($_[0] eq "!begin" and $_[1] eq "help") { $divert = \$help; next; }
76
 
  if ($_[0] eq "!name") { $project_name = $_[1]; next; }
77
 
  if ($_[0] eq "!srcdir") { push @srcdirs, $_[1]; next; }
78
 
  if ($_[0] eq "!makefile" and &mfval($_[1])) { $makefiles{$_[1]}=$_[2]; next;}
79
 
  if ($_[0] eq "!specialobj" and &mfval($_[1])) { $specialobj{$_[1]}->{$_[2]} = 1; next;}
80
 
  if ($_[0] eq "!begin") {
81
 
      if ($_[1] =~ /^>(.*)/) {
82
 
          $divert = \$auxfiles{$1};
83
 
      } elsif (&mfval($_[1])) {
84
 
          $divert = \$makefile_extra{$_[1]};
85
 
      }
86
 
      next;
87
 
  }
88
 
  if ($_[0] eq "!include") {
89
 
      @newfiles = ();
90
 
      for ($i = 1; $i <= $#_; $i++) {
91
 
          push @newfiles, (sort glob $_[$i]);
92
 
      }
93
 
      for ($i = $#newfiles; $i >= 0; $i--) {
94
 
          $file = $newfiles[$i];
95
 
          $f = new IO::Handle;
96
 
          open $f, "<$file" or die "unable to open include file '$file'\n";
97
 
          push @filestack, $f;
98
 
      }
99
 
      next;
100
 
  }
101
 
 
102
 
  # Now we have an ordinary line. See if it's an = line, a : line
103
 
  # or a + line.
104
 
  @objs = @_;
105
 
 
106
 
  if ($_[0] eq "+") {
107
 
    $listref = $lastlistref;
108
 
    $prog = undef;
109
 
    die "$.: unexpected + line\n" if !defined $lastlistref;
110
 
  } elsif ($_[1] eq "=") {
111
 
    $groups{$_[0]} = [];
112
 
    $listref = $groups{$_[0]};
113
 
    $prog = undef;
114
 
    shift @objs; # eat the group name
115
 
  } elsif ($_[1] eq "+=") {
116
 
    $groups{$_[0]} = [] if !defined $groups{$_[0]};
117
 
    $listref = $groups{$_[0]};
118
 
    $prog = undef;
119
 
    shift @objs; # eat the group name
120
 
  } elsif ($_[1] eq ":") {
121
 
    $listref = [];
122
 
    $prog = $_[0];
123
 
    shift @objs; # eat the program name
124
 
  } else {
125
 
    die "$.: unrecognised line type: '$_'\n";
126
 
  }
127
 
  shift @objs; # eat the +, the = or the :
128
 
 
129
 
  while (scalar @objs > 0) {
130
 
    $i = shift @objs;
131
 
    if ($groups{$i}) {
132
 
      foreach $j (@{$groups{$i}}) { unshift @objs, $j; }
133
 
    } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or
134
 
              $i eq "[X]" or $i eq "[U]" or $i eq "[MX]") and defined $prog) {
135
 
      $type = substr($i,1,(length $i)-2);
136
 
    } else {
137
 
      if ($i =~ /\?$/) {
138
 
        # Object files with a trailing question mark are optional:
139
 
        # the build can proceed fine without them, so we only use
140
 
        # them if their primary source files are present.
141
 
        $i =~ s/\?$//;
142
 
        $i = undef unless defined &finddep($i);
143
 
      } elsif ($i =~ /\|/) {
144
 
        # Object file descriptions containing a vertical bar are
145
 
        # lists of choices: we use the _first_ one whose primary
146
 
        # source file is present.
147
 
        @options = split /\|/, $i;
148
 
        $j = undef;
149
 
        foreach $k (@options) {
150
 
          $j=$k, last if defined &finddep($k);
151
 
        }
152
 
        die "no alternative found for $i\n" unless defined $j;
153
 
        $i = $j;
154
 
      }
155
 
      if (defined $i) {
156
 
        push @$listref, $i;
157
 
        push @allobjs, $i;
158
 
      }
159
 
    }
160
 
  }
161
 
  if ($prog and $type) {
162
 
    die "multiple program entries for $prog [$type]\n"
163
 
        if defined $programs{$prog . "," . $type};
164
 
    $programs{$prog . "," . $type} = $listref;
165
 
  }
166
 
  $lastlistref = $listref;
167
 
}
168
 
 
169
 
foreach $aux (sort keys %auxfiles) {
170
 
    open AUX, ">$aux";
171
 
    print AUX $auxfiles{$aux};
172
 
    close AUX;
173
 
}
174
 
 
175
 
# Find object file names with predefines (in square brackets after
176
 
# the module name), and decide on actual object names for them.
177
 
foreach $i (@allobjs) {
178
 
  if ($i !~ /\[/) {
179
 
    $objname{$i} = $i;
180
 
    $srcname{$i} = $i;
181
 
    $usedobjname{$i} = 1;
182
 
  }
183
 
}
184
 
foreach $i (@allobjs) {
185
 
  if ($i =~ /^(.*)\[([^\]]*)/) {
186
 
    $defs{$i} = [ split ",",$2 ];
187
 
    $srcname{$i} = $s = $1;
188
 
    $index = 1;
189
 
    while (1) {
190
 
      $maxlen = length $s;
191
 
      $maxlen = 8 if $maxlen < 8;
192
 
      $chop = $maxlen - length $index;
193
 
      $chop = length $s if $chop > length $s;
194
 
      $chop = 0 if $chop < 0;
195
 
      $name = substr($s, 0, $chop) . $index;
196
 
      $index++, next if $usedobjname{$name};
197
 
      $objname{$i} = $name;
198
 
      $usedobjname{$name} = 1;
199
 
      last;
200
 
    }
201
 
  }
202
 
}
203
 
 
204
 
# Now retrieve the complete list of objects and resource files, and
205
 
# construct dependency data for them. While we're here, expand the
206
 
# object list for each program, and complain if its type isn't set.
207
 
@prognames = sort keys %programs;
208
 
%depends = ();
209
 
@scanlist = ();
210
 
foreach $i (@prognames) {
211
 
  ($prog, $type) = split ",", $i;
212
 
  # Strip duplicate object names.
213
 
  $prev = '';
214
 
  @list = grep { $status = ($prev ne $_); $prev=$_; $status }
215
 
          sort @{$programs{$i}};
216
 
  $programs{$i} = [@list];
217
 
  foreach $jj (@list) {
218
 
    $j = $srcname{$jj};
219
 
    $file = &finddep($j);
220
 
    if (defined $file) {
221
 
      $depends{$jj} = [$file];
222
 
      push @scanlist, $file;
223
 
    }
224
 
  }
225
 
}
226
 
 
227
 
# Scan each file on @scanlist and find further inclusions.
228
 
# Inclusions are given by lines of the form `#include "otherfile"'
229
 
# (system headers are automatically ignored by this because they'll
230
 
# be given in angle brackets). Files included by this method are
231
 
# added back on to @scanlist to be scanned in turn (if not already
232
 
# done).
233
 
#
234
 
# Resource scripts (.rc) can also include a file by means of a line
235
 
# ending `ICON "filename"'. Files included by this method are not
236
 
# added to @scanlist because they can never include further files.
237
 
#
238
 
# In this pass we write out a hash %further which maps a source
239
 
# file name into a listref containing further source file names.
240
 
 
241
 
%further = ();
242
 
while (scalar @scanlist > 0) {
243
 
  $file = shift @scanlist;
244
 
  next if defined $further{$file}; # skip if we've already done it
245
 
  $further{$file} = [];
246
 
  $dirfile = &findfile($file);
247
 
  open IN, "$dirfile" or die "unable to open source file $file\n";
248
 
  while (<IN>) {
249
 
    chomp;
250
 
    /^\s*#include\s+\"([^\"]+)\"/ and do {
251
 
      push @{$further{$file}}, $1;
252
 
      push @scanlist, $1;
253
 
      next;
254
 
    };
255
 
    /ICON\s+\"([^\"]+)\"\s*$/ and do {
256
 
      push @{$further{$file}}, $1;
257
 
      next;
258
 
    }
259
 
  }
260
 
  close IN;
261
 
}
262
 
 
263
 
# Now we're ready to generate the final dependencies section. For
264
 
# each key in %depends, we must expand the dependencies list by
265
 
# iteratively adding entries from %further.
266
 
foreach $i (keys %depends) {
267
 
  %dep = ();
268
 
  @scanlist = @{$depends{$i}};
269
 
  foreach $i (@scanlist) { $dep{$i} = 1; }
270
 
  while (scalar @scanlist > 0) {
271
 
    $file = shift @scanlist;
272
 
    foreach $j (@{$further{$file}}) {
273
 
      if (!$dep{$j}) {
274
 
        $dep{$j} = 1;
275
 
        push @{$depends{$i}}, $j;
276
 
        push @scanlist, $j;
277
 
      }
278
 
    }
279
 
  }
280
 
#  printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
281
 
}
282
 
 
283
 
# Validation of input.
284
 
 
285
 
sub mfval($) {
286
 
    my ($type) = @_;
287
 
    # Returns true if the argument is a known makefile type. Otherwise,
288
 
    # prints a warning and returns false;
289
 
    if (grep { $type eq $_ }
290
 
        ("vc","vcproj","cygwin","borland","lcc","gtk","mpw","nestedvm","osx","wce","gnustep","emcc")) {
291
 
            return 1;
292
 
        }
293
 
    warn "$.:unknown makefile type '$type'\n";
294
 
    return 0;
295
 
}
296
 
 
297
 
# Utility routines while writing out the Makefiles.
298
 
 
299
 
sub dirpfx {
300
 
    my ($path) = shift @_;
301
 
    my ($sep) = shift @_;
302
 
    my $ret = "";
303
 
    my $i;
304
 
    while (($i = index $path, $sep) >= 0) {
305
 
        $path = substr $path, ($i + length $sep);
306
 
        $ret .= "..$sep";
307
 
    }
308
 
    return $ret;
309
 
}
310
 
 
311
 
sub findfile {
312
 
  my ($name) = @_;
313
 
  my $dir;
314
 
  my $i;
315
 
  my $outdir = undef;
316
 
  unless (defined $findfilecache{$name}) {
317
 
    $i = 0;
318
 
    foreach $dir (@srcdirs) {
319
 
      $outdir = $dir, $i++ if -f "$dir$name";
320
 
    }
321
 
    die "multiple instances of source file $name\n" if $i > 1;
322
 
    $findfilecache{$name} = (defined $outdir ? $outdir . $name : undef);
323
 
  }
324
 
  return $findfilecache{$name};
325
 
}
326
 
 
327
 
sub finddep {
328
 
  my $j = shift @_;
329
 
  my $file;
330
 
  # Find the first dependency of an object.
331
 
 
332
 
  # Dependencies for "x" start with "x.c" or "x.m" (depending on
333
 
  # which one exists).
334
 
  # Dependencies for "x.res" start with "x.rc".
335
 
  # Dependencies for "x.rsrc" start with "x.r".
336
 
  # Both types of file are pushed on the list of files to scan.
337
 
  # Libraries (.lib) don't have dependencies at all.
338
 
  if ($j =~ /^(.*)\.res$/) {
339
 
    $file = "$1.rc";
340
 
  } elsif ($j =~ /^(.*)\.rsrc$/) {
341
 
    $file = "$1.r";
342
 
  } elsif ($j !~ /\./) {
343
 
    $file = "$j.c";
344
 
    $file = "$j.m" unless &findfile($file);
345
 
  } else {
346
 
    # For everything else, we assume it's its own dependency.
347
 
    $file = $j;
348
 
  }
349
 
  $file = undef unless &findfile($file);
350
 
  return $file;
351
 
}
352
 
 
353
 
sub objects {
354
 
  my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
355
 
  my @ret;
356
 
  my ($i, $x, $y);
357
 
  ($otmpl, $rtmpl, $ltmpl) = map { defined $_ ? $_ : "" } ($otmpl, $rtmpl, $ltmpl);
358
 
  @ret = ();
359
 
  foreach $ii (@{$programs{$prog}}) {
360
 
    $i = $objname{$ii};
361
 
    $x = "";
362
 
    if ($i =~ /^(.*)\.(res|rsrc)/) {
363
 
      $y = $1;
364
 
      ($x = $rtmpl) =~ s/X/$y/;
365
 
    } elsif ($i =~ /^(.*)\.lib/) {
366
 
      $y = $1;
367
 
      ($x = $ltmpl) =~ s/X/$y/;
368
 
    } elsif ($i !~ /\./) {
369
 
      ($x = $otmpl) =~ s/X/$i/;
370
 
    }
371
 
    push @ret, $x if $x ne "";
372
 
  }
373
 
  return join " ", @ret;
374
 
}
375
 
 
376
 
sub special {
377
 
  my ($prog, $suffix) = @_;
378
 
  my @ret;
379
 
  my ($i, $x, $y);
380
 
  @ret = ();
381
 
  foreach $ii (@{$programs{$prog}}) {
382
 
    $i = $objname{$ii};
383
 
    if (substr($i, (length $i) - (length $suffix)) eq $suffix) {
384
 
      push @ret, $i;
385
 
    }
386
 
  }
387
 
  return join " ", @ret;
388
 
}
389
 
 
390
 
sub splitline {
391
 
  my ($line, $width, $splitchar) = @_;
392
 
  my $result = "";
393
 
  my $len;
394
 
  $len = (defined $width ? $width : 76);
395
 
  $splitchar = (defined $splitchar ? $splitchar : '\\');
396
 
  while (length $line > $len) {
397
 
    $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
398
 
    $result .= $1;
399
 
    $result .= " ${splitchar}\n\t\t" if $2 ne '';
400
 
    $line = $2;
401
 
    $len = 60;
402
 
  }
403
 
  return $result . $line;
404
 
}
405
 
 
406
 
sub deps {
407
 
  my ($otmpl, $rtmpl, $prefix, $dirsep, $depchar, $splitchar) = @_;
408
 
  my ($i, $x, $y);
409
 
  my @deps;
410
 
  my @ret;
411
 
  @ret = ();
412
 
  $depchar ||= ':';
413
 
  foreach $ii (sort keys %depends) {
414
 
    $i = $objname{$ii};
415
 
    next if $specialobj{$mftyp}->{$i};
416
 
    if ($i =~ /^(.*)\.(res|rsrc)/) {
417
 
      next if !defined $rtmpl;
418
 
      $y = $1;
419
 
      ($x = $rtmpl) =~ s/X/$y/;
420
 
    } else {
421
 
      ($x = $otmpl) =~ s/X/$i/;
422
 
    }
423
 
    @deps = @{$depends{$ii}};
424
 
    # Skip things which are their own dependency.
425
 
    next if grep { $_ eq $i } @deps;
426
 
    @deps = map {
427
 
      $_ = &findfile($_);
428
 
      s/\//$dirsep/g;
429
 
      $_ = $prefix . $_;
430
 
    } @deps;
431
 
    push @ret, {obj => $x, deps => [@deps], defs => $defs{$ii}};
432
 
  }
433
 
  return @ret;
434
 
}
435
 
 
436
 
sub prognames {
437
 
  my ($types) = @_;
438
 
  my ($n, $prog, $type);
439
 
  my @ret;
440
 
  @ret = ();
441
 
  foreach $n (@prognames) {
442
 
    ($prog, $type) = split ",", $n;
443
 
    push @ret, $n if index(":$types:", ":$type:") >= 0;
444
 
  }
445
 
  return @ret;
446
 
}
447
 
 
448
 
sub progrealnames {
449
 
  my ($types) = @_;
450
 
  my ($n, $prog, $type);
451
 
  my @ret;
452
 
  @ret = ();
453
 
  foreach $n (@prognames) {
454
 
    ($prog, $type) = split ",", $n;
455
 
    push @ret, $prog if index(":$types:", ":$type:") >= 0;
456
 
  }
457
 
  return @ret;
458
 
}
459
 
 
460
 
sub manpages {
461
 
  my ($types,$suffix) = @_;
462
 
 
463
 
  # assume that all UNIX programs have a man page
464
 
  if($suffix eq "1" && $types =~ /:X:/) {
465
 
    return map("$_.1", &progrealnames($types));
466
 
  }
467
 
  return ();
468
 
}
469
 
 
470
 
# Now we're ready to output the actual Makefiles.
471
 
 
472
 
if (defined $makefiles{'cygwin'}) {
473
 
    $mftyp = 'cygwin';
474
 
    $dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
475
 
 
476
 
    ##-- CygWin makefile
477
 
    open OUT, ">$makefiles{'cygwin'}"; select OUT;
478
 
    print
479
 
    "# Makefile for $project_name under cygwin.\n".
480
 
    "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
481
 
    "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
482
 
    # gcc command line option is -D not /D
483
 
    ($_ = $help) =~ s/=\/D/=-D/gs;
484
 
    print $_;
485
 
    print
486
 
    "\n".
487
 
    "# You can define this path to point at your tools if you need to\n".
488
 
    "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
489
 
    "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
490
 
    "CC = \$(TOOLPATH)gcc\n".
491
 
    "RC = \$(TOOLPATH)windres\n".
492
 
    "# Uncomment the following two lines to compile under Winelib\n".
493
 
    "# CC = winegcc\n".
494
 
    "# RC = wrc\n".
495
 
    "# You may also need to tell windres where to find include files:\n".
496
 
    "# RCINC = --include-dir c:\\cygwin\\include\\\n".
497
 
    "\n".
498
 
    &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
499
 
      " -D_NO_OLDNAMES -DNO_MULTIMON -DNO_HTMLHELP " .
500
 
               (join " ", map {"-I$dirpfx$_"} @srcdirs)) .
501
 
               "\n".
502
 
    "LDFLAGS = -mno-cygwin -s\n".
503
 
    &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1".
504
 
      " --define WINVER=0x0400 --define MINGW32_FIX=1 " .
505
 
        (join " ", map {"--include $dirpfx$_"} @srcdirs) )."\n".
506
 
    "\n";
507
 
    print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
508
 
    print "\n\n";
509
 
    foreach $p (&prognames("G:C")) {
510
 
      ($prog, $type) = split ",", $p;
511
 
      $objstr = &objects($p, "X.o", "X.res.o", undef);
512
 
      print &splitline($prog . ".exe: " . $objstr), "\n";
513
 
      my $mw = $type eq "G" ? " -mwindows" : "";
514
 
      $libstr = &objects($p, undef, undef, "-lX");
515
 
      print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
516
 
                       "-Wl,-Map,$prog.map " .
517
 
                       $objstr . " $libstr", 69), "\n\n";
518
 
    }
519
 
    foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/")) {
520
 
      print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
521
 
        "\n";
522
 
      if ($d->{obj} =~ /\.res\.o$/) {
523
 
        print "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n";
524
 
      } else {
525
 
        $deflist = join "", map { " -D$_" } @{$d->{defs}};
526
 
        print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS)" .
527
 
            " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
528
 
      }
529
 
    }
530
 
    print "\n";
531
 
    print $makefile_extra{'cygwin'} || "";
532
 
    print "\nclean:\n".
533
 
    "\trm -f *.o *.exe *.res.o *.map\n".
534
 
    "\n";
535
 
    select STDOUT; close OUT;
536
 
 
537
 
}
538
 
 
539
 
##-- Borland makefile
540
 
if (defined $makefiles{'borland'}) {
541
 
    $mftyp = 'borland';
542
 
    $dirpfx = &dirpfx($makefiles{'borland'}, "\\");
543
 
 
544
 
    %stdlibs = (  # Borland provides many Win32 API libraries intrinsically
545
 
      "advapi32" => 1,
546
 
      "comctl32" => 1,
547
 
      "comdlg32" => 1,
548
 
      "gdi32" => 1,
549
 
      "imm32" => 1,
550
 
      "shell32" => 1,
551
 
      "user32" => 1,
552
 
      "winmm" => 1,
553
 
      "winspool" => 1,
554
 
      "wsock32" => 1,
555
 
    );
556
 
    open OUT, ">$makefiles{'borland'}"; select OUT;
557
 
    print
558
 
    "# Makefile for $project_name under Borland C.\n".
559
 
    "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
560
 
    "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
561
 
    # bcc32 command line option is -D not /D
562
 
    ($_ = $help) =~ s/=\/D/=-D/gs;
563
 
    print $_;
564
 
    print
565
 
    "\n".
566
 
    "# If you rename this file to `Makefile', you should change this line,\n".
567
 
    "# so that the .rsp files still depend on the correct makefile.\n".
568
 
    "MAKEFILE = Makefile.bor\n".
569
 
    "\n".
570
 
    "# C compilation flags\n".
571
 
    "CFLAGS = -D_WINDOWS -DWINVER=0x0401\n".
572
 
    "\n".
573
 
    "# Get include directory for resource compiler\n".
574
 
    "!if !\$d(BCB)\n".
575
 
    "BCB = \$(MAKEDIR)\\..\n".
576
 
    "!endif\n".
577
 
    "\n";
578
 
    print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
579
 
    print "\n\n";
580
 
    foreach $p (&prognames("G:C")) {
581
 
      ($prog, $type) = split ",", $p;
582
 
      $objstr =  &objects($p, "X.obj", "X.res", undef);
583
 
      print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
584
 
      my $ap = ($type eq "G") ? "-aa" : "-ap";
585
 
      print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n";
586
 
    }
587
 
    foreach $p (&prognames("G:C")) {
588
 
      ($prog, $type) = split ",", $p;
589
 
      print $prog, ".rsp: \$(MAKEFILE)\n";
590
 
      $objstr = &objects($p, "X.obj", undef, undef);
591
 
      @objlist = split " ", $objstr;
592
 
      @objlines = ("");
593
 
      foreach $i (@objlist) {
594
 
        if (length($objlines[$#objlines] . " $i") > 50) {
595
 
          push @objlines, "";
596
 
        }
597
 
        $objlines[$#objlines] .= " $i";
598
 
      }
599
 
      $c0w = ($type eq "G") ? "c0w32" : "c0x32";
600
 
      print "\techo $c0w + > $prog.rsp\n";
601
 
      for ($i=0; $i<=$#objlines; $i++) {
602
 
        $plus = ($i < $#objlines ? " +" : "");
603
 
        print "\techo$objlines[$i]$plus >> $prog.rsp\n";
604
 
      }
605
 
      print "\techo $prog.exe >> $prog.rsp\n";
606
 
      $objstr = &objects($p, "X.obj", "X.res", undef);
607
 
      @libs = split " ", &objects($p, undef, undef, "X");
608
 
      @libs = grep { !$stdlibs{$_} } @libs;
609
 
      unshift @libs, "cw32", "import32";
610
 
      $libstr = join ' ', @libs;
611
 
      print "\techo nul,$libstr, >> $prog.rsp\n";
612
 
      print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n";
613
 
      print "\n";
614
 
    }
615
 
    foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
616
 
      print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
617
 
        "\n";
618
 
      if ($d->{obj} =~ /\.res$/) {
619
 
        print &splitline("\tbrcc32 \$(FWHACK) \$(RCFL) " .
620
 
                         "-i \$(BCB)\\include -r -DNO_WINRESRC_H -DWIN32".
621
 
                         " -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n";
622
 
      } else {
623
 
        $deflist = join "", map { " -D$_" } @{$d->{defs}};
624
 
        print &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT)" .
625
 
                         " \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist ".
626
 
                         (join " ", map {"-I$dirpfx$_"} @srcdirs) .
627
 
                         " /o$d->{obj} /c ".$d->{deps}->[0],69)."\n";
628
 
      }
629
 
    }
630
 
    print "\n";
631
 
    print $makefile_extra{'borland'} || "";
632
 
    print "\nclean:\n".
633
 
    "\t-del *.obj\n".
634
 
    "\t-del *.exe\n".
635
 
    "\t-del *.res\n".
636
 
    "\t-del *.pch\n".
637
 
    "\t-del *.aps\n".
638
 
    "\t-del *.il*\n".
639
 
    "\t-del *.pdb\n".
640
 
    "\t-del *.rsp\n".
641
 
    "\t-del *.tds\n".
642
 
    "\t-del *.\$\$\$\$\$\$\n";
643
 
    select STDOUT; close OUT;
644
 
}
645
 
 
646
 
if (defined $makefiles{'vc'}) {
647
 
    $mftyp = 'vc';
648
 
    $dirpfx = &dirpfx($makefiles{'vc'}, "\\");
649
 
 
650
 
    ##-- Visual C++ makefile
651
 
    open OUT, ">$makefiles{'vc'}"; select OUT;
652
 
    print
653
 
      "# Makefile for $project_name under Visual C.\n".
654
 
      "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
655
 
      "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
656
 
    print $help;
657
 
    print
658
 
      "\n".
659
 
      "# If you rename this file to `Makefile', you should change this line,\n".
660
 
      "# so that the .rsp files still depend on the correct makefile.\n".
661
 
      "MAKEFILE = Makefile.vc\n".
662
 
      "\n".
663
 
      "# C compilation flags\n".
664
 
      "CFLAGS = /nologo /W3 /O1 /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401 /I.\n".
665
 
      "LFLAGS = /incremental:no /fixed\n".
666
 
      "\n";
667
 
    print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
668
 
    print "\n\n";
669
 
    foreach $p (&prognames("G:C")) {
670
 
        ($prog, $type) = split ",", $p;
671
 
        $objstr = &objects($p, "X.obj", "X.res", undef);
672
 
        print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
673
 
        print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
674
 
    }
675
 
    foreach $p (&prognames("G:C")) {
676
 
        ($prog, $type) = split ",", $p;
677
 
        print $prog, ".rsp: \$(MAKEFILE)\n";
678
 
        $objstr = &objects($p, "X.obj", "X.res", "X.lib");
679
 
        @objlist = split " ", $objstr;
680
 
        @objlines = ("");
681
 
        foreach $i (@objlist) {
682
 
            if (length($objlines[$#objlines] . " $i") > 50) {
683
 
                push @objlines, "";
684
 
            }
685
 
            $objlines[$#objlines] .= " $i";
686
 
        }
687
 
        $subsys = ($type eq "G") ? "windows" : "console";
688
 
        print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
689
 
        for ($i=0; $i<=$#objlines; $i++) {
690
 
            print "\techo$objlines[$i] >> $prog.rsp\n";
691
 
        }
692
 
        print "\n";
693
 
    }
694
 
    foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
695
 
        print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
696
 
          "\n";
697
 
        if ($d->{obj} =~ /\.res$/) {
698
 
            print "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 ".
699
 
              "-DWINVER=0x0400 -fo".$d->{obj}." ".$d->{deps}->[0]."\n";
700
 
        } else {
701
 
            $deflist = join "", map { " /D$_" } @{$d->{defs}};
702
 
            print "\tcl \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist".
703
 
              " /c ".$d->{deps}->[0]." /Fo$d->{obj}\n";
704
 
        }
705
 
    }
706
 
    print "\n";
707
 
    print $makefile_extra{'vc'} || "";
708
 
    print "\nclean: tidy\n".
709
 
      "\t-del *.exe\n\n".
710
 
      "tidy:\n".
711
 
      "\t-del *.obj\n".
712
 
      "\t-del *.res\n".
713
 
      "\t-del *.pch\n".
714
 
      "\t-del *.aps\n".
715
 
      "\t-del *.ilk\n".
716
 
      "\t-del *.pdb\n".
717
 
      "\t-del *.rsp\n".
718
 
      "\t-del *.dsp\n".
719
 
      "\t-del *.dsw\n".
720
 
      "\t-del *.ncb\n".
721
 
      "\t-del *.opt\n".
722
 
      "\t-del *.plg\n".
723
 
      "\t-del *.map\n".
724
 
      "\t-del *.idb\n".
725
 
      "\t-del debug.log\n";
726
 
    select STDOUT; close OUT;
727
 
}
728
 
 
729
 
if (defined $makefiles{'wce'}) {
730
 
    $mftyp = 'wce';
731
 
    $dirpfx = &dirpfx($makefiles{'wce'}, "\\");
732
 
 
733
 
    ##-- eMbedded Visual C PocketPC makefile
734
 
    open OUT, ">$makefiles{'wce'}"; select OUT;
735
 
    print
736
 
      "# Makefile for $project_name on PocketPC using eMbedded Visual C.\n".
737
 
      "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
738
 
      "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
739
 
    print $help;
740
 
    print
741
 
      "\n".
742
 
      "# If you rename this file to `Makefile', you should change this line,\n".
743
 
      "# so that the .rsp files still depend on the correct makefile.\n".
744
 
      "MAKEFILE = Makefile.wce\n".
745
 
      "\n".
746
 
      "# This makefile expects the environment to have been set up by one\n".
747
 
      "# of the PocketPC batch files wcearmv4.bat and wceemulator.bat. No\n".
748
 
      "# other build targets are currently supported, because they would\n".
749
 
      "# need a section in this if statement.\n".
750
 
      "!if \"\$(TARGETCPU)\" == \"emulator\"\n".
751
 
      "PLATFORM_DEFS=/D \"_i386_\" /D \"i_386_\" /D \"_X86_\" /D \"x86\"\n".
752
 
      "CC=cl\n".
753
 
      "BASELIBS=commctrl.lib coredll.lib corelibc.lib aygshell.lib\n".
754
 
      "MACHINE=IX86\n".
755
 
      "!else\n".
756
 
      "PLATFORM_DEFS=/D \"ARM\" /D \"_ARM_\" /D \"ARMV4\"\n".
757
 
      "CC=clarm\n".
758
 
      "BASELIBS=commctrl.lib coredll.lib aygshell.lib\n".
759
 
      "MACHINE=ARM\n".
760
 
      "!endif\n".
761
 
      "\n".
762
 
      "# C compilation flags\n".
763
 
      "CFLAGS = /nologo /W3 /O1 /MC /D _WIN32_WCE=420 /D \"WIN32_PLATFORM_PSPC=400\" /D UNDER_CE=420 \\\n".
764
 
      "         \$(PLATFORM_DEFS) \\\n".
765
 
      "         /D \"UNICODE\" /D \"_UNICODE\" /D \"NDEBUG\" /D \"NO_HTMLHELP\"\n".
766
 
      "\n".
767
 
      "LFLAGS = /nologo /incremental:no \\\n".
768
 
      "         /base:0x00010000 /stack:0x10000,0x1000 /entry:WinMainCRTStartup \\\n".
769
 
      "         /nodefaultlib:libc.lib /nodefaultlib:libcmt.lib /nodefaultlib:msvcrt.lib /nodefaultlib:OLDNAMES.lib \\\n".
770
 
      "         /subsystem:windowsce,4.20 /align:4096 /MACHINE:\$(MACHINE)\n".
771
 
      "\n".
772
 
      "RCFL = /d UNDER_CE=420 /d _WIN32_WCE=420 /d \"WIN32_PLATFORM_PSPC=400\" \\\n".
773
 
      "       \$(PLATFORM_DEFS) \\\n".
774
 
      "       /d \"NDEBUG\" /d \"UNICODE\" /d \"_UNICODE\"\n".
775
 
      "\n";
776
 
    print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G"));
777
 
    print "\n\n";
778
 
    foreach $p (&prognames("G")) {
779
 
        ($prog, $type) = split ",", $p;
780
 
        $objstr = &objects($p, "X.obj", "X.res", undef);
781
 
        print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
782
 
        print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
783
 
    }
784
 
    foreach $p (&prognames("G")) {
785
 
        ($prog, $type) = split ",", $p;
786
 
        print $prog, ".rsp: \$(MAKEFILE)\n";
787
 
        $objstr = &objects($p, "X.obj", "X.res", undef);
788
 
        @objlist = split " ", $objstr;
789
 
        @objlines = ("");
790
 
        foreach $i (@objlist) {
791
 
            if (length($objlines[$#objlines] . " $i") > 50) {
792
 
                push @objlines, "";
793
 
            }
794
 
            $objlines[$#objlines] .= " $i";
795
 
        }
796
 
        print "\techo \$(BASELIBS) > $prog.rsp\n";
797
 
        for ($i=0; $i<=$#objlines; $i++) {
798
 
            print "\techo$objlines[$i] >> $prog.rsp\n";
799
 
        }
800
 
        print "\n";
801
 
    }
802
 
    foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
803
 
        print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
804
 
          "\n";
805
 
        if ($d->{obj} =~ /\.res$/) {
806
 
            print "\trc \$(FWHACK) \$(RCFL) -r -fo".
807
 
              $d->{obj}." ".$d->{deps}->[0]."\n";
808
 
        } else {
809
 
            $deflist = join "", map { " /D$_" } @{$d->{defs}};
810
 
            print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist".
811
 
              " /c ".$d->{deps}->[0]." /Fo$d->{obj}\n";
812
 
        }
813
 
    }
814
 
    print "\n";
815
 
    print $makefile_extra{'wce'} || "";
816
 
    print "\nclean: tidy\n".
817
 
      "\t-del *.exe\n\n".
818
 
      "tidy:\n".
819
 
      "\t-del *.obj\n".
820
 
      "\t-del *.res\n".
821
 
      "\t-del *.pch\n".
822
 
      "\t-del *.aps\n".
823
 
      "\t-del *.ilk\n".
824
 
      "\t-del *.pdb\n".
825
 
      "\t-del *.rsp\n".
826
 
      "\t-del *.dsp\n".
827
 
      "\t-del *.dsw\n".
828
 
      "\t-del *.ncb\n".
829
 
      "\t-del *.opt\n".
830
 
      "\t-del *.plg\n".
831
 
      "\t-del *.map\n".
832
 
      "\t-del *.idb\n".
833
 
      "\t-del debug.log\n";
834
 
    select STDOUT; close OUT;
835
 
}
836
 
 
837
 
if (defined $makefiles{'vcproj'}) {
838
 
    $mftyp = 'vcproj';
839
 
 
840
 
    $orig_dir = cwd;
841
 
 
842
 
    ##-- MSVC 6 Workspace and projects
843
 
    #
844
 
    # Note: All files created in this section are written in binary
845
 
    # mode, because although MSVC's command-line make can deal with
846
 
    # LF-only line endings, MSVC project files really _need_ to be
847
 
    # CRLF. Hence, in order for mkfiles.pl to generate usable project
848
 
    # files even when run from Unix, I make sure all files are binary
849
 
    # and explicitly write the CRLFs.
850
 
    #
851
 
    # Create directories if necessary
852
 
    mkdir $makefiles{'vcproj'}
853
 
        if(! -d $makefiles{'vcproj'});
854
 
    chdir $makefiles{'vcproj'};
855
 
    @deps = &deps("X.obj", "X.res", "", "\\");
856
 
    %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
857
 
    # Create the project files
858
 
    # Get names of all Windows projects (GUI and console)
859
 
    my @prognames = &prognames("G:C");
860
 
    foreach $progname (@prognames) {
861
 
        create_project(\%all_object_deps, $progname);
862
 
    }
863
 
    # Create the workspace file
864
 
    open OUT, ">$project_name.dsw"; binmode OUT; select OUT;
865
 
    print
866
 
    "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
867
 
    "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
868
 
    "\r\n".
869
 
    "###############################################################################\r\n".
870
 
    "\r\n";
871
 
    # List projects
872
 
    foreach $progname (@prognames) {
873
 
      ($windows_project, $type) = split ",", $progname;
874
 
        print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n";
875
 
    }
876
 
    print
877
 
    "\r\n".
878
 
    "Package=<5>\r\n".
879
 
    "{{{\r\n".
880
 
    "}}}\r\n".
881
 
    "\r\n".
882
 
    "Package=<4>\r\n".
883
 
    "{{{\r\n".
884
 
    "}}}\r\n".
885
 
    "\r\n".
886
 
    "###############################################################################\r\n".
887
 
    "\r\n".
888
 
    "Global:\r\n".
889
 
    "\r\n".
890
 
    "Package=<5>\r\n".
891
 
    "{{{\r\n".
892
 
    "}}}\r\n".
893
 
    "\r\n".
894
 
    "Package=<3>\r\n".
895
 
    "{{{\r\n".
896
 
    "}}}\r\n".
897
 
    "\r\n".
898
 
    "###############################################################################\r\n".
899
 
    "\r\n";
900
 
    select STDOUT; close OUT;
901
 
    chdir $orig_dir;
902
 
 
903
 
    sub create_project {
904
 
        my ($all_object_deps, $progname) = @_;
905
 
        # Construct program's dependency info
906
 
        %seen_objects = ();
907
 
        %lib_files = ();
908
 
        %source_files = ();
909
 
        %header_files = ();
910
 
        %resource_files = ();
911
 
        @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
912
 
        foreach $object_file (@object_files) {
913
 
            next if defined $seen_objects{$object_file};
914
 
            $seen_objects{$object_file} = 1;
915
 
            if($object_file =~ /\.lib$/io) {
916
 
                $lib_files{$object_file} = 1;
917
 
                next;
918
 
            }
919
 
            $object_deps = $all_object_deps{$object_file};
920
 
            foreach $object_dep (@$object_deps) {
921
 
                if($object_dep =~ /\.c$/io) {
922
 
                    $source_files{$object_dep} = 1;
923
 
                    next;
924
 
                }
925
 
                if($object_dep =~ /\.h$/io) {
926
 
                    $header_files{$object_dep} = 1;
927
 
                    next;
928
 
                }
929
 
                if($object_dep =~ /\.(rc|ico)$/io) {
930
 
                    $resource_files{$object_dep} = 1;
931
 
                    next;
932
 
                }
933
 
            }
934
 
        }
935
 
        $libs = join " ", sort keys %lib_files;
936
 
        @source_files = sort keys %source_files;
937
 
        @header_files = sort keys %header_files;
938
 
        @resources = sort keys %resource_files;
939
 
        ($windows_project, $type) = split ",", $progname;
940
 
        mkdir $windows_project
941
 
            if(! -d $windows_project);
942
 
        chdir $windows_project;
943
 
        $subsys = ($type eq "G") ? "windows" : "console";
944
 
        open OUT, ">$windows_project.dsp"; binmode OUT; select OUT;
945
 
        print
946
 
        "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n".
947
 
        "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n".
948
 
        "# ** DO NOT EDIT **\r\n".
949
 
        "\r\n".
950
 
        "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n".
951
 
        "\r\n".
952
 
        "CFG=$windows_project - Win32 Debug\r\n".
953
 
        "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n".
954
 
        "!MESSAGE use the Export Makefile command and run\r\n".
955
 
        "!MESSAGE \r\n".
956
 
        "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n".
957
 
        "!MESSAGE \r\n".
958
 
        "!MESSAGE You can specify a configuration when running NMAKE\r\n".
959
 
        "!MESSAGE by defining the macro CFG on the command line. For example:\r\n".
960
 
        "!MESSAGE \r\n".
961
 
        "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
962
 
        "!MESSAGE \r\n".
963
 
        "!MESSAGE Possible choices for configuration are:\r\n".
964
 
        "!MESSAGE \r\n".
965
 
        "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n".
966
 
        "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n".
967
 
        "!MESSAGE \r\n".
968
 
        "\r\n".
969
 
        "# Begin Project\r\n".
970
 
        "# PROP AllowPerConfigDependencies 0\r\n".
971
 
        "# PROP Scc_ProjName \"\"\r\n".
972
 
        "# PROP Scc_LocalPath \"\"\r\n".
973
 
        "CPP=cl.exe\r\n".
974
 
        "MTL=midl.exe\r\n".
975
 
        "RSC=rc.exe\r\n".
976
 
        "\r\n".
977
 
        "!IF  \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
978
 
        "\r\n".
979
 
        "# PROP BASE Use_MFC 0\r\n".
980
 
        "# PROP BASE Use_Debug_Libraries 0\r\n".
981
 
        "# PROP BASE Output_Dir \"Release\"\r\n".
982
 
        "# PROP BASE Intermediate_Dir \"Release\"\r\n".
983
 
        "# PROP BASE Target_Dir \"\"\r\n".
984
 
        "# PROP Use_MFC 0\r\n".
985
 
        "# PROP Use_Debug_Libraries 0\r\n".
986
 
        "# PROP Output_Dir \"Release\"\r\n".
987
 
        "# PROP Intermediate_Dir \"Release\"\r\n".
988
 
        "# PROP Ignore_Export_Lib 0\r\n".
989
 
        "# PROP Target_Dir \"\"\r\n".
990
 
        "# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
991
 
        "# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
992
 
        "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
993
 
        "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
994
 
        "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n".
995
 
        "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n".
996
 
        "BSC32=bscmake.exe\r\n".
997
 
        "# ADD BASE BSC32 /nologo\r\n".
998
 
        "# ADD BSC32 /nologo\r\n".
999
 
        "LINK32=link.exe\r\n".
1000
 
        "# 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".
1001
 
        "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n".
1002
 
        "# SUBTRACT LINK32 /pdb:none\r\n".
1003
 
        "\r\n".
1004
 
        "!ELSEIF  \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
1005
 
        "\r\n".
1006
 
        "# PROP BASE Use_MFC 0\r\n".
1007
 
        "# PROP BASE Use_Debug_Libraries 1\r\n".
1008
 
        "# PROP BASE Output_Dir \"Debug\"\r\n".
1009
 
        "# PROP BASE Intermediate_Dir \"Debug\"\r\n".
1010
 
        "# PROP BASE Target_Dir \"\"\r\n".
1011
 
        "# PROP Use_MFC 0\r\n".
1012
 
        "# PROP Use_Debug_Libraries 1\r\n".
1013
 
        "# PROP Output_Dir \"Debug\"\r\n".
1014
 
        "# PROP Intermediate_Dir \"Debug\"\r\n".
1015
 
        "# PROP Ignore_Export_Lib 0\r\n".
1016
 
        "# PROP Target_Dir \"\"\r\n".
1017
 
        "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
1018
 
        "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
1019
 
        "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
1020
 
        "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
1021
 
        "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n".
1022
 
        "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n".
1023
 
        "BSC32=bscmake.exe\r\n".
1024
 
        "# ADD BASE BSC32 /nologo\r\n".
1025
 
        "# ADD BSC32 /nologo\r\n".
1026
 
        "LINK32=link.exe\r\n".
1027
 
        "# 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".
1028
 
        "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
1029
 
        "# SUBTRACT LINK32 /pdb:none\r\n".
1030
 
        "\r\n".
1031
 
        "!ENDIF \r\n".
1032
 
        "\r\n".
1033
 
        "# Begin Target\r\n".
1034
 
        "\r\n".
1035
 
        "# Name \"$windows_project - Win32 Release\"\r\n".
1036
 
        "# Name \"$windows_project - Win32 Debug\"\r\n".
1037
 
        "# Begin Group \"Source Files\"\r\n".
1038
 
        "\r\n".
1039
 
        "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
1040
 
        foreach $source_file (@source_files) {
1041
 
            print
1042
 
              "# Begin Source File\r\n".
1043
 
              "\r\n".
1044
 
              "SOURCE=..\\..\\$source_file\r\n";
1045
 
            if($source_file =~ /ssh\.c/io) {
1046
 
                # Disable 'Edit and continue' as Visual Studio can't handle the macros
1047
 
                print
1048
 
                  "\r\n".
1049
 
                  "!IF  \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
1050
 
                  "\r\n".
1051
 
                  "!ELSEIF  \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
1052
 
                  "\r\n".
1053
 
                  "# ADD CPP /Zi\r\n".
1054
 
                  "\r\n".
1055
 
                  "!ENDIF \r\n".
1056
 
                  "\r\n";
1057
 
            }
1058
 
            print "# End Source File\r\n";
1059
 
        }
1060
 
        print
1061
 
        "# End Group\r\n".
1062
 
        "# Begin Group \"Header Files\"\r\n".
1063
 
        "\r\n".
1064
 
        "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
1065
 
        foreach $header_file (@header_files) {
1066
 
            print
1067
 
              "# Begin Source File\r\n".
1068
 
              "\r\n".
1069
 
              "SOURCE=..\\..\\$header_file\r\n".
1070
 
              "# End Source File\r\n";
1071
 
        }
1072
 
        print
1073
 
        "# End Group\r\n".
1074
 
        "# Begin Group \"Resource Files\"\r\n".
1075
 
        "\r\n".
1076
 
        "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
1077
 
        foreach $resource_file (@resources) {
1078
 
            print
1079
 
              "# Begin Source File\r\n".
1080
 
              "\r\n".
1081
 
              "SOURCE=..\\..\\$resource_file\r\n".
1082
 
              "# End Source File\r\n";
1083
 
        }
1084
 
        print
1085
 
        "# End Group\r\n".
1086
 
        "# End Target\r\n".
1087
 
        "# End Project\r\n";
1088
 
        select STDOUT; close OUT;
1089
 
        chdir "..";
1090
 
    }
1091
 
}
1092
 
 
1093
 
if (defined $makefiles{'gtk'}) {
1094
 
    $mftyp = 'gtk';
1095
 
    $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
1096
 
 
1097
 
    ##-- X/GTK/Unix makefile
1098
 
    open OUT, ">$makefiles{'gtk'}"; select OUT;
1099
 
    print
1100
 
    "# Makefile for $project_name under X/GTK and Unix.\n".
1101
 
    "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1102
 
    "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1103
 
    # gcc command line option is -D not /D
1104
 
    ($_ = $help) =~ s/=\/D/=-D/gs;
1105
 
    print $_;
1106
 
    print
1107
 
    "\n".
1108
 
    "# You can define this path to point at your tools if you need to\n".
1109
 
    "# TOOLPATH = /opt/gcc/bin\n".
1110
 
    "CC := \$(TOOLPATH)\$(CC)\n".
1111
 
    "# You can manually set this to `gtk-config' or `pkg-config gtk+-1.2'\n".
1112
 
    "# (depending on what works on your system) if you want to enforce\n".
1113
 
    "# building with GTK 1.2, or you can set it to `pkg-config gtk+-2.0'\n".
1114
 
    "# if you want to enforce 2.0. The default is to try 2.0 and fall back\n".
1115
 
    "# to 1.2 if it isn't found.\n".
1116
 
    "GTK_CONFIG = sh -c 'pkg-config gtk+-2.0 \$\$0 2>/dev/null || gtk-config \$\$0'\n".
1117
 
    "\n".
1118
 
    &splitline("CFLAGS := -O2 -Wall -Werror -ansi -pedantic -g " .
1119
 
               (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1120
 
               " `\$(GTK_CONFIG) --cflags` \$(CFLAGS)")."\n".
1121
 
    "XLIBS = `\$(GTK_CONFIG) --libs` -lm\n".
1122
 
    "ULIBS = -lm#\n".
1123
 
    "INSTALL=install\n",
1124
 
    "INSTALL_PROGRAM=\$(INSTALL)\n",
1125
 
    "INSTALL_DATA=\$(INSTALL)\n",
1126
 
    "prefix=/usr/local\n",
1127
 
    "exec_prefix=\$(prefix)\n",
1128
 
    "bindir=\$(exec_prefix)/bin\n",
1129
 
    "gamesdir=\$(exec_prefix)/games\n",
1130
 
    "sharedir=\$(prefix)/share\n",
1131
 
    "mandir=\$(prefix)/man\n",
1132
 
    "man1dir=\$(mandir)/man1\n",
1133
 
    "CFLAGS += -DSHAREDIR=\"\\\"\$(sharedir)\\\"\"\n",
1134
 
    "\n";
1135
 
    print &splitline("all:" . join "", map { " \$(BINPREFIX)$_" }
1136
 
                     &progrealnames("X:U"));
1137
 
    print "\n\n";
1138
 
    foreach $p (&prognames("X:U")) {
1139
 
      ($prog, $type) = split ",", $p;
1140
 
      $objstr = &objects($p, "X.o", undef, undef);
1141
 
      print &splitline("\$(BINPREFIX)" . $prog . ": " . $objstr), "\n";
1142
 
      $libstr = &objects($p, undef, undef, "-lX");
1143
 
      print &splitline("\t\$(CC) -o \$@ $objstr $libstr \$(XLFLAGS) \$(${type}LIBS)", 69),
1144
 
          "\n\n";
1145
 
    }
1146
 
    foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1147
 
      print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1148
 
          "\n";
1149
 
      $deflist = join "", map { " -D$_" } @{$d->{defs}};
1150
 
      print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1151
 
          " -c \$< -o \$\@\n";
1152
 
    }
1153
 
    print "\n";
1154
 
    print $makefile_extra{'gtk'} || "";
1155
 
    print "\nclean:\n".
1156
 
    "\trm -f *.o". (join "", map { " \$(BINPREFIX)$_" } &progrealnames("X:U")) . "\n";
1157
 
    select STDOUT; close OUT;
1158
 
}
1159
 
 
1160
 
if (defined $makefiles{'mpw'}) {
1161
 
    $mftyp = 'mpw';
1162
 
    ##-- MPW Makefile
1163
 
    open OUT, ">$makefiles{'mpw'}"; select OUT;
1164
 
    print
1165
 
    "# Makefile for $project_name under MPW.\n#\n".
1166
 
    "# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1167
 
    "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1168
 
    # MPW command line option is -d not /D
1169
 
    ($_ = $help) =~ s/=\/D/=-d /gs;
1170
 
    print $_;
1171
 
    print "\n\n".
1172
 
    "ROptions     = `Echo \"{VER}\" | StreamEdit -e \"1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6\"' \xa81 '\xb6\xb6\xb6\xb6\xb6\"'\"`".
1173
 
    "\n".
1174
 
    "C_68K = {C}\n".
1175
 
    "C_CFM68K = {C}\n".
1176
 
    "C_PPC = {PPCC}\n".
1177
 
    "C_Carbon = {PPCC}\n".
1178
 
    "\n".
1179
 
    "# -w 35 disables \"unused parameter\" warnings\n".
1180
 
    "COptions     = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6\n".
1181
 
    "          -notOnce\n".
1182
 
    "COptions_68K = {COptions} -model far -opt time\n".
1183
 
    "# Enabling \"-opt space\" for CFM-68K gives me undefined references to\n".
1184
 
    "# _\$LDIVT and _\$LMODT.\n".
1185
 
    "COptions_CFM68K = {COptions} -model cfmSeg -opt time\n".
1186
 
    "COptions_PPC = {COptions} -opt size -traceback\n".
1187
 
    "COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON\n".
1188
 
    "\n".
1189
 
    "Link_68K = ILink\n".
1190
 
    "Link_CFM68K = ILink\n".
1191
 
    "Link_PPC = PPCLink\n".
1192
 
    "Link_Carbon = PPCLink\n".
1193
 
    "\n".
1194
 
    "LinkOptions = -c 'pTTY'\n".
1195
 
    "LinkOptions_68K = {LinkOptions} -br 68k -model far -compact\n".
1196
 
    "LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact\n".
1197
 
    "LinkOptions_PPC = {LinkOptions}\n".
1198
 
    "LinkOptions_Carbon = -m __appstart -w {LinkOptions}\n".
1199
 
    "\n".
1200
 
    "Libs_68K = \"{CLibraries}StdCLib.far.o\" \xb6\n".
1201
 
    "           \"{Libraries}MacRuntime.o\" \xb6\n".
1202
 
    "           \"{Libraries}MathLib.far.o\" \xb6\n".
1203
 
    "           \"{Libraries}IntEnv.far.o\" \xb6\n".
1204
 
    "           \"{Libraries}Interface.o\" \xb6\n".
1205
 
    "           \"{Libraries}Navigation.far.o\" \xb6\n".
1206
 
    "           \"{Libraries}OpenTransport.o\" \xb6\n".
1207
 
    "           \"{Libraries}OpenTransportApp.o\" \xb6\n".
1208
 
    "           \"{Libraries}OpenTptInet.o\" \xb6\n".
1209
 
    "           \"{Libraries}UnicodeConverterLib.far.o\"\n".
1210
 
    "\n".
1211
 
    "Libs_CFM = \"{SharedLibraries}InterfaceLib\" \xb6\n".
1212
 
    "           \"{SharedLibraries}StdCLib\" \xb6\n".
1213
 
    "           \"{SharedLibraries}AppearanceLib\" \xb6\n".
1214
 
    "                   -weaklib AppearanceLib \xb6\n".
1215
 
    "           \"{SharedLibraries}NavigationLib\" \xb6\n".
1216
 
    "                   -weaklib NavigationLib \xb6\n".
1217
 
    "           \"{SharedLibraries}TextCommon\" \xb6\n".
1218
 
    "                   -weaklib TextCommon \xb6\n".
1219
 
    "           \"{SharedLibraries}UnicodeConverter\" \xb6\n".
1220
 
    "                   -weaklib UnicodeConverter\n".
1221
 
    "\n".
1222
 
    "Libs_CFM68K =      {Libs_CFM} \xb6\n".
1223
 
    "           \"{CFM68KLibraries}NuMacRuntime.o\"\n".
1224
 
    "\n".
1225
 
    "Libs_PPC = {Libs_CFM} \xb6\n".
1226
 
    "           \"{SharedLibraries}ControlsLib\" \xb6\n".
1227
 
    "                   -weaklib ControlsLib \xb6\n".
1228
 
    "           \"{SharedLibraries}WindowsLib\" \xb6\n".
1229
 
    "                   -weaklib WindowsLib \xb6\n".
1230
 
    "           \"{SharedLibraries}OpenTransportLib\" \xb6\n".
1231
 
    "                   -weaklib OTClientLib \xb6\n".
1232
 
    "                   -weaklib OTClientUtilLib \xb6\n".
1233
 
    "           \"{SharedLibraries}OpenTptInternetLib\" \xb6\n".
1234
 
    "                   -weaklib OTInetClientLib \xb6\n".
1235
 
    "           \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1236
 
    "           \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1237
 
    "           \"{PPCLibraries}CarbonAccessors.o\" \xb6\n".
1238
 
    "           \"{PPCLibraries}OpenTransportAppPPC.o\" \xb6\n".
1239
 
    "           \"{PPCLibraries}OpenTptInetPPC.o\"\n".
1240
 
    "\n".
1241
 
    "Libs_Carbon =      \"{PPCLibraries}CarbonStdCLib.o\" \xb6\n".
1242
 
    "           \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1243
 
    "           \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1244
 
    "           \"{SharedLibraries}CarbonLib\" \xb6\n".
1245
 
    "           \"{SharedLibraries}StdCLib\"\n".
1246
 
    "\n";
1247
 
    print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6");
1248
 
    print "\n\n";
1249
 
    foreach $p (&prognames("M")) {
1250
 
      ($prog, $type) = split ",", $p;
1251
 
 
1252
 
      print &splitline("$prog \xc4 $prog.68k $prog.ppc $prog.carbon",
1253
 
                   undef, "\xb6"), "\n\n";
1254
 
 
1255
 
      $rsrc = &objects($p, "", "X.rsrc", undef);
1256
 
 
1257
 
      foreach $arch (qw(68K CFM68K PPC Carbon)) {
1258
 
          $objstr = &objects($p, "X.\L$arch\E.o", "", undef);
1259
 
          print &splitline("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6");
1260
 
          print "\n";
1261
 
          print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
1262
 
          print &splitline("\t{Link_$arch} -o {Targ} -fragname $prog " .
1263
 
                       "{LinkOptions_$arch} " .
1264
 
                       $objstr . " {Libs_$arch}", 69, "\xb6"), "\n";
1265
 
          print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
1266
 
      }
1267
 
 
1268
 
    }
1269
 
    foreach $d (&deps("", "X.rsrc", "::", ":")) {
1270
 
      next unless $d->{obj};
1271
 
      print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
1272
 
                   undef, "\xb6"), "\n";
1273
 
      print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n";
1274
 
    }
1275
 
    foreach $arch (qw(68K CFM68K)) {
1276
 
        foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1277
 
         next unless $d->{obj};
1278
 
        print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1279
 
                                 join " ", @{$d->{deps}}),
1280
 
                         undef, "\xb6"), "\n";
1281
 
         print "\t{C_$arch} ", $d->{deps}->[0],
1282
 
               " -o {Targ} {COptions_$arch}\n\n";
1283
 
         }
1284
 
    }
1285
 
    foreach $arch (qw(PPC Carbon)) {
1286
 
        foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1287
 
         next unless $d->{obj};
1288
 
        print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1289
 
                                 join " ", @{$d->{deps}}),
1290
 
                         undef, "\xb6"), "\n";
1291
 
         # The odd stuff here seems to stop afpd getting confused.
1292
 
         print "\techo -n > {Targ}\n";
1293
 
         print "\tsetfile -t XCOF {Targ}\n";
1294
 
         print "\t{C_$arch} ", $d->{deps}->[0],
1295
 
               " -o {Targ} {COptions_$arch}\n\n";
1296
 
         }
1297
 
    }
1298
 
    select STDOUT; close OUT;
1299
 
}
1300
 
 
1301
 
if (defined $makefiles{'lcc'}) {
1302
 
    $mftyp = 'lcc';
1303
 
    $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
1304
 
 
1305
 
    ##-- lcc makefile
1306
 
    open OUT, ">$makefiles{'lcc'}"; select OUT;
1307
 
    print
1308
 
    "# Makefile for $project_name under lcc.\n".
1309
 
    "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1310
 
    "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1311
 
    # lcc command line option is -D not /D
1312
 
    ($_ = $help) =~ s/=\/D/=-D/gs;
1313
 
    print $_;
1314
 
    print
1315
 
    "\n".
1316
 
    "# If you rename this file to `Makefile', you should change this line,\n".
1317
 
    "# so that the .rsp files still depend on the correct makefile.\n".
1318
 
    "MAKEFILE = Makefile.lcc\n".
1319
 
    "\n".
1320
 
    "# C compilation flags\n".
1321
 
    "CFLAGS = -D_WINDOWS " .
1322
 
      (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1323
 
      "\n".
1324
 
    "\n".
1325
 
    "# Get include directory for resource compiler\n".
1326
 
    "\n";
1327
 
    print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
1328
 
    print "\n\n";
1329
 
    foreach $p (&prognames("G:C")) {
1330
 
      ($prog, $type) = split ",", $p;
1331
 
      $objstr = &objects($p, "X.obj", "X.res", undef);
1332
 
      print &splitline("$prog.exe: " . $objstr ), "\n";
1333
 
      $subsystemtype = undef;
1334
 
      if ($type eq "G") { $subsystemtype = "-subsystem  windows"; }
1335
 
      my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1336
 
      print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1337
 
      print "\n\n";
1338
 
    }
1339
 
 
1340
 
    foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
1341
 
      print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1342
 
        "\n";
1343
 
      if ($d->{obj} =~ /\.res$/) {
1344
 
        print &splitline("\tlrc \$(FWHACK) \$(RCFL) -r \$*.rc",69)."\n";
1345
 
      } else {
1346
 
        $deflist = join "", map { " -D$_" } @{$d->{defs}};
1347
 
        print &splitline("\tlcc -O -p6 \$(COMPAT) \$(FWHACK) \$(CFLAGS)".
1348
 
                         " \$(XFLAGS)$deflist ".$d->{deps}->[0]." -o \$\@",69)."\n";
1349
 
      }
1350
 
    }
1351
 
    print "\n";
1352
 
    print $makefile_extra{'lcc'} || "";
1353
 
    print "\nclean:\n".
1354
 
    "\t-del *.obj\n".
1355
 
    "\t-del *.exe\n".
1356
 
    "\t-del *.res\n";
1357
 
 
1358
 
    select STDOUT; close OUT;
1359
 
}
1360
 
 
1361
 
if (defined $makefiles{'nestedvm'}) {
1362
 
    $mftyp = 'nestedvm';
1363
 
    $dirpfx = &dirpfx($makefiles{'nestedvm'}, "/");
1364
 
 
1365
 
    ##-- NestedVM makefile
1366
 
    open OUT, ">$makefiles{'nestedvm'}"; select OUT;
1367
 
    print
1368
 
    "# Makefile for $project_name under NestedVM.\n".
1369
 
    "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1370
 
    "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1371
 
    # gcc command line option is -D not /D
1372
 
    ($_ = $help) =~ s/=\/D/=-D/gs;
1373
 
    print $_;
1374
 
    print
1375
 
    "\n".
1376
 
    "# This path points at the nestedvm root directory\n".
1377
 
    "NESTEDVM = /opt/nestedvm\n".
1378
 
    "# You can define this path to point at your tools if you need to\n".
1379
 
    "TOOLPATH = \$(NESTEDVM)/upstream/install/bin\n".
1380
 
    "CC = \$(TOOLPATH)/mips-unknown-elf-gcc\n".
1381
 
    "\n".
1382
 
    &splitline("CFLAGS = -O2 -Wall -Werror -DSLOW_SYSTEM -g " .
1383
 
               (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1384
 
    "\n";
1385
 
    print &splitline("all:" . join "", map { " $_.jar" } &progrealnames("X"));
1386
 
    print "\n\n";
1387
 
    foreach $p (&prognames("X")) {
1388
 
      ($prog, $type) = split ",", $p;
1389
 
      $objstr = &objects($p, "X.o", undef, undef);
1390
 
      $objstr =~ s/gtk\.o/nestedvm\.o/g;
1391
 
      print &splitline($prog . ".mips: " . $objstr), "\n";
1392
 
      $libstr = &objects($p, undef, undef, "-lX");
1393
 
      print &splitline("\t\$(CC) \$(${type}LDFLAGS) -o \$@ " .
1394
 
                       $objstr . " $libstr -lm", 69), "\n\n";
1395
 
    }
1396
 
    foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1397
 
      $oobjs = $d->{obj};
1398
 
      $ddeps= join " ", @{$d->{deps}};
1399
 
      $oobjs =~ s/gtk/nestedvm/g;
1400
 
      $ddeps =~ s/gtk/nestedvm/g;
1401
 
      print &splitline(sprintf("%s: %s", $oobjs, $ddeps)),
1402
 
          "\n";
1403
 
      $deflist = join "", map { " -D$_" } @{$d->{defs}};
1404
 
      print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1405
 
          " -c \$< -o \$\@\n";
1406
 
    }
1407
 
    print "\n";
1408
 
    print $makefile_extra{'nestedvm'} || "";
1409
 
    print "\nclean:\n".
1410
 
    "\trm -rf *.o *.mips *.class *.html *.jar org applet.manifest\n";
1411
 
    select STDOUT; close OUT;
1412
 
}
1413
 
 
1414
 
if (defined $makefiles{'osx'}) {
1415
 
    $mftyp = 'osx';
1416
 
    $dirpfx = &dirpfx($makefiles{'osx'}, "/");
1417
 
    @osxarchs = ('i386');
1418
 
 
1419
 
    ##-- Mac OS X makefile
1420
 
    open OUT, ">$makefiles{'osx'}"; select OUT;
1421
 
    print
1422
 
    "# Makefile for $project_name under Mac OS X.\n".
1423
 
    "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1424
 
    "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1425
 
    # gcc command line option is -D not /D
1426
 
    ($_ = $help) =~ s/=\/D/=-D/gs;
1427
 
    print $_;
1428
 
    print
1429
 
    "CC = \$(TOOLPATH)gcc\n".
1430
 
    "LIPO = \$(TOOLPATH)lipo\n".
1431
 
    "\n".
1432
 
    &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1433
 
               (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1434
 
    "LDFLAGS = -framework Cocoa\n".
1435
 
    &splitline("all:" . join "", map { " $_" } &progrealnames("MX:U")) .
1436
 
    "\n";
1437
 
    print $makefile_extra{'osx'} || "";
1438
 
    print "\n".
1439
 
    ".SUFFIXES: .o .c .m\n".
1440
 
    "\n";
1441
 
    print "\n\n";
1442
 
    foreach $p (&prognames("MX")) {
1443
 
      ($prog, $type) = split ",", $p;
1444
 
      $icon = &special($p, ".icns");
1445
 
      $infoplist = &special($p, "info.plist");
1446
 
      print "${prog}.app:\n\tmkdir -p \$\@\n";
1447
 
      print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n";
1448
 
      print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1449
 
      $targets = "${prog}.app/Contents/MacOS/$prog";
1450
 
      if (defined $icon) {
1451
 
        print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1452
 
        print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n";
1453
 
        $targets .= " ${prog}.app/Contents/Resources/${prog}.icns";
1454
 
      }
1455
 
      if (defined $infoplist) {
1456
 
        print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n";
1457
 
        $targets .= " ${prog}.app/Contents/Info.plist";
1458
 
      }
1459
 
      $targets .= " \$(${prog}_extra)";
1460
 
      print &splitline("${prog}: $targets", 69) . "\n\n";
1461
 
      $libstr = &objects($p, undef, undef, "-lX");
1462
 
      $archbins = "";
1463
 
      foreach $arch (@osxarchs) {
1464
 
        $objstr = &objects($p, "X.${arch}.o", undef, undef);
1465
 
        print &splitline("${prog}.${arch}.bin: " . $objstr), "\n";
1466
 
        print &splitline("\t\$(CC) -arch ${arch} -mmacosx-version-min=10.4 \$(LDFLAGS) -o \$@ " .
1467
 
                       $objstr . " $libstr", 69), "\n\n";
1468
 
        $archbins .= " ${prog}.${arch}.bin";
1469
 
      }
1470
 
      print &splitline("${prog}.app/Contents/MacOS/$prog: ".
1471
 
                       "${prog}.app/Contents/MacOS" . $archbins), "\n";
1472
 
      print &splitline("\t\$(LIPO) -create $archbins -output \$@", 69), "\n\n";
1473
 
    }
1474
 
    foreach $p (&prognames("U")) {
1475
 
      ($prog, $type) = split ",", $p;
1476
 
      $libstr = &objects($p, undef, undef, "-lX");
1477
 
      $archbins = "";
1478
 
      foreach $arch (@osxarchs) {
1479
 
        $objstr = &objects($p, "X.${arch}.o", undef, undef);
1480
 
        print &splitline("${prog}.${arch}: " . $objstr), "\n";
1481
 
        print &splitline("\t\$(CC) -arch ${arch} -mmacosx-version-min=10.4 \$(ULDFLAGS) -o \$@ " .
1482
 
                       $objstr . " $libstr", 69), "\n\n";
1483
 
        $archbins .= " ${prog}.${arch}";
1484
 
      }
1485
 
      print &splitline("${prog}:" . $archbins), "\n";
1486
 
      print &splitline("\t\$(LIPO) -create $archbins -output \$@", 69), "\n\n";
1487
 
    }
1488
 
    foreach $arch (@osxarchs) {
1489
 
      foreach $d (&deps("X.${arch}.o", undef, $dirpfx, "/")) {
1490
 
        print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1491
 
            "\n";
1492
 
        $deflist = join "", map { " -D$_" } @{$d->{defs}};
1493
 
        if ($d->{deps}->[0] =~ /\.m$/) {
1494
 
          print "\t\$(CC) -arch $arch -mmacosx-version-min=10.4 -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS)".
1495
 
              " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
1496
 
        } else {
1497
 
          print "\t\$(CC) -arch $arch -mmacosx-version-min=10.4 \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1498
 
              " -c \$< -o \$\@\n";
1499
 
        }
1500
 
      }
1501
 
    }
1502
 
    print "\nclean:\n".
1503
 
    "\trm -f *.o *.dmg". (join "", map { my $a=$_; (" $a", map { " ${a}.$_" } @osxarchs) } &progrealnames("U")) . "\n".
1504
 
    "\trm -rf *.app\n";
1505
 
    select STDOUT; close OUT;
1506
 
}
1507
 
 
1508
 
if (defined $makefiles{'gnustep'}) {
1509
 
    $mftyp = 'gnustep';
1510
 
    $dirpfx = &dirpfx($makefiles{'gnustep'}, "/");
1511
 
 
1512
 
    ##-- GNUstep makefile (use with 'gs_make -f Makefile.gnustep')
1513
 
 
1514
 
    # This is a pretty evil way to do things. In an ideal world, I'd
1515
 
    # use the approved GNUstep makefile mechanism which just defines a
1516
 
    # variable or two saying what source files go into what binary and
1517
 
    # then includes application.make. Unfortunately, that has the
1518
 
    # automake-ish limitation that it doesn't let you choose different
1519
 
    # command lines for each object, so I can't arrange for all those
1520
 
    # files with -DTHIS and -DTHAT to Just Work.
1521
 
    #
1522
 
    # A simple if ugly fix would be to have mkfiles.pl construct a
1523
 
    # directory full of stub C files of the form '#define thing',
1524
 
    # '#include "real_source_file"', and then reference those in this
1525
 
    # makefile. That would also make it easy to build a proper
1526
 
    # automake makefile.
1527
 
    open OUT, ">$makefiles{'gnustep'}"; select OUT;
1528
 
    print
1529
 
    "# Makefile for $project_name under GNUstep.\n".
1530
 
    "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1531
 
    "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1532
 
    # gcc command line option is -D not /D
1533
 
    ($_ = $help) =~ s/=\/D/=-D/gs;
1534
 
    print $_;
1535
 
    print
1536
 
    "NEEDS_GUI=yes\n".
1537
 
    "include \$(GNUSTEP_MAKEFILES)/common.make\n".
1538
 
    "include \$(GNUSTEP_MAKEFILES)/rules.make\n".
1539
 
    "include \$(GNUSTEP_MAKEFILES)/Instance/rules.make\n".
1540
 
    "\n".
1541
 
    &splitline("all::" . join "", map { " $_" } &progrealnames("MX:U")) .
1542
 
    "\n";
1543
 
    print $makefile_extra{'gnustep'} || "";
1544
 
    print "\n".
1545
 
    ".SUFFIXES: .o .c .m\n".
1546
 
    "\n";
1547
 
    print "\n\n";
1548
 
    foreach $p (&prognames("MX")) {
1549
 
      ($prog, $type) = split ",", $p;
1550
 
      $icon = &special($p, ".icns");
1551
 
      $infoplist = &special($p, "info.plist");
1552
 
      print "${prog}.app:\n\tmkdir -p \$\@\n";
1553
 
      $targets = "${prog}.app ${prog}.app/$prog";
1554
 
      if (defined $icon) {
1555
 
        print "${prog}.app/Resources: ${prog}.app\n\tmkdir -p \$\@\n";
1556
 
        print "${prog}.app/Resources/${prog}.icns: ${prog}.app/Resources $icon\n\tcp $icon \$\@\n";
1557
 
        $targets .= " ${prog}.app/Resources/${prog}.icns";
1558
 
      }
1559
 
      if (defined $infoplist) {
1560
 
        print "${prog}.app/Info.plist: ${prog}.app $infoplist\n\tcp $infoplist \$\@\n";
1561
 
        $targets .= " ${prog}.app/Info.plist";
1562
 
      }
1563
 
      $targets .= " \$(${prog}_extra)";
1564
 
      print &splitline("${prog}: $targets", 69) . "\n\n";
1565
 
      $libstr = &objects($p, undef, undef, "-lX");
1566
 
      $objstr = &objects($p, "X.o", undef, undef);
1567
 
      print &splitline("${prog}.app/$prog: " . $objstr), "\n";
1568
 
      print &splitline("\t\$(CC) \$(ALL_LDFLAGS) -o \$@ " . $objstr . " \$(ALL_LIB_DIRS) $libstr \$(ALL_LIBS)", 69), "\n\n";
1569
 
    }
1570
 
    foreach $p (&prognames("U")) {
1571
 
      ($prog, $type) = split ",", $p;
1572
 
      $libstr = &objects($p, undef, undef, "-lX");
1573
 
      $objstr = &objects($p, "X.o", undef, undef);
1574
 
      print &splitline("${prog}: " . $objstr), "\n";
1575
 
      print &splitline("\t\$(CC) \$(ULDFLAGS) -o \$@ " . $objstr . " $libstr", 69), "\n\n";
1576
 
    }
1577
 
    foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1578
 
      print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1579
 
      "\n";
1580
 
      $deflist = join "", map { " -D$_" } @{$d->{defs}};
1581
 
      if ($d->{deps}->[0] =~ /\.m$/) {
1582
 
        print "\t\$(CC) -DGNUSTEP \$(ALL_OBJCFLAGS) \$(COMPAT) \$(FWHACK) \$(OBJCFLAGS)".
1583
 
                " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
1584
 
      } else {
1585
 
        print "\t\$(CC) \$(ALL_CFLAGS) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1586
 
              " -c \$< -o \$\@\n";
1587
 
      }
1588
 
    }
1589
 
    print "\nclean::\n".
1590
 
    "\trm -f *.o ". (join " ", &progrealnames("U")) . "\n".
1591
 
    "\trm -rf *.app\n";
1592
 
    select STDOUT; close OUT;
1593
 
}
1594
 
 
1595
 
if (defined $makefiles{'emcc'}) {
1596
 
    $mftyp = 'emcc';
1597
 
    $dirpfx = &dirpfx($makefiles{'emcc'}, "/");
1598
 
 
1599
 
    ##-- Makefile for building Javascript puzzles via Emscripten
1600
 
 
1601
 
    open OUT, ">$makefiles{'emcc'}"; select OUT;
1602
 
    print
1603
 
    "# Makefile for $project_name using Emscripten. Requires GNU make.\n".
1604
 
    "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1605
 
    "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1606
 
    # emcc command line option is -D not /D
1607
 
    ($_ = $help) =~ s/=\/D/=-D/gs;
1608
 
    print $_;
1609
 
    print
1610
 
    "\n".
1611
 
    "# This can be set on the command line to point at the emcc command,\n".
1612
 
    "# if it is not on your PATH.\n".
1613
 
    "EMCC = emcc\n".
1614
 
    "\n".
1615
 
    &splitline("CFLAGS = -DSLOW_SYSTEM " .
1616
 
               (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1617
 
    "\n";
1618
 
    $output_js_files = join "", map { " \$(OUTPREFIX)$_.js" } &progrealnames("X");
1619
 
    print &splitline("all:" . $output_js_files);
1620
 
    print "\n\n";
1621
 
    foreach $p (&prognames("X")) {
1622
 
      ($prog, $type) = split ",", $p;
1623
 
      $objstr = &objects($p, "X.o", undef, undef);
1624
 
      $objstr =~ s/gtk\.o/emcc\.o/g;
1625
 
      print &splitline("\$(OUTPREFIX)" . $prog . ".js: " . $objstr . " emccpre.js emcclib.js emccx.json"), "\n";
1626
 
      print "\t\$(EMCC) -o \$(OUTPREFIX)".$prog.".js ".
1627
 
          "-O2 ".
1628
 
          "-s ASM_JS=1 ".
1629
 
          "--pre-js emccpre.js ".
1630
 
          "--js-library emcclib.js ".
1631
 
          "-s EXPORTED_FUNCTIONS=\"`sed 's://.*::' emccx.json | tr -d ' \\n'`\" " . $objstr . "\n\n";
1632
 
    }
1633
 
    foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1634
 
      $oobjs = $d->{obj};
1635
 
      $ddeps= join " ", @{$d->{deps}};
1636
 
      $oobjs =~ s/gtk/emcc/g;
1637
 
      $ddeps =~ s/gtk/emcc/g;
1638
 
      print &splitline(sprintf("%s: %s", $oobjs, $ddeps)),
1639
 
          "\n";
1640
 
      $deflist = join "", map { " -D$_" } @{$d->{defs}};
1641
 
      print "\t\$(EMCC) \$(CFLAGS) \$(XFLAGS)$deflist" .
1642
 
          " -c \$< -o \$\@\n";
1643
 
    }
1644
 
    print "\n";
1645
 
    print $makefile_extra{'emcc'} || "";
1646
 
    print "\nclean:\n".
1647
 
    "\trm -rf *.o $output_js_files\n";
1648
 
    select STDOUT; close OUT;
1649
 
}