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