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