Fixed some issues found by winapi_check.
[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 $makefiles = `find . -name Makefile.in -print`;
24
25 %imports = ();
26 %directories = ();
27 %altnames = ();
28 %linked_dlls = ();
29
30 # list of special dlls that can be switched on or off by configure
31 %special_dlls =
32 (
33   "ddraw"    => "XFILES",
34   "glu32"    => "GLU32FILES",
35   "opengl32" => "OPENGLFILES",
36   "x11drv"   => "XFILES"
37 );
38
39 foreach $i (split(/\s/,$makefiles))
40 {
41     open MAKE,$i;
42     while (<MAKE>)
43     {
44         chop;
45         if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
46         {
47             $module = $1;
48             ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
49             next;
50         }
51         if (/^ALTNAMES\s*=\s*(.*)/)
52         {
53             my @list = split(/\s/,$1);
54             $altnames{$module} = \@list;
55             next;
56         }
57         if (/^IMPORTS\s*=\s*(.*)/)
58         {
59             my @list = split(/\s/,$1);
60             $linked_dlls{$module} = \@list;
61             next;
62         }
63     }
64 }
65
66 foreach $mod (sort keys %directories)
67 {
68     my $dll = $mod;
69     $dll =~ s/\.dll$//;
70     my $spec = sprintf("%s/%s.spec", $directories{$mod}, $dll);
71     open SPEC,$spec or die "cannot open $spec";
72     $imports{$mod} = [ ];
73     while (<SPEC>)
74     {
75         if (/^\#?import\s+(-delay\s+)?([a-zA-Z0-9_]+)\.dll/)
76         {
77             my $imp = $2 . ".dll";
78             push @{$imports{$mod}}, $imp;
79             next;
80         }
81         if (/^\#?import\s+(-delay\s+)?([a-zA-Z0-9_.]+)/)
82         {
83             my $imp = $2;
84             $imp .= ".dll" unless ($imp =~ /\./);
85             push @{$imports{$mod}}, $imp;
86             next;
87         }
88     }
89 }
90
91 open NEWMAKE,">Makefile.in.new" or die "cannot create Makefile.in.new";
92
93 ################################################################
94 # makefile header
95
96 print NEWMAKE <<EOF;
97 # Automatically generated by make_dlls; DO NOT EDIT!!
98
99 TOPSRCDIR = \@top_srcdir\@
100 TOPOBJDIR = ..
101 SRCDIR    = \@srcdir\@
102 VPATH     = \@srcdir\@
103
104 EOF
105
106 ################################################################
107 # output special dlls configure definitions
108
109 printf NEWMAKE "# special configure-dependent targets\n\n";
110 my %specials = ();
111 foreach $mod (sort keys %special_dlls)
112 {
113     $specials{$special_dlls{$mod}} .= " " . $mod;
114 }
115 foreach $i (sort keys %specials)
116 {
117     printf NEWMAKE "%s =%s\n", $i, $specials{$i};
118 }
119 printf NEWMAKE "EXTRADIRS =";
120 foreach $i (sort keys %specials) { printf NEWMAKE " \@%s\@", $i; }
121 printf NEWMAKE "\n\n";
122
123
124 ################################################################
125 # output the subdirs list
126
127 print NEWMAKE <<EOF;
128 # Subdir list
129
130 SUBDIRS = \\
131 EOF
132 printf NEWMAKE "\t\$(EXTRADIRS)";
133 foreach $dir (sort values %directories)
134 {
135     next if defined($special_dlls{$dir});  # skip special dlls
136     printf NEWMAKE " \\\n\t%s", $dir;
137 }
138 printf NEWMAKE "\n";
139
140
141 ################################################################
142 # output the all: target
143
144 my %targets = ();  # use a hash to get rid of duplicate target names
145 foreach $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 $i (sort @{$altnames{$mod}})
151     {
152         $targets{sprintf("%s\$(DLLEXT)",$i)} = 1;
153     }
154 }
155 print NEWMAKE <<EOF;
156
157 # Main target
158
159 \@MAKE_RULES\@
160
161 all: \\
162         \$(EXTRADIRS:%=%.dll\$(DLLEXT)) \\
163 EOF
164 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );
165
166
167 ################################################################
168 # output the lib name -> directory rules
169
170 print NEWMAKE <<EOF;
171
172 # Map library name to directory
173
174 EOF
175
176 foreach $mod (sort keys %directories)
177 {
178     printf NEWMAKE "%s\$(DLLEXT)", $mod;
179     if (defined $altnames{$mod})
180     {
181         my $count = 1;
182         foreach $i (sort @{$altnames{$mod}})
183         {
184             if (!($count++ % 3)) { printf NEWMAKE " \\\n "; }
185             printf NEWMAKE " %s\$(DLLEXT)", $i;
186         }
187     }
188     printf NEWMAKE ": %s/%s\$(DLLEXT)\n", $directories{$mod}, $mod;
189     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
190 }
191
192
193 ################################################################
194 # output the inter-dll dependencies and rules
195
196 print NEWMAKE "# Inter-dll dependencies\n\n";
197
198 my @depends = ();
199 foreach $mod (sort keys %imports)
200 {
201     my $count = 1;
202     my $dep = sprintf("%s/%s\$(DLLEXT): dummy", $directories{$mod}, $mod);
203     foreach $i (@{$imports{$mod}})
204     {
205         if ($count++ >= 3)
206         {
207             $count = 0;
208             $dep .= " \\\n ";
209         }
210         $dep .= sprintf(" %s\$(DLLEXT)", $i);
211     }
212     foreach $i (@{$linked_dlls{$mod}})
213     {
214         if ($count++ >= 3)
215         {
216             $count = 0;
217             $dep .= " \\\n ";
218         }
219         $dep .= sprintf(" lib%s.\$(LIBEXT)", $i);
220     }
221     $dep .= sprintf("\n\t\@cd %s && \$(MAKE) %s\$(DLLEXT)\n\n",$directories{$mod}, $mod);
222     push @depends, $dep;
223 }
224 print NEWMAKE sort @depends;
225
226
227 ################################################################
228 # output the linkable dlls special links
229
230 %linkable_dlls = ();
231 foreach $mod (keys %imports)
232 {
233     foreach $i (@{$linked_dlls{$mod}}) { $linkable_dlls{$i} = 1; }
234 }
235
236 print NEWMAKE "# Special targets for dlls that we need to link to\n\n";
237 foreach $mod (keys %linkable_dlls)
238 {
239     printf NEWMAKE "lib%s.\$(LIBEXT): %s/%s\$(DLLEXT)\n", $mod, $directories{$mod}, $mod;
240     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
241 }
242
243 ################################################################
244 # makefile trailer
245
246 print NEWMAKE <<EOF;
247 # Misc rules
248
249 \$(SUBDIRS:%=%/__checklink__): dummy
250         \@cd `dirname \$\@` && \$(MAKE) checklink
251
252 \$(SUBDIRS:%=%/__debug_channels__): dummy
253         \@cd `dirname \$\@` && \$(MAKE) debug_channels
254
255 install:: \$(SUBDIRS:%=%/__install__)
256
257 uninstall:: \$(SUBDIRS:%=%/__uninstall__)
258         -rmdir \$(dlldir)
259
260 check test:: \$(SUBDIRS:%=%/__test__)
261
262 checklink:: \$(SUBDIRS:%=%/__checklink__)
263
264 debug_channels:: \$(SUBDIRS:%=%/__debug_channels__)
265 EOF
266
267 close NEWMAKE;
268 rename "Makefile.in.new", "Makefile.in";
269 printf "Successfully updated Makefile.in\n";