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