| 1 | #!/usr/bin/env perl |
| 2 | # |
| 3 | # Makefile generator for PuTTY. |
| 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 | use FileHandle; |
| 11 | |
| 12 | open IN, "Recipe" or do { |
| 13 | # We want to deal correctly with being run from one of the |
| 14 | # subdirs in the source tree. So if we can't find Recipe here, |
| 15 | # try one level up. |
| 16 | chdir ".."; |
| 17 | open IN, "Recipe" or die "unable to open Recipe file\n"; |
| 18 | }; |
| 19 | |
| 20 | # HACK: One of the source files in `charset' is auto-generated by |
| 21 | # sbcsgen.pl. We need to generate that _now_, before attempting |
| 22 | # dependency analysis. |
| 23 | eval 'chdir "charset"; require "sbcsgen.pl"; chdir ".."'; |
| 24 | |
| 25 | @incdirs = ("", "charset/", "unix/", "mac/"); |
| 26 | |
| 27 | $help = ""; # list of newline-free lines of help text |
| 28 | %programs = (); # maps prog name + type letter to listref of objects/resources |
| 29 | %groups = (); # maps group name to listref of objects/resources |
| 30 | |
| 31 | while (<IN>) { |
| 32 | # Skip comments (unless the comments belong, for example because |
| 33 | # they're part of the help text). |
| 34 | next if /^\s*#/ and !$in_help; |
| 35 | |
| 36 | chomp; |
| 37 | split; |
| 38 | if ($_[0] eq "!begin" and $_[1] eq "help") { $in_help = 1; next; } |
| 39 | if ($_[0] eq "!end" and $in_help) { $in_help = 0; next; } |
| 40 | # If we're gathering help text, keep doing so. |
| 41 | if ($in_help) { $help .= "$_\n"; next; } |
| 42 | # Ignore blank lines. |
| 43 | next if scalar @_ == 0; |
| 44 | |
| 45 | # Now we have an ordinary line. See if it's an = line, a : line |
| 46 | # or a + line. |
| 47 | @objs = @_; |
| 48 | |
| 49 | if ($_[0] eq "+") { |
| 50 | $listref = $lastlistref; |
| 51 | $prog = undef; |
| 52 | die "$.: unexpected + line\n" if !defined $lastlistref; |
| 53 | } elsif ($_[1] eq "=") { |
| 54 | $groups{$_[0]} = [] if !defined $groups{$_[0]}; |
| 55 | $listref = $groups{$_[0]}; |
| 56 | $prog = undef; |
| 57 | shift @objs; # eat the group name |
| 58 | } elsif ($_[1] eq ":") { |
| 59 | $listref = []; |
| 60 | $prog = $_[0]; |
| 61 | shift @objs; # eat the program name |
| 62 | } else { |
| 63 | die "$.: unrecognised line type\n"; |
| 64 | } |
| 65 | shift @objs; # eat the +, the = or the : |
| 66 | |
| 67 | while (scalar @objs > 0) { |
| 68 | $i = shift @objs; |
| 69 | if ($groups{$i}) { |
| 70 | foreach $j (@{$groups{$i}}) { unshift @objs, $j; } |
| 71 | } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or |
| 72 | $i eq "[X]" or $i eq "[U]") and defined $prog) { |
| 73 | $type = substr($i,1,1); |
| 74 | } else { |
| 75 | push @$listref, $i; |
| 76 | } |
| 77 | } |
| 78 | if ($prog and $type) { |
| 79 | die "multiple program entries for $prog [$type]\n" |
| 80 | if defined $programs{$prog . "," . $type}; |
| 81 | $programs{$prog . "," . $type} = $listref; |
| 82 | } |
| 83 | $lastlistref = $listref; |
| 84 | } |
| 85 | |
| 86 | close IN; |
| 87 | |
| 88 | # Now retrieve the complete list of objects and resource files, and |
| 89 | # construct dependency data for them. While we're here, expand the |
| 90 | # object list for each program, and complain if its type isn't set. |
| 91 | @prognames = sort keys %programs; |
| 92 | %depends = (); |
| 93 | @scanlist = (); |
| 94 | foreach $i (@prognames) { |
| 95 | ($prog, $type) = split ",", $i; |
| 96 | # Strip duplicate object names. |
| 97 | $prev = undef; |
| 98 | @list = grep { $status = ($prev ne $_); $prev=$_; $status } |
| 99 | sort @{$programs{$i}}; |
| 100 | $programs{$i} = [@list]; |
| 101 | foreach $j (@list) { |
| 102 | # Dependencies for "x" start with "x.c". |
| 103 | # Dependencies for "x.res" start with "x.rc". |
| 104 | # Dependencies for "x.rsrc" start with "x.r". |
| 105 | # Both types of file are pushed on the list of files to scan. |
| 106 | # Libraries (.lib) don't have dependencies at all. |
| 107 | if ($j =~ /^(.*)\.res$/) { |
| 108 | $file = "$1.rc"; |
| 109 | $depends{$j} = [$file]; |
| 110 | push @scanlist, $file; |
| 111 | } elsif ($j =~ /^(.*)\.rsrc$/) { |
| 112 | $file = "$1.r"; |
| 113 | $depends{$j} = [$file]; |
| 114 | push @scanlist, $file; |
| 115 | } elsif ($j =~ /\.lib$/) { |
| 116 | # libraries don't have dependencies |
| 117 | } else { |
| 118 | $file = "$j.c"; |
| 119 | $depends{$j} = [$file]; |
| 120 | push @scanlist, $file; |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | # Scan each file on @scanlist and find further inclusions. |
| 126 | # Inclusions are given by lines of the form `#include "otherfile"' |
| 127 | # (system headers are automatically ignored by this because they'll |
| 128 | # be given in angle brackets). Files included by this method are |
| 129 | # added back on to @scanlist to be scanned in turn (if not already |
| 130 | # done). |
| 131 | # |
| 132 | # Resource scripts (.rc) can also include a file by means of a line |
| 133 | # ending `ICON "filename"'. Files included by this method are not |
| 134 | # added to @scanlist because they can never include further files. |
| 135 | # |
| 136 | # In this pass we write out a hash %further which maps a source |
| 137 | # file name into a listref containing further source file names. |
| 138 | |
| 139 | %further = (); |
| 140 | while (scalar @scanlist > 0) { |
| 141 | $file = shift @scanlist; |
| 142 | next if defined $further{$file}; # skip if we've already done it |
| 143 | $resource = ($file =~ /\.rc$/ ? 1 : 0); |
| 144 | $further{$file} = []; |
| 145 | $dirfile = &findfile($file); |
| 146 | open IN, "$dirfile" or die "unable to open source file $file\n"; |
| 147 | while (<IN>) { |
| 148 | chomp; |
| 149 | /^\s*#include\s+\"([^\"]+)\"/ and do { |
| 150 | push @{$further{$file}}, $1; |
| 151 | push @scanlist, $1; |
| 152 | next; |
| 153 | }; |
| 154 | /ICON\s+\"([^\"]+)\"\s*$/ and do { |
| 155 | push @{$further{$file}}, $1; |
| 156 | next; |
| 157 | } |
| 158 | } |
| 159 | close IN; |
| 160 | } |
| 161 | |
| 162 | # Now we're ready to generate the final dependencies section. For |
| 163 | # each key in %depends, we must expand the dependencies list by |
| 164 | # iteratively adding entries from %further. |
| 165 | foreach $i (keys %depends) { |
| 166 | %dep = (); |
| 167 | @scanlist = @{$depends{$i}}; |
| 168 | foreach $i (@scanlist) { $dep{$i} = 1; } |
| 169 | while (scalar @scanlist > 0) { |
| 170 | $file = shift @scanlist; |
| 171 | foreach $j (@{$further{$file}}) { |
| 172 | if ($dep{$j} != 1) { |
| 173 | $dep{$j} = 1; |
| 174 | push @{$depends{$i}}, $j; |
| 175 | push @scanlist, $j; |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | # printf "%s: %s\n", $i, join ' ',@{$depends{$i}}; |
| 180 | } |
| 181 | |
| 182 | # Utility routines while writing out the Makefiles. |
| 183 | |
| 184 | sub findfile { |
| 185 | my ($name) = @_; |
| 186 | my $dir, $i, $outdir = ""; |
| 187 | $i = 0; |
| 188 | foreach $dir (@incdirs) { |
| 189 | $outdir = $dir, $i++ if -f "$dir$name"; |
| 190 | } |
| 191 | die "multiple instances of source file $name\n" if $i > 1; |
| 192 | return "$outdir$name"; |
| 193 | } |
| 194 | |
| 195 | sub objects { |
| 196 | my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_; |
| 197 | my @ret; |
| 198 | my ($i, $x, $y); |
| 199 | @ret = (); |
| 200 | foreach $i (@{$programs{$prog}}) { |
| 201 | $x = ""; |
| 202 | if ($i =~ /^(.*)\.(res|rsrc)/) { |
| 203 | $y = $1; |
| 204 | ($x = $rtmpl) =~ s/X/$y/; |
| 205 | } elsif ($i =~ /^(.*)\.lib/) { |
| 206 | $y = $1; |
| 207 | ($x = $ltmpl) =~ s/X/$y/; |
| 208 | } else { |
| 209 | ($x = $otmpl) =~ s/X/$i/; |
| 210 | } |
| 211 | push @ret, $x if $x ne ""; |
| 212 | } |
| 213 | return join " ", @ret; |
| 214 | } |
| 215 | |
| 216 | sub splitline { |
| 217 | my ($line, $width, $splitchar) = @_; |
| 218 | my ($result, $len); |
| 219 | $len = (defined $width ? $width : 76); |
| 220 | $splitchar = (defined $splitchar ? $splitchar : '\\'); |
| 221 | while (length $line > $len) { |
| 222 | $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/; |
| 223 | $result .= $1 . " ${splitchar}\n\t\t"; |
| 224 | $line = $2; |
| 225 | $len = 60; |
| 226 | } |
| 227 | return $result . $line; |
| 228 | } |
| 229 | |
| 230 | sub deps { |
| 231 | my ($otmpl, $rtmpl, $prefix, $dirsep, $depchar, $splitchar) = @_; |
| 232 | my ($i, $x, $y); |
| 233 | my @deps, @ret; |
| 234 | @ret = (); |
| 235 | $depchar ||= ':'; |
| 236 | foreach $i (sort keys %depends) { |
| 237 | if ($i =~ /^(.*)\.(res|rsrc)/) { |
| 238 | next if !defined $rtmpl; |
| 239 | $y = $1; |
| 240 | ($x = $rtmpl) =~ s/X/$y/; |
| 241 | } else { |
| 242 | ($x = $otmpl) =~ s/X/$i/; |
| 243 | } |
| 244 | @deps = @{$depends{$i}}; |
| 245 | @deps = map { |
| 246 | $_ = &findfile($_); |
| 247 | s/\//$dirsep/g; |
| 248 | $_ = $prefix . $_; |
| 249 | } @deps; |
| 250 | push @ret, {obj => $x, deps => [@deps]}; |
| 251 | } |
| 252 | return @ret; |
| 253 | } |
| 254 | |
| 255 | sub prognames { |
| 256 | my ($types) = @_; |
| 257 | my ($n, $prog, $type); |
| 258 | my @ret; |
| 259 | @ret = (); |
| 260 | foreach $n (@prognames) { |
| 261 | ($prog, $type) = split ",", $n; |
| 262 | push @ret, $n if index($types, $type) >= 0; |
| 263 | } |
| 264 | return @ret; |
| 265 | } |
| 266 | |
| 267 | sub progrealnames { |
| 268 | my ($types) = @_; |
| 269 | my ($n, $prog, $type); |
| 270 | my @ret; |
| 271 | @ret = (); |
| 272 | foreach $n (@prognames) { |
| 273 | ($prog, $type) = split ",", $n; |
| 274 | push @ret, $prog if index($types, $type) >= 0; |
| 275 | } |
| 276 | return @ret; |
| 277 | } |
| 278 | |
| 279 | sub manpages { |
| 280 | my ($types,$suffix) = @_; |
| 281 | |
| 282 | # assume that all UNIX programs have a man page |
| 283 | if($suffix eq "1" && $types =~ /X/) { |
| 284 | return map("$_.1", &progrealnames($types)); |
| 285 | } |
| 286 | return (); |
| 287 | } |
| 288 | |
| 289 | # Now we're ready to output the actual Makefiles. |
| 290 | |
| 291 | ##-- CygWin makefile |
| 292 | open OUT, ">Makefile.cyg"; select OUT; |
| 293 | print |
| 294 | "# Makefile for PuTTY under cygwin.\n". |
| 295 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
| 296 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
| 297 | # gcc command line option is -D not /D |
| 298 | ($_ = $help) =~ s/=\/D/=-D/gs; |
| 299 | print $_; |
| 300 | print |
| 301 | "\n". |
| 302 | "# You can define this path to point at your tools if you need to\n". |
| 303 | "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n". |
| 304 | "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n". |
| 305 | "CC = \$(TOOLPATH)gcc\n". |
| 306 | "RC = \$(TOOLPATH)windres\n". |
| 307 | "# Uncomment the following two lines to compile under Winelib\n". |
| 308 | "# CC = winegcc\n". |
| 309 | "# RC = wrc\n". |
| 310 | "# You may also need to tell windres where to find include files:\n". |
| 311 | "# RCINC = --include-dir c:\\cygwin\\include\\\n". |
| 312 | "\n". |
| 313 | &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT". |
| 314 | " -DNO_SECURITY -D_NO_OLDNAMES -DNO_MULTIMON -I.")."\n". |
| 315 | "LDFLAGS = -mno-cygwin -s\n". |
| 316 | &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1". |
| 317 | " --define WINVER=0x0400 --define MINGW32_FIX=1")."\n". |
| 318 | "\n". |
| 319 | ".SUFFIXES:\n". |
| 320 | "\n". |
| 321 | "%.o: %.c\n". |
| 322 | "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n". |
| 323 | "\n". |
| 324 | "%.res.o: %.rc\n". |
| 325 | "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n". |
| 326 | "\n"; |
| 327 | print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC")); |
| 328 | print "\n\n"; |
| 329 | foreach $p (&prognames("GC")) { |
| 330 | ($prog, $type) = split ",", $p; |
| 331 | $objstr = &objects($p, "X.o", "X.res.o", undef); |
| 332 | print &splitline($prog . ".exe: " . $objstr), "\n"; |
| 333 | my $mw = $type eq "G" ? " -mwindows" : ""; |
| 334 | $libstr = &objects($p, undef, undef, "-lX"); |
| 335 | print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " . |
| 336 | $objstr . " $libstr", 69), "\n\n"; |
| 337 | } |
| 338 | foreach $d (&deps("X.o", "X.res.o", "", "/")) { |
| 339 | print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), |
| 340 | "\n"; |
| 341 | } |
| 342 | print |
| 343 | "\n". |
| 344 | "version.o: FORCE;\n". |
| 345 | "# Hack to force version.o to be rebuilt always\n". |
| 346 | "FORCE:\n". |
| 347 | "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) \$(VER) -c version.c\n". |
| 348 | "clean:\n". |
| 349 | "\trm -f *.o *.exe *.res.o\n". |
| 350 | "\n"; |
| 351 | select STDOUT; close OUT; |
| 352 | |
| 353 | ##-- Borland makefile |
| 354 | %stdlibs = ( # Borland provides many Win32 API libraries intrinsically |
| 355 | "advapi32" => 1, |
| 356 | "comctl32" => 1, |
| 357 | "comdlg32" => 1, |
| 358 | "gdi32" => 1, |
| 359 | "imm32" => 1, |
| 360 | "shell32" => 1, |
| 361 | "user32" => 1, |
| 362 | "winmm" => 1, |
| 363 | "winspool" => 1, |
| 364 | "wsock32" => 1, |
| 365 | ); |
| 366 | open OUT, ">Makefile.bor"; select OUT; |
| 367 | print |
| 368 | "# Makefile for PuTTY under Borland C.\n". |
| 369 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
| 370 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
| 371 | # bcc32 command line option is -D not /D |
| 372 | ($_ = $help) =~ s/=\/D/=-D/gs; |
| 373 | print $_; |
| 374 | print |
| 375 | "\n". |
| 376 | "# If you rename this file to `Makefile', you should change this line,\n". |
| 377 | "# so that the .rsp files still depend on the correct makefile.\n". |
| 378 | "MAKEFILE = Makefile.bor\n". |
| 379 | "\n". |
| 380 | "# C compilation flags\n". |
| 381 | "CFLAGS = -D_WINDOWS -DWINVER=0x0401\n". |
| 382 | "\n". |
| 383 | "# Get include directory for resource compiler\n". |
| 384 | "!if !\$d(BCB)\n". |
| 385 | "BCB = \$(MAKEDIR)\\..\n". |
| 386 | "!endif\n". |
| 387 | "\n". |
| 388 | ".c.obj:\n". |
| 389 | &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT) \$(FWHACK)". |
| 390 | " \$(XFLAGS) \$(CFLAGS) /c \$*.c",69)."\n". |
| 391 | ".rc.res:\n". |
| 392 | &splitline("\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include -r". |
| 393 | " -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n". |
| 394 | "\n"; |
| 395 | print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC")); |
| 396 | print "\n\n"; |
| 397 | foreach $p (&prognames("GC")) { |
| 398 | ($prog, $type) = split ",", $p; |
| 399 | $objstr = &objects($p, "X.obj", "X.res", undef); |
| 400 | print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n"; |
| 401 | my $ap = ($type eq "G") ? "-aa" : "-ap"; |
| 402 | print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n"; |
| 403 | } |
| 404 | foreach $p (&prognames("GC")) { |
| 405 | ($prog, $type) = split ",", $p; |
| 406 | print $prog, ".rsp: \$(MAKEFILE)\n"; |
| 407 | $objstr = &objects($p, "X.obj", undef, undef); |
| 408 | @objlist = split " ", $objstr; |
| 409 | @objlines = (""); |
| 410 | foreach $i (@objlist) { |
| 411 | if (length($objlines[$#objlines] . " $i") > 50) { |
| 412 | push @objlines, ""; |
| 413 | } |
| 414 | $objlines[$#objlines] .= " $i"; |
| 415 | } |
| 416 | $c0w = ($type eq "G") ? "c0w32" : "c0x32"; |
| 417 | print "\techo $c0w + > $prog.rsp\n"; |
| 418 | for ($i=0; $i<=$#objlines; $i++) { |
| 419 | $plus = ($i < $#objlines ? " +" : ""); |
| 420 | print "\techo$objlines[$i]$plus >> $prog.rsp\n"; |
| 421 | } |
| 422 | print "\techo $prog.exe >> $prog.rsp\n"; |
| 423 | $objstr = &objects($p, "X.obj", "X.res", undef); |
| 424 | @libs = split " ", &objects($p, undef, undef, "X"); |
| 425 | @libs = grep { !$stdlibs{$_} } @libs; |
| 426 | unshift @libs, "cw32", "import32"; |
| 427 | $libstr = join ' ', @libs; |
| 428 | print "\techo nul,$libstr, >> $prog.rsp\n"; |
| 429 | print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n"; |
| 430 | print "\n"; |
| 431 | } |
| 432 | foreach $d (&deps("X.obj", "X.res", "", "\\")) { |
| 433 | print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), |
| 434 | "\n"; |
| 435 | } |
| 436 | print |
| 437 | "\n". |
| 438 | "version.o: FORCE\n". |
| 439 | "# Hack to force version.o to be rebuilt always\n". |
| 440 | "FORCE:\n". |
| 441 | "\tbcc32 \$(FWHACK) \$(VER) \$(CFLAGS) /c version.c\n\n". |
| 442 | "clean:\n". |
| 443 | "\t-del *.obj\n". |
| 444 | "\t-del *.exe\n". |
| 445 | "\t-del *.res\n". |
| 446 | "\t-del *.pch\n". |
| 447 | "\t-del *.aps\n". |
| 448 | "\t-del *.il*\n". |
| 449 | "\t-del *.pdb\n". |
| 450 | "\t-del *.rsp\n". |
| 451 | "\t-del *.tds\n". |
| 452 | "\t-del *.\$\$\$\$\$\$\n"; |
| 453 | select STDOUT; close OUT; |
| 454 | |
| 455 | ##-- Visual C++ makefile |
| 456 | open OUT, ">Makefile.vc"; select OUT; |
| 457 | print |
| 458 | "# Makefile for PuTTY under Visual C.\n". |
| 459 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
| 460 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
| 461 | print $help; |
| 462 | print |
| 463 | "\n". |
| 464 | "# If you rename this file to `Makefile', you should change this line,\n". |
| 465 | "# so that the .rsp files still depend on the correct makefile.\n". |
| 466 | "MAKEFILE = Makefile.vc\n". |
| 467 | "\n". |
| 468 | "# C compilation flags\n". |
| 469 | "CFLAGS = /nologo /W3 /O1 /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401\n". |
| 470 | "LFLAGS = /incremental:no /fixed\n". |
| 471 | "\n". |
| 472 | ".c.obj:\n". |
| 473 | "\tcl \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) /c \$*.c\n". |
| 474 | ".rc.res:\n". |
| 475 | "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 -DWINVER=0x0400 \$*.rc\n". |
| 476 | "\n"; |
| 477 | print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC")); |
| 478 | print "\n\n"; |
| 479 | foreach $p (&prognames("GC")) { |
| 480 | ($prog, $type) = split ",", $p; |
| 481 | $objstr = &objects($p, "X.obj", "X.res", undef); |
| 482 | print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n"; |
| 483 | print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n"; |
| 484 | } |
| 485 | foreach $p (&prognames("GC")) { |
| 486 | ($prog, $type) = split ",", $p; |
| 487 | print $prog, ".rsp: \$(MAKEFILE)\n"; |
| 488 | $objstr = &objects($p, "X.obj", "X.res", "X.lib"); |
| 489 | @objlist = split " ", $objstr; |
| 490 | @objlines = (""); |
| 491 | foreach $i (@objlist) { |
| 492 | if (length($objlines[$#objlines] . " $i") > 50) { |
| 493 | push @objlines, ""; |
| 494 | } |
| 495 | $objlines[$#objlines] .= " $i"; |
| 496 | } |
| 497 | $subsys = ($type eq "G") ? "windows" : "console"; |
| 498 | print "\techo /nologo /subsystem:$subsys > $prog.rsp\n"; |
| 499 | for ($i=0; $i<=$#objlines; $i++) { |
| 500 | print "\techo$objlines[$i] >> $prog.rsp\n"; |
| 501 | } |
| 502 | print "\n"; |
| 503 | } |
| 504 | foreach $d (&deps("X.obj", "X.res", "", "\\")) { |
| 505 | print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), |
| 506 | "\n"; |
| 507 | } |
| 508 | print |
| 509 | "\n". |
| 510 | "# Hack to force version.o to be rebuilt always\n". |
| 511 | "version.obj: *.c *.h *.rc\n". |
| 512 | "\tcl \$(FWHACK) \$(VER) \$(CFLAGS) /c version.c\n\n". |
| 513 | "clean: tidy\n". |
| 514 | "\t-del *.exe\n\n". |
| 515 | "tidy:\n". |
| 516 | "\t-del *.obj\n". |
| 517 | "\t-del *.res\n". |
| 518 | "\t-del *.pch\n". |
| 519 | "\t-del *.aps\n". |
| 520 | "\t-del *.ilk\n". |
| 521 | "\t-del *.pdb\n". |
| 522 | "\t-del *.rsp\n". |
| 523 | "\t-del *.dsp\n". |
| 524 | "\t-del *.dsw\n". |
| 525 | "\t-del *.ncb\n". |
| 526 | "\t-del *.opt\n". |
| 527 | "\t-del *.plg\n". |
| 528 | "\t-del *.map\n". |
| 529 | "\t-del *.idb\n". |
| 530 | "\t-del debug.log\n"; |
| 531 | select STDOUT; close OUT; |
| 532 | |
| 533 | ##-- X/GTK/Unix makefile |
| 534 | open OUT, ">unix/Makefile.gtk"; select OUT; |
| 535 | print |
| 536 | "# Makefile for PuTTY under X/GTK and Unix.\n". |
| 537 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
| 538 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
| 539 | # gcc command line option is -D not /D |
| 540 | ($_ = $help) =~ s/=\/D/=-D/gs; |
| 541 | print $_; |
| 542 | print |
| 543 | "\n". |
| 544 | "# You can define this path to point at your tools if you need to\n". |
| 545 | "# TOOLPATH = /opt/gcc/bin\n". |
| 546 | "CC = \$(TOOLPATH)cc\n". |
| 547 | "\n". |
| 548 | &splitline("CFLAGS = -O2 -Wall -Werror -g -I. -I.. -I../charset `gtk-config --cflags`")."\n". |
| 549 | "XLDFLAGS = `gtk-config --libs`\n". |
| 550 | "ULDFLAGS =#\n". |
| 551 | "INSTALL=install\n", |
| 552 | "INSTALL_PROGRAM=\$(INSTALL)\n", |
| 553 | "INSTALL_DATA=\$(INSTALL)\n", |
| 554 | "prefix=/usr/local\n", |
| 555 | "exec_prefix=\$(prefix)\n", |
| 556 | "bindir=\$(exec_prefix)/bin\n", |
| 557 | "mandir=\$(prefix)/man\n", |
| 558 | "man1dir=\$(mandir)/man1\n", |
| 559 | "\n". |
| 560 | ".SUFFIXES:\n". |
| 561 | "\n". |
| 562 | "%.o:\n". |
| 563 | "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n". |
| 564 | "\n"; |
| 565 | print &splitline("all:" . join "", map { " $_" } &progrealnames("XU")); |
| 566 | print "\n\n"; |
| 567 | foreach $p (&prognames("XU")) { |
| 568 | ($prog, $type) = split ",", $p; |
| 569 | $objstr = &objects($p, "X.o", undef, undef); |
| 570 | print &splitline($prog . ": " . $objstr), "\n"; |
| 571 | $libstr = &objects($p, undef, undef, "-lX"); |
| 572 | print &splitline("\t\$(CC)" . $mw . " \$(${type}LDFLAGS) -o \$@ " . |
| 573 | $objstr . " $libstr", 69), "\n\n"; |
| 574 | } |
| 575 | foreach $d (&deps("X.o", undef, "../", "/")) { |
| 576 | print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), |
| 577 | "\n"; |
| 578 | } |
| 579 | print |
| 580 | "\n". |
| 581 | "version.o: FORCE;\n". |
| 582 | "# Hack to force version.o to be rebuilt always\n". |
| 583 | "FORCE:\n". |
| 584 | "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) \$(VER) -c ../version.c\n". |
| 585 | "clean:\n". |
| 586 | "\trm -f *.o". (join "", map { " $_" } &progrealnames("XU")) . "\n". |
| 587 | "\n", |
| 588 | "install:\n", |
| 589 | map("\t\$(INSTALL_PROGRAM) -m 755 $_ \$(bindir)/$_\n", &progrealnames("XU")), |
| 590 | map("\t\$(INSTALL_DATA) -m 644 $_ \$(man1dir)/$_\n", &manpages("XU", "1")), |
| 591 | "\n", |
| 592 | "install-strip:\n", |
| 593 | "\t\$(MAKE) install INSTALL_PROGRAM=\"\$(INSTALL_PROGRAM) -s\"\n", |
| 594 | "\n"; |
| 595 | select STDOUT; close OUT; |
| 596 | |
| 597 | ##-- MPW Makefile |
| 598 | open OUT, ">mac/Makefile.mpw"; select OUT; |
| 599 | print <<END; |
| 600 | # Makefile for PuTTY under MPW. |
| 601 | # |
| 602 | # This file was created by `mkfiles.pl' from the `Recipe' file. |
| 603 | # DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead. |
| 604 | END |
| 605 | # MPW command line option is -d not /D |
| 606 | ($_ = $help) =~ s/=\/D/=-d /gs; |
| 607 | print $_; |
| 608 | print <<END; |
| 609 | |
| 610 | ROptions = `Echo "{VER}" | StreamEdit -e "1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6"' \xa81 '\xb6\xb6\xb6\xb6\xb6"'"` |
| 611 | |
| 612 | C_68K = {C} |
| 613 | C_CFM68K = {C} |
| 614 | C_PPC = {PPCC} |
| 615 | C_Carbon = {PPCC} |
| 616 | |
| 617 | # -w 35 disables "unused parameter" warnings |
| 618 | COptions = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6 |
| 619 | -notOnce |
| 620 | COptions_68K = {COptions} -model far -opt time |
| 621 | # Enabling "-opt space" for CFM-68K gives me undefined references to |
| 622 | # _\$LDIVT and _\$LMODT. |
| 623 | COptions_CFM68K = {COptions} -model cfmSeg -opt time |
| 624 | COptions_PPC = {COptions} -opt size -traceback |
| 625 | COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON |
| 626 | |
| 627 | Link_68K = ILink |
| 628 | Link_CFM68K = ILink |
| 629 | Link_PPC = PPCLink |
| 630 | Link_Carbon = PPCLink |
| 631 | |
| 632 | LinkOptions = -c 'pTTY' |
| 633 | LinkOptions_68K = {LinkOptions} -br 68k -model far -compact |
| 634 | LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact |
| 635 | LinkOptions_PPC = {LinkOptions} |
| 636 | LinkOptions_Carbon = -m __appstart -w {LinkOptions} |
| 637 | |
| 638 | Libs_68K = "{CLibraries}StdCLib.far.o" \xb6 |
| 639 | "{Libraries}MacRuntime.o" \xb6 |
| 640 | "{Libraries}MathLib.far.o" \xb6 |
| 641 | "{Libraries}IntEnv.far.o" \xb6 |
| 642 | "{Libraries}Interface.o" \xb6 |
| 643 | "{Libraries}Navigation.far.o" \xb6 |
| 644 | "{Libraries}OpenTransport.o" \xb6 |
| 645 | "{Libraries}OpenTransportApp.o" \xb6 |
| 646 | "{Libraries}OpenTptInet.o" \xb6 |
| 647 | "{Libraries}UnicodeConverterLib.far.o" |
| 648 | |
| 649 | Libs_CFM = "{SharedLibraries}InterfaceLib" \xb6 |
| 650 | "{SharedLibraries}StdCLib" \xb6 |
| 651 | "{SharedLibraries}AppearanceLib" \xb6 |
| 652 | -weaklib AppearanceLib \xb6 |
| 653 | "{SharedLibraries}NavigationLib" \xb6 |
| 654 | -weaklib NavigationLib \xb6 |
| 655 | "{SharedLibraries}TextCommon" \xb6 |
| 656 | -weaklib TextCommon \xb6 |
| 657 | "{SharedLibraries}UnicodeConverter" \xb6 |
| 658 | -weaklib UnicodeConverter |
| 659 | |
| 660 | Libs_CFM68K = {Libs_CFM} \xb6 |
| 661 | "{CFM68KLibraries}NuMacRuntime.o" |
| 662 | |
| 663 | Libs_PPC = {Libs_CFM} \xb6 |
| 664 | "{SharedLibraries}ControlsLib" \xb6 |
| 665 | -weaklib ControlsLib \xb6 |
| 666 | "{SharedLibraries}WindowsLib" \xb6 |
| 667 | -weaklib WindowsLib \xb6 |
| 668 | "{SharedLibraries}OpenTransportLib" \xb6 |
| 669 | -weaklib OTClientLib \xb6 |
| 670 | -weaklib OTClientUtilLib \xb6 |
| 671 | "{SharedLibraries}OpenTptInternetLib" \xb6 |
| 672 | -weaklib OTInetClientLib \xb6 |
| 673 | "{PPCLibraries}StdCRuntime.o" \xb6 |
| 674 | "{PPCLibraries}PPCCRuntime.o" \xb6 |
| 675 | "{PPCLibraries}CarbonAccessors.o" \xb6 |
| 676 | "{PPCLibraries}OpenTransportAppPPC.o" \xb6 |
| 677 | "{PPCLibraries}OpenTptInetPPC.o" |
| 678 | |
| 679 | Libs_Carbon = "{PPCLibraries}CarbonStdCLib.o" \xb6 |
| 680 | "{PPCLibraries}StdCRuntime.o" \xb6 |
| 681 | "{PPCLibraries}PPCCRuntime.o" \xb6 |
| 682 | "{SharedLibraries}CarbonLib" \xb6 |
| 683 | "{SharedLibraries}StdCLib" |
| 684 | |
| 685 | END |
| 686 | print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6"); |
| 687 | print "\n\n"; |
| 688 | foreach $p (&prognames("M")) { |
| 689 | ($prog, $type) = split ",", $p; |
| 690 | |
| 691 | print &splitline("$prog \xc4 $prog.68k $prog.ppc $prog.carbon", |
| 692 | undef, "\xb6"), "\n\n"; |
| 693 | |
| 694 | $rsrc = &objects($p, "", "X.rsrc", undef); |
| 695 | |
| 696 | foreach $arch (qw(68K CFM68K PPC Carbon)) { |
| 697 | $objstr = &objects($p, "X.\L$arch\E.o", "", undef); |
| 698 | print &splitline("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6"); |
| 699 | print "\n"; |
| 700 | print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n"; |
| 701 | print &splitline("\t{Link_$arch} -o {Targ} -fragname $prog " . |
| 702 | "{LinkOptions_$arch} " . |
| 703 | $objstr . " {Libs_$arch}", 69, "\xb6"), "\n"; |
| 704 | print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n"; |
| 705 | } |
| 706 | |
| 707 | } |
| 708 | foreach $d (&deps("", "X.rsrc", "::", ":")) { |
| 709 | next unless $d->{obj}; |
| 710 | print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}), |
| 711 | undef, "\xb6"), "\n"; |
| 712 | print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n"; |
| 713 | } |
| 714 | foreach $arch (qw(68K CFM68K)) { |
| 715 | foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) { |
| 716 | next unless $d->{obj}; |
| 717 | print &splitline(sprintf("%s \xc4 %s", $d->{obj}, |
| 718 | join " ", @{$d->{deps}}), |
| 719 | undef, "\xb6"), "\n"; |
| 720 | print "\t{C_$arch} ", $d->{deps}->[0], |
| 721 | " -o {Targ} {COptions_$arch}\n\n"; |
| 722 | } |
| 723 | } |
| 724 | foreach $arch (qw(PPC Carbon)) { |
| 725 | foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) { |
| 726 | next unless $d->{obj}; |
| 727 | print &splitline(sprintf("%s \xc4 %s", $d->{obj}, |
| 728 | join " ", @{$d->{deps}}), |
| 729 | undef, "\xb6"), "\n"; |
| 730 | # The odd stuff here seems to stop afpd getting confused. |
| 731 | print "\techo -n > {Targ}\n"; |
| 732 | print "\tsetfile -t XCOF {Targ}\n"; |
| 733 | print "\t{C_$arch} ", $d->{deps}->[0], |
| 734 | " -o {Targ} {COptions_$arch}\n\n"; |
| 735 | } |
| 736 | } |
| 737 | select STDOUT; close OUT; |