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