Implemented NetQueryDisplayInformation, NetUserGetInfo, created
[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 my %linked_dlls = ();
31
32 # list of special dlls that can be switched on or off by configure
33 my %special_dlls =
34 (
35   "ddraw"    => "XFILES",
36   "glu32"    => "GLU32FILES",
37   "opengl32" => "OPENGLFILES",
38   "x11drv"   => "XFILES"
39 );
40
41 foreach my $i (split(/\s/,$makefiles))
42 {
43     my $module;
44
45     next if $i =~ /\/tests\/Makefile.in/;
46
47     open MAKE,$i;
48
49     $module = undef;
50     while (<MAKE>)
51     {
52         chop;
53         # EPP hack to disable this DLL... the MKDLL_SKIP comment must appear
54         # at the very top of the Makefile.in
55         last if (/^\#\s*MKDLL_SKIP/);
56
57         if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
58         {
59             $module = $1;
60             $imports{$module} = [ ];
61             ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
62             next;
63         }
64         if (/^ALTNAMES\s*=\s*(.*)/)
65         {
66             my @list = split(/\s/,$1);
67             $altnames{$module} = \@list;
68             next;
69         }
70         if (/^(DELAYIMPORTS|IMPORTS)\s*=\s*(.*)/)
71         {
72             my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$2);
73             push @{$imports{$module}}, @list;
74             next;
75         }
76         if (/^LDIMPORTS\s*=\s*(.*)/)
77         {
78             my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$1);
79             $linked_dlls{$module} = \@list;
80             next;
81         }
82     }
83     close MAKE;
84     push @{$imports{$module}}, "kernel32.dll" unless !defined($module) || @{$imports{$module}} || $module eq "ntdll.dll";
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)
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 foreach my $mod (sort keys %directories)
148 {
149     next if defined($special_dlls{$directories{$mod}});  # skip special dlls
150     $targets{sprintf("%s\$(DLLEXT)",$mod)} = 1;
151     next unless defined $altnames{$mod};
152     foreach my $i (sort @{$altnames{$mod}})
153     {
154         $targets{sprintf("%s\$(DLLEXT)",$i)} = 1;
155     }
156 }
157 print NEWMAKE <<EOF;
158
159 # Main target
160
161 \@MAKE_RULES\@
162
163 all: \\
164         \$(EXTRADIRS:%=%.dll\$(DLLEXT)) \\
165 EOF
166 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );
167
168
169 ################################################################
170 # output the lib name -> directory rules
171
172 print NEWMAKE <<EOF;
173
174 # Map symlink name to the corresponding library
175
176 EOF
177
178 foreach my $mod (sort keys %directories)
179 {
180     printf NEWMAKE "%s\$(DLLEXT)", $mod;
181     if (defined $altnames{$mod})
182     {
183         my $count = 1;
184         foreach my $i (sort @{$altnames{$mod}})
185         {
186             if (!($count++ % 3)) { printf NEWMAKE " \\\n "; }
187             printf NEWMAKE " %s\$(DLLEXT)", $i;
188         }
189     }
190     printf NEWMAKE ": %s/%s\$(DLLEXT)\n", $directories{$mod}, $mod;
191     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
192 }
193
194
195 ################################################################
196 # output the inter-dll dependencies and rules
197
198 print NEWMAKE "# Map library name to the corresponding directory\n\n";
199
200 foreach my $mod (sort keys %directories)
201 {
202     printf NEWMAKE "%s/%s\$(DLLEXT): %s\n", $directories{$mod}, $mod, $directories{$mod};
203 }
204
205 print NEWMAKE "\n# Install dependencies\n\n";
206
207 foreach my $mod (sort keys %directories)
208 {
209     printf NEWMAKE "%s/__install__: %s\$(DLLEXT)\n", $directories{$mod}, $mod;
210 }
211
212 print NEWMAKE "\n# Inter-dll dependencies\n\n";
213
214 my @depends = ();
215 foreach my $mod (sort keys %imports)
216 {
217     next unless @{$imports{$mod}};
218     my $count = 0;
219     my $dep = sprintf("%s:", $directories{$mod});
220     $dep .= " " x (8-length($directories{$mod}));
221     foreach my $i (@{$imports{$mod}})
222     {
223         if ($count++ >= 4)
224         {
225             $count = 1;
226             $dep .= " \\\n" . " " x 9;
227         }
228         $dep .= sprintf(" %s\$(DLLEXT)", $i);
229     }
230     foreach my $i (@{$linked_dlls{$mod}})
231     {
232         if ($count++ >= 4)
233         {
234             $count = 1;
235             $dep .= " \\\n" . " " x 9;
236         }
237         $dep .= sprintf(" lib%s.\$(LIBEXT)", $i);
238     }
239     push @depends, $dep . "\n";
240 }
241 print NEWMAKE sort @depends;
242
243
244 ################################################################
245 # output the linkable dlls special links
246
247 my %linkable_dlls = ();
248 foreach my $mod (keys %imports)
249 {
250     foreach my $i (@{$linked_dlls{$mod}}) { $linkable_dlls{$i} = 1; }
251 }
252
253 print NEWMAKE "\n# Special targets for dlls that we need to link to\n\n";
254 printf NEWMAKE "LINKABLE_DLLS = %s\n\n", join( " ", keys %linkable_dlls );
255
256 foreach my $mod (keys %linkable_dlls)
257 {
258     printf NEWMAKE "lib%s.\$(LIBEXT): %s/%s\$(DLLEXT)\n", $mod, $directories{$mod}, $mod;
259     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
260 }
261
262 print NEWMAKE <<EOF;
263 uninstall::
264         \$(RM) \$(LINKABLE_DLLS:%=\$(libdir)/lib%.\$(LIBEXT))
265
266 install::
267         \$(RM) \$(LINKABLE_DLLS:%=\$(libdir)/lib%.\$(LIBEXT))
268         cd \$(libdir) && if [ "\$(dlldir)" = "\$(libdir)/wine" ]; \\
269         then \\
270 EOF
271 foreach my $mod (keys %linkable_dlls)
272 {
273     printf NEWMAKE "\t  \$(LN_S) wine/%s\$(DLLEXT) lib%s.\$(LIBEXT); \\\n", $mod, $mod;
274 }
275 print NEWMAKE "\telse \\\n";
276 foreach my $mod (keys %linkable_dlls)
277 {
278     printf NEWMAKE "\t  \$(LN_S) \$(dlldir)/%s\$(DLLEXT) lib%s.\$(LIBEXT); \\\n", $mod, $mod;
279 }
280 print NEWMAKE "\tfi\n\n";
281
282 ################################################################
283 # makefile trailer
284
285 print NEWMAKE <<EOF;
286 # Misc rules
287
288 uninstall::
289         -rmdir \$(dlldir)
290
291 check test:: \$(BUILDSUBDIRS:%=%/__test__)
292
293 crosstest:: \$(BUILDSUBDIRS:%=%/__crosstest__)
294
295 checklink:: \$(BUILDSUBDIRS:%=%/__checklink__)
296
297 ### Dependencies:
298 EOF
299
300 close NEWMAKE;
301 rename "Makefile.in.new", "Makefile.in";
302 printf "Successfully updated Makefile.in\n";