Fix signed/unsigned comparison warnings.
[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 %directories = ();
28 my %implib_dirs = ();
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   "glut32"   => "GLUT32FILES",
37   "opengl32" => "OPENGLFILES",
38   "d3d8"     => "OPENGLFILES",
39   "d3d9"     => "OPENGLFILES",
40   "d3dx8"    => "OPENGLFILES",
41   "wined3d"  => "OPENGLFILES",
42   "x11drv"   => "XFILES"
43 );
44
45 foreach my $i (split(/\s/,$makefiles))
46 {
47     my $module;
48
49     next if $i =~ /\/tests\/Makefile.in/;
50
51     open MAKE,$i;
52
53     $module = undef;
54     while (<MAKE>)
55     {
56         chop;
57         # EPP hack to disable this DLL... the MKDLL_SKIP comment must appear
58         # at the very top of the Makefile.in
59         last if (/^\#\s*MKDLL_SKIP/);
60
61         if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
62         {
63             $module = $1;
64             if ($module =~ /^lib.*\.a$/)
65             {
66                 ($implib_dirs{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
67             }
68             else
69             {
70                 ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
71             }
72             next;
73         }
74         if (/^SPEC_SRCS16\s*=\s*(.*)/)
75         {
76             my $specs = $1;
77             while ($specs =~ /\s*(.*)\\$/) { $specs = $1 . <MAKE>; }
78             my @list = split(/\s+/,$specs);
79             @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @list;
80             $altnames{$module} = \@list;
81             next;
82         }
83     }
84     close MAKE;
85 }
86
87 open NEWMAKE,">Makefile.in.new" or die "cannot create Makefile.in.new";
88
89 ################################################################
90 # makefile header
91
92 print NEWMAKE <<EOF;
93 # Automatically generated by make_dlls; DO NOT EDIT!!
94
95 TOPSRCDIR = \@top_srcdir\@
96 TOPOBJDIR = ..
97 SRCDIR    = \@srcdir\@
98 VPATH     = \@srcdir\@
99
100 EOF
101
102 ################################################################
103 # output special dlls configure definitions
104
105 printf NEWMAKE "# special configure-dependent targets\n\n";
106 my %specials = ();
107 foreach my $mod (sort keys %special_dlls)
108 {
109     $specials{$special_dlls{$mod}} .= " " . $mod;
110 }
111 foreach my $i (sort keys %specials)
112 {
113     printf NEWMAKE "%s =%s\n", $i, $specials{$i};
114 }
115 printf NEWMAKE "EXTRADIRS =";
116 foreach my $i (sort keys %specials) { printf NEWMAKE " \@%s\@", $i; }
117 printf NEWMAKE "\n\n";
118
119
120 ################################################################
121 # output the subdirs list
122
123 print NEWMAKE "# Subdir list\n\nBASEDIRS =";
124 foreach my $dir (sort values %directories)
125 {
126     next if defined($special_dlls{$dir});  # skip special dlls
127     printf NEWMAKE " \\\n\t%s", $dir;
128 }
129
130 printf NEWMAKE "\n\nSUBDIRS = \\\n\t\$(BASEDIRS)";
131 foreach my $dir (sort (keys %special_dlls, values %implib_dirs))
132 {
133     printf NEWMAKE " \\\n\t%s", $dir;
134 }
135 printf NEWMAKE <<EOF;
136
137
138 BUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)
139
140 INSTALLSUBDIRS = \$(BUILDSUBDIRS)
141 EOF
142
143 ################################################################
144 # output the all: target
145
146 my %targets = ();  # use a hash to get rid of duplicate target names
147 my %targets16 = ();
148 foreach my $mod (sort keys %directories)
149 {
150     next if defined($special_dlls{$directories{$mod}});  # skip special dlls
151     $targets{$mod . ".so"} = 1;
152     next unless defined $altnames{$mod};
153     foreach my $i (sort @{$altnames{$mod}})
154     {
155         $targets16{sprintf("%s.so",$i)} = 1;
156     }
157 }
158 foreach my $mod (sort keys %implib_dirs) { $targets{$mod} = 1; }
159
160 print NEWMAKE <<EOF;
161
162 \@MAKE_RULES\@
163
164 # Symbolic links
165
166 WIN16_FILES = \\
167 EOF
168 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets16 );
169
170 print NEWMAKE <<EOF;
171
172 SYMLINKS_SO = \\
173         \$(EXTRADIRS:%=%.dll.so) \\
174         \@WIN16_FILES\@ \\
175 EOF
176 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );
177
178 print NEWMAKE <<EOF;
179
180 # Main target
181
182 all: symlinks\$(DLLEXT)
183
184 .PHONY: symlinks symlinks.so implib
185
186 symlinks.so: \$(SYMLINKS_SO)
187
188 symlinks: \$(BUILDSUBDIRS)
189
190 EOF
191
192 ################################################################
193 # output the lib name -> directory rules
194
195 print NEWMAKE <<EOF;
196
197 # Map symlink name to the corresponding library
198
199 EOF
200
201 foreach my $mod (sort keys %directories)
202 {
203     printf NEWMAKE "%s.so: %s/%s.so\n", $mod, $directories{$mod}, $mod;
204     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s.so \$@\n\n", $directories{$mod}, $mod;
205
206     if (defined $altnames{$mod})
207     {
208         my $count = 0;
209         foreach my $i (sort @{$altnames{$mod}})
210         {
211             if ($count++ == 3) { printf NEWMAKE "\\\n  "; $count = 1; }
212             printf NEWMAKE "%s.so ", $i;
213         }
214         printf NEWMAKE ": %s.so\n", $mod;
215         printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s.so \$@\n\n", $mod;
216     }
217 }
218 foreach my $mod (sort keys %implib_dirs)
219 {
220     printf NEWMAKE "%s: %s/%s\n", $mod, $implib_dirs{$mod}, $mod;
221     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $implib_dirs{$mod}, $mod;
222 }
223
224 ################################################################
225 # output the import libraries rules
226
227 my @implibs = grep /\.dll$/, keys %directories;
228 push @implibs, "winspool.drv";
229
230 print NEWMAKE "\n# Import libraries\n\nIMPORT_LIBS =";
231 foreach my $mod (sort @implibs)
232 {
233     my $def = $mod;
234     $def =~ s/\.(dll|drv)$//;
235     printf NEWMAKE " \\\n\tlib%s.\$(IMPLIBEXT)", $def;
236 }
237 foreach my $mod (sort keys %implib_dirs)
238 {
239     printf NEWMAKE " \\\n\t%s", $mod;
240 }
241 print NEWMAKE "\n\n";
242 print NEWMAKE "implib: \$(IMPORT_LIBS)\n\n";
243
244 foreach my $mod (sort @implibs)
245 {
246     my $dir = $directories{$mod};
247     my $def = $mod;
248     my $spec = $mod;
249     $spec =~ s/\.dll$//;
250     $def =~ s/\.(dll|drv)$//;
251     printf NEWMAKE "lib%s.def: %s/%s.spec.def\n", $def, $dir, $spec;
252     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s.spec.def \$@\n", $dir, $spec;
253     printf NEWMAKE "lib%s.a: %s/%s.spec.def\n", $def, $dir, $spec;
254     printf NEWMAKE "\t\$(DLLTOOL) -k -l \$@ -d %s/%s.spec.def\n\n", $dir, $spec;
255 }
256 foreach my $mod (sort @implibs)
257 {
258     my $dir = $directories{$mod};
259     my $spec = $mod;
260     $spec =~ s/\.dll$//;
261     printf NEWMAKE "%s/%s.spec.def: \$(WINEBUILD)\n", $dir, $spec;
262 }
263
264
265 print NEWMAKE <<EOF;
266
267 \$(BUILDSUBDIRS): \$(IMPORT_LIBS)
268 \$(INSTALLSUBDIRS:%=%/__install__): \$(IMPORT_LIBS)
269
270 EOF
271
272 ################################################################
273 # output the inter-dll dependencies and rules
274
275 print NEWMAKE "# Map library name to the corresponding directory\n\n";
276
277 foreach my $mod (sort keys %directories)
278 {
279     printf NEWMAKE "%s/%s.so: %s\n", $directories{$mod}, $mod, $directories{$mod};
280 }
281 foreach my $mod (sort keys %implib_dirs)
282 {
283     printf NEWMAKE "%s/%s: %s\n", $implib_dirs{$mod}, $mod, $implib_dirs{$mod};
284 }
285
286 ################################################################
287 # makefile trailer
288
289 print NEWMAKE <<EOF;
290
291 # Rules for auto documentation
292
293 \$(SUBDIRS:%=%/__man__): dummy
294         cd `dirname \$@` && \$(MAKE) man
295
296 man: \$(SUBDIRS:%=%/__man__)
297
298 \$(SUBDIRS:%=%/__doc_html__): dummy
299         cd `dirname \$@` && \$(MAKE) doc-html
300
301 doc-html: \$(SUBDIRS:%=%/__doc_html__)
302
303 \$(SUBDIRS:%=%/__doc_sgml__): dummy
304         cd `dirname \$@` && \$(MAKE) doc-sgml
305
306 doc-sgml: \$(SUBDIRS:%=%/__doc_sgml__)
307
308 .PHONY: man doc-html doc-sgml \$(SUBDIRS:%=%/__man__) \$(SUBDIRS:%=%/__doc_html__) \$(SUBDIRS:%=%/__doc_sgml__)
309
310 # Misc rules
311
312 install install-dev:: \$(IMPORT_LIBS)
313         \$(MKINSTALLDIRS) \$(dlldir)
314         for f in \$(IMPORT_LIBS); do \$(INSTALL_DATA) \$\$f \$(dlldir)/\$\$f; done
315
316 install install-lib:: \$(INSTALLSUBDIRS:%=%/__install__)
317
318 uninstall::
319         -cd \$(dlldir) && \$(RM) \$(IMPORT_LIBS)
320         -rmdir \$(dlldir)
321
322 clean::
323         \$(RM) \$(IMPORT_LIBS) \$(SYMLINKS)
324
325 check test:: \$(BUILDSUBDIRS:%=%/__test__)
326
327 crosstest:: \$(BUILDSUBDIRS:%=%/__crosstest__)
328
329 checklink:: \$(BUILDSUBDIRS:%=%/__checklink__)
330
331 ### Dependencies:
332 EOF
333
334 close NEWMAKE;
335 rename "Makefile.in.new", "Makefile.in";
336 printf "Successfully updated Makefile.in\n";