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