Fixed bitmap range checking to avoid integer overflows.
[wine] / dlls / make_dlls
1 #!/usr/bin/perl -w
2 #
3 # Update the dll dependencies in the dlls main Makefile.in.
4 # Must be run in the dlls/ directory of the Wine tree.
5 #
6 # Copyright 2001 Alexandre Julliard
7 #
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 #
22
23 use strict;
24
25 my $makefiles = `find . -name Makefile.in -print`;
26
27 my %imports = ();
28 my %directories = ();
29 my %altnames = ();
30
31 # list of special dlls that can be switched on or off by configure
32 my %special_dlls =
33 (
34   "ddraw"    => "XFILES",
35   "glu32"    => "GLU32FILES",
36   "opengl32" => "OPENGLFILES",
37   "d3d8"     => "OPENGLFILES",
38   "d3d9"     => "OPENGLFILES",
39   "d3dx8"    => "OPENGLFILES",
40   "wined3d"  => "OPENGLFILES",
41   "x11drv"   => "XFILES"
42 );
43
44 foreach my $i (split(/\s/,$makefiles))
45 {
46     my $module;
47
48     next if $i =~ /\/tests\/Makefile.in/;
49
50     open MAKE,$i;
51
52     $module = undef;
53     while (<MAKE>)
54     {
55         chop;
56         # EPP hack to disable this DLL... the MKDLL_SKIP comment must appear
57         # at the very top of the Makefile.in
58         last if (/^\#\s*MKDLL_SKIP/);
59
60         if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
61         {
62             $module = $1;
63             $imports{$module} = [ ];
64             ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
65             next;
66         }
67         if (/^ALTNAMES\s*=\s*(.*)/)
68         {
69             my @list = split(/\s/,$1);
70             $altnames{$module} = \@list;
71             next;
72         }
73         if (/^(DELAYIMPORTS|IMPORTS)\s*=\s*(.*)/)
74         {
75             my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$2);
76             push @{$imports{$module}}, @list;
77             next;
78         }
79     }
80     close MAKE;
81     push @{$imports{$module}}, "kernel32.dll" unless !defined($module) || @{$imports{$module}} || $module eq "ntdll.dll";
82 }
83
84 open NEWMAKE,">Makefile.in.new" or die "cannot create Makefile.in.new";
85
86 ################################################################
87 # makefile header
88
89 print NEWMAKE <<EOF;
90 # Automatically generated by make_dlls; DO NOT EDIT!!
91
92 TOPSRCDIR = \@top_srcdir\@
93 TOPOBJDIR = ..
94 SRCDIR    = \@srcdir\@
95 VPATH     = \@srcdir\@
96
97 EOF
98
99 ################################################################
100 # output special dlls configure definitions
101
102 printf NEWMAKE "# special configure-dependent targets\n\n";
103 my %specials = ();
104 foreach my $mod (sort keys %special_dlls)
105 {
106     $specials{$special_dlls{$mod}} .= " " . $mod;
107 }
108 foreach my $i (sort keys %specials)
109 {
110     printf NEWMAKE "%s =%s\n", $i, $specials{$i};
111 }
112 printf NEWMAKE "EXTRADIRS =";
113 foreach my $i (sort keys %specials) { printf NEWMAKE " \@%s\@", $i; }
114 printf NEWMAKE "\n\n";
115
116
117 ################################################################
118 # output the subdirs list
119
120 print NEWMAKE "# Subdir list\n\nBASEDIRS =";
121 foreach my $dir (sort values %directories)
122 {
123     next if defined($special_dlls{$dir});  # skip special dlls
124     printf NEWMAKE " \\\n\t%s", $dir;
125 }
126
127 printf NEWMAKE "\n\nSUBDIRS = \\\n\t\$(BASEDIRS)";
128 foreach my $dir (sort keys %special_dlls)
129 {
130     printf NEWMAKE " \\\n\t%s", $dir;
131 }
132 printf NEWMAKE <<EOF;
133
134
135 BUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)
136
137 INSTALLSUBDIRS = \$(BUILDSUBDIRS)
138 EOF
139
140 ################################################################
141 # output the all: target
142
143 my %targets = ();  # use a hash to get rid of duplicate target names
144 my %targets16 = ();
145 foreach my $mod (sort keys %directories)
146 {
147     next if defined($special_dlls{$directories{$mod}});  # skip special dlls
148     $targets{sprintf("%s\$(DLLEXT)",$mod)} = 1;
149     next unless defined $altnames{$mod};
150     foreach my $i (sort @{$altnames{$mod}})
151     {
152         $targets16{sprintf("%s\$(DLLEXT)",$i)} = 1;
153     }
154 }
155 print NEWMAKE <<EOF;
156
157 \@MAKE_RULES\@
158
159 # Symbolic links
160
161 WIN16_FILES = \\
162 EOF
163 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets16 );
164
165 print NEWMAKE <<EOF;
166
167 SYMLINKS = \\
168         \$(EXTRADIRS:%=%.dll\$(DLLEXT)) \\
169         \@WIN16_FILES\@ \\
170 EOF
171 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );
172
173 print NEWMAKE <<EOF;
174
175 # Main target
176
177 all: \$(SYMLINKS)
178 EOF
179
180 ################################################################
181 # output the lib name -> directory rules
182
183 print NEWMAKE <<EOF;
184
185 # Map symlink name to the corresponding library
186
187 EOF
188
189 foreach my $mod (sort keys %directories)
190 {
191     printf NEWMAKE "%s\$(DLLEXT)", $mod;
192     if (defined $altnames{$mod})
193     {
194         my $count = 1;
195         foreach my $i (sort @{$altnames{$mod}})
196         {
197             if (!($count++ % 3)) { printf NEWMAKE " \\\n "; }
198             printf NEWMAKE " %s\$(DLLEXT)", $i;
199         }
200     }
201     printf NEWMAKE ": %s/%s\$(DLLEXT)\n", $directories{$mod}, $mod;
202     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
203 }
204
205
206 ################################################################
207 # output the import libraries rules
208
209 my @implibs = grep /\.dll$/, keys %directories;
210 push @implibs, "winspool.drv";
211
212 print NEWMAKE "\n# Import libraries\n\nIMPORT_LIBS =";
213 foreach my $mod (sort @implibs)
214 {
215     my $def = $mod;
216     $def =~ s/\.(dll|drv)$//;
217     printf NEWMAKE " \\\n\tlib%s", $def;
218 }
219 print NEWMAKE "\n\n";
220
221 foreach my $mod (sort @implibs)
222 {
223     my $dir = $directories{$mod};
224     my $def = $mod;
225     my $spec = $mod;
226     $spec =~ s/\.dll$//;
227     $def =~ s/\.(dll|drv)$//;
228     printf NEWMAKE "lib%s.def: %s/%s.spec.def\n", $def, $dir, $spec;
229     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s.spec.def \$@\n", $dir, $spec;
230     printf NEWMAKE "lib%s.a: %s/%s.spec.def\n", $def, $dir, $spec;
231     printf NEWMAKE "\t\$(DLLTOOL) -k -l \$@ -d %s/%s.spec.def\n\n", $dir, $spec;
232 }
233 foreach my $mod (sort @implibs)
234 {
235     my $dir = $directories{$mod};
236     my $spec = $mod;
237     $spec =~ s/\.dll$//;
238     printf NEWMAKE "%s/%s.spec.def: \$(WINEBUILD)\n", $dir, $spec;
239 }
240
241
242 print NEWMAKE <<EOF;
243
244 \$(SUBDIRS): \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT))
245 \$(SUBDIRS:%=%/__install__): \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT))
246 \$(SUBDIRS:%=%/__crosstest__): \$(IMPORT_LIBS:%=%.a)
247
248 EOF
249
250 ################################################################
251 # output the inter-dll dependencies and rules
252
253 print NEWMAKE "# Map library name to the corresponding directory\n\n";
254
255 foreach my $mod (sort keys %directories)
256 {
257     printf NEWMAKE "%s/%s\$(DLLEXT): %s\n", $directories{$mod}, $mod, $directories{$mod};
258 }
259
260 ################################################################
261 # makefile trailer
262
263 print NEWMAKE <<EOF;
264 # Rules for auto documentation
265
266 \$(SUBDIRS:%=%/__man__): dummy
267         cd `dirname \$@` && \$(MAKE) man
268
269 man: \$(SUBDIRS:%=%/__man__)
270
271 \$(SUBDIRS:%=%/__doc_html__): dummy
272         cd `dirname \$@` && \$(MAKE) doc-html
273
274 doc-html: \$(SUBDIRS:%=%/__doc_html__)
275
276 \$(SUBDIRS:%=%/__doc_sgml__): dummy
277         cd `dirname \$@` && \$(MAKE) doc-sgml
278
279 doc-sgml: \$(SUBDIRS:%=%/__doc_sgml__)
280
281 .PHONY: man doc-html doc-sgml \$(SUBDIRS:%=%/__man__) \$(SUBDIRS:%=%/__doc_html__) \$(SUBDIRS:%=%/__doc_sgml__)
282
283 # Misc rules
284
285 install install-dev:: \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT))
286         \$(MKINSTALLDIRS) \$(dlldir)
287         for f in \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT)); do \$(INSTALL_DATA) \$\$f \$(dlldir)/\$\$f; done
288
289 install install-lib:: \$(INSTALLSUBDIRS:%=%/__install__)
290
291 uninstall::
292         \$(RM) \$(IMPORT_LIBS:%=\$(dlldir)/%.\$(IMPLIBEXT))
293         -rmdir \$(dlldir)
294
295 clean::
296         \$(RM) \$(IMPORT_LIBS:%=%.a) \$(IMPORT_LIBS:%=%.def) \$(SYMLINKS)
297
298 check test:: \$(BUILDSUBDIRS:%=%/__test__)
299
300 crosstest:: \$(BUILDSUBDIRS:%=%/__crosstest__)
301
302 checklink:: \$(BUILDSUBDIRS:%=%/__checklink__)
303
304 ### Dependencies:
305 EOF
306
307 close NEWMAKE;
308 rename "Makefile.in.new", "Makefile.in";
309 printf "Successfully updated Makefile.in\n";