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 = ""; |
187 | $i = 0; |
188 | foreach $dir (@incdirs) { |
189 | $outdir = $dir, $i++ if -f "$dir$name"; |
190 | } |
191 | die "multiple instances of source file $name\n" if $i > 1; |
192 | return "$outdir$name"; |
193 | } |
194 | |
7603011f |
195 | sub objects { |
f7f27309 |
196 | my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_; |
7603011f |
197 | my @ret; |
198 | my ($i, $x, $y); |
199 | @ret = (); |
200 | foreach $i (@{$programs{$prog}}) { |
f7f27309 |
201 | $x = ""; |
c88dc003 |
202 | if ($i =~ /^(.*)\.(res|rsrc)/) { |
7603011f |
203 | $y = $1; |
204 | ($x = $rtmpl) =~ s/X/$y/; |
7603011f |
205 | } elsif ($i =~ /^(.*)\.lib/) { |
206 | $y = $1; |
207 | ($x = $ltmpl) =~ s/X/$y/; |
7603011f |
208 | } else { |
209 | ($x = $otmpl) =~ s/X/$i/; |
7603011f |
210 | } |
f7f27309 |
211 | push @ret, $x if $x ne ""; |
7603011f |
212 | } |
213 | return join " ", @ret; |
3d541627 |
214 | } |
215 | |
7603011f |
216 | sub splitline { |
a86a2725 |
217 | my ($line, $width, $splitchar) = @_; |
7603011f |
218 | my ($result, $len); |
219 | $len = (defined $width ? $width : 76); |
a86a2725 |
220 | $splitchar = (defined $splitchar ? $splitchar : '\\'); |
7603011f |
221 | while (length $line > $len) { |
222 | $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/; |
a86a2725 |
223 | $result .= $1 . " ${splitchar}\n\t\t"; |
7603011f |
224 | $line = $2; |
225 | $len = 60; |
226 | } |
227 | return $result . $line; |
228 | } |
229 | |
230 | sub deps { |
a86a2725 |
231 | my ($otmpl, $rtmpl, $prefix, $dirsep, $depchar, $splitchar) = @_; |
7603011f |
232 | my ($i, $x, $y); |
a86a2725 |
233 | my @deps, @ret; |
234 | @ret = (); |
235 | $depchar ||= ':'; |
7603011f |
236 | foreach $i (sort keys %depends) { |
c88dc003 |
237 | if ($i =~ /^(.*)\.(res|rsrc)/) { |
f7f27309 |
238 | next if !defined $rtmpl; |
7603011f |
239 | $y = $1; |
240 | ($x = $rtmpl) =~ s/X/$y/; |
241 | } else { |
242 | ($x = $otmpl) =~ s/X/$i/; |
243 | } |
f7f27309 |
244 | @deps = @{$depends{$i}}; |
245 | @deps = map { |
246 | $_ = &findfile($_); |
247 | s/\//$dirsep/g; |
248 | $_ = $prefix . $_; |
249 | } @deps; |
a86a2725 |
250 | push @ret, {obj => $x, deps => [@deps]}; |
7603011f |
251 | } |
a86a2725 |
252 | return @ret; |
3d541627 |
253 | } |
254 | |
f7f27309 |
255 | sub prognames { |
256 | my ($types) = @_; |
c282cde3 |
257 | my ($n, $prog, $type); |
258 | my @ret; |
259 | @ret = (); |
260 | foreach $n (@prognames) { |
261 | ($prog, $type) = split ",", $n; |
262 | push @ret, $n if index($types, $type) >= 0; |
263 | } |
264 | return @ret; |
265 | } |
266 | |
267 | sub progrealnames { |
268 | my ($types) = @_; |
269 | my ($n, $prog, $type); |
f7f27309 |
270 | my @ret; |
271 | @ret = (); |
272 | foreach $n (@prognames) { |
c282cde3 |
273 | ($prog, $type) = split ",", $n; |
274 | push @ret, $prog if index($types, $type) >= 0; |
f7f27309 |
275 | } |
276 | return @ret; |
277 | } |
278 | |
c76d309d |
279 | sub manpages { |
280 | my ($types,$suffix) = @_; |
281 | |
282 | # assume that all UNIX programs have a man page |
283 | if($suffix eq "1" && $types =~ /X/) { |
284 | return map("$_.1", &progrealnames($types)); |
285 | } |
286 | return (); |
287 | } |
288 | |
7603011f |
289 | # Now we're ready to output the actual Makefiles. |
290 | |
3d541627 |
291 | ##-- CygWin makefile |
292 | open OUT, ">Makefile.cyg"; select OUT; |
293 | print |
7603011f |
294 | "# Makefile for PuTTY under cygwin.\n". |
295 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
296 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
3d541627 |
297 | # gcc command line option is -D not /D |
7603011f |
298 | ($_ = $help) =~ s/=\/D/=-D/gs; |
3d541627 |
299 | print $_; |
300 | print |
301 | "\n". |
302 | "# You can define this path to point at your tools if you need to\n". |
303 | "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n". |
304 | "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n". |
305 | "CC = \$(TOOLPATH)gcc\n". |
306 | "RC = \$(TOOLPATH)windres\n". |
3ea61c49 |
307 | "# Uncomment the following two lines to compile under Winelib\n". |
308 | "# CC = winegcc\n". |
309 | "# RC = wrc\n". |
3d541627 |
310 | "# You may also need to tell windres where to find include files:\n". |
311 | "# RCINC = --include-dir c:\\cygwin\\include\\\n". |
312 | "\n". |
7603011f |
313 | &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT". |
12ef307d |
314 | " -D_NO_OLDNAMES -DNO_MULTIMON -I.")."\n". |
f730b86a |
315 | "LDFLAGS = -mno-cygwin -s\n". |
7603011f |
316 | &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1". |
317 | " --define WINVER=0x0400 --define MINGW32_FIX=1")."\n". |
3d541627 |
318 | "\n". |
319 | ".SUFFIXES:\n". |
320 | "\n". |
201e9294 |
321 | "%.o: %.c\n". |
cf03419b |
322 | "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n". |
3d541627 |
323 | "\n". |
f730b86a |
324 | "%.res.o: %.rc\n". |
6ed3635b |
325 | "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n". |
3d541627 |
326 | "\n"; |
c282cde3 |
327 | print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC")); |
14232990 |
328 | print "\n\n"; |
f7f27309 |
329 | foreach $p (&prognames("GC")) { |
c282cde3 |
330 | ($prog, $type) = split ",", $p; |
7603011f |
331 | $objstr = &objects($p, "X.o", "X.res.o", undef); |
c282cde3 |
332 | print &splitline($prog . ".exe: " . $objstr), "\n"; |
333 | my $mw = $type eq "G" ? " -mwindows" : ""; |
7603011f |
334 | $libstr = &objects($p, undef, undef, "-lX"); |
335 | print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " . |
336 | $objstr . " $libstr", 69), "\n\n"; |
3d541627 |
337 | } |
a86a2725 |
338 | foreach $d (&deps("X.o", "X.res.o", "", "/")) { |
339 | print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), |
340 | "\n"; |
341 | } |
3d541627 |
342 | print |
343 | "\n". |
74091dff |
344 | "version.o: FORCE;\n". |
3d541627 |
345 | "# Hack to force version.o to be rebuilt always\n". |
346 | "FORCE:\n". |
7603011f |
347 | "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) \$(VER) -c version.c\n". |
3d541627 |
348 | "clean:\n". |
7603011f |
349 | "\trm -f *.o *.exe *.res.o\n". |
3d541627 |
350 | "\n"; |
351 | select STDOUT; close OUT; |
352 | |
353 | ##-- Borland makefile |
7603011f |
354 | %stdlibs = ( # Borland provides many Win32 API libraries intrinsically |
355 | "advapi32" => 1, |
356 | "comctl32" => 1, |
357 | "comdlg32" => 1, |
358 | "gdi32" => 1, |
359 | "imm32" => 1, |
360 | "shell32" => 1, |
361 | "user32" => 1, |
362 | "winmm" => 1, |
363 | "winspool" => 1, |
364 | "wsock32" => 1, |
365 | ); |
3d541627 |
366 | open OUT, ">Makefile.bor"; select OUT; |
367 | print |
7603011f |
368 | "# Makefile for PuTTY under Borland C.\n". |
369 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
370 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
3d541627 |
371 | # bcc32 command line option is -D not /D |
7603011f |
372 | ($_ = $help) =~ s/=\/D/=-D/gs; |
3d541627 |
373 | print $_; |
374 | print |
375 | "\n". |
376 | "# If you rename this file to `Makefile', you should change this line,\n". |
377 | "# so that the .rsp files still depend on the correct makefile.\n". |
378 | "MAKEFILE = Makefile.bor\n". |
379 | "\n". |
a401e5f3 |
380 | "# C compilation flags\n". |
95912ebc |
381 | "CFLAGS = -D_WINDOWS -DWINVER=0x0401\n". |
a401e5f3 |
382 | "\n". |
3d541627 |
383 | "# Get include directory for resource compiler\n". |
384 | "!if !\$d(BCB)\n". |
385 | "BCB = \$(MAKEDIR)\\..\n". |
386 | "!endif\n". |
387 | "\n". |
388 | ".c.obj:\n". |
8aa5bfd9 |
389 | &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT) \$(FWHACK)". |
7603011f |
390 | " \$(XFLAGS) \$(CFLAGS) /c \$*.c",69)."\n". |
3d541627 |
391 | ".rc.res:\n". |
7603011f |
392 | &splitline("\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include -r". |
393 | " -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n". |
3d541627 |
394 | "\n"; |
c282cde3 |
395 | print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC")); |
3d541627 |
396 | print "\n\n"; |
f7f27309 |
397 | foreach $p (&prognames("GC")) { |
c282cde3 |
398 | ($prog, $type) = split ",", $p; |
7603011f |
399 | $objstr = &objects($p, "X.obj", "X.res", undef); |
c282cde3 |
400 | print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n"; |
401 | my $ap = ($type eq "G") ? "-aa" : "-ap"; |
402 | print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n"; |
3d541627 |
403 | } |
f7f27309 |
404 | foreach $p (&prognames("GC")) { |
c282cde3 |
405 | ($prog, $type) = split ",", $p; |
406 | print $prog, ".rsp: \$(MAKEFILE)\n"; |
7603011f |
407 | $objstr = &objects($p, "X.obj", undef, undef); |
408 | @objlist = split " ", $objstr; |
409 | @objlines = (""); |
410 | foreach $i (@objlist) { |
411 | if (length($objlines[$#objlines] . " $i") > 50) { |
412 | push @objlines, ""; |
413 | } |
414 | $objlines[$#objlines] .= " $i"; |
415 | } |
c282cde3 |
416 | $c0w = ($type eq "G") ? "c0w32" : "c0x32"; |
417 | print "\techo $c0w + > $prog.rsp\n"; |
a7088bde |
418 | for ($i=0; $i<=$#objlines; $i++) { |
419 | $plus = ($i < $#objlines ? " +" : ""); |
c282cde3 |
420 | print "\techo$objlines[$i]$plus >> $prog.rsp\n"; |
3d541627 |
421 | } |
c282cde3 |
422 | print "\techo $prog.exe >> $prog.rsp\n"; |
7603011f |
423 | $objstr = &objects($p, "X.obj", "X.res", undef); |
424 | @libs = split " ", &objects($p, undef, undef, "X"); |
425 | @libs = grep { !$stdlibs{$_} } @libs; |
6d2d5e8d |
426 | unshift @libs, "cw32", "import32"; |
427 | $libstr = join ' ', @libs; |
c282cde3 |
428 | print "\techo nul,$libstr, >> $prog.rsp\n"; |
429 | print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n"; |
3d541627 |
430 | print "\n"; |
431 | } |
a86a2725 |
432 | foreach $d (&deps("X.obj", "X.res", "", "\\")) { |
433 | print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), |
434 | "\n"; |
435 | } |
3d541627 |
436 | print |
437 | "\n". |
438 | "version.o: FORCE\n". |
439 | "# Hack to force version.o to be rebuilt always\n". |
440 | "FORCE:\n". |
441 | "\tbcc32 \$(FWHACK) \$(VER) \$(CFLAGS) /c version.c\n\n". |
442 | "clean:\n". |
2e792012 |
443 | "\t-del *.obj\n". |
444 | "\t-del *.exe\n". |
445 | "\t-del *.res\n". |
446 | "\t-del *.pch\n". |
447 | "\t-del *.aps\n". |
448 | "\t-del *.il*\n". |
449 | "\t-del *.pdb\n". |
450 | "\t-del *.rsp\n". |
451 | "\t-del *.tds\n". |
452 | "\t-del *.\$\$\$\$\$\$\n"; |
3d541627 |
453 | select STDOUT; close OUT; |
7603011f |
454 | |
455 | ##-- Visual C++ makefile |
456 | open OUT, ">Makefile.vc"; select OUT; |
457 | print |
458 | "# Makefile for PuTTY under Visual C.\n". |
459 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
460 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
461 | print $help; |
462 | print |
463 | "\n". |
464 | "# If you rename this file to `Makefile', you should change this line,\n". |
465 | "# so that the .rsp files still depend on the correct makefile.\n". |
466 | "MAKEFILE = Makefile.vc\n". |
467 | "\n". |
468 | "# C compilation flags\n". |
469 | "CFLAGS = /nologo /W3 /O1 /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401\n". |
470 | "LFLAGS = /incremental:no /fixed\n". |
471 | "\n". |
472 | ".c.obj:\n". |
473 | "\tcl \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) /c \$*.c\n". |
474 | ".rc.res:\n". |
475 | "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 -DWINVER=0x0400 \$*.rc\n". |
476 | "\n"; |
c282cde3 |
477 | print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC")); |
7603011f |
478 | print "\n\n"; |
f7f27309 |
479 | foreach $p (&prognames("GC")) { |
c282cde3 |
480 | ($prog, $type) = split ",", $p; |
7603011f |
481 | $objstr = &objects($p, "X.obj", "X.res", undef); |
c282cde3 |
482 | print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n"; |
483 | print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n"; |
7603011f |
484 | } |
f7f27309 |
485 | foreach $p (&prognames("GC")) { |
c282cde3 |
486 | ($prog, $type) = split ",", $p; |
487 | print $prog, ".rsp: \$(MAKEFILE)\n"; |
7603011f |
488 | $objstr = &objects($p, "X.obj", "X.res", "X.lib"); |
489 | @objlist = split " ", $objstr; |
490 | @objlines = (""); |
491 | foreach $i (@objlist) { |
492 | if (length($objlines[$#objlines] . " $i") > 50) { |
493 | push @objlines, ""; |
494 | } |
495 | $objlines[$#objlines] .= " $i"; |
496 | } |
c282cde3 |
497 | $subsys = ($type eq "G") ? "windows" : "console"; |
498 | print "\techo /nologo /subsystem:$subsys > $prog.rsp\n"; |
7603011f |
499 | for ($i=0; $i<=$#objlines; $i++) { |
c282cde3 |
500 | print "\techo$objlines[$i] >> $prog.rsp\n"; |
7603011f |
501 | } |
502 | print "\n"; |
503 | } |
a86a2725 |
504 | foreach $d (&deps("X.obj", "X.res", "", "\\")) { |
505 | print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), |
506 | "\n"; |
507 | } |
7603011f |
508 | print |
509 | "\n". |
510 | "# Hack to force version.o to be rebuilt always\n". |
511 | "version.obj: *.c *.h *.rc\n". |
512 | "\tcl \$(FWHACK) \$(VER) \$(CFLAGS) /c version.c\n\n". |
513 | "clean: tidy\n". |
514 | "\t-del *.exe\n\n". |
515 | "tidy:\n". |
516 | "\t-del *.obj\n". |
517 | "\t-del *.res\n". |
518 | "\t-del *.pch\n". |
519 | "\t-del *.aps\n". |
520 | "\t-del *.ilk\n". |
521 | "\t-del *.pdb\n". |
522 | "\t-del *.rsp\n". |
523 | "\t-del *.dsp\n". |
524 | "\t-del *.dsw\n". |
525 | "\t-del *.ncb\n". |
526 | "\t-del *.opt\n". |
527 | "\t-del *.plg\n". |
528 | "\t-del *.map\n". |
529 | "\t-del *.idb\n". |
530 | "\t-del debug.log\n"; |
531 | select STDOUT; close OUT; |
f7f27309 |
532 | |
533 | ##-- X/GTK/Unix makefile |
534 | open OUT, ">unix/Makefile.gtk"; select OUT; |
535 | print |
536 | "# Makefile for PuTTY under X/GTK and Unix.\n". |
537 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
538 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
539 | # gcc command line option is -D not /D |
540 | ($_ = $help) =~ s/=\/D/=-D/gs; |
541 | print $_; |
542 | print |
543 | "\n". |
544 | "# You can define this path to point at your tools if you need to\n". |
545 | "# TOOLPATH = /opt/gcc/bin\n". |
546 | "CC = \$(TOOLPATH)cc\n". |
547 | "\n". |
7ffdbc1a |
548 | &splitline("CFLAGS = -O2 -Wall -Werror -g -I. -I.. -I../charset `gtk-config --cflags`")."\n". |
32bb2723 |
549 | "XLDFLAGS = `gtk-config --libs`\n". |
550 | "ULDFLAGS =#\n". |
c76d309d |
551 | "INSTALL=install\n", |
552 | "INSTALL_PROGRAM=\$(INSTALL)\n", |
553 | "INSTALL_DATA=\$(INSTALL)\n", |
554 | "prefix=/usr/local\n", |
555 | "exec_prefix=\$(prefix)\n", |
556 | "bindir=\$(exec_prefix)/bin\n", |
557 | "mandir=\$(prefix)/man\n", |
558 | "man1dir=\$(mandir)/man1\n", |
f7f27309 |
559 | "\n". |
560 | ".SUFFIXES:\n". |
561 | "\n". |
1709795f |
562 | "%.o:\n". |
f7f27309 |
563 | "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n". |
564 | "\n"; |
32bb2723 |
565 | print &splitline("all:" . join "", map { " $_" } &progrealnames("XU")); |
f7f27309 |
566 | print "\n\n"; |
32bb2723 |
567 | foreach $p (&prognames("XU")) { |
c282cde3 |
568 | ($prog, $type) = split ",", $p; |
f7f27309 |
569 | $objstr = &objects($p, "X.o", undef, undef); |
c282cde3 |
570 | print &splitline($prog . ": " . $objstr), "\n"; |
f7f27309 |
571 | $libstr = &objects($p, undef, undef, "-lX"); |
32bb2723 |
572 | print &splitline("\t\$(CC)" . $mw . " \$(${type}LDFLAGS) -o \$@ " . |
f7f27309 |
573 | $objstr . " $libstr", 69), "\n\n"; |
574 | } |
a86a2725 |
575 | foreach $d (&deps("X.o", undef, "../", "/")) { |
576 | print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), |
577 | "\n"; |
578 | } |
f7f27309 |
579 | print |
580 | "\n". |
581 | "version.o: FORCE;\n". |
582 | "# Hack to force version.o to be rebuilt always\n". |
583 | "FORCE:\n". |
c282cde3 |
584 | "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) \$(VER) -c ../version.c\n". |
f7f27309 |
585 | "clean:\n". |
32bb2723 |
586 | "\trm -f *.o". (join "", map { " $_" } &progrealnames("XU")) . "\n". |
c76d309d |
587 | "\n", |
588 | "install:\n", |
7eea9cf8 |
589 | map("\t\$(INSTALL_PROGRAM) -m 755 $_ \$(DESTDIR)\$(bindir)/$_\n", &progrealnames("XU")), |
590 | map("\t\$(INSTALL_DATA) -m 644 $_ \$(DESTDIR)\$(man1dir)/$_\n", &manpages("XU", "1")), |
c76d309d |
591 | "\n", |
592 | "install-strip:\n", |
593 | "\t\$(MAKE) install INSTALL_PROGRAM=\"\$(INSTALL_PROGRAM) -s\"\n", |
f7f27309 |
594 | "\n"; |
595 | select STDOUT; close OUT; |
a86a2725 |
596 | |
597 | ##-- MPW Makefile |
598 | open OUT, ">mac/Makefile.mpw"; select OUT; |
599 | print <<END; |
600 | # Makefile for PuTTY under MPW. |
601 | # |
602 | # This file was created by `mkfiles.pl' from the `Recipe' file. |
603 | # DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead. |
604 | END |
605 | # MPW command line option is -d not /D |
606 | ($_ = $help) =~ s/=\/D/=-d /gs; |
607 | print $_; |
608 | print <<END; |
609 | |
2afa5f5d |
610 | ROptions = `Echo "{VER}" | StreamEdit -e "1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6"' \xa81 '\xb6\xb6\xb6\xb6\xb6"'"` |
611 | |
b941ca10 |
612 | C_68K = {C} |
613 | C_CFM68K = {C} |
614 | C_PPC = {PPCC} |
615 | C_Carbon = {PPCC} |
616 | |
f8422c0b |
617 | # -w 35 disables "unused parameter" warnings |
1ad5fcb0 |
618 | COptions = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6 |
619 | -notOnce |
084f31bc |
620 | COptions_68K = {COptions} -model far -opt time |
c1324500 |
621 | # Enabling "-opt space" for CFM-68K gives me undefined references to |
b941ca10 |
622 | # _\$LDIVT and _\$LMODT. |
c1324500 |
623 | COptions_CFM68K = {COptions} -model cfmSeg -opt time |
7bc30e49 |
624 | COptions_PPC = {COptions} -opt size -traceback |
625 | COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON |
f8422c0b |
626 | |
b941ca10 |
627 | Link_68K = ILink |
628 | Link_CFM68K = ILink |
629 | Link_PPC = PPCLink |
630 | Link_Carbon = PPCLink |
631 | |
904713b3 |
632 | LinkOptions = -c 'pTTY' |
f8422c0b |
633 | LinkOptions_68K = {LinkOptions} -br 68k -model far -compact |
c1324500 |
634 | LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact |
f8422c0b |
635 | LinkOptions_PPC = {LinkOptions} |
9098d00a |
636 | LinkOptions_Carbon = -m __appstart -w {LinkOptions} |
a86a2725 |
637 | |
728c2c88 |
638 | Libs_68K = "{CLibraries}StdCLib.far.o" \xb6 |
a86a2725 |
639 | "{Libraries}MacRuntime.o" \xb6 |
640 | "{Libraries}MathLib.far.o" \xb6 |
728c2c88 |
641 | "{Libraries}IntEnv.far.o" \xb6 |
a86a2725 |
642 | "{Libraries}Interface.o" \xb6 |
9ef3c1ca |
643 | "{Libraries}Navigation.far.o" \xb6 |
27a3458f |
644 | "{Libraries}OpenTransport.o" \xb6 |
645 | "{Libraries}OpenTransportApp.o" \xb6 |
646 | "{Libraries}OpenTptInet.o" \xb6 |
8768ce31 |
647 | "{Libraries}UnicodeConverterLib.far.o" |
a86a2725 |
648 | |
f8422c0b |
649 | Libs_CFM = "{SharedLibraries}InterfaceLib" \xb6 |
a86a2725 |
650 | "{SharedLibraries}StdCLib" \xb6 |
a86a2725 |
651 | "{SharedLibraries}AppearanceLib" \xb6 |
652 | -weaklib AppearanceLib \xb6 |
9ef3c1ca |
653 | "{SharedLibraries}NavigationLib" \xb6 |
654 | -weaklib NavigationLib \xb6 |
f8422c0b |
655 | "{SharedLibraries}TextCommon" \xb6 |
656 | -weaklib TextCommon \xb6 |
657 | "{SharedLibraries}UnicodeConverter" \xb6 |
658 | -weaklib UnicodeConverter |
659 | |
c1324500 |
660 | Libs_CFM68K = {Libs_CFM} \xb6 |
eb6d356b |
661 | "{CFM68KLibraries}NuMacRuntime.o" |
c1324500 |
662 | |
f8422c0b |
663 | Libs_PPC = {Libs_CFM} \xb6 |
1fc898ea |
664 | "{SharedLibraries}ControlsLib" \xb6 |
665 | -weaklib ControlsLib \xb6 |
666 | "{SharedLibraries}WindowsLib" \xb6 |
667 | -weaklib WindowsLib \xb6 |
27a3458f |
668 | "{SharedLibraries}OpenTransportLib" \xb6 |
669 | -weaklib OTClientLib \xb6 |
670 | -weaklib OTClientUtilLib \xb6 |
27a3458f |
671 | "{SharedLibraries}OpenTptInternetLib" \xb6 |
672 | -weaklib OTInetClientLib \xb6 |
a86a2725 |
673 | "{PPCLibraries}StdCRuntime.o" \xb6 |
674 | "{PPCLibraries}PPCCRuntime.o" \xb6 |
27a3458f |
675 | "{PPCLibraries}CarbonAccessors.o" \xb6 |
676 | "{PPCLibraries}OpenTransportAppPPC.o" \xb6 |
677 | "{PPCLibraries}OpenTptInetPPC.o" |
a86a2725 |
678 | |
9098d00a |
679 | Libs_Carbon = "{PPCLibraries}CarbonStdCLib.o" \xb6 |
680 | "{PPCLibraries}StdCRuntime.o" \xb6 |
681 | "{PPCLibraries}PPCCRuntime.o" \xb6 |
682 | "{SharedLibraries}CarbonLib" \xb6 |
683 | "{SharedLibraries}StdCLib" |
d37a507a |
684 | |
a86a2725 |
685 | END |
686 | print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6"); |
687 | print "\n\n"; |
688 | foreach $p (&prognames("M")) { |
689 | ($prog, $type) = split ",", $p; |
f8422c0b |
690 | |
b7bd2131 |
691 | print &splitline("$prog \xc4 $prog.68k $prog.ppc $prog.carbon", |
c1324500 |
692 | undef, "\xb6"), "\n\n"; |
f8422c0b |
693 | |
c88dc003 |
694 | $rsrc = &objects($p, "", "X.rsrc", undef); |
695 | |
fa8ebf26 |
696 | foreach $arch (qw(68K CFM68K PPC Carbon)) { |
b941ca10 |
697 | $objstr = &objects($p, "X.\L$arch\E.o", "", undef); |
698 | print &splitline("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6"); |
699 | print "\n"; |
700 | print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n"; |
904713b3 |
701 | print &splitline("\t{Link_$arch} -o {Targ} -fragname $prog " . |
702 | "{LinkOptions_$arch} " . |
b941ca10 |
703 | $objstr . " {Libs_$arch}", 69, "\xb6"), "\n"; |
704 | print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n"; |
705 | } |
706 | |
a86a2725 |
707 | } |
c88dc003 |
708 | foreach $d (&deps("", "X.rsrc", "::", ":")) { |
709 | next unless $d->{obj}; |
710 | print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}), |
711 | undef, "\xb6"), "\n"; |
712 | print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n"; |
a86a2725 |
713 | } |
fa8ebf26 |
714 | foreach $arch (qw(68K CFM68K)) { |
b941ca10 |
715 | foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) { |
716 | next unless $d->{obj}; |
717 | print &splitline(sprintf("%s \xc4 %s", $d->{obj}, |
718 | join " ", @{$d->{deps}}), |
719 | undef, "\xb6"), "\n"; |
720 | print "\t{C_$arch} ", $d->{deps}->[0], |
721 | " -o {Targ} {COptions_$arch}\n\n"; |
722 | } |
a86a2725 |
723 | } |
fa8ebf26 |
724 | foreach $arch (qw(PPC Carbon)) { |
b941ca10 |
725 | foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) { |
726 | next unless $d->{obj}; |
727 | print &splitline(sprintf("%s \xc4 %s", $d->{obj}, |
728 | join " ", @{$d->{deps}}), |
729 | undef, "\xb6"), "\n"; |
730 | # The odd stuff here seems to stop afpd getting confused. |
731 | print "\techo -n > {Targ}\n"; |
732 | print "\tsetfile -t XCOF {Targ}\n"; |
733 | print "\t{C_$arch} ", $d->{deps}->[0], |
734 | " -o {Targ} {COptions_$arch}\n\n"; |
735 | } |
d37a507a |
736 | } |
a86a2725 |
737 | select STDOUT; close OUT; |