52a1ed22 |
1 | #!/usr/bin/env perl |
3d541627 |
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. |
976374cd |
15 | # |
16 | # FIXME: no attempt made to handle !forceobj in the project files. |
cdd310bb |
17 | |
52a1ed22 |
18 | use warnings; |
f7f27309 |
19 | use FileHandle; |
bc7af299 |
20 | use File::Basename; |
e35fb54b |
21 | use Cwd; |
f7f27309 |
22 | |
bc7af299 |
23 | if ($#ARGV >= 0 and $ARGV[0] eq "-u") { |
24 | # Convenience for Unix users: -u means that after we finish what |
25 | # we're doing here, we also run mkauto.sh and then 'configure' in |
26 | # the Unix subdirectory. So it's a one-stop shop for regenerating |
27 | # the actual end-product Unix makefile. |
28 | # |
29 | # Arguments supplied after -u go to configure. |
30 | shift @ARGV; |
31 | @confargs = @ARGV; |
32 | $do_unix = 1; |
33 | } |
34 | |
e3109730 |
35 | open IN, "Recipe" or do { |
36 | # We want to deal correctly with being run from one of the |
37 | # subdirs in the source tree. So if we can't find Recipe here, |
38 | # try one level up. |
39 | chdir ".."; |
40 | open IN, "Recipe" or die "unable to open Recipe file\n"; |
41 | }; |
7603011f |
42 | |
2dc6356a |
43 | # HACK: One of the source files in `charset' is auto-generated by |
44 | # sbcsgen.pl. We need to generate that _now_, before attempting |
45 | # dependency analysis. |
46 | eval 'chdir "charset"; require "sbcsgen.pl"; chdir ".."'; |
47 | |
cdd310bb |
48 | @srcdirs = ("./"); |
f7f27309 |
49 | |
e35fb54b |
50 | $divert = undef; # ref to scalar in which text is currently being put |
7603011f |
51 | $help = ""; # list of newline-free lines of help text |
e35fb54b |
52 | $project_name = "project"; # this is a good enough default |
53 | %makefiles = (); # maps makefile types to output makefile pathnames |
54 | %makefile_extra = (); # maps makefile types to extra Makefile text |
c282cde3 |
55 | %programs = (); # maps prog name + type letter to listref of objects/resources |
7603011f |
56 | %groups = (); # maps group name to listref of objects/resources |
3d541627 |
57 | |
3d541627 |
58 | while (<IN>) { |
59 | chomp; |
4877ec8d |
60 | @_ = split; |
61 | |
62 | # If we're gathering help text, keep doing so. |
63 | if (defined $divert) { |
64 | if ((defined $_[0]) && $_[0] eq "!end") { |
65 | $divert = undef; |
66 | } else { |
67 | ${$divert} .= "$_\n"; |
68 | } |
69 | next; |
70 | } |
71 | # Skip comments and blank lines. |
72 | next if /^\s*#/ or scalar @_ == 0; |
73 | |
e35fb54b |
74 | if ($_[0] eq "!begin" and $_[1] eq "help") { $divert = \$help; next; } |
75 | if ($_[0] eq "!end") { $divert = undef; next; } |
76 | if ($_[0] eq "!name") { $project_name = $_[1]; next; } |
cdd310bb |
77 | if ($_[0] eq "!srcdir") { push @srcdirs, $_[1]; next; } |
e35fb54b |
78 | if ($_[0] eq "!makefile" and &mfval($_[1])) { $makefiles{$_[1]}=$_[2]; next;} |
6da41155 |
79 | if ($_[0] eq "!specialobj" and &mfval($_[1])) { $specialobj{$_[1]}->{$_[2]} = 1; next;} |
44747c53 |
80 | if ($_[0] eq "!cflags" and &mfval($_[1])) { |
81 | ($rest = $_) =~ s/^\s*\S+\s+\S+\s+\S+\s*//; # find rest of input line |
82 | $rest = 1 if $rest eq ""; |
83 | $cflags{$_[1]}->{$_[2]} = $rest; |
84 | next; |
85 | } |
976374cd |
86 | if ($_[0] eq "!forceobj") { $forceobj{$_[1]} = 1; next; } |
e35fb54b |
87 | if ($_[0] eq "!begin") { |
88 | if (&mfval($_[1])) { |
77603464 |
89 | $sect = $_[2] ? $_[2] : "end"; |
90 | $divert = \($makefile_extra{$_[1]}->{$sect}); |
e35fb54b |
91 | } else { |
4877ec8d |
92 | $dummy = ''; |
e35fb54b |
93 | $divert = \$dummy; |
94 | } |
95 | next; |
96 | } |
77603464 |
97 | # If we're gathering help/verbatim text, keep doing so. |
e35fb54b |
98 | if (defined $divert) { ${$divert} .= "$_\n"; next; } |
7603011f |
99 | # Ignore blank lines. |
100 | next if scalar @_ == 0; |
101 | |
102 | # Now we have an ordinary line. See if it's an = line, a : line |
103 | # or a + line. |
104 | @objs = @_; |
105 | |
106 | if ($_[0] eq "+") { |
107 | $listref = $lastlistref; |
108 | $prog = undef; |
109 | die "$.: unexpected + line\n" if !defined $lastlistref; |
110 | } elsif ($_[1] eq "=") { |
111 | $groups{$_[0]} = [] if !defined $groups{$_[0]}; |
112 | $listref = $groups{$_[0]}; |
113 | $prog = undef; |
114 | shift @objs; # eat the group name |
115 | } elsif ($_[1] eq ":") { |
c282cde3 |
116 | $listref = []; |
7603011f |
117 | $prog = $_[0]; |
118 | shift @objs; # eat the program name |
3d541627 |
119 | } else { |
7603011f |
120 | die "$.: unrecognised line type\n"; |
3d541627 |
121 | } |
7603011f |
122 | shift @objs; # eat the +, the = or the : |
123 | |
124 | while (scalar @objs > 0) { |
125 | $i = shift @objs; |
126 | if ($groups{$i}) { |
127 | foreach $j (@{$groups{$i}}) { unshift @objs, $j; } |
a86a2725 |
128 | } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or |
1ddda1ca |
129 | $i eq "[X]" or $i eq "[U]" or $i eq "[MX]") and defined $prog) { |
130 | $type = substr($i,1,(length $i)-2); |
7603011f |
131 | } else { |
132 | push @$listref, $i; |
133 | } |
134 | } |
c282cde3 |
135 | if ($prog and $type) { |
136 | die "multiple program entries for $prog [$type]\n" |
e35fb54b |
137 | if defined $programs{$prog . "," . $type}; |
c282cde3 |
138 | $programs{$prog . "," . $type} = $listref; |
139 | } |
7603011f |
140 | $lastlistref = $listref; |
3d541627 |
141 | } |
7603011f |
142 | |
3d541627 |
143 | close IN; |
7603011f |
144 | |
145 | # Now retrieve the complete list of objects and resource files, and |
146 | # construct dependency data for them. While we're here, expand the |
147 | # object list for each program, and complain if its type isn't set. |
148 | @prognames = sort keys %programs; |
149 | %depends = (); |
150 | @scanlist = (); |
151 | foreach $i (@prognames) { |
c282cde3 |
152 | ($prog, $type) = split ",", $i; |
7603011f |
153 | # Strip duplicate object names. |
4877ec8d |
154 | $prev = ''; |
7603011f |
155 | @list = grep { $status = ($prev ne $_); $prev=$_; $status } |
156 | sort @{$programs{$i}}; |
157 | $programs{$i} = [@list]; |
158 | foreach $j (@list) { |
1ddda1ca |
159 | # Dependencies for "x" start with "x.c" or "x.m" (depending on |
160 | # which one exists). |
7603011f |
161 | # Dependencies for "x.res" start with "x.rc". |
c88dc003 |
162 | # Dependencies for "x.rsrc" start with "x.r". |
7603011f |
163 | # Both types of file are pushed on the list of files to scan. |
164 | # Libraries (.lib) don't have dependencies at all. |
165 | if ($j =~ /^(.*)\.res$/) { |
166 | $file = "$1.rc"; |
167 | $depends{$j} = [$file]; |
168 | push @scanlist, $file; |
c88dc003 |
169 | } elsif ($j =~ /^(.*)\.rsrc$/) { |
170 | $file = "$1.r"; |
171 | $depends{$j} = [$file]; |
172 | push @scanlist, $file; |
1ddda1ca |
173 | } elsif ($j !~ /\./) { |
7603011f |
174 | $file = "$j.c"; |
1ddda1ca |
175 | $file = "$j.m" unless &findfile($file); |
7603011f |
176 | $depends{$j} = [$file]; |
177 | push @scanlist, $file; |
178 | } |
179 | } |
180 | } |
181 | |
182 | # Scan each file on @scanlist and find further inclusions. |
183 | # Inclusions are given by lines of the form `#include "otherfile"' |
184 | # (system headers are automatically ignored by this because they'll |
185 | # be given in angle brackets). Files included by this method are |
186 | # added back on to @scanlist to be scanned in turn (if not already |
187 | # done). |
188 | # |
0f2ab471 |
189 | # Resource scripts (.rc) can also include a file by means of: |
190 | # - a line # ending `ICON "filename"'; |
191 | # - a line ending `RT_MANIFEST "filename"'. |
192 | # Files included by this method are not added to @scanlist because |
193 | # they can never include further files. |
7603011f |
194 | # |
195 | # In this pass we write out a hash %further which maps a source |
196 | # file name into a listref containing further source file names. |
197 | |
198 | %further = (); |
44747c53 |
199 | %allsourcefiles = (); # this is wanted by some makefiles |
7603011f |
200 | while (scalar @scanlist > 0) { |
201 | $file = shift @scanlist; |
202 | next if defined $further{$file}; # skip if we've already done it |
7603011f |
203 | $further{$file} = []; |
f7f27309 |
204 | $dirfile = &findfile($file); |
44747c53 |
205 | $allsourcefiles{$dirfile} = 1; |
f7f27309 |
206 | open IN, "$dirfile" or die "unable to open source file $file\n"; |
7603011f |
207 | while (<IN>) { |
208 | chomp; |
209 | /^\s*#include\s+\"([^\"]+)\"/ and do { |
210 | push @{$further{$file}}, $1; |
211 | push @scanlist, $1; |
212 | next; |
213 | }; |
0f2ab471 |
214 | /(RT_MANIFEST|ICON)\s+\"([^\"]+)\"\s*$/ and do { |
215 | push @{$further{$file}}, $2; |
7603011f |
216 | next; |
217 | } |
218 | } |
219 | close IN; |
3d541627 |
220 | } |
221 | |
7603011f |
222 | # Now we're ready to generate the final dependencies section. For |
223 | # each key in %depends, we must expand the dependencies list by |
224 | # iteratively adding entries from %further. |
225 | foreach $i (keys %depends) { |
226 | %dep = (); |
227 | @scanlist = @{$depends{$i}}; |
228 | foreach $i (@scanlist) { $dep{$i} = 1; } |
229 | while (scalar @scanlist > 0) { |
230 | $file = shift @scanlist; |
231 | foreach $j (@{$further{$file}}) { |
4877ec8d |
232 | if (!$dep{$j}) { |
7603011f |
233 | $dep{$j} = 1; |
e35fb54b |
234 | push @{$depends{$i}}, $j; |
235 | push @scanlist, $j; |
7603011f |
236 | } |
237 | } |
238 | } |
239 | # printf "%s: %s\n", $i, join ' ',@{$depends{$i}}; |
3d541627 |
240 | } |
241 | |
e35fb54b |
242 | # Validation of input. |
243 | |
244 | sub mfval($) { |
245 | my ($type) = @_; |
246 | # Returns true if the argument is a known makefile type. Otherwise, |
247 | # prints a warning and returns false; |
248 | if (grep { $type eq $_ } |
b89e7e07 |
249 | ("vc","vcproj","cygwin","borland","lcc","devcppproj","gtk","unix", |
44747c53 |
250 | "am","osx",)) { |
e35fb54b |
251 | return 1; |
252 | } |
253 | warn "$.:unknown makefile type '$type'\n"; |
254 | return 0; |
255 | } |
256 | |
7603011f |
257 | # Utility routines while writing out the Makefiles. |
258 | |
4877ec8d |
259 | sub def { |
260 | my ($x) = shift @_; |
261 | return (defined $x) ? $x : ""; |
262 | } |
263 | |
cdd310bb |
264 | sub dirpfx { |
265 | my ($path) = shift @_; |
266 | my ($sep) = shift @_; |
4877ec8d |
267 | my $ret = ""; |
268 | my $i; |
6da41155 |
269 | |
270 | while (($i = index $path, $sep) >= 0 || |
271 | ($j = index $path, "/") >= 0) { |
272 | if ($i >= 0 and ($j < 0 or $i < $j)) { |
273 | $path = substr $path, ($i + length $sep); |
274 | } else { |
275 | $path = substr $path, ($j + 1); |
276 | } |
cdd310bb |
277 | $ret .= "..$sep"; |
278 | } |
279 | return $ret; |
280 | } |
281 | |
f7f27309 |
282 | sub findfile { |
283 | my ($name) = @_; |
4877ec8d |
284 | my $dir = ''; |
1ddda1ca |
285 | my $i; |
286 | my $outdir = undef; |
b6b40d9b |
287 | unless (defined $findfilecache{$name}) { |
288 | $i = 0; |
cdd310bb |
289 | foreach $dir (@srcdirs) { |
4877ec8d |
290 | if (-f "$dir$name") { |
291 | $outdir = $dir; |
292 | $i++; |
293 | $outdir =~ s/^\.\///; |
294 | } |
b6b40d9b |
295 | } |
296 | die "multiple instances of source file $name\n" if $i > 1; |
1ddda1ca |
297 | $findfilecache{$name} = (defined $outdir ? $outdir . $name : undef); |
f7f27309 |
298 | } |
b6b40d9b |
299 | return $findfilecache{$name}; |
f7f27309 |
300 | } |
301 | |
7603011f |
302 | sub objects { |
f7f27309 |
303 | my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_; |
7603011f |
304 | my @ret; |
305 | my ($i, $x, $y); |
4877ec8d |
306 | ($otmpl, $rtmpl, $ltmpl) = map { defined $_ ? $_ : "" } ($otmpl, $rtmpl, $ltmpl); |
7603011f |
307 | @ret = (); |
308 | foreach $i (@{$programs{$prog}}) { |
f7f27309 |
309 | $x = ""; |
c88dc003 |
310 | if ($i =~ /^(.*)\.(res|rsrc)/) { |
7603011f |
311 | $y = $1; |
312 | ($x = $rtmpl) =~ s/X/$y/; |
7603011f |
313 | } elsif ($i =~ /^(.*)\.lib/) { |
314 | $y = $1; |
315 | ($x = $ltmpl) =~ s/X/$y/; |
1ddda1ca |
316 | } elsif ($i !~ /\./) { |
7603011f |
317 | ($x = $otmpl) =~ s/X/$i/; |
7603011f |
318 | } |
f7f27309 |
319 | push @ret, $x if $x ne ""; |
7603011f |
320 | } |
321 | return join " ", @ret; |
3d541627 |
322 | } |
323 | |
1ddda1ca |
324 | sub special { |
325 | my ($prog, $suffix) = @_; |
326 | my @ret; |
327 | my ($i, $x, $y); |
4877ec8d |
328 | ($otmpl, $rtmpl, $ltmpl) = map { defined $_ ? $_ : "" } ($otmpl, $rtmpl, $ltmpl); |
1ddda1ca |
329 | @ret = (); |
330 | foreach $i (@{$programs{$prog}}) { |
331 | if (substr($i, (length $i) - (length $suffix)) eq $suffix) { |
332 | push @ret, $i; |
333 | } |
334 | } |
335 | return (scalar @ret) ? (join " ", @ret) : undef; |
336 | } |
337 | |
7603011f |
338 | sub splitline { |
a86a2725 |
339 | my ($line, $width, $splitchar) = @_; |
4877ec8d |
340 | my $result = ""; |
341 | my $len; |
7603011f |
342 | $len = (defined $width ? $width : 76); |
a86a2725 |
343 | $splitchar = (defined $splitchar ? $splitchar : '\\'); |
7603011f |
344 | while (length $line > $len) { |
345 | $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/; |
b76d219a |
346 | $result .= $1; |
347 | $result .= " ${splitchar}\n\t\t" if $2 ne ''; |
7603011f |
348 | $line = $2; |
349 | $len = 60; |
350 | } |
351 | return $result . $line; |
352 | } |
353 | |
354 | sub deps { |
6da41155 |
355 | my ($otmpl, $rtmpl, $prefix, $dirsep, $mftyp, $depchar, $splitchar) = @_; |
7603011f |
356 | my ($i, $x, $y); |
4877ec8d |
357 | my @deps; |
358 | my @ret; |
a86a2725 |
359 | @ret = (); |
360 | $depchar ||= ':'; |
7603011f |
361 | foreach $i (sort keys %depends) { |
6da41155 |
362 | next if $specialobj{$mftyp}->{$i}; |
c88dc003 |
363 | if ($i =~ /^(.*)\.(res|rsrc)/) { |
f7f27309 |
364 | next if !defined $rtmpl; |
7603011f |
365 | $y = $1; |
366 | ($x = $rtmpl) =~ s/X/$y/; |
367 | } else { |
368 | ($x = $otmpl) =~ s/X/$i/; |
369 | } |
f7f27309 |
370 | @deps = @{$depends{$i}}; |
371 | @deps = map { |
372 | $_ = &findfile($_); |
373 | s/\//$dirsep/g; |
374 | $_ = $prefix . $_; |
375 | } @deps; |
976374cd |
376 | push @ret, {obj => $x, obj_orig => $i, deps => [@deps]}; |
7603011f |
377 | } |
a86a2725 |
378 | return @ret; |
3d541627 |
379 | } |
380 | |
f7f27309 |
381 | sub prognames { |
382 | my ($types) = @_; |
c282cde3 |
383 | my ($n, $prog, $type); |
384 | my @ret; |
385 | @ret = (); |
386 | foreach $n (@prognames) { |
387 | ($prog, $type) = split ",", $n; |
1ddda1ca |
388 | push @ret, $n if index(":$types:", ":$type:") >= 0; |
c282cde3 |
389 | } |
390 | return @ret; |
391 | } |
392 | |
393 | sub progrealnames { |
394 | my ($types) = @_; |
395 | my ($n, $prog, $type); |
f7f27309 |
396 | my @ret; |
397 | @ret = (); |
398 | foreach $n (@prognames) { |
c282cde3 |
399 | ($prog, $type) = split ",", $n; |
1ddda1ca |
400 | push @ret, $prog if index(":$types:", ":$type:") >= 0; |
f7f27309 |
401 | } |
402 | return @ret; |
403 | } |
404 | |
c76d309d |
405 | sub manpages { |
406 | my ($types,$suffix) = @_; |
407 | |
408 | # assume that all UNIX programs have a man page |
1ddda1ca |
409 | if($suffix eq "1" && $types =~ /:X:/) { |
c76d309d |
410 | return map("$_.1", &progrealnames($types)); |
411 | } |
412 | return (); |
413 | } |
414 | |
bc7af299 |
415 | $orig_dir = cwd; |
416 | |
7603011f |
417 | # Now we're ready to output the actual Makefiles. |
418 | |
e35fb54b |
419 | if (defined $makefiles{'cygwin'}) { |
cdd310bb |
420 | $dirpfx = &dirpfx($makefiles{'cygwin'}, "/"); |
3d541627 |
421 | |
e35fb54b |
422 | ##-- CygWin makefile |
423 | open OUT, ">$makefiles{'cygwin'}"; select OUT; |
424 | print |
425 | "# Makefile for $project_name under cygwin.\n". |
426 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
427 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
428 | # gcc command line option is -D not /D |
4877ec8d |
429 | ($_ = $help) =~ s/([=" ])\/D/$1-D/gs; |
e35fb54b |
430 | print $_; |
431 | print |
432 | "\n". |
433 | "# You can define this path to point at your tools if you need to\n". |
434 | "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n". |
435 | "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n". |
436 | "CC = \$(TOOLPATH)gcc\n". |
437 | "RC = \$(TOOLPATH)windres\n". |
438 | "# Uncomment the following two lines to compile under Winelib\n". |
439 | "# CC = winegcc\n". |
440 | "# RC = wrc\n". |
441 | "# You may also need to tell windres where to find include files:\n". |
442 | "# RCINC = --include-dir c:\\cygwin\\include\\\n". |
443 | "\n". |
444 | &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT". |
db6452be |
445 | " -D_NO_OLDNAMES -DNO_MULTIMON -DNO_HTMLHELP " . |
cdd310bb |
446 | (join " ", map {"-I$dirpfx$_"} @srcdirs)) . |
447 | "\n". |
e35fb54b |
448 | "LDFLAGS = -mno-cygwin -s\n". |
449 | &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1". |
33205978 |
450 | " --define WINVER=0x0400")."\n". |
e35fb54b |
451 | "\n". |
77603464 |
452 | $makefile_extra{'cygwin'}->{'vars'} . |
453 | "\n". |
e35fb54b |
454 | ".SUFFIXES:\n". |
e35fb54b |
455 | "\n"; |
1ddda1ca |
456 | print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C")); |
e35fb54b |
457 | print "\n\n"; |
1ddda1ca |
458 | foreach $p (&prognames("G:C")) { |
e35fb54b |
459 | ($prog, $type) = split ",", $p; |
460 | $objstr = &objects($p, "X.o", "X.res.o", undef); |
461 | print &splitline($prog . ".exe: " . $objstr), "\n"; |
462 | my $mw = $type eq "G" ? " -mwindows" : ""; |
463 | $libstr = &objects($p, undef, undef, "-lX"); |
464 | print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " . |
465 | "-Wl,-Map,$prog.map " . |
466 | $objstr . " $libstr", 69), "\n\n"; |
7603011f |
467 | } |
6da41155 |
468 | foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/", "cygwin")) { |
976374cd |
469 | if ($forceobj{$d->{obj_orig}}) { |
470 | printf ("%s: FORCE\n", $d->{obj}); |
471 | } else { |
472 | print &splitline(sprintf("%s: %s", $d->{obj}, |
473 | join " ", @{$d->{deps}})), "\n"; |
474 | } |
6da41155 |
475 | if ($d->{obj} =~ /\.res\.o$/) { |
d8284c29 |
476 | print "\t\$(RC) \$(RCFL) \$(RCFLAGS) ".$d->{deps}->[0]." ".$d->{obj}."\n\n"; |
6da41155 |
477 | } else { |
a77c6ed3 |
478 | print "\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c ".$d->{deps}->[0]."\n\n"; |
6da41155 |
479 | } |
e35fb54b |
480 | } |
481 | print "\n"; |
77603464 |
482 | print $makefile_extra{'cygwin'}->{'end'}; |
e35fb54b |
483 | print "\nclean:\n". |
484 | "\trm -f *.o *.exe *.res.o *.map\n". |
976374cd |
485 | "\n". |
486 | "FORCE:\n"; |
e35fb54b |
487 | select STDOUT; close OUT; |
7603011f |
488 | |
7603011f |
489 | } |
e35fb54b |
490 | |
491 | ##-- Borland makefile |
492 | if (defined $makefiles{'borland'}) { |
cdd310bb |
493 | $dirpfx = &dirpfx($makefiles{'borland'}, "\\"); |
494 | |
e35fb54b |
495 | %stdlibs = ( # Borland provides many Win32 API libraries intrinsically |
496 | "advapi32" => 1, |
497 | "comctl32" => 1, |
498 | "comdlg32" => 1, |
499 | "gdi32" => 1, |
500 | "imm32" => 1, |
501 | "shell32" => 1, |
502 | "user32" => 1, |
503 | "winmm" => 1, |
504 | "winspool" => 1, |
505 | "wsock32" => 1, |
506 | ); |
507 | open OUT, ">$makefiles{'borland'}"; select OUT; |
508 | print |
509 | "# Makefile for $project_name under Borland C.\n". |
510 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
511 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
512 | # bcc32 command line option is -D not /D |
4877ec8d |
513 | ($_ = $help) =~ s/([=" ])\/D/$1-D/gs; |
e35fb54b |
514 | print $_; |
515 | print |
516 | "\n". |
517 | "# If you rename this file to `Makefile', you should change this line,\n". |
518 | "# so that the .rsp files still depend on the correct makefile.\n". |
519 | "MAKEFILE = Makefile.bor\n". |
520 | "\n". |
521 | "# C compilation flags\n". |
06c3eadd |
522 | "CFLAGS = -D_WINDOWS -DWINVER=0x0500\n". |
976374cd |
523 | "# Resource compilation flags\n". |
524 | "RCFLAGS = -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401\n". |
e35fb54b |
525 | "\n". |
526 | "# Get include directory for resource compiler\n". |
527 | "!if !\$d(BCB)\n". |
528 | "BCB = \$(MAKEDIR)\\..\n". |
529 | "!endif\n". |
530 | "\n". |
77603464 |
531 | $makefile_extra{'borland'}->{'vars'} . |
532 | "\n". |
e35fb54b |
533 | ".c.obj:\n". |
d8284c29 |
534 | &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT)". |
a77c6ed3 |
535 | " \$(CFLAGS) \$(XFLAGS) ". |
cdd310bb |
536 | (join " ", map {"-I$dirpfx$_"} @srcdirs) . |
ba58fbaa |
537 | " /c \$*.c",69)."\n". |
e35fb54b |
538 | ".rc.res:\n". |
d8284c29 |
539 | &splitline("\tbrcc32 \$(RCFL) -i \$(BCB)\\include -r". |
976374cd |
540 | " \$(RCFLAGS) \$*.rc",69)."\n". |
e35fb54b |
541 | "\n"; |
1ddda1ca |
542 | print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C")); |
e35fb54b |
543 | print "\n\n"; |
1ddda1ca |
544 | foreach $p (&prognames("G:C")) { |
e35fb54b |
545 | ($prog, $type) = split ",", $p; |
4877ec8d |
546 | $objstr = &objects($p, "X.obj", "X.res", undef); |
e35fb54b |
547 | print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n"; |
548 | my $ap = ($type eq "G") ? "-aa" : "-ap"; |
549 | print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n"; |
7603011f |
550 | } |
1ddda1ca |
551 | foreach $p (&prognames("G:C")) { |
e35fb54b |
552 | ($prog, $type) = split ",", $p; |
553 | print $prog, ".rsp: \$(MAKEFILE)\n"; |
554 | $objstr = &objects($p, "X.obj", undef, undef); |
555 | @objlist = split " ", $objstr; |
556 | @objlines = (""); |
557 | foreach $i (@objlist) { |
558 | if (length($objlines[$#objlines] . " $i") > 50) { |
559 | push @objlines, ""; |
560 | } |
561 | $objlines[$#objlines] .= " $i"; |
562 | } |
563 | $c0w = ($type eq "G") ? "c0w32" : "c0x32"; |
564 | print "\techo $c0w + > $prog.rsp\n"; |
565 | for ($i=0; $i<=$#objlines; $i++) { |
566 | $plus = ($i < $#objlines ? " +" : ""); |
567 | print "\techo$objlines[$i]$plus >> $prog.rsp\n"; |
568 | } |
569 | print "\techo $prog.exe >> $prog.rsp\n"; |
570 | $objstr = &objects($p, "X.obj", "X.res", undef); |
571 | @libs = split " ", &objects($p, undef, undef, "X"); |
572 | @libs = grep { !$stdlibs{$_} } @libs; |
573 | unshift @libs, "cw32", "import32"; |
574 | $libstr = join ' ', @libs; |
575 | print "\techo nul,$libstr, >> $prog.rsp\n"; |
576 | print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n"; |
577 | print "\n"; |
578 | } |
6da41155 |
579 | foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "borland")) { |
976374cd |
580 | if ($forceobj{$d->{obj_orig}}) { |
581 | printf("%s: FORCE\n", $d->{obj}); |
582 | } else { |
583 | print &splitline(sprintf("%s: %s", $d->{obj}, |
584 | join " ", @{$d->{deps}})), "\n"; |
585 | } |
e35fb54b |
586 | } |
587 | print "\n"; |
77603464 |
588 | print $makefile_extra{'borland'}->{'end'}; |
e35fb54b |
589 | print "\nclean:\n". |
590 | "\t-del *.obj\n". |
591 | "\t-del *.exe\n". |
592 | "\t-del *.res\n". |
593 | "\t-del *.pch\n". |
594 | "\t-del *.aps\n". |
595 | "\t-del *.il*\n". |
596 | "\t-del *.pdb\n". |
597 | "\t-del *.rsp\n". |
598 | "\t-del *.tds\n". |
976374cd |
599 | "\t-del *.\$\$\$\$\$\$\n". |
600 | "\n". |
601 | "FORCE:\n". |
602 | "\t-rem dummy command\n"; |
e35fb54b |
603 | select STDOUT; close OUT; |
7603011f |
604 | } |
e35fb54b |
605 | |
606 | if (defined $makefiles{'vc'}) { |
cdd310bb |
607 | $dirpfx = &dirpfx($makefiles{'vc'}, "\\"); |
608 | |
e35fb54b |
609 | ##-- Visual C++ makefile |
610 | open OUT, ">$makefiles{'vc'}"; select OUT; |
611 | print |
612 | "# Makefile for $project_name under Visual C.\n". |
613 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
614 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
615 | print $help; |
616 | print |
617 | "\n". |
618 | "# If you rename this file to `Makefile', you should change this line,\n". |
619 | "# so that the .rsp files still depend on the correct makefile.\n". |
620 | "MAKEFILE = Makefile.vc\n". |
621 | "\n". |
622 | "# C compilation flags\n". |
6da41155 |
623 | "CFLAGS = /nologo /W3 /O1 " . |
624 | (join " ", map {"-I$dirpfx$_"} @srcdirs) . |
06c3eadd |
625 | " /D_WINDOWS /D_WIN32_WINDOWS=0x500 /DWINVER=0x500\n". |
e35fb54b |
626 | "LFLAGS = /incremental:no /fixed\n". |
976374cd |
627 | "RCFLAGS = -DWIN32 -D_WIN32 -DWINVER=0x0400\n". |
e35fb54b |
628 | "\n". |
77603464 |
629 | $makefile_extra{'vc'}->{'vars'} . |
630 | "\n". |
a86a2725 |
631 | "\n"; |
1ddda1ca |
632 | print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C")); |
e35fb54b |
633 | print "\n\n"; |
1ddda1ca |
634 | foreach $p (&prognames("G:C")) { |
e35fb54b |
635 | ($prog, $type) = split ",", $p; |
636 | $objstr = &objects($p, "X.obj", "X.res", undef); |
637 | print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n"; |
d7656baf |
638 | print "\tlink \$(LFLAGS) \$(XLFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n"; |
e35fb54b |
639 | } |
1ddda1ca |
640 | foreach $p (&prognames("G:C")) { |
e35fb54b |
641 | ($prog, $type) = split ",", $p; |
642 | print $prog, ".rsp: \$(MAKEFILE)\n"; |
643 | $objstr = &objects($p, "X.obj", "X.res", "X.lib"); |
644 | @objlist = split " ", $objstr; |
645 | @objlines = (""); |
646 | foreach $i (@objlist) { |
647 | if (length($objlines[$#objlines] . " $i") > 50) { |
648 | push @objlines, ""; |
649 | } |
650 | $objlines[$#objlines] .= " $i"; |
651 | } |
652 | $subsys = ($type eq "G") ? "windows" : "console"; |
653 | print "\techo /nologo /subsystem:$subsys > $prog.rsp\n"; |
654 | for ($i=0; $i<=$#objlines; $i++) { |
655 | print "\techo$objlines[$i] >> $prog.rsp\n"; |
656 | } |
657 | print "\n"; |
658 | } |
6da41155 |
659 | foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "vc")) { |
976374cd |
660 | $extradeps = $forceobj{$d->{obj_orig}} ? ["*.c","*.h","*.rc"] : []; |
661 | print &splitline(sprintf("%s: %s", $d->{obj}, |
662 | join " ", @$extradeps, @{$d->{deps}})), "\n"; |
6da41155 |
663 | if ($d->{obj} =~ /.obj$/) { |
a77c6ed3 |
664 | print "\tcl \$(COMPAT) \$(CFLAGS) \$(XFLAGS) /c ".$d->{deps}->[0],"\n\n"; |
6da41155 |
665 | } else { |
976374cd |
666 | print "\trc \$(RCFL) -r \$(RCFLAGS) ".$d->{deps}->[0],"\n\n"; |
6da41155 |
667 | } |
e35fb54b |
668 | } |
669 | print "\n"; |
77603464 |
670 | print $makefile_extra{'vc'}->{'end'}; |
e35fb54b |
671 | print "\nclean: tidy\n". |
672 | "\t-del *.exe\n\n". |
673 | "tidy:\n". |
674 | "\t-del *.obj\n". |
675 | "\t-del *.res\n". |
676 | "\t-del *.pch\n". |
677 | "\t-del *.aps\n". |
678 | "\t-del *.ilk\n". |
679 | "\t-del *.pdb\n". |
680 | "\t-del *.rsp\n". |
681 | "\t-del *.dsp\n". |
682 | "\t-del *.dsw\n". |
683 | "\t-del *.ncb\n". |
684 | "\t-del *.opt\n". |
685 | "\t-del *.plg\n". |
686 | "\t-del *.map\n". |
687 | "\t-del *.idb\n". |
688 | "\t-del debug.log\n"; |
689 | select STDOUT; close OUT; |
a86a2725 |
690 | } |
f7f27309 |
691 | |
e35fb54b |
692 | if (defined $makefiles{'vcproj'}) { |
6da41155 |
693 | $dirpfx = &dirpfx($makefiles{'vcproj'}, "\\"); |
58de2f3c |
694 | |
e35fb54b |
695 | ##-- MSVC 6 Workspace and projects |
696 | # |
697 | # Note: All files created in this section are written in binary |
698 | # mode, because although MSVC's command-line make can deal with |
699 | # LF-only line endings, MSVC project files really _need_ to be |
700 | # CRLF. Hence, in order for mkfiles.pl to generate usable project |
701 | # files even when run from Unix, I make sure all files are binary |
702 | # and explicitly write the CRLFs. |
703 | # |
704 | # Create directories if necessary |
705 | mkdir $makefiles{'vcproj'} |
706 | if(! -d $makefiles{'vcproj'}); |
707 | chdir $makefiles{'vcproj'}; |
6da41155 |
708 | @deps = &deps("X.obj", "X.res", $dirpfx, "\\", "vcproj"); |
e35fb54b |
709 | %all_object_deps = map {$_->{obj} => $_->{deps}} @deps; |
710 | # Create the project files |
711 | # Get names of all Windows projects (GUI and console) |
1ddda1ca |
712 | my @prognames = &prognames("G:C"); |
e35fb54b |
713 | foreach $progname (@prognames) { |
985b6440 |
714 | create_vc_project(\%all_object_deps, $progname); |
e35fb54b |
715 | } |
716 | # Create the workspace file |
717 | open OUT, ">$project_name.dsw"; binmode OUT; select OUT; |
718 | print |
719 | "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n". |
720 | "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n". |
721 | "\r\n". |
722 | "###############################################################################\r\n". |
723 | "\r\n"; |
724 | # List projects |
725 | foreach $progname (@prognames) { |
726 | ($windows_project, $type) = split ",", $progname; |
727 | print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n"; |
728 | } |
729 | print |
730 | "\r\n". |
731 | "Package=<5>\r\n". |
732 | "{{{\r\n". |
733 | "}}}\r\n". |
734 | "\r\n". |
735 | "Package=<4>\r\n". |
736 | "{{{\r\n". |
737 | "}}}\r\n". |
738 | "\r\n". |
739 | "###############################################################################\r\n". |
740 | "\r\n". |
741 | "Global:\r\n". |
742 | "\r\n". |
743 | "Package=<5>\r\n". |
744 | "{{{\r\n". |
745 | "}}}\r\n". |
746 | "\r\n". |
747 | "Package=<3>\r\n". |
748 | "{{{\r\n". |
749 | "}}}\r\n". |
750 | "\r\n". |
751 | "###############################################################################\r\n". |
752 | "\r\n"; |
753 | select STDOUT; close OUT; |
754 | chdir $orig_dir; |
755 | |
985b6440 |
756 | sub create_vc_project { |
e35fb54b |
757 | my ($all_object_deps, $progname) = @_; |
758 | # Construct program's dependency info |
759 | %seen_objects = (); |
760 | %lib_files = (); |
761 | %source_files = (); |
762 | %header_files = (); |
763 | %resource_files = (); |
764 | @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib"); |
765 | foreach $object_file (@object_files) { |
766 | next if defined $seen_objects{$object_file}; |
767 | $seen_objects{$object_file} = 1; |
768 | if($object_file =~ /\.lib$/io) { |
769 | $lib_files{$object_file} = 1; |
770 | next; |
771 | } |
772 | $object_deps = $all_object_deps{$object_file}; |
773 | foreach $object_dep (@$object_deps) { |
774 | if($object_dep =~ /\.c$/io) { |
775 | $source_files{$object_dep} = 1; |
776 | next; |
58de2f3c |
777 | } |
e35fb54b |
778 | if($object_dep =~ /\.h$/io) { |
779 | $header_files{$object_dep} = 1; |
780 | next; |
58de2f3c |
781 | } |
e35fb54b |
782 | if($object_dep =~ /\.(rc|ico)$/io) { |
783 | $resource_files{$object_dep} = 1; |
784 | next; |
58de2f3c |
785 | } |
e35fb54b |
786 | } |
787 | } |
788 | $libs = join " ", sort keys %lib_files; |
789 | @source_files = sort keys %source_files; |
790 | @header_files = sort keys %header_files; |
791 | @resources = sort keys %resource_files; |
792 | ($windows_project, $type) = split ",", $progname; |
793 | mkdir $windows_project |
794 | if(! -d $windows_project); |
795 | chdir $windows_project; |
796 | $subsys = ($type eq "G") ? "windows" : "console"; |
797 | open OUT, ">$windows_project.dsp"; binmode OUT; select OUT; |
798 | print |
799 | "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n". |
800 | "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n". |
801 | "# ** DO NOT EDIT **\r\n". |
802 | "\r\n". |
803 | "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n". |
804 | "\r\n". |
805 | "CFG=$windows_project - Win32 Debug\r\n". |
806 | "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n". |
807 | "!MESSAGE use the Export Makefile command and run\r\n". |
808 | "!MESSAGE \r\n". |
809 | "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n". |
810 | "!MESSAGE \r\n". |
811 | "!MESSAGE You can specify a configuration when running NMAKE\r\n". |
812 | "!MESSAGE by defining the macro CFG on the command line. For example:\r\n". |
813 | "!MESSAGE \r\n". |
814 | "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n". |
815 | "!MESSAGE \r\n". |
816 | "!MESSAGE Possible choices for configuration are:\r\n". |
817 | "!MESSAGE \r\n". |
818 | "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n". |
819 | "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n". |
820 | "!MESSAGE \r\n". |
821 | "\r\n". |
822 | "# Begin Project\r\n". |
823 | "# PROP AllowPerConfigDependencies 0\r\n". |
824 | "# PROP Scc_ProjName \"\"\r\n". |
825 | "# PROP Scc_LocalPath \"\"\r\n". |
826 | "CPP=cl.exe\r\n". |
827 | "MTL=midl.exe\r\n". |
828 | "RSC=rc.exe\r\n". |
829 | "\r\n". |
830 | "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n". |
831 | "\r\n". |
832 | "# PROP BASE Use_MFC 0\r\n". |
833 | "# PROP BASE Use_Debug_Libraries 0\r\n". |
834 | "# PROP BASE Output_Dir \"Release\"\r\n". |
835 | "# PROP BASE Intermediate_Dir \"Release\"\r\n". |
836 | "# PROP BASE Target_Dir \"\"\r\n". |
837 | "# PROP Use_MFC 0\r\n". |
838 | "# PROP Use_Debug_Libraries 0\r\n". |
839 | "# PROP Output_Dir \"Release\"\r\n". |
840 | "# PROP Intermediate_Dir \"Release\"\r\n". |
841 | "# PROP Ignore_Export_Lib 0\r\n". |
842 | "# PROP Target_Dir \"\"\r\n". |
6da41155 |
843 | "# ADD BASE CPP /nologo /W3 /GX /O2 ". |
844 | (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) . |
845 | " /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n". |
846 | "# ADD CPP /nologo /W3 /GX /O2 ". |
847 | (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) . |
848 | " /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n". |
e35fb54b |
849 | "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n". |
850 | "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n". |
851 | "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n". |
852 | "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n". |
853 | "BSC32=bscmake.exe\r\n". |
854 | "# ADD BASE BSC32 /nologo\r\n". |
855 | "# ADD BSC32 /nologo\r\n". |
856 | "LINK32=link.exe\r\n". |
857 | "# 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". |
858 | "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n". |
859 | "# SUBTRACT LINK32 /pdb:none\r\n". |
860 | "\r\n". |
861 | "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n". |
862 | "\r\n". |
863 | "# PROP BASE Use_MFC 0\r\n". |
864 | "# PROP BASE Use_Debug_Libraries 1\r\n". |
865 | "# PROP BASE Output_Dir \"Debug\"\r\n". |
866 | "# PROP BASE Intermediate_Dir \"Debug\"\r\n". |
867 | "# PROP BASE Target_Dir \"\"\r\n". |
868 | "# PROP Use_MFC 0\r\n". |
869 | "# PROP Use_Debug_Libraries 1\r\n". |
870 | "# PROP Output_Dir \"Debug\"\r\n". |
871 | "# PROP Intermediate_Dir \"Debug\"\r\n". |
872 | "# PROP Ignore_Export_Lib 0\r\n". |
873 | "# PROP Target_Dir \"\"\r\n". |
6da41155 |
874 | "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od ". |
875 | (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) . |
876 | " /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n". |
877 | "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od ". |
878 | (join " ", map {"/I \"..\\..\\$dirpfx$_\""} @srcdirs) . |
879 | " /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n". |
e35fb54b |
880 | "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n". |
881 | "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n". |
882 | "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n". |
883 | "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n". |
884 | "BSC32=bscmake.exe\r\n". |
885 | "# ADD BASE BSC32 /nologo\r\n". |
886 | "# ADD BSC32 /nologo\r\n". |
887 | "LINK32=link.exe\r\n". |
888 | "# 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". |
889 | "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n". |
890 | "# SUBTRACT LINK32 /pdb:none\r\n". |
891 | "\r\n". |
892 | "!ENDIF \r\n". |
893 | "\r\n". |
894 | "# Begin Target\r\n". |
895 | "\r\n". |
896 | "# Name \"$windows_project - Win32 Release\"\r\n". |
897 | "# Name \"$windows_project - Win32 Debug\"\r\n". |
898 | "# Begin Group \"Source Files\"\r\n". |
899 | "\r\n". |
900 | "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n"; |
901 | foreach $source_file (@source_files) { |
902 | print |
903 | "# Begin Source File\r\n". |
904 | "\r\n". |
905 | "SOURCE=..\\..\\$source_file\r\n"; |
906 | if($source_file =~ /ssh\.c/io) { |
907 | # Disable 'Edit and continue' as Visual Studio can't handle the macros |
58de2f3c |
908 | print |
e35fb54b |
909 | "\r\n". |
910 | "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n". |
911 | "\r\n". |
912 | "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n". |
913 | "\r\n". |
914 | "# ADD CPP /Zi\r\n". |
915 | "\r\n". |
916 | "!ENDIF \r\n". |
917 | "\r\n"; |
918 | } |
919 | print "# End Source File\r\n"; |
920 | } |
921 | print |
922 | "# End Group\r\n". |
923 | "# Begin Group \"Header Files\"\r\n". |
924 | "\r\n". |
925 | "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n"; |
926 | foreach $header_file (@header_files) { |
927 | print |
928 | "# Begin Source File\r\n". |
929 | "\r\n". |
930 | "SOURCE=..\\..\\$header_file\r\n". |
931 | "# End Source File\r\n"; |
58de2f3c |
932 | } |
e35fb54b |
933 | print |
934 | "# End Group\r\n". |
935 | "# Begin Group \"Resource Files\"\r\n". |
936 | "\r\n". |
937 | "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n"; |
938 | foreach $resource_file (@resources) { |
939 | print |
940 | "# Begin Source File\r\n". |
941 | "\r\n". |
942 | "SOURCE=..\\..\\$resource_file\r\n". |
943 | "# End Source File\r\n"; |
944 | } |
945 | print |
946 | "# End Group\r\n". |
947 | "# End Target\r\n". |
948 | "# End Project\r\n"; |
949 | select STDOUT; close OUT; |
950 | chdir ".."; |
951 | } |
a86a2725 |
952 | } |
a86a2725 |
953 | |
e35fb54b |
954 | if (defined $makefiles{'gtk'}) { |
cdd310bb |
955 | $dirpfx = &dirpfx($makefiles{'gtk'}, "/"); |
d37a507a |
956 | |
e35fb54b |
957 | ##-- X/GTK/Unix makefile |
958 | open OUT, ">$makefiles{'gtk'}"; select OUT; |
959 | print |
960 | "# Makefile for $project_name under X/GTK and Unix.\n". |
961 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
962 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
963 | # gcc command line option is -D not /D |
4877ec8d |
964 | ($_ = $help) =~ s/([=" ])\/D/$1-D/gs; |
e35fb54b |
965 | print $_; |
966 | print |
967 | "\n". |
968 | "# You can define this path to point at your tools if you need to\n". |
969 | "# TOOLPATH = /opt/gcc/bin\n". |
970 | "CC = \$(TOOLPATH)cc\n". |
42af6a67 |
971 | "# If necessary set the path to krb5-config here\n". |
972 | "KRB5CONFIG=krb5-config\n". |
f160b7b8 |
973 | "# You can manually set this to `gtk-config' or `pkg-config gtk+-1.2'\n". |
974 | "# (depending on what works on your system) if you want to enforce\n". |
c349ffb1 |
975 | "# building with GTK 1.2, or you can set it to `pkg-config gtk+-2.0 x11'\n". |
f160b7b8 |
976 | "# if you want to enforce 2.0. The default is to try 2.0 and fall back\n". |
977 | "# to 1.2 if it isn't found.\n". |
c349ffb1 |
978 | "GTK_CONFIG = sh -c 'pkg-config gtk+-2.0 x11 \$\$0 2>/dev/null || gtk-config \$\$0'\n". |
e35fb54b |
979 | "\n". |
3290cec9 |
980 | "-include Makefile.local\n". |
981 | "\n". |
9ac18d71 |
982 | "unexport CFLAGS # work around a weird issue with krb5-config\n". |
983 | "\n". |
cdd310bb |
984 | &splitline("CFLAGS = -O2 -Wall -Werror -g " . |
985 | (join " ", map {"-I$dirpfx$_"} @srcdirs) . |
c407e146 |
986 | " \$(shell \$(GTK_CONFIG) --cflags)"). |
0ac1920c |
987 | " -D _FILE_OFFSET_BITS=64\n". |
c407e146 |
988 | "XLDFLAGS = \$(LDFLAGS) \$(shell \$(GTK_CONFIG) --libs)\n". |
0dbe2956 |
989 | "ULDFLAGS = \$(LDFLAGS)\n". |
42af6a67 |
990 | "ifeq (,\$(findstring NO_GSSAPI,\$(COMPAT)))\n". |
b3d375b2 |
991 | "ifeq (,\$(findstring STATIC_GSSAPI,\$(COMPAT)))\n". |
992 | "XLDFLAGS+= -ldl\n". |
993 | "ULDFLAGS+= -ldl\n". |
994 | "else\n". |
995 | "CFLAGS+= -DNO_LIBDL \$(shell \$(KRB5CONFIG) --cflags gssapi)\n". |
c407e146 |
996 | "XLDFLAGS+= \$(shell \$(KRB5CONFIG) --libs gssapi)\n". |
b3d375b2 |
997 | "ULDFLAGS+= \$(shell \$(KRB5CONFIG) --libs gssapi)\n". |
998 | "endif\n". |
666b0d2a |
999 | "endif\n". |
1000 | "INSTALL=install\n". |
1001 | "INSTALL_PROGRAM=\$(INSTALL)\n". |
1002 | "INSTALL_DATA=\$(INSTALL)\n". |
1003 | "prefix=/usr/local\n". |
1004 | "exec_prefix=\$(prefix)\n". |
1005 | "bindir=\$(exec_prefix)/bin\n". |
1006 | "mandir=\$(prefix)/man\n". |
1007 | "man1dir=\$(mandir)/man1\n". |
e35fb54b |
1008 | "\n". |
4877ec8d |
1009 | &def($makefile_extra{'gtk'}->{'vars'}) . |
77603464 |
1010 | "\n". |
e35fb54b |
1011 | ".SUFFIXES:\n". |
1012 | "\n". |
e35fb54b |
1013 | "\n"; |
1ddda1ca |
1014 | print &splitline("all:" . join "", map { " $_" } &progrealnames("X:U")); |
e35fb54b |
1015 | print "\n\n"; |
1ddda1ca |
1016 | foreach $p (&prognames("X:U")) { |
e35fb54b |
1017 | ($prog, $type) = split ",", $p; |
1018 | $objstr = &objects($p, "X.o", undef, undef); |
1019 | print &splitline($prog . ": " . $objstr), "\n"; |
1020 | $libstr = &objects($p, undef, undef, "-lX"); |
4877ec8d |
1021 | print &splitline("\t\$(CC) -o \$@ " . |
0dbe2956 |
1022 | $objstr . " \$(${type}LDFLAGS) $libstr", 69), "\n\n"; |
e35fb54b |
1023 | } |
6da41155 |
1024 | foreach $d (&deps("X.o", undef, $dirpfx, "/", "gtk")) { |
976374cd |
1025 | if ($forceobj{$d->{obj_orig}}) { |
1026 | printf("%s: FORCE\n", $d->{obj}); |
1027 | } else { |
1028 | print &splitline(sprintf("%s: %s", $d->{obj}, |
1029 | join " ", @{$d->{deps}})), "\n"; |
1030 | } |
a77c6ed3 |
1031 | print &splitline("\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c $d->{deps}->[0]\n"); |
76d3a838 |
1032 | } |
1033 | print "\n"; |
1034 | print $makefile_extra{'gtk'}->{'end'}; |
1035 | print "\nclean:\n". |
1036 | "\trm -f *.o". (join "", map { " $_" } &progrealnames("X:U")) . "\n"; |
976374cd |
1037 | print "\nFORCE:\n"; |
76d3a838 |
1038 | select STDOUT; close OUT; |
1039 | } |
1040 | |
b89e7e07 |
1041 | if (defined $makefiles{'unix'}) { |
1042 | $dirpfx = &dirpfx($makefiles{'unix'}, "/"); |
1043 | |
1044 | ##-- GTK-free pure-Unix makefile for non-GUI apps only |
1045 | open OUT, ">$makefiles{'unix'}"; select OUT; |
1046 | print |
1047 | "# Makefile for $project_name under Unix.\n". |
1048 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
1049 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
1050 | # gcc command line option is -D not /D |
4877ec8d |
1051 | ($_ = $help) =~ s/([=" ])\/D/$1-D/gs; |
b89e7e07 |
1052 | print $_; |
1053 | print |
1054 | "\n". |
1055 | "# You can define this path to point at your tools if you need to\n". |
1056 | "# TOOLPATH = /opt/gcc/bin\n". |
1057 | "CC = \$(TOOLPATH)cc\n". |
b89e7e07 |
1058 | "\n". |
1059 | "-include Makefile.local\n". |
1060 | "\n". |
1061 | "unexport CFLAGS # work around a weird issue with krb5-config\n". |
1062 | "\n". |
1063 | &splitline("CFLAGS = -O2 -Wall -Werror -g " . |
1064 | (join " ", map {"-I$dirpfx$_"} @srcdirs)). |
1065 | " -D _FILE_OFFSET_BITS=64\n". |
1066 | "ULDFLAGS = \$(LDFLAGS)\n". |
b89e7e07 |
1067 | "INSTALL=install\n". |
1068 | "INSTALL_PROGRAM=\$(INSTALL)\n". |
1069 | "INSTALL_DATA=\$(INSTALL)\n". |
1070 | "prefix=/usr/local\n". |
1071 | "exec_prefix=\$(prefix)\n". |
1072 | "bindir=\$(exec_prefix)/bin\n". |
1073 | "mandir=\$(prefix)/man\n". |
1074 | "man1dir=\$(mandir)/man1\n". |
1075 | "\n". |
4877ec8d |
1076 | &def($makefile_extra{'unix'}->{'vars'}) . |
b89e7e07 |
1077 | "\n". |
1078 | ".SUFFIXES:\n". |
1079 | "\n". |
1080 | "\n"; |
1081 | print &splitline("all:" . join "", map { " $_" } &progrealnames("U")); |
1082 | print "\n\n"; |
1083 | foreach $p (&prognames("U")) { |
1084 | ($prog, $type) = split ",", $p; |
1085 | $objstr = &objects($p, "X.o", undef, undef); |
1086 | print &splitline($prog . ": " . $objstr), "\n"; |
1087 | $libstr = &objects($p, undef, undef, "-lX"); |
4877ec8d |
1088 | print &splitline("\t\$(CC) -o \$@ " . |
b89e7e07 |
1089 | $objstr . " \$(${type}LDFLAGS) $libstr", 69), "\n\n"; |
1090 | } |
1091 | foreach $d (&deps("X.o", undef, $dirpfx, "/", "unix")) { |
1092 | if ($forceobj{$d->{obj_orig}}) { |
1093 | printf("%s: FORCE\n", $d->{obj}); |
1094 | } else { |
1095 | print &splitline(sprintf("%s: %s", $d->{obj}, |
1096 | join " ", @{$d->{deps}})), "\n"; |
1097 | } |
1098 | print &splitline("\t\$(CC) \$(COMPAT) \$(CFLAGS) \$(XFLAGS) -c $d->{deps}->[0]\n"); |
1099 | } |
1100 | print "\n"; |
4877ec8d |
1101 | print &def($makefile_extra{'unix'}->{'end'}); |
b89e7e07 |
1102 | print "\nclean:\n". |
1103 | "\trm -f *.o". (join "", map { " $_" } &progrealnames("U")) . "\n"; |
1104 | print "\nFORCE:\n"; |
1105 | select STDOUT; close OUT; |
1106 | } |
1107 | |
44747c53 |
1108 | if (defined $makefiles{'am'}) { |
1109 | $dirpfx = "\$(srcdir)/" . &dirpfx($makefiles{'am'}, "/"); |
76d3a838 |
1110 | |
44747c53 |
1111 | ##-- Unix/autoconf Makefile.am |
1112 | open OUT, ">$makefiles{'am'}"; select OUT; |
76d3a838 |
1113 | print |
44747c53 |
1114 | "# Makefile.am for $project_name under Unix with Autoconf/Automake.\n". |
76d3a838 |
1115 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
44747c53 |
1116 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n\n"; |
1117 | |
1118 | # Complete list of source and header files. Not used by the |
1119 | # auto-generated parts of this makefile, but Recipe might like to |
1120 | # have it available as a variable so that mandatory-rebuild things |
1121 | # (version.o) can conveniently be made to depend on it. |
1122 | @sources = ("allsources", "=", |
1123 | map {"${dirpfx}$_"} sort keys %allsourcefiles); |
1124 | print &splitline(join " ", @sources), "\n\n"; |
1125 | |
1126 | @cliprogs = ("bin_PROGRAMS", "="); |
1127 | foreach $p (&prognames("U")) { |
76d3a838 |
1128 | ($prog, $type) = split ",", $p; |
44747c53 |
1129 | push @cliprogs, $prog; |
76d3a838 |
1130 | } |
44747c53 |
1131 | @allprogs = @cliprogs; |
1132 | foreach $p (&prognames("X")) { |
1133 | ($prog, $type) = split ",", $p; |
1134 | push @allprogs, $prog; |
1135 | } |
1136 | print "if HAVE_GTK\n"; |
1137 | print &splitline(join " ", @allprogs), "\n"; |
1138 | print "else\n"; |
1139 | print &splitline(join " ", @cliprogs), "\n"; |
1140 | print "endif\n\n"; |
1141 | |
1142 | %objtosrc = (); |
1143 | foreach $d (&deps("X", undef, $dirpfx, "/", "am")) { |
1144 | $objtosrc{$d->{obj}} = $d->{deps}->[0]; |
1145 | } |
1146 | |
1147 | @amcflags = ("\$(COMPAT)", "\$(XFLAGS)", map {"-I$dirpfx$_"} @srcdirs); |
1148 | print "if HAVE_GTK\n"; |
1149 | print &splitline(join " ", "AM_CFLAGS", "=", |
1150 | "\$(GTK_CFLAGS)", @amcflags), "\n"; |
1151 | print "else\n"; |
1152 | print &splitline(join " ", "AM_CFLAGS", "=", @amcflags), "\n"; |
1153 | print "endif\n\n"; |
1154 | |
1155 | %amspeciallibs = (); |
1156 | foreach $obj (sort { $a cmp $b } keys %{$cflags{'am'}}) { |
1157 | print "lib${obj}_a_SOURCES = ", $objtosrc{$obj}, "\n"; |
1158 | print &splitline(join " ", "lib${obj}_a_CFLAGS", "=", @amcflags, |
1159 | $cflags{'am'}->{$obj}), "\n"; |
1160 | $amspeciallibs{$obj} = "lib${obj}.a"; |
1161 | } |
1162 | print &splitline(join " ", "noinst_LIBRARIES", "=", |
1163 | sort { $a cmp $b } values %amspeciallibs), "\n\n"; |
1164 | |
1165 | foreach $p (&prognames("X:U")) { |
1166 | ($prog, $type) = split ",", $p; |
1167 | print "if HAVE_GTK\n" if $type eq "X"; |
1168 | @progsources = ("${prog}_SOURCES", "="); |
1169 | %sourcefiles = (); |
1170 | @ldadd = (); |
1171 | $objstr = &objects($p, "X", undef, undef); |
1172 | foreach $obj (split / /,$objstr) { |
1173 | if ($amspeciallibs{$obj}) { |
1174 | push @ldadd, $amspeciallibs{$obj}; |
1175 | } else { |
1176 | $sourcefiles{$objtosrc{$obj}} = 1; |
1177 | } |
976374cd |
1178 | } |
44747c53 |
1179 | push @progsources, sort { $a cmp $b } keys %sourcefiles; |
1180 | print &splitline(join " ", @progsources), "\n"; |
1181 | if ($type eq "X") { |
1182 | push @ldadd, "\$(GTK_LIBS)"; |
1183 | } |
1184 | if (@ldadd) { |
1185 | print &splitline(join " ", "${prog}_LDADD", "=", @ldadd), "\n"; |
1186 | } |
1187 | print "endif\n" if $type eq "X"; |
1188 | print "\n"; |
e35fb54b |
1189 | } |
44747c53 |
1190 | print $makefile_extra{'am'}->{'end'}; |
e35fb54b |
1191 | select STDOUT; close OUT; |
1192 | } |
f8422c0b |
1193 | |
e35fb54b |
1194 | if (defined $makefiles{'lcc'}) { |
cdd310bb |
1195 | $dirpfx = &dirpfx($makefiles{'lcc'}, "\\"); |
1196 | |
e35fb54b |
1197 | ##-- lcc makefile |
1198 | open OUT, ">$makefiles{'lcc'}"; select OUT; |
1199 | print |
1200 | "# Makefile for $project_name under lcc.\n". |
1201 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
1202 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
1203 | # lcc command line option is -D not /D |
4877ec8d |
1204 | ($_ = $help) =~ s/([=" ])\/D/$1-D/gs; |
e35fb54b |
1205 | print $_; |
1206 | print |
1207 | "\n". |
1208 | "# If you rename this file to `Makefile', you should change this line,\n". |
1209 | "# so that the .rsp files still depend on the correct makefile.\n". |
1210 | "MAKEFILE = Makefile.lcc\n". |
1211 | "\n". |
1212 | "# C compilation flags\n". |
cdd310bb |
1213 | "CFLAGS = -D_WINDOWS " . |
1214 | (join " ", map {"-I$dirpfx$_"} @srcdirs) . |
1215 | "\n". |
976374cd |
1216 | "# Resource compilation flags\n". |
1217 | "RCFLAGS = \n". |
e35fb54b |
1218 | "\n". |
1219 | "# Get include directory for resource compiler\n". |
77603464 |
1220 | "\n". |
1221 | $makefile_extra{'lcc'}->{'vars'} . |
4e95095a |
1222 | "\n"; |
1ddda1ca |
1223 | print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C")); |
e35fb54b |
1224 | print "\n\n"; |
1ddda1ca |
1225 | foreach $p (&prognames("G:C")) { |
e35fb54b |
1226 | ($prog, $type) = split ",", $p; |
1227 | $objstr = &objects($p, "X.obj", "X.res", undef); |
1228 | print &splitline("$prog.exe: " . $objstr ), "\n"; |
4877ec8d |
1229 | $subsystemtype = ''; |
e35fb54b |
1230 | if ($type eq "G") { $subsystemtype = "-subsystem windows"; } |
1231 | my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib"; |
1232 | print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss"); |
1233 | print "\n\n"; |
1234 | } |
4e95095a |
1235 | |
6da41155 |
1236 | foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\", "lcc")) { |
976374cd |
1237 | if ($forceobj{$d->{obj_orig}}) { |
1238 | printf("%s: FORCE\n", $d->{obj}); |
1239 | } else { |
1240 | print &splitline(sprintf("%s: %s", $d->{obj}, |
1241 | join " ", @{$d->{deps}})), "\n"; |
1242 | } |
6da41155 |
1243 | if ($d->{obj} =~ /\.obj$/) { |
d8284c29 |
1244 | print &splitline("\tlcc -O -p6 \$(COMPAT)". |
a77c6ed3 |
1245 | " \$(CFLAGS) \$(XFLAGS) ".$d->{deps}->[0],69)."\n"; |
6da41155 |
1246 | } else { |
976374cd |
1247 | print &splitline("\tlrc \$(RCFL) -r \$(RCFLAGS) ". |
1248 | $d->{deps}->[0],69)."\n"; |
6da41155 |
1249 | } |
e35fb54b |
1250 | } |
1251 | print "\n"; |
77603464 |
1252 | print $makefile_extra{'lcc'}->{'end'}; |
e35fb54b |
1253 | print "\nclean:\n". |
1254 | "\t-del *.obj\n". |
1255 | "\t-del *.exe\n". |
976374cd |
1256 | "\t-del *.res\n". |
1257 | "\n". |
1258 | "FORCE:\n"; |
4e95095a |
1259 | |
e35fb54b |
1260 | select STDOUT; close OUT; |
1261 | } |
1ddda1ca |
1262 | |
1263 | if (defined $makefiles{'osx'}) { |
1264 | $dirpfx = &dirpfx($makefiles{'osx'}, "/"); |
1265 | |
1266 | ##-- Mac OS X makefile |
1267 | open OUT, ">$makefiles{'osx'}"; select OUT; |
1268 | print |
1269 | "# Makefile for $project_name under Mac OS X.\n". |
1270 | "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n". |
1271 | "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n"; |
1272 | # gcc command line option is -D not /D |
4877ec8d |
1273 | ($_ = $help) =~ s/([=" ])\/D/$1-D/gs; |
1ddda1ca |
1274 | print $_; |
1275 | print |
1276 | "CC = \$(TOOLPATH)gcc\n". |
1277 | "\n". |
1278 | &splitline("CFLAGS = -O2 -Wall -Werror -g " . |
1279 | (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n". |
1280 | "MLDFLAGS = -framework Cocoa\n". |
1281 | "ULDFLAGS =\n". |
1ddda1ca |
1282 | "\n" . |
77603464 |
1283 | $makefile_extra{'osx'}->{'vars'} . |
1284 | "\n" . |
1285 | &splitline("all:" . join "", map { " $_" } &progrealnames("MX:U")) . |
1ddda1ca |
1286 | "\n"; |
1287 | foreach $p (&prognames("MX")) { |
1288 | ($prog, $type) = split ",", $p; |
1289 | $objstr = &objects($p, "X.o", undef, undef); |
1290 | $icon = &special($p, ".icns"); |
1291 | $infoplist = &special($p, "info.plist"); |
1292 | print "${prog}.app:\n\tmkdir -p \$\@\n"; |
1293 | print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n"; |
1294 | print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n"; |
1295 | $targets = "${prog}.app/Contents/MacOS/$prog"; |
1296 | if (defined $icon) { |
1297 | print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n"; |
1298 | print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n"; |
1299 | $targets .= " ${prog}.app/Contents/Resources/${prog}.icns"; |
1300 | } |
1301 | if (defined $infoplist) { |
1302 | print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n"; |
1303 | $targets .= " ${prog}.app/Contents/Info.plist"; |
1304 | } |
1305 | $targets .= " \$(${prog}_extra)"; |
1306 | print &splitline("${prog}: $targets", 69) . "\n\n"; |
1307 | print &splitline("${prog}.app/Contents/MacOS/$prog: ". |
1308 | "${prog}.app/Contents/MacOS " . $objstr), "\n"; |
1309 | $libstr = &objects($p, undef, undef, "-lX"); |
4877ec8d |
1310 | print &splitline("\t\$(CC) \$(MLDFLAGS) -o \$@ " . |
1ddda1ca |
1311 | $objstr . " $libstr", 69), "\n\n"; |
1312 | } |
1313 | foreach $p (&prognames("U")) { |
1314 | ($prog, $type) = split ",", $p; |
1315 | $objstr = &objects($p, "X.o", undef, undef); |
1316 | print &splitline($prog . ": " . $objstr), "\n"; |
1317 | $libstr = &objects($p, undef, undef, "-lX"); |
4877ec8d |
1318 | print &splitline("\t\$(CC) \$(ULDFLAGS) -o \$@ " . |
1ddda1ca |
1319 | $objstr . " $libstr", 69), "\n\n"; |
1320 | } |
4877ec8d |
1321 | foreach $d (&deps("X.o", undef, $dirpfx, "/", "osx")) { |
976374cd |
1322 | if ($forceobj{$d->{obj_orig}}) { |
1323 | printf("%s: FORCE\n", $d->{obj}); |
1324 | } else { |
1325 | print &splitline(sprintf("%s: %s", $d->{obj}, |
1326 | join " ", @{$d->{deps}})), "\n"; |
1327 | } |
1ddda1ca |
1328 | $firstdep = $d->{deps}->[0]; |
1329 | if ($firstdep =~ /\.c$/) { |
a77c6ed3 |
1330 | print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS) -c \$<\n"; |
1ddda1ca |
1331 | } elsif ($firstdep =~ /\.m$/) { |
a77c6ed3 |
1332 | print "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS) -c \$<\n"; |
1ddda1ca |
1333 | } |
1334 | } |
4877ec8d |
1335 | print "\n".&def($makefile_extra{'osx'}->{'end'}); |
1ddda1ca |
1336 | print "\nclean:\n". |
976374cd |
1337 | "\trm -f *.o *.dmg". (join "", map { " $_" } &progrealnames("U")) . "\n". |
4877ec8d |
1338 | "\trm -rf *.app\n". |
976374cd |
1339 | "\n". |
1340 | "FORCE:\n"; |
1ddda1ca |
1341 | select STDOUT; close OUT; |
1342 | } |
985b6440 |
1343 | |
1344 | if (defined $makefiles{'devcppproj'}) { |
1345 | $dirpfx = &dirpfx($makefiles{'devcppproj'}, "\\"); |
1346 | $orig_dir = cwd; |
1347 | |
1348 | ##-- Dev-C++ 5 projects |
1349 | # |
1350 | # Note: All files created in this section are written in binary |
1351 | # mode to prevent any posibility of misinterpreted line endings. |
1352 | # I don't know if Dev-C++ is as touchy as MSVC with LF-only line |
1353 | # endings. But however, CRLF line endings are the common way on |
1354 | # Win32 machines where Dev-C++ is running. |
1355 | # Hence, in order for mkfiles.pl to generate CRLF project files |
1356 | # even when run from Unix, I make sure all files are binary and |
1357 | # explicitly write the CRLFs. |
1358 | # |
1359 | # Create directories if necessary |
1360 | mkdir $makefiles{'devcppproj'} |
1361 | if(! -d $makefiles{'devcppproj'}); |
1362 | chdir $makefiles{'devcppproj'}; |
1363 | @deps = &deps("X.obj", "X.res", $dirpfx, "\\", "devcppproj"); |
1364 | %all_object_deps = map {$_->{obj} => $_->{deps}} @deps; |
1365 | # Make dir names FAT/NTFS compatible |
1366 | my @srcdirs = @srcdirs; |
1367 | for ($i=0; $i<@srcdirs; $i++) { |
1368 | $srcdirs[$i] =~ s/\//\\/g; |
1369 | $srcdirs[$i] =~ s/\\$//; |
1370 | } |
1371 | # Create the project files |
1372 | # Get names of all Windows projects (GUI and console) |
1373 | my @prognames = &prognames("G:C"); |
1374 | foreach $progname (@prognames) { |
1375 | create_devcpp_project(\%all_object_deps, $progname); |
1376 | } |
1377 | |
bc7af299 |
1378 | chdir $orig_dir; |
1379 | |
985b6440 |
1380 | sub create_devcpp_project { |
1381 | my ($all_object_deps, $progname) = @_; |
1382 | # Construct program's dependency info (Taken from 'vcproj', seems to work right here, too.) |
1383 | %seen_objects = (); |
1384 | %lib_files = (); |
1385 | %source_files = (); |
1386 | %header_files = (); |
1387 | %resource_files = (); |
1388 | @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib"); |
1389 | foreach $object_file (@object_files) { |
1390 | next if defined $seen_objects{$object_file}; |
1391 | $seen_objects{$object_file} = 1; |
1392 | if($object_file =~ /\.lib$/io) { |
1393 | $lib_files{$object_file} = 1; |
1394 | next; |
1395 | } |
1396 | $object_deps = $all_object_deps{$object_file}; |
1397 | foreach $object_dep (@$object_deps) { |
1398 | if($object_dep =~ /\.c$/io) { |
1399 | $source_files{$object_dep} = 1; |
1400 | next; |
1401 | } |
1402 | if($object_dep =~ /\.h$/io) { |
1403 | $header_files{$object_dep} = 1; |
1404 | next; |
1405 | } |
1406 | if($object_dep =~ /\.(rc|ico)$/io) { |
1407 | $resource_files{$object_dep} = 1; |
1408 | next; |
1409 | } |
1410 | } |
1411 | } |
1412 | $libs = join " ", sort keys %lib_files; |
1413 | @source_files = sort keys %source_files; |
1414 | @header_files = sort keys %header_files; |
1415 | @resources = sort keys %resource_files; |
1416 | ($windows_project, $type) = split ",", $progname; |
1417 | mkdir $windows_project |
1418 | if(! -d $windows_project); |
1419 | chdir $windows_project; |
1420 | |
1421 | $subsys = ($type eq "G") ? "0" : "1"; # 0 = Win32 GUI, 1 = Win32 Console |
1422 | open OUT, ">$windows_project.dev"; binmode OUT; select OUT; |
1423 | print |
1424 | "# DEV-C++ 5 Project File - $windows_project.dev\r\n". |
1425 | "# ** DO NOT EDIT **\r\n". |
1426 | "\r\n". |
1427 | # No difference between DEBUG and RELEASE here as in 'vcproj', because |
1428 | # Dev-C++ does not support mutiple compilation profiles in one single project. |
1429 | # (At least I can say this for Dev-C++ 5 Beta) |
1430 | "[Project]\r\n". |
1431 | "FileName=$windows_project.dev\r\n". |
1432 | "Name=$windows_project\r\n". |
1433 | "Ver=1\r\n". |
1434 | "IsCpp=1\r\n". |
1435 | "Type=$subsys\r\n". |
1436 | # Multimon is disabled here, as Dev-C++ (Version 5 Beta) does not have multimon.h |
1437 | "Compiler=-W -D__GNUWIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNO_MULTIMON -D_MBCS_\@\@_\r\n". |
1438 | "CppCompiler=-W -D__GNUWIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNO_MULTIMON -D_MBCS_\@\@_\r\n". |
1439 | "Includes=" . (join ";", map {"..\\..\\$dirpfx$_"} @srcdirs) . "\r\n". |
1440 | "Linker=-ladvapi32 -lcomctl32 -lcomdlg32 -lgdi32 -limm32 -lshell32 -luser32 -lwinmm -lwinspool_\@\@_\r\n". |
1441 | "Libs=\r\n". |
1442 | "UnitCount=" . (@source_files + @header_files + @resources) . "\r\n". |
1443 | "Folders=\"Header Files\",\"Resource Files\",\"Source Files\"\r\n". |
1444 | "ObjFiles=\r\n". |
1445 | "PrivateResource=${windows_project}_private.rc\r\n". |
1446 | "ResourceIncludes=..\\..\\..\\WINDOWS\r\n". |
1447 | "MakeIncludes=\r\n". |
1448 | "Icon=\r\n". # It's ok to leave this blank. |
1449 | "ExeOutput=\r\n". |
1450 | "ObjectOutput=\r\n". |
1451 | "OverrideOutput=0\r\n". |
1452 | "OverrideOutputName=$windows_project.exe\r\n". |
1453 | "HostApplication=\r\n". |
1454 | "CommandLine=\r\n". |
1455 | "UseCustomMakefile=0\r\n". |
1456 | "CustomMakefile=\r\n". |
1457 | "IncludeVersionInfo=0\r\n". |
1458 | "SupportXPThemes=0\r\n". |
1459 | "CompilerSet=0\r\n". |
1460 | "CompilerSettings=0000000000000000000000\r\n". |
1461 | "\r\n"; |
1462 | $unit_count = 1; |
1463 | foreach $source_file (@source_files) { |
1464 | print |
1465 | "[Unit$unit_count]\r\n". |
1466 | "FileName=..\\..\\$source_file\r\n". |
1467 | "Folder=Source Files\r\n". |
1468 | "Compile=1\r\n". |
1469 | "CompileCpp=0\r\n". |
1470 | "Link=1\r\n". |
1471 | "Priority=1000\r\n". |
1472 | "OverrideBuildCmd=0\r\n". |
1473 | "BuildCmd=\r\n". |
1474 | "\r\n"; |
1475 | $unit_count++; |
1476 | } |
1477 | foreach $header_file (@header_files) { |
1478 | print |
1479 | "[Unit$unit_count]\r\n". |
1480 | "FileName=..\\..\\$header_file\r\n". |
1481 | "Folder=Header Files\r\n". |
1482 | "Compile=1\r\n". |
1483 | "CompileCpp=1\r\n". # Dev-C++ want's to compile all header files with both compilers C and C++. It does not hurt. |
1484 | "Link=1\r\n". |
1485 | "Priority=1000\r\n". |
1486 | "OverrideBuildCmd=0\r\n". |
1487 | "BuildCmd=\r\n". |
1488 | "\r\n"; |
1489 | $unit_count++; |
1490 | } |
1491 | foreach $resource_file (@resources) { |
1492 | if ($resource_file =~ /.*\.(ico|cur|bmp|dlg|rc2|rct|bin|rgs|gif|jpg|jpeg|jpe)/io) { # Default filter as in 'vcproj' |
1493 | $Compile = "0"; # Don't compile images and other binary resource files |
1494 | $CompileCpp = "0"; |
1495 | } else { |
1496 | $Compile = "1"; |
1497 | $CompileCpp = "1"; # Dev-C++ want's to compile all .rc files with both compilers C and C++. It does not hurt. |
1498 | } |
1499 | print |
1500 | "[Unit$unit_count]\r\n". |
1501 | "FileName=..\\..\\$resource_file\r\n". |
1502 | "Folder=Resource Files\r\n". |
1503 | "Compile=$Compile\r\n". |
1504 | "CompileCpp=$CompileCpp\r\n". |
1505 | "Link=0\r\n". |
1506 | "Priority=1000\r\n". |
1507 | "OverrideBuildCmd=0\r\n". |
1508 | "BuildCmd=\r\n". |
1509 | "\r\n"; |
1510 | $unit_count++; |
1511 | } |
1512 | #Note: By default, [VersionInfo] is not used. |
1513 | print |
1514 | "[VersionInfo]\r\n". |
1515 | "Major=0\r\n". |
1516 | "Minor=0\r\n". |
1517 | "Release=1\r\n". |
1518 | "Build=1\r\n". |
1519 | "LanguageID=1033\r\n". |
1520 | "CharsetID=1252\r\n". |
1521 | "CompanyName=\r\n". |
1522 | "FileVersion=0.1\r\n". |
1523 | "FileDescription=\r\n". |
1524 | "InternalName=\r\n". |
1525 | "LegalCopyright=\r\n". |
1526 | "LegalTrademarks=\r\n". |
1527 | "OriginalFilename=$windows_project.exe\r\n". |
1528 | "ProductName=$windows_project\r\n". |
1529 | "ProductVersion=0.1\r\n". |
1530 | "AutoIncBuildNr=0\r\n"; |
1531 | select STDOUT; close OUT; |
1532 | chdir ".."; |
1533 | } |
1534 | } |
bc7af299 |
1535 | |
1536 | # All done, so do the Unix postprocessing if asked to. |
1537 | |
1538 | if ($do_unix) { |
1539 | chdir $orig_dir; |
1540 | system "./mkauto.sh"; |
1541 | die "mkfiles.pl: mkauto.sh returned $?\n" if $? > 0; |
1542 | chdir ($targetdir = dirname($makefiles{"am"})) |
1543 | or die "$targetdir: chdir: $!\n"; |
1544 | system "./configure", @confargs; |
1545 | die "mkfiles.pl: configure returned $?\n" if $? > 0; |
1546 | } |