| 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 FileHandle; |
| 21 | use Cwd; |
| 22 | |
| 23 | open IN, "Recipe" or do { |
| 24 | # We want to deal correctly with being run from one of the |
| 25 | # subdirs in the source tree. So if we can't find Recipe here, |
| 26 | # try one level up. |
| 27 | chdir ".."; |
| 28 | open IN, "Recipe" or die "unable to open Recipe file\n"; |
| 29 | }; |
| 30 | |
| 31 | # HACK: One of the source files in `charset' is auto-generated by |
| 32 | # sbcsgen.pl. We need to generate that _now_, before attempting |
| 33 | # dependency analysis. |
| 34 | eval 'chdir "charset"; require "sbcsgen.pl"; chdir ".."'; |
| 35 | |
| 36 | @srcdirs = ("./"); |
| 37 | |
| 38 | $divert = undef; # ref to scalar in which text is currently being put |
| 39 | $help = ""; # list of newline-free lines of help text |
| 40 | $project_name = "project"; # this is a good enough default |
| 41 | %makefiles = (); # maps makefile types to output makefile pathnames |
| 42 | %makefile_extra = (); # maps makefile types to extra Makefile text |
| 43 | %programs = (); # maps prog name + type letter to listref of objects/resources |
| 44 | %groups = (); # maps group name to listref of objects/resources |
| 45 | |
| 46 | @allobjs = (); # all object file names |
| 47 | |
| 48 | while (<IN>) { |
| 49 | # Skip comments (unless the comments belong, for example because |
| 50 | # they're part of a diversion). |
| 51 | next if /^\s*#/ and !defined $divert; |
| 52 | |
| 53 | chomp; |
| 54 | split; |
| 55 | if ($_[0] eq "!begin" and $_[1] eq "help") { $divert = \$help; next; } |
| 56 | if ($_[0] eq "!end") { $divert = undef; next; } |
| 57 | if ($_[0] eq "!name") { $project_name = $_[1]; next; } |
| 58 | if ($_[0] eq "!srcdir") { push @srcdirs, $_[1]; next; } |
| 59 | if ($_[0] eq "!makefile" and &mfval($_[1])) { $makefiles{$_[1]}=$_[2]; next;} |
| 60 | if ($_[0] eq "!specialobj" and &mfval($_[1])) { $specialobj{$_[1]}->{$_[2]} = 1; next;} |
| 61 | if ($_[0] eq "!begin") { |
| 62 | if (&mfval($_[1])) { |
| 63 | $divert = \$makefile_extra{$_[1]}; |
| 64 | } else { |
| 65 | $divert = \$dummy; |
| 66 | } |
| 67 | next; |
| 68 | } |
| 69 | # If we're gathering help text, keep doing so. |
| 70 | if (defined $divert) { ${$divert} .= "$_\n"; next; } |
| 71 | # Ignore blank lines. |
| 72 | next if scalar @_ == 0; |
| 73 | |
| 74 | # Now we have an ordinary line. See if it's an = line, a : line |
| 75 | # or a + line. |
| 76 | @objs = @_; |
| 77 | |
| 78 | if ($_[0] eq "+") { |
| 79 | $listref = $lastlistref; |
| 80 | $prog = undef; |
| 81 | die "$.: unexpected + line\n" if !defined $lastlistref; |
| 82 | } elsif ($_[1] eq "=") { |
| 83 | $groups{$_[0]} = [] if !defined $groups{$_[0]}; |
| 84 | $listref = $groups{$_[0]}; |
| 85 | $prog = undef; |
| 86 | shift @objs; # eat the group name |
| 87 | } elsif ($_[1] eq ":") { |
| 88 | $listref = []; |
| 89 | $prog = $_[0]; |
| 90 | shift @objs; # eat the program name |
| 91 | } else { |
| 92 | die "$.: unrecognised line type\n"; |
| 93 | } |
| 94 | shift @objs; # eat the +, the = or the : |
| 95 | |
| 96 | while (scalar @objs > 0) { |
| 97 | $i = shift @objs; |
| 98 | if ($groups{$i}) { |
| 99 | foreach $j (@{$groups{$i}}) { unshift @objs, $j; } |
| 100 | } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or |
| 101 | $i eq "[X]" or $i eq "[U]" or $i eq "[MX]") and defined $prog) { |
| 102 | $type = substr($i,1,(length $i)-2); |
| 103 | } else { |
| 104 | push @$listref, $i; |
| 105 | push @allobjs, $i; |
| 106 | } |
| 107 | } |
| 108 | if ($prog and $type) { |
| 109 | die "multiple program entries for $prog [$type]\n" |
| 110 | if defined $programs{$prog . "," . $type}; |
| 111 | $programs{$prog . "," . $type} = $listref; |
| 112 | } |
| 113 | $lastlistref = $listref; |
| 114 | } |
| 115 | |
| 116 | close IN; |
| 117 | |
| 118 | # Find object file names with predefines (in square brackets after |
| 119 | # the module name), and decide on actual object names for them. |
| 120 | foreach $i (@allobjs) { |
| 121 | if ($i !~ /\[/) { |
| 122 | $objname{$i} = $i; |
| 123 | $srcname{$i} = $i; |
| 124 | $usedobjname{$i} = 1; |
| 125 | } |
| 126 | } |
| 127 | foreach $i (@allobjs) { |
| 128 | if ($i =~ /^(.*)\[([^\]]*)/) { |
| 129 | $defs{$i} = [ split ",",$2 ]; |
| 130 | $srcname{$i} = $s = $1; |
| 131 | $index = 1; |
| 132 | while (1) { |
| 133 | $maxlen = length $s; |
| 134 | $maxlen = 8 if $maxlen < 8; |
| 135 | $chop = $maxlen - length $index; |
| 136 | $chop = length $s if $chop > length $s; |
| 137 | $chop = 0 if $chop < 0; |
| 138 | $name = substr($s, 0, $chop) . $index; |
| 139 | $index++, next if $usedobjname{$name}; |
| 140 | $objname{$i} = $name; |
| 141 | $usedobjname{$name} = 1; |
| 142 | last; |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | # Now retrieve the complete list of objects and resource files, and |
| 148 | # construct dependency data for them. While we're here, expand the |
| 149 | # object list for each program, and complain if its type isn't set. |
| 150 | @prognames = sort keys %programs; |
| 151 | %depends = (); |
| 152 | @scanlist = (); |
| 153 | foreach $i (@prognames) { |
| 154 | ($prog, $type) = split ",", $i; |
| 155 | # Strip duplicate object names. |
| 156 | $prev = undef; |
| 157 | @list = grep { $status = ($prev ne $_); $prev=$_; $status } |
| 158 | sort @{$programs{$i}}; |
| 159 | $programs{$i} = [@list]; |
| 160 | foreach $jj (@list) { |
| 161 | $j = $srcname{$jj}; |
| 162 | # Dependencies for "x" start with "x.c" or "x.m" (depending on |
| 163 | # which one exists). |
| 164 | # Dependencies for "x.res" start with "x.rc". |
| 165 | # Dependencies for "x.rsrc" start with "x.r". |
| 166 | # Both types of file are pushed on the list of files to scan. |
| 167 | # Libraries (.lib) don't have dependencies at all. |
| 168 | if ($j =~ /^(.*)\.res$/) { |
| 169 | $file = "$1.rc"; |
| 170 | $depends{$jj} = [$file]; |
| 171 | push @scanlist, $file; |
| 172 | } elsif ($j =~ /^(.*)\.rsrc$/) { |
| 173 | $file = "$1.r"; |
| 174 | $depends{$jj} = [$file]; |
| 175 | push @scanlist, $file; |
| 176 | } elsif ($j !~ /\./) { |
| 177 | $file = "$j.c"; |
| 178 | $file = "$j.m" unless &findfile($file); |
| 179 | $depends{$jj} = [$file]; |
| 180 | push @scanlist, $file; |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | # Scan each file on @scanlist and find further inclusions. |
| 186 | # Inclusions are given by lines of the form `#include "otherfile"' |
| 187 | # (system headers are automatically ignored by this because they'll |
| 188 | # be given in angle brackets). Files included by this method are |
| 189 | # added back on to @scanlist to be scanned in turn (if not already |
| 190 | # done). |
| 191 | # |
| 192 | # Resource scripts (.rc) can also include a file by means of a line |
| 193 | # ending `ICON "filename"'. Files included by this method are not |
| 194 | # added to @scanlist because they can never include further files. |
| 195 | # |
| 196 | # In this pass we write out a hash %further which maps a source |
| 197 | # file name into a listref containing further source file names. |
| 198 | |
| 199 | %further = (); |
| 200 | while (scalar @scanlist > 0) { |
| 201 | $file = shift @scanlist; |
| 202 | next if defined $further{$file}; # skip if we've already done it |
| 203 | $resource = ($file =~ /\.rc$/ ? 1 : 0); |
| 204 | $further{$file} = []; |
| 205 | $dirfile = &findfile($file); |
| 206 | open IN, "$dirfile" or die "unable to open source file $file\n"; |
| 207 | while (<IN>) { |
| 208 | chomp; |
| 209 | /^\s*#include\s+\"([^\"]+)\"/ and do { |
| 210 | push @{$further{$file}}, $1; |
| 211 | push @scanlist, $1; |
| 212 | next; |
| 213 | }; |
| 214 | /ICON\s+\"([^\"]+)\"\s*$/ and do { |
| 215 | push @{$further{$file}}, $1; |
| 216 | next; |
| 217 | } |
| 218 | } |
| 219 | close IN; |
| 220 | } |
| 221 | |
| 222 | # Now we're ready to generate the final dependencies section. For |
| 223 | # each key in %depends, we must expand the dependencies list by |
| 224 | # iteratively adding entries from %further. |
| 225 | foreach $i (keys %depends) { |
| 226 | %dep = (); |
| 227 | @scanlist = @{$depends{$i}}; |
| 228 | foreach $i (@scanlist) { $dep{$i} = 1; } |
| 229 | while (scalar @scanlist > 0) { |
| 230 | $file = shift @scanlist; |
| 231 | foreach $j (@{$further{$file}}) { |
| 232 | if ($dep{$j} != 1) { |
| 233 | $dep{$j} = 1; |
| 234 | push @{$depends{$i}}, $j; |
| 235 | push @scanlist, $j; |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | # printf "%s: %s\n", $i, join ' ',@{$depends{$i}}; |
| 240 | } |
| 241 | |
| 242 | # Validation of input. |
| 243 | |
| 244 | sub mfval($) { |
| 245 | my ($type) = @_; |
| 246 | # Returns true if the argument is a known makefile type. Otherwise, |
| 247 | # prints a warning and returns false; |
| 248 | if (grep { $type eq $_ } |
| 249 | ("vc","vcproj","cygwin","borland","lcc","gtk","mpw","osx")) { |
| 250 | return 1; |
| 251 | } |
| 252 | warn "$.:unknown makefile type '$type'\n"; |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | # Utility routines while writing out the Makefiles. |
| 257 | |
| 258 | sub dirpfx { |
| 259 | my ($path) = shift @_; |
| 260 | my ($sep) = shift @_; |
| 261 | my $ret = "", $i; |
| 262 | while (($i = index $path, $sep) >= 0) { |
| 263 | $path = substr $path, ($i + length $sep); |
| 264 | $ret .= "..$sep"; |
| 265 | } |
| 266 | return $ret; |
| 267 | } |
| 268 | |
| 269 | sub findfile { |
| 270 | my ($name) = @_; |
| 271 | my $dir; |
| 272 | my $i; |
| 273 | my $outdir = undef; |
| 274 | unless (defined $findfilecache{$name}) { |
| 275 | $i = 0; |
| 276 | foreach $dir (@srcdirs) { |
| 277 | $outdir = $dir, $i++ if -f "$dir$name"; |
| 278 | } |
| 279 | die "multiple instances of source file $name\n" if $i > 1; |
| 280 | $findfilecache{$name} = (defined $outdir ? $outdir . $name : undef); |
| 281 | } |
| 282 | return $findfilecache{$name}; |
| 283 | } |
| 284 | |
| 285 | sub objects { |
| 286 | my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_; |
| 287 | my @ret; |
| 288 | my ($i, $x, $y); |
| 289 | @ret = (); |
| 290 | foreach $ii (@{$programs{$prog}}) { |
| 291 | $i = $objname{$ii}; |
| 292 | $x = ""; |
| 293 | if ($i =~ /^(.*)\.(res|rsrc)/) { |
| 294 | $y = $1; |
| 295 | ($x = $rtmpl) =~ s/X/$y/; |
| 296 | } elsif ($i =~ /^(.*)\.lib/) { |
| 297 | $y = $1; |
| 298 | ($x = $ltmpl) =~ s/X/$y/; |
| 299 | } elsif ($i !~ /\./) { |
| 300 | ($x = $otmpl) =~ s/X/$i/; |
| 301 | } |
| 302 | push @ret, $x if $x ne ""; |
| 303 | } |
| 304 | return join " ", @ret; |
| 305 | } |
| 306 | |
| 307 | sub special { |
| 308 | my ($prog, $suffix) = @_; |
| 309 | my @ret; |
| 310 | my ($i, $x, $y); |
| 311 | @ret = (); |
| 312 | foreach $ii (@{$programs{$prog}}) { |
| 313 | $i = $objname{$ii}; |
| 314 | if (substr($i, (length $i) - (length $suffix)) eq $suffix) { |
| 315 | push @ret, $i; |
| 316 | } |
| 317 | } |
| 318 | return join " ", @ret; |
| 319 | } |
| 320 | |
| 321 | sub splitline { |
| 322 | my ($line, $width, $splitchar) = @_; |
| 323 | my ($result, $len); |
| 324 | $len = (defined $width ? $width : 76); |
| 325 | $splitchar = (defined $splitchar ? $splitchar : '\\'); |
| 326 | while (length $line > $len) { |
| 327 | $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/; |
| 328 | $result .= $1 . " ${splitchar}\n\t\t"; |
| 329 | $line = $2; |
| 330 | $len = 60; |
| 331 | } |
| 332 | return $result . $line; |
| 333 | } |
| 334 | |
| 335 | sub deps { |
| 336 | my ($otmpl, $rtmpl, $prefix, $dirsep, $depchar, $splitchar) = @_; |
| 337 | my ($i, $x, $y); |
| 338 | my @deps, @ret; |
| 339 | @ret = (); |
| 340 | $depchar ||= ':'; |
| 341 | foreach $ii (sort keys %depends) { |
| 342 | $i = $objname{$ii}; |
| 343 | next if $specialobj{$mftyp}->{$i}; |
| 344 | if ($i =~ /^(.*)\.(res|rsrc)/) { |
| 345 | next if !defined $rtmpl; |
| 346 | $y = $1; |
| 347 | ($x = $rtmpl) =~ s/X/$y/; |
| 348 | } else { |
| 349 | ($x = $otmpl) =~ s/X/$i/; |
| 350 | } |
| 351 | @deps = @{$depends{$ii}}; |
| 352 | @deps = map { |
| 353 | $_ = &findfile($_); |
| 354 | s/\//$dirsep/g; |
| 355 | $_ = $prefix . $_; |
| 356 | } @deps; |
| 357 | push @ret, {obj => $x, deps => [@deps], defs => $defs{$ii}}; |
| 358 | } |
| 359 | return @ret; |
| 360 | } |
| 361 | |
| 362 | sub prognames { |
| 363 | my ($types) = @_; |
| 364 | my ($n, $prog, $type); |
| 365 | my @ret; |
| 366 | @ret = (); |
| 367 | foreach $n (@prognames) { |
| 368 | ($prog, $type) = split ",", $n; |
| 369 | push @ret, $n if index(":$types:", ":$type:") >= 0; |
| 370 | } |
| 371 | return @ret; |
| 372 | } |
| 373 | |
| 374 | sub progrealnames { |
| 375 | my ($types) = @_; |
| 376 | my ($n, $prog, $type); |
| 377 | my @ret; |
| 378 | @ret = (); |
| 379 | foreach $n (@prognames) { |
| 380 | ($prog, $type) = split ",", $n; |
| 381 | push @ret, $prog if index(":$types:", ":$type:") >= 0; |
| 382 | } |
| 383 | return @ret; |
| 384 | } |
| 385 | |
| 386 | sub manpages { |
| 387 | my ($types,$suffix) = @_; |
| 388 | |
| 389 | # assume that all UNIX programs have a man page |
| 390 | if($suffix eq "1" && $types =~ /:X:/) { |
| 391 | return map("$_.1", &progrealnames($types)); |
| 392 | } |
| 393 | return (); |
| 394 | } |
| 395 | |
| 396 | # Now we're ready to output the actual Makefiles. |
| 397 | |
| 398 | if (defined $makefiles{'cygwin'}) { |
| 399 | $mftyp = 'cygwin'; |
| 400 | $dirpfx = &dirpfx($makefiles{'cygwin'}, "/"); |
| 401 | |
| 402 | ##-- CygWin makefile |
| 403 | open OUT, ">$makefiles{'cygwin'}"; select OUT; |
| 404 | print |
| 405 | "# Makefile for $project_name under cygwin.\n". |
| 406 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
| 407 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
| 408 | # gcc command line option is -D not /D |
| 409 | ($_ = $help) =~ s/=\/D/=-D/gs; |
| 410 | print $_; |
| 411 | print |
| 412 | "\n". |
| 413 | "# You can define this path to point at your tools if you need to\n". |
| 414 | "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n". |
| 415 | "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n". |
| 416 | "CC = \$(TOOLPATH)gcc\n". |
| 417 | "RC = \$(TOOLPATH)windres\n". |
| 418 | "# Uncomment the following two lines to compile under Winelib\n". |
| 419 | "# CC = winegcc\n". |
| 420 | "# RC = wrc\n". |
| 421 | "# You may also need to tell windres where to find include files:\n". |
| 422 | "# RCINC = --include-dir c:\\cygwin\\include\\\n". |
| 423 | "\n". |
| 424 | &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT". |
| 425 | " -D_NO_OLDNAMES -DNO_MULTIMON " . |
| 426 | (join " ", map {"-I$dirpfx$_"} @srcdirs)) . |
| 427 | "\n". |
| 428 | "LDFLAGS = -mno-cygwin -s\n". |
| 429 | &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1". |
| 430 | " --define WINVER=0x0400 --define MINGW32_FIX=1")."\n". |
| 431 | "\n"; |
| 432 | print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C")); |
| 433 | print "\n\n"; |
| 434 | foreach $p (&prognames("G:C")) { |
| 435 | ($prog, $type) = split ",", $p; |
| 436 | $objstr = &objects($p, "X.o", "X.res.o", undef); |
| 437 | print &splitline($prog . ".exe: " . $objstr), "\n"; |
| 438 | my $mw = $type eq "G" ? " -mwindows" : ""; |
| 439 | $libstr = &objects($p, undef, undef, "-lX"); |
| 440 | print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " . |
| 441 | "-Wl,-Map,$prog.map " . |
| 442 | $objstr . " $libstr", 69), "\n\n"; |
| 443 | } |
| 444 | foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/")) { |
| 445 | print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), |
| 446 | "\n"; |
| 447 | if ($d->{obj} =~ /\.res\.o$/) { |
| 448 | print "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n"; |
| 449 | } else { |
| 450 | $deflist = join "", map { " -D$_" } @{$d->{defs}}; |
| 451 | print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS)" . |
| 452 | " \$(XFLAGS)$deflist -c \$< -o \$\@\n"; |
| 453 | } |
| 454 | } |
| 455 | print "\n"; |
| 456 | print $makefile_extra{'cygwin'}; |
| 457 | print "\nclean:\n". |
| 458 | "\trm -f *.o *.exe *.res.o *.map\n". |
| 459 | "\n"; |
| 460 | select STDOUT; close OUT; |
| 461 | |
| 462 | } |
| 463 | |
| 464 | ##-- Borland makefile |
| 465 | if (defined $makefiles{'borland'}) { |
| 466 | $mftyp = 'borland'; |
| 467 | $dirpfx = &dirpfx($makefiles{'borland'}, "\\"); |
| 468 | |
| 469 | %stdlibs = ( # Borland provides many Win32 API libraries intrinsically |
| 470 | "advapi32" => 1, |
| 471 | "comctl32" => 1, |
| 472 | "comdlg32" => 1, |
| 473 | "gdi32" => 1, |
| 474 | "imm32" => 1, |
| 475 | "shell32" => 1, |
| 476 | "user32" => 1, |
| 477 | "winmm" => 1, |
| 478 | "winspool" => 1, |
| 479 | "wsock32" => 1, |
| 480 | ); |
| 481 | open OUT, ">$makefiles{'borland'}"; select OUT; |
| 482 | print |
| 483 | "# Makefile for $project_name under Borland C.\n". |
| 484 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
| 485 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
| 486 | # bcc32 command line option is -D not /D |
| 487 | ($_ = $help) =~ s/=\/D/=-D/gs; |
| 488 | print $_; |
| 489 | print |
| 490 | "\n". |
| 491 | "# If you rename this file to `Makefile', you should change this line,\n". |
| 492 | "# so that the .rsp files still depend on the correct makefile.\n". |
| 493 | "MAKEFILE = Makefile.bor\n". |
| 494 | "\n". |
| 495 | "# C compilation flags\n". |
| 496 | "CFLAGS = -D_WINDOWS -DWINVER=0x0401\n". |
| 497 | "\n". |
| 498 | "# Get include directory for resource compiler\n". |
| 499 | "!if !\$d(BCB)\n". |
| 500 | "BCB = \$(MAKEDIR)\\..\n". |
| 501 | "!endif\n". |
| 502 | "\n"; |
| 503 | print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C")); |
| 504 | print "\n\n"; |
| 505 | foreach $p (&prognames("G:C")) { |
| 506 | ($prog, $type) = split ",", $p; |
| 507 | $objstr = &objects($p, "X.obj", "X.res", undef); |
| 508 | print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n"; |
| 509 | my $ap = ($type eq "G") ? "-aa" : "-ap"; |
| 510 | print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n"; |
| 511 | } |
| 512 | foreach $p (&prognames("G:C")) { |
| 513 | ($prog, $type) = split ",", $p; |
| 514 | print $prog, ".rsp: \$(MAKEFILE)\n"; |
| 515 | $objstr = &objects($p, "X.obj", undef, undef); |
| 516 | @objlist = split " ", $objstr; |
| 517 | @objlines = (""); |
| 518 | foreach $i (@objlist) { |
| 519 | if (length($objlines[$#objlines] . " $i") > 50) { |
| 520 | push @objlines, ""; |
| 521 | } |
| 522 | $objlines[$#objlines] .= " $i"; |
| 523 | } |
| 524 | $c0w = ($type eq "G") ? "c0w32" : "c0x32"; |
| 525 | print "\techo $c0w + > $prog.rsp\n"; |
| 526 | for ($i=0; $i<=$#objlines; $i++) { |
| 527 | $plus = ($i < $#objlines ? " +" : ""); |
| 528 | print "\techo$objlines[$i]$plus >> $prog.rsp\n"; |
| 529 | } |
| 530 | print "\techo $prog.exe >> $prog.rsp\n"; |
| 531 | $objstr = &objects($p, "X.obj", "X.res", undef); |
| 532 | @libs = split " ", &objects($p, undef, undef, "X"); |
| 533 | @libs = grep { !$stdlibs{$_} } @libs; |
| 534 | unshift @libs, "cw32", "import32"; |
| 535 | $libstr = join ' ', @libs; |
| 536 | print "\techo nul,$libstr, >> $prog.rsp\n"; |
| 537 | print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n"; |
| 538 | print "\n"; |
| 539 | } |
| 540 | foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) { |
| 541 | print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), |
| 542 | "\n"; |
| 543 | if ($d->{obj} =~ /\.res$/) { |
| 544 | print &splitline("\tbrcc32 \$(FWHACK) \$(RCFL) " . |
| 545 | "-i \$(BCB)\\include -r -DNO_WINRESRC_H -DWIN32". |
| 546 | " -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n"; |
| 547 | } else { |
| 548 | $deflist = join "", map { " -D$_" } @{$d->{defs}}; |
| 549 | print &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT)" . |
| 550 | " \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist ". |
| 551 | (join " ", map {"-I$dirpfx$_"} @srcdirs) . |
| 552 | " /o$d->{obj} /c ".$d->{deps}->[0],69)."\n"; |
| 553 | } |
| 554 | } |
| 555 | print "\n"; |
| 556 | print $makefile_extra{'borland'}; |
| 557 | print "\nclean:\n". |
| 558 | "\t-del *.obj\n". |
| 559 | "\t-del *.exe\n". |
| 560 | "\t-del *.res\n". |
| 561 | "\t-del *.pch\n". |
| 562 | "\t-del *.aps\n". |
| 563 | "\t-del *.il*\n". |
| 564 | "\t-del *.pdb\n". |
| 565 | "\t-del *.rsp\n". |
| 566 | "\t-del *.tds\n". |
| 567 | "\t-del *.\$\$\$\$\$\$\n"; |
| 568 | select STDOUT; close OUT; |
| 569 | } |
| 570 | |
| 571 | if (defined $makefiles{'vc'}) { |
| 572 | $mftyp = 'vc'; |
| 573 | $dirpfx = &dirpfx($makefiles{'vc'}, "\\"); |
| 574 | |
| 575 | ##-- Visual C++ makefile |
| 576 | open OUT, ">$makefiles{'vc'}"; select OUT; |
| 577 | print |
| 578 | "# Makefile for $project_name under Visual C.\n". |
| 579 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
| 580 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
| 581 | print $help; |
| 582 | print |
| 583 | "\n". |
| 584 | "# If you rename this file to `Makefile', you should change this line,\n". |
| 585 | "# so that the .rsp files still depend on the correct makefile.\n". |
| 586 | "MAKEFILE = Makefile.vc\n". |
| 587 | "\n". |
| 588 | "# C compilation flags\n". |
| 589 | "CFLAGS = /nologo /W3 /O1 /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401\n". |
| 590 | "LFLAGS = /incremental:no /fixed\n". |
| 591 | "\n"; |
| 592 | print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C")); |
| 593 | print "\n\n"; |
| 594 | foreach $p (&prognames("G:C")) { |
| 595 | ($prog, $type) = split ",", $p; |
| 596 | $objstr = &objects($p, "X.obj", "X.res", undef); |
| 597 | print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n"; |
| 598 | print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n"; |
| 599 | } |
| 600 | foreach $p (&prognames("G:C")) { |
| 601 | ($prog, $type) = split ",", $p; |
| 602 | print $prog, ".rsp: \$(MAKEFILE)\n"; |
| 603 | $objstr = &objects($p, "X.obj", "X.res", "X.lib"); |
| 604 | @objlist = split " ", $objstr; |
| 605 | @objlines = (""); |
| 606 | foreach $i (@objlist) { |
| 607 | if (length($objlines[$#objlines] . " $i") > 50) { |
| 608 | push @objlines, ""; |
| 609 | } |
| 610 | $objlines[$#objlines] .= " $i"; |
| 611 | } |
| 612 | $subsys = ($type eq "G") ? "windows" : "console"; |
| 613 | print "\techo /nologo /subsystem:$subsys > $prog.rsp\n"; |
| 614 | for ($i=0; $i<=$#objlines; $i++) { |
| 615 | print "\techo$objlines[$i] >> $prog.rsp\n"; |
| 616 | } |
| 617 | print "\n"; |
| 618 | } |
| 619 | foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) { |
| 620 | print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), |
| 621 | "\n"; |
| 622 | if ($d->{obj} =~ /\.res$/) { |
| 623 | print "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 ". |
| 624 | "-DWINVER=0x0400 ".$d->{deps}->[0]."\n"; |
| 625 | } else { |
| 626 | $deflist = join "", map { " /D$_" } @{$d->{defs}}; |
| 627 | print "\tcl \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist". |
| 628 | " /c ".$d->{deps}->[0]." /Fo$d->{obj}\n"; |
| 629 | } |
| 630 | } |
| 631 | print "\n"; |
| 632 | print $makefile_extra{'vc'}; |
| 633 | print "\nclean: tidy\n". |
| 634 | "\t-del *.exe\n\n". |
| 635 | "tidy:\n". |
| 636 | "\t-del *.obj\n". |
| 637 | "\t-del *.res\n". |
| 638 | "\t-del *.pch\n". |
| 639 | "\t-del *.aps\n". |
| 640 | "\t-del *.ilk\n". |
| 641 | "\t-del *.pdb\n". |
| 642 | "\t-del *.rsp\n". |
| 643 | "\t-del *.dsp\n". |
| 644 | "\t-del *.dsw\n". |
| 645 | "\t-del *.ncb\n". |
| 646 | "\t-del *.opt\n". |
| 647 | "\t-del *.plg\n". |
| 648 | "\t-del *.map\n". |
| 649 | "\t-del *.idb\n". |
| 650 | "\t-del debug.log\n"; |
| 651 | select STDOUT; close OUT; |
| 652 | } |
| 653 | |
| 654 | if (defined $makefiles{'vcproj'}) { |
| 655 | $mftyp = 'vcproj'; |
| 656 | |
| 657 | $orig_dir = cwd; |
| 658 | |
| 659 | ##-- MSVC 6 Workspace and projects |
| 660 | # |
| 661 | # Note: All files created in this section are written in binary |
| 662 | # mode, because although MSVC's command-line make can deal with |
| 663 | # LF-only line endings, MSVC project files really _need_ to be |
| 664 | # CRLF. Hence, in order for mkfiles.pl to generate usable project |
| 665 | # files even when run from Unix, I make sure all files are binary |
| 666 | # and explicitly write the CRLFs. |
| 667 | # |
| 668 | # Create directories if necessary |
| 669 | mkdir $makefiles{'vcproj'} |
| 670 | if(! -d $makefiles{'vcproj'}); |
| 671 | chdir $makefiles{'vcproj'}; |
| 672 | @deps = &deps("X.obj", "X.res", "", "\\"); |
| 673 | %all_object_deps = map {$_->{obj} => $_->{deps}} @deps; |
| 674 | # Create the project files |
| 675 | # Get names of all Windows projects (GUI and console) |
| 676 | my @prognames = &prognames("G:C"); |
| 677 | foreach $progname (@prognames) { |
| 678 | create_project(\%all_object_deps, $progname); |
| 679 | } |
| 680 | # Create the workspace file |
| 681 | open OUT, ">$project_name.dsw"; binmode OUT; select OUT; |
| 682 | print |
| 683 | "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n". |
| 684 | "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n". |
| 685 | "\r\n". |
| 686 | "###############################################################################\r\n". |
| 687 | "\r\n"; |
| 688 | # List projects |
| 689 | foreach $progname (@prognames) { |
| 690 | ($windows_project, $type) = split ",", $progname; |
| 691 | print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n"; |
| 692 | } |
| 693 | print |
| 694 | "\r\n". |
| 695 | "Package=<5>\r\n". |
| 696 | "{{{\r\n". |
| 697 | "}}}\r\n". |
| 698 | "\r\n". |
| 699 | "Package=<4>\r\n". |
| 700 | "{{{\r\n". |
| 701 | "}}}\r\n". |
| 702 | "\r\n". |
| 703 | "###############################################################################\r\n". |
| 704 | "\r\n". |
| 705 | "Global:\r\n". |
| 706 | "\r\n". |
| 707 | "Package=<5>\r\n". |
| 708 | "{{{\r\n". |
| 709 | "}}}\r\n". |
| 710 | "\r\n". |
| 711 | "Package=<3>\r\n". |
| 712 | "{{{\r\n". |
| 713 | "}}}\r\n". |
| 714 | "\r\n". |
| 715 | "###############################################################################\r\n". |
| 716 | "\r\n"; |
| 717 | select STDOUT; close OUT; |
| 718 | chdir $orig_dir; |
| 719 | |
| 720 | sub create_project { |
| 721 | my ($all_object_deps, $progname) = @_; |
| 722 | # Construct program's dependency info |
| 723 | %seen_objects = (); |
| 724 | %lib_files = (); |
| 725 | %source_files = (); |
| 726 | %header_files = (); |
| 727 | %resource_files = (); |
| 728 | @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib"); |
| 729 | foreach $object_file (@object_files) { |
| 730 | next if defined $seen_objects{$object_file}; |
| 731 | $seen_objects{$object_file} = 1; |
| 732 | if($object_file =~ /\.lib$/io) { |
| 733 | $lib_files{$object_file} = 1; |
| 734 | next; |
| 735 | } |
| 736 | $object_deps = $all_object_deps{$object_file}; |
| 737 | foreach $object_dep (@$object_deps) { |
| 738 | if($object_dep =~ /\.c$/io) { |
| 739 | $source_files{$object_dep} = 1; |
| 740 | next; |
| 741 | } |
| 742 | if($object_dep =~ /\.h$/io) { |
| 743 | $header_files{$object_dep} = 1; |
| 744 | next; |
| 745 | } |
| 746 | if($object_dep =~ /\.(rc|ico)$/io) { |
| 747 | $resource_files{$object_dep} = 1; |
| 748 | next; |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | $libs = join " ", sort keys %lib_files; |
| 753 | @source_files = sort keys %source_files; |
| 754 | @header_files = sort keys %header_files; |
| 755 | @resources = sort keys %resource_files; |
| 756 | ($windows_project, $type) = split ",", $progname; |
| 757 | mkdir $windows_project |
| 758 | if(! -d $windows_project); |
| 759 | chdir $windows_project; |
| 760 | $subsys = ($type eq "G") ? "windows" : "console"; |
| 761 | open OUT, ">$windows_project.dsp"; binmode OUT; select OUT; |
| 762 | print |
| 763 | "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n". |
| 764 | "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n". |
| 765 | "# ** DO NOT EDIT **\r\n". |
| 766 | "\r\n". |
| 767 | "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n". |
| 768 | "\r\n". |
| 769 | "CFG=$windows_project - Win32 Debug\r\n". |
| 770 | "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n". |
| 771 | "!MESSAGE use the Export Makefile command and run\r\n". |
| 772 | "!MESSAGE \r\n". |
| 773 | "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n". |
| 774 | "!MESSAGE \r\n". |
| 775 | "!MESSAGE You can specify a configuration when running NMAKE\r\n". |
| 776 | "!MESSAGE by defining the macro CFG on the command line. For example:\r\n". |
| 777 | "!MESSAGE \r\n". |
| 778 | "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n". |
| 779 | "!MESSAGE \r\n". |
| 780 | "!MESSAGE Possible choices for configuration are:\r\n". |
| 781 | "!MESSAGE \r\n". |
| 782 | "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n". |
| 783 | "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n". |
| 784 | "!MESSAGE \r\n". |
| 785 | "\r\n". |
| 786 | "# Begin Project\r\n". |
| 787 | "# PROP AllowPerConfigDependencies 0\r\n". |
| 788 | "# PROP Scc_ProjName \"\"\r\n". |
| 789 | "# PROP Scc_LocalPath \"\"\r\n". |
| 790 | "CPP=cl.exe\r\n". |
| 791 | "MTL=midl.exe\r\n". |
| 792 | "RSC=rc.exe\r\n". |
| 793 | "\r\n". |
| 794 | "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n". |
| 795 | "\r\n". |
| 796 | "# PROP BASE Use_MFC 0\r\n". |
| 797 | "# PROP BASE Use_Debug_Libraries 0\r\n". |
| 798 | "# PROP BASE Output_Dir \"Release\"\r\n". |
| 799 | "# PROP BASE Intermediate_Dir \"Release\"\r\n". |
| 800 | "# PROP BASE Target_Dir \"\"\r\n". |
| 801 | "# PROP Use_MFC 0\r\n". |
| 802 | "# PROP Use_Debug_Libraries 0\r\n". |
| 803 | "# PROP Output_Dir \"Release\"\r\n". |
| 804 | "# PROP Intermediate_Dir \"Release\"\r\n". |
| 805 | "# PROP Ignore_Export_Lib 0\r\n". |
| 806 | "# PROP Target_Dir \"\"\r\n". |
| 807 | "# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n". |
| 808 | "# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n". |
| 809 | "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n". |
| 810 | "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n". |
| 811 | "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n". |
| 812 | "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n". |
| 813 | "BSC32=bscmake.exe\r\n". |
| 814 | "# ADD BASE BSC32 /nologo\r\n". |
| 815 | "# ADD BSC32 /nologo\r\n". |
| 816 | "LINK32=link.exe\r\n". |
| 817 | "# 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". |
| 818 | "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n". |
| 819 | "# SUBTRACT LINK32 /pdb:none\r\n". |
| 820 | "\r\n". |
| 821 | "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n". |
| 822 | "\r\n". |
| 823 | "# PROP BASE Use_MFC 0\r\n". |
| 824 | "# PROP BASE Use_Debug_Libraries 1\r\n". |
| 825 | "# PROP BASE Output_Dir \"Debug\"\r\n". |
| 826 | "# PROP BASE Intermediate_Dir \"Debug\"\r\n". |
| 827 | "# PROP BASE Target_Dir \"\"\r\n". |
| 828 | "# PROP Use_MFC 0\r\n". |
| 829 | "# PROP Use_Debug_Libraries 1\r\n". |
| 830 | "# PROP Output_Dir \"Debug\"\r\n". |
| 831 | "# PROP Intermediate_Dir \"Debug\"\r\n". |
| 832 | "# PROP Ignore_Export_Lib 0\r\n". |
| 833 | "# PROP Target_Dir \"\"\r\n". |
| 834 | "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n". |
| 835 | "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n". |
| 836 | "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n". |
| 837 | "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n". |
| 838 | "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n". |
| 839 | "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n". |
| 840 | "BSC32=bscmake.exe\r\n". |
| 841 | "# ADD BASE BSC32 /nologo\r\n". |
| 842 | "# ADD BSC32 /nologo\r\n". |
| 843 | "LINK32=link.exe\r\n". |
| 844 | "# 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". |
| 845 | "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n". |
| 846 | "# SUBTRACT LINK32 /pdb:none\r\n". |
| 847 | "\r\n". |
| 848 | "!ENDIF \r\n". |
| 849 | "\r\n". |
| 850 | "# Begin Target\r\n". |
| 851 | "\r\n". |
| 852 | "# Name \"$windows_project - Win32 Release\"\r\n". |
| 853 | "# Name \"$windows_project - Win32 Debug\"\r\n". |
| 854 | "# Begin Group \"Source Files\"\r\n". |
| 855 | "\r\n". |
| 856 | "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n"; |
| 857 | foreach $source_file (@source_files) { |
| 858 | print |
| 859 | "# Begin Source File\r\n". |
| 860 | "\r\n". |
| 861 | "SOURCE=..\\..\\$source_file\r\n"; |
| 862 | if($source_file =~ /ssh\.c/io) { |
| 863 | # Disable 'Edit and continue' as Visual Studio can't handle the macros |
| 864 | print |
| 865 | "\r\n". |
| 866 | "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n". |
| 867 | "\r\n". |
| 868 | "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n". |
| 869 | "\r\n". |
| 870 | "# ADD CPP /Zi\r\n". |
| 871 | "\r\n". |
| 872 | "!ENDIF \r\n". |
| 873 | "\r\n"; |
| 874 | } |
| 875 | print "# End Source File\r\n"; |
| 876 | } |
| 877 | print |
| 878 | "# End Group\r\n". |
| 879 | "# Begin Group \"Header Files\"\r\n". |
| 880 | "\r\n". |
| 881 | "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n"; |
| 882 | foreach $header_file (@header_files) { |
| 883 | print |
| 884 | "# Begin Source File\r\n". |
| 885 | "\r\n". |
| 886 | "SOURCE=..\\..\\$header_file\r\n". |
| 887 | "# End Source File\r\n"; |
| 888 | } |
| 889 | print |
| 890 | "# End Group\r\n". |
| 891 | "# Begin Group \"Resource Files\"\r\n". |
| 892 | "\r\n". |
| 893 | "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n"; |
| 894 | foreach $resource_file (@resources) { |
| 895 | print |
| 896 | "# Begin Source File\r\n". |
| 897 | "\r\n". |
| 898 | "SOURCE=..\\..\\$resource_file\r\n". |
| 899 | "# End Source File\r\n"; |
| 900 | } |
| 901 | print |
| 902 | "# End Group\r\n". |
| 903 | "# End Target\r\n". |
| 904 | "# End Project\r\n"; |
| 905 | select STDOUT; close OUT; |
| 906 | chdir ".."; |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | if (defined $makefiles{'gtk'}) { |
| 911 | $mftyp = 'gtk'; |
| 912 | $dirpfx = &dirpfx($makefiles{'gtk'}, "/"); |
| 913 | |
| 914 | ##-- X/GTK/Unix makefile |
| 915 | open OUT, ">$makefiles{'gtk'}"; select OUT; |
| 916 | print |
| 917 | "# Makefile for $project_name under X/GTK and Unix.\n". |
| 918 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
| 919 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
| 920 | # gcc command line option is -D not /D |
| 921 | ($_ = $help) =~ s/=\/D/=-D/gs; |
| 922 | print $_; |
| 923 | print |
| 924 | "\n". |
| 925 | "# You can define this path to point at your tools if you need to\n". |
| 926 | "# TOOLPATH = /opt/gcc/bin\n". |
| 927 | "CC = \$(TOOLPATH)cc\n". |
| 928 | "# You can manually set this to `gtk-config' or `pkg-config gtk+-1.2'\n". |
| 929 | "# (depending on what works on your system) if you want to enforce\n". |
| 930 | "# building with GTK 1.2, or you can set it to `pkg-config gtk+-2.0'\n". |
| 931 | "# if you want to enforce 2.0. The default is to try 2.0 and fall back\n". |
| 932 | "# to 1.2 if it isn't found.\n". |
| 933 | "GTK_CONFIG = sh -c 'pkg-config gtk+-2.0 \$\$0 2>/dev/null || gtk-config \$\$0'\n". |
| 934 | "\n". |
| 935 | &splitline("CFLAGS = -O2 -Wall -Werror -g " . |
| 936 | (join " ", map {"-I$dirpfx$_"} @srcdirs) . |
| 937 | " `\$(GTK_CONFIG) --cflags`")."\n". |
| 938 | "XLDFLAGS = `\$(GTK_CONFIG) --libs`\n". |
| 939 | "ULDFLAGS =#\n". |
| 940 | "INSTALL=install\n", |
| 941 | "INSTALL_PROGRAM=\$(INSTALL)\n", |
| 942 | "INSTALL_DATA=\$(INSTALL)\n", |
| 943 | "prefix=/usr/local\n", |
| 944 | "exec_prefix=\$(prefix)\n", |
| 945 | "bindir=\$(exec_prefix)/bin\n", |
| 946 | "gamesdir=\$(exec_prefix)/games\n", |
| 947 | "mandir=\$(prefix)/man\n", |
| 948 | "man1dir=\$(mandir)/man1\n", |
| 949 | "\n"; |
| 950 | print &splitline("all:" . join "", map { " $_" } &progrealnames("X:U")); |
| 951 | print "\n\n"; |
| 952 | foreach $p (&prognames("X:U")) { |
| 953 | ($prog, $type) = split ",", $p; |
| 954 | $objstr = &objects($p, "X.o", undef, undef); |
| 955 | print &splitline($prog . ": " . $objstr), "\n"; |
| 956 | $libstr = &objects($p, undef, undef, "-lX"); |
| 957 | print &splitline("\t\$(CC)" . $mw . " \$(${type}LDFLAGS) -o \$@ " . |
| 958 | $objstr . " $libstr", 69), "\n\n"; |
| 959 | } |
| 960 | foreach $d (&deps("X.o", undef, $dirpfx, "/")) { |
| 961 | print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), |
| 962 | "\n"; |
| 963 | $deflist = join "", map { " -D$_" } @{$d->{defs}}; |
| 964 | print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" . |
| 965 | " -c \$< -o \$\@\n"; |
| 966 | } |
| 967 | print "\n"; |
| 968 | print $makefile_extra{'gtk'}; |
| 969 | print "\nclean:\n". |
| 970 | "\trm -f *.o". (join "", map { " $_" } &progrealnames("X:U")) . "\n"; |
| 971 | select STDOUT; close OUT; |
| 972 | } |
| 973 | |
| 974 | if (defined $makefiles{'mpw'}) { |
| 975 | $mftyp = 'mpw'; |
| 976 | ##-- MPW Makefile |
| 977 | open OUT, ">$makefiles{'mpw'}"; select OUT; |
| 978 | print |
| 979 | "# Makefile for $project_name under MPW.\n#\n". |
| 980 | "# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
| 981 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
| 982 | # MPW command line option is -d not /D |
| 983 | ($_ = $help) =~ s/=\/D/=-d /gs; |
| 984 | print $_; |
| 985 | print "\n\n". |
| 986 | "ROptions = `Echo \"{VER}\" | StreamEdit -e \"1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6\"' \xa81 '\xb6\xb6\xb6\xb6\xb6\"'\"`". |
| 987 | "\n". |
| 988 | "C_68K = {C}\n". |
| 989 | "C_CFM68K = {C}\n". |
| 990 | "C_PPC = {PPCC}\n". |
| 991 | "C_Carbon = {PPCC}\n". |
| 992 | "\n". |
| 993 | "# -w 35 disables \"unused parameter\" warnings\n". |
| 994 | "COptions = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6\n". |
| 995 | " -notOnce\n". |
| 996 | "COptions_68K = {COptions} -model far -opt time\n". |
| 997 | "# Enabling \"-opt space\" for CFM-68K gives me undefined references to\n". |
| 998 | "# _\$LDIVT and _\$LMODT.\n". |
| 999 | "COptions_CFM68K = {COptions} -model cfmSeg -opt time\n". |
| 1000 | "COptions_PPC = {COptions} -opt size -traceback\n". |
| 1001 | "COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON\n". |
| 1002 | "\n". |
| 1003 | "Link_68K = ILink\n". |
| 1004 | "Link_CFM68K = ILink\n". |
| 1005 | "Link_PPC = PPCLink\n". |
| 1006 | "Link_Carbon = PPCLink\n". |
| 1007 | "\n". |
| 1008 | "LinkOptions = -c 'pTTY'\n". |
| 1009 | "LinkOptions_68K = {LinkOptions} -br 68k -model far -compact\n". |
| 1010 | "LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact\n". |
| 1011 | "LinkOptions_PPC = {LinkOptions}\n". |
| 1012 | "LinkOptions_Carbon = -m __appstart -w {LinkOptions}\n". |
| 1013 | "\n". |
| 1014 | "Libs_68K = \"{CLibraries}StdCLib.far.o\" \xb6\n". |
| 1015 | " \"{Libraries}MacRuntime.o\" \xb6\n". |
| 1016 | " \"{Libraries}MathLib.far.o\" \xb6\n". |
| 1017 | " \"{Libraries}IntEnv.far.o\" \xb6\n". |
| 1018 | " \"{Libraries}Interface.o\" \xb6\n". |
| 1019 | " \"{Libraries}Navigation.far.o\" \xb6\n". |
| 1020 | " \"{Libraries}OpenTransport.o\" \xb6\n". |
| 1021 | " \"{Libraries}OpenTransportApp.o\" \xb6\n". |
| 1022 | " \"{Libraries}OpenTptInet.o\" \xb6\n". |
| 1023 | " \"{Libraries}UnicodeConverterLib.far.o\"\n". |
| 1024 | "\n". |
| 1025 | "Libs_CFM = \"{SharedLibraries}InterfaceLib\" \xb6\n". |
| 1026 | " \"{SharedLibraries}StdCLib\" \xb6\n". |
| 1027 | " \"{SharedLibraries}AppearanceLib\" \xb6\n". |
| 1028 | " -weaklib AppearanceLib \xb6\n". |
| 1029 | " \"{SharedLibraries}NavigationLib\" \xb6\n". |
| 1030 | " -weaklib NavigationLib \xb6\n". |
| 1031 | " \"{SharedLibraries}TextCommon\" \xb6\n". |
| 1032 | " -weaklib TextCommon \xb6\n". |
| 1033 | " \"{SharedLibraries}UnicodeConverter\" \xb6\n". |
| 1034 | " -weaklib UnicodeConverter\n". |
| 1035 | "\n". |
| 1036 | "Libs_CFM68K = {Libs_CFM} \xb6\n". |
| 1037 | " \"{CFM68KLibraries}NuMacRuntime.o\"\n". |
| 1038 | "\n". |
| 1039 | "Libs_PPC = {Libs_CFM} \xb6\n". |
| 1040 | " \"{SharedLibraries}ControlsLib\" \xb6\n". |
| 1041 | " -weaklib ControlsLib \xb6\n". |
| 1042 | " \"{SharedLibraries}WindowsLib\" \xb6\n". |
| 1043 | " -weaklib WindowsLib \xb6\n". |
| 1044 | " \"{SharedLibraries}OpenTransportLib\" \xb6\n". |
| 1045 | " -weaklib OTClientLib \xb6\n". |
| 1046 | " -weaklib OTClientUtilLib \xb6\n". |
| 1047 | " \"{SharedLibraries}OpenTptInternetLib\" \xb6\n". |
| 1048 | " -weaklib OTInetClientLib \xb6\n". |
| 1049 | " \"{PPCLibraries}StdCRuntime.o\" \xb6\n". |
| 1050 | " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n". |
| 1051 | " \"{PPCLibraries}CarbonAccessors.o\" \xb6\n". |
| 1052 | " \"{PPCLibraries}OpenTransportAppPPC.o\" \xb6\n". |
| 1053 | " \"{PPCLibraries}OpenTptInetPPC.o\"\n". |
| 1054 | "\n". |
| 1055 | "Libs_Carbon = \"{PPCLibraries}CarbonStdCLib.o\" \xb6\n". |
| 1056 | " \"{PPCLibraries}StdCRuntime.o\" \xb6\n". |
| 1057 | " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n". |
| 1058 | " \"{SharedLibraries}CarbonLib\" \xb6\n". |
| 1059 | " \"{SharedLibraries}StdCLib\"\n". |
| 1060 | "\n"; |
| 1061 | print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6"); |
| 1062 | print "\n\n"; |
| 1063 | foreach $p (&prognames("M")) { |
| 1064 | ($prog, $type) = split ",", $p; |
| 1065 | |
| 1066 | print &splitline("$prog \xc4 $prog.68k $prog.ppc $prog.carbon", |
| 1067 | undef, "\xb6"), "\n\n"; |
| 1068 | |
| 1069 | $rsrc = &objects($p, "", "X.rsrc", undef); |
| 1070 | |
| 1071 | foreach $arch (qw(68K CFM68K PPC Carbon)) { |
| 1072 | $objstr = &objects($p, "X.\L$arch\E.o", "", undef); |
| 1073 | print &splitline("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6"); |
| 1074 | print "\n"; |
| 1075 | print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n"; |
| 1076 | print &splitline("\t{Link_$arch} -o {Targ} -fragname $prog " . |
| 1077 | "{LinkOptions_$arch} " . |
| 1078 | $objstr . " {Libs_$arch}", 69, "\xb6"), "\n"; |
| 1079 | print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n"; |
| 1080 | } |
| 1081 | |
| 1082 | } |
| 1083 | foreach $d (&deps("", "X.rsrc", "::", ":")) { |
| 1084 | next unless $d->{obj}; |
| 1085 | print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}), |
| 1086 | undef, "\xb6"), "\n"; |
| 1087 | print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n"; |
| 1088 | } |
| 1089 | foreach $arch (qw(68K CFM68K)) { |
| 1090 | foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) { |
| 1091 | next unless $d->{obj}; |
| 1092 | print &splitline(sprintf("%s \xc4 %s", $d->{obj}, |
| 1093 | join " ", @{$d->{deps}}), |
| 1094 | undef, "\xb6"), "\n"; |
| 1095 | print "\t{C_$arch} ", $d->{deps}->[0], |
| 1096 | " -o {Targ} {COptions_$arch}\n\n"; |
| 1097 | } |
| 1098 | } |
| 1099 | foreach $arch (qw(PPC Carbon)) { |
| 1100 | foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) { |
| 1101 | next unless $d->{obj}; |
| 1102 | print &splitline(sprintf("%s \xc4 %s", $d->{obj}, |
| 1103 | join " ", @{$d->{deps}}), |
| 1104 | undef, "\xb6"), "\n"; |
| 1105 | # The odd stuff here seems to stop afpd getting confused. |
| 1106 | print "\techo -n > {Targ}\n"; |
| 1107 | print "\tsetfile -t XCOF {Targ}\n"; |
| 1108 | print "\t{C_$arch} ", $d->{deps}->[0], |
| 1109 | " -o {Targ} {COptions_$arch}\n\n"; |
| 1110 | } |
| 1111 | } |
| 1112 | select STDOUT; close OUT; |
| 1113 | } |
| 1114 | |
| 1115 | if (defined $makefiles{'lcc'}) { |
| 1116 | $mftyp = 'lcc'; |
| 1117 | $dirpfx = &dirpfx($makefiles{'lcc'}, "\\"); |
| 1118 | |
| 1119 | ##-- lcc makefile |
| 1120 | open OUT, ">$makefiles{'lcc'}"; select OUT; |
| 1121 | print |
| 1122 | "# Makefile for $project_name under lcc.\n". |
| 1123 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
| 1124 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
| 1125 | # lcc command line option is -D not /D |
| 1126 | ($_ = $help) =~ s/=\/D/=-D/gs; |
| 1127 | print $_; |
| 1128 | print |
| 1129 | "\n". |
| 1130 | "# If you rename this file to `Makefile', you should change this line,\n". |
| 1131 | "# so that the .rsp files still depend on the correct makefile.\n". |
| 1132 | "MAKEFILE = Makefile.lcc\n". |
| 1133 | "\n". |
| 1134 | "# C compilation flags\n". |
| 1135 | "CFLAGS = -D_WINDOWS " . |
| 1136 | (join " ", map {"-I$dirpfx$_"} @srcdirs) . |
| 1137 | "\n". |
| 1138 | "\n". |
| 1139 | "# Get include directory for resource compiler\n". |
| 1140 | "\n"; |
| 1141 | print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C")); |
| 1142 | print "\n\n"; |
| 1143 | foreach $p (&prognames("G:C")) { |
| 1144 | ($prog, $type) = split ",", $p; |
| 1145 | $objstr = &objects($p, "X.obj", "X.res", undef); |
| 1146 | print &splitline("$prog.exe: " . $objstr ), "\n"; |
| 1147 | $subsystemtype = undef; |
| 1148 | if ($type eq "G") { $subsystemtype = "-subsystem windows"; } |
| 1149 | my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib"; |
| 1150 | print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss"); |
| 1151 | print "\n\n"; |
| 1152 | } |
| 1153 | |
| 1154 | foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) { |
| 1155 | print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), |
| 1156 | "\n"; |
| 1157 | if ($d->{obj} =~ /\.res$/) { |
| 1158 | print &splitline("\tlrc \$(FWHACK) \$(RCFL) -r \$*.rc",69)."\n"; |
| 1159 | } else { |
| 1160 | $deflist = join "", map { " -D$_" } @{$d->{defs}}; |
| 1161 | print &splitline("\tlcc -O -p6 \$(COMPAT) \$(FWHACK) \$(CFLAGS)". |
| 1162 | " \$(XFLAGS)$deflist ".$d->{deps}->[0]." -o \$\@",69)."\n"; |
| 1163 | } |
| 1164 | } |
| 1165 | print "\n"; |
| 1166 | print $makefile_extra{'lcc'}; |
| 1167 | print "\nclean:\n". |
| 1168 | "\t-del *.obj\n". |
| 1169 | "\t-del *.exe\n". |
| 1170 | "\t-del *.res\n"; |
| 1171 | |
| 1172 | select STDOUT; close OUT; |
| 1173 | } |
| 1174 | |
| 1175 | if (defined $makefiles{'osx'}) { |
| 1176 | $mftyp = 'osx'; |
| 1177 | $dirpfx = &dirpfx($makefiles{'osx'}, "/"); |
| 1178 | |
| 1179 | ##-- Mac OS X makefile |
| 1180 | open OUT, ">$makefiles{'osx'}"; select OUT; |
| 1181 | print |
| 1182 | "# Makefile for $project_name under Mac OS X.\n". |
| 1183 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
| 1184 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
| 1185 | # gcc command line option is -D not /D |
| 1186 | ($_ = $help) =~ s/=\/D/=-D/gs; |
| 1187 | print $_; |
| 1188 | print |
| 1189 | "CC = \$(TOOLPATH)gcc\n". |
| 1190 | "\n". |
| 1191 | &splitline("CFLAGS = -O2 -Wall -Werror -g " . |
| 1192 | (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n". |
| 1193 | "LDFLAGS = -framework Cocoa\n". |
| 1194 | &splitline("all:" . join "", map { " $_" } &progrealnames("MX:U")) . |
| 1195 | "\n" . |
| 1196 | $makefile_extra{'osx'} . |
| 1197 | "\n". |
| 1198 | ".SUFFIXES: .o .c .m\n". |
| 1199 | "\n"; |
| 1200 | print "\n\n"; |
| 1201 | foreach $p (&prognames("MX")) { |
| 1202 | ($prog, $type) = split ",", $p; |
| 1203 | $objstr = &objects($p, "X.o", undef, undef); |
| 1204 | $icon = &special($p, ".icns"); |
| 1205 | $infoplist = &special($p, "info.plist"); |
| 1206 | print "${prog}.app:\n\tmkdir -p \$\@\n"; |
| 1207 | print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n"; |
| 1208 | print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n"; |
| 1209 | $targets = "${prog}.app/Contents/MacOS/$prog"; |
| 1210 | if (defined $icon) { |
| 1211 | print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n"; |
| 1212 | print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n"; |
| 1213 | $targets .= " ${prog}.app/Contents/Resources/${prog}.icns"; |
| 1214 | } |
| 1215 | if (defined $infoplist) { |
| 1216 | print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n"; |
| 1217 | $targets .= " ${prog}.app/Contents/Info.plist"; |
| 1218 | } |
| 1219 | $targets .= " \$(${prog}_extra)"; |
| 1220 | print &splitline("${prog}: $targets", 69) . "\n\n"; |
| 1221 | print &splitline("${prog}.app/Contents/MacOS/$prog: ". |
| 1222 | "${prog}.app/Contents/MacOS " . $objstr), "\n"; |
| 1223 | $libstr = &objects($p, undef, undef, "-lX"); |
| 1224 | print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " . |
| 1225 | $objstr . " $libstr", 69), "\n\n"; |
| 1226 | } |
| 1227 | foreach $p (&prognames("U")) { |
| 1228 | ($prog, $type) = split ",", $p; |
| 1229 | $objstr = &objects($p, "X.o", undef, undef); |
| 1230 | print &splitline($prog . ": " . $objstr), "\n"; |
| 1231 | $libstr = &objects($p, undef, undef, "-lX"); |
| 1232 | print &splitline("\t\$(CC)" . $mw . " \$(ULDFLAGS) -o \$@ " . |
| 1233 | $objstr . " $libstr", 69), "\n\n"; |
| 1234 | } |
| 1235 | foreach $d (&deps("X.o", undef, $dirpfx, "/")) { |
| 1236 | print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), |
| 1237 | "\n"; |
| 1238 | $deflist = join "", map { " -D$_" } @{$d->{defs}}; |
| 1239 | if ($d->{deps}->[0] =~ /\.m$/) { |
| 1240 | print "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS)". |
| 1241 | " \$(XFLAGS)$deflist -c \$< -o \$\@\n"; |
| 1242 | } else { |
| 1243 | print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" . |
| 1244 | " -c \$< -o \$\@\n"; |
| 1245 | } |
| 1246 | } |
| 1247 | print "\nclean:\n". |
| 1248 | "\trm -f *.o *.dmg". (join "", map { " $_" } &progrealnames("U")) . "\n". |
| 1249 | "\trm -rf *.app\n"; |
| 1250 | select STDOUT; close OUT; |
| 1251 | } |