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