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