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