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