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