OSDN Git Service

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