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