- correct return value of SHGetPathFromIDList[AW]() for virtual
[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   "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             $imports{$module} = [ ];
65             ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
66             next;
67         }
68         if (/^ALTNAMES\s*=\s*(.*)/)
69         {
70             my @list = split(/\s/,$1);
71             $altnames{$module} = \@list;
72             next;
73         }
74         if (/^(DELAYIMPORTS|IMPORTS)\s*=\s*(.*)/)
75         {
76             my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$2);
77             push @{$imports{$module}}, @list;
78             next;
79         }
80     }
81     close MAKE;
82     push @{$imports{$module}}, "kernel32.dll" unless !defined($module) || @{$imports{$module}} || $module eq "ntdll.dll";
83 }
84
85 open NEWMAKE,">Makefile.in.new" or die "cannot create Makefile.in.new";
86
87 ################################################################
88 # makefile header
89
90 print NEWMAKE <<EOF;
91 # Automatically generated by make_dlls; DO NOT EDIT!!
92
93 TOPSRCDIR = \@top_srcdir\@
94 TOPOBJDIR = ..
95 SRCDIR    = \@srcdir\@
96 VPATH     = \@srcdir\@
97
98 EOF
99
100 ################################################################
101 # output special dlls configure definitions
102
103 printf NEWMAKE "# special configure-dependent targets\n\n";
104 my %specials = ();
105 foreach my $mod (sort keys %special_dlls)
106 {
107     $specials{$special_dlls{$mod}} .= " " . $mod;
108 }
109 foreach my $i (sort keys %specials)
110 {
111     printf NEWMAKE "%s =%s\n", $i, $specials{$i};
112 }
113 printf NEWMAKE "EXTRADIRS =";
114 foreach my $i (sort keys %specials) { printf NEWMAKE " \@%s\@", $i; }
115 printf NEWMAKE "\n\n";
116
117
118 ################################################################
119 # output the subdirs list
120
121 print NEWMAKE "# Subdir list\n\nBASEDIRS =";
122 foreach my $dir (sort values %directories)
123 {
124     next if defined($special_dlls{$dir});  # skip special dlls
125     printf NEWMAKE " \\\n\t%s", $dir;
126 }
127
128 printf NEWMAKE "\n\nSUBDIRS = \\\n\t\$(BASEDIRS)";
129 foreach my $dir (sort keys %special_dlls)
130 {
131     printf NEWMAKE " \\\n\t%s", $dir;
132 }
133 printf NEWMAKE <<EOF;
134
135
136 BUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)
137
138 INSTALLSUBDIRS = \$(BUILDSUBDIRS)
139 EOF
140
141 ################################################################
142 # output the all: target
143
144 my %targets = ();  # use a hash to get rid of duplicate target names
145 my %targets16 = ();
146 foreach my $mod (sort keys %directories)
147 {
148     next if defined($special_dlls{$directories{$mod}});  # skip special dlls
149     $targets{sprintf("%s\$(DLLEXT)",$mod)} = 1;
150     next unless defined $altnames{$mod};
151     foreach my $i (sort @{$altnames{$mod}})
152     {
153         $targets16{sprintf("%s\$(DLLEXT)",$i)} = 1;
154     }
155 }
156 print NEWMAKE <<EOF;
157
158 \@MAKE_RULES\@
159
160 # Symbolic links
161
162 WIN16_FILES = \\
163 EOF
164 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets16 );
165
166 print NEWMAKE <<EOF;
167
168 SYMLINKS = \\
169         \$(EXTRADIRS:%=%.dll\$(DLLEXT)) \\
170         \@WIN16_FILES\@ \\
171 EOF
172 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );
173
174 print NEWMAKE <<EOF;
175
176 # Main target
177
178 all: \$(SYMLINKS)
179 EOF
180
181 ################################################################
182 # output the lib name -> directory rules
183
184 print NEWMAKE <<EOF;
185
186 # Map symlink name to the corresponding library
187
188 EOF
189
190 foreach my $mod (sort keys %directories)
191 {
192     printf NEWMAKE "%s\$(DLLEXT)", $mod;
193     if (defined $altnames{$mod})
194     {
195         my $count = 1;
196         foreach my $i (sort @{$altnames{$mod}})
197         {
198             if (!($count++ % 3)) { printf NEWMAKE " \\\n "; }
199             printf NEWMAKE " %s\$(DLLEXT)", $i;
200         }
201     }
202     printf NEWMAKE ": %s/%s\$(DLLEXT)\n", $directories{$mod}, $mod;
203     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
204 }
205
206
207 ################################################################
208 # output the import libraries rules
209
210 my @implibs = grep /\.dll$/, keys %directories;
211 push @implibs, "winspool.drv";
212
213 print NEWMAKE "\n# Import libraries\n\nIMPORT_LIBS =";
214 foreach my $mod (sort @implibs)
215 {
216     my $def = $mod;
217     $def =~ s/\.(dll|drv)$//;
218     printf NEWMAKE " \\\n\tlib%s", $def;
219 }
220 print NEWMAKE "\n\n";
221
222 foreach my $mod (sort @implibs)
223 {
224     my $dir = $directories{$mod};
225     my $def = $mod;
226     my $spec = $mod;
227     $spec =~ s/\.dll$//;
228     $def =~ s/\.(dll|drv)$//;
229     printf NEWMAKE "lib%s.def: %s/%s.spec.def\n", $def, $dir, $spec;
230     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s.spec.def \$@\n", $dir, $spec;
231     printf NEWMAKE "lib%s.a: %s/%s.spec.def\n", $def, $dir, $spec;
232     printf NEWMAKE "\t\$(DLLTOOL) -k -l \$@ -d %s/%s.spec.def\n\n", $dir, $spec;
233 }
234 foreach my $mod (sort @implibs)
235 {
236     my $dir = $directories{$mod};
237     my $spec = $mod;
238     $spec =~ s/\.dll$//;
239     printf NEWMAKE "%s/%s.spec.def: \$(WINEBUILD)\n", $dir, $spec;
240 }
241
242
243 print NEWMAKE <<EOF;
244
245 \$(SUBDIRS): \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT))
246 \$(SUBDIRS:%=%/__install__): \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT))
247 \$(SUBDIRS:%=%/__crosstest__): \$(IMPORT_LIBS:%=%.a)
248
249 EOF
250
251 ################################################################
252 # output the inter-dll dependencies and rules
253
254 print NEWMAKE "# Map library name to the corresponding directory\n\n";
255
256 foreach my $mod (sort keys %directories)
257 {
258     printf NEWMAKE "%s/%s\$(DLLEXT): %s\n", $directories{$mod}, $mod, $directories{$mod};
259 }
260
261 ################################################################
262 # makefile trailer
263
264 print NEWMAKE <<EOF;
265 # Rules for auto documentation
266
267 \$(SUBDIRS:%=%/__man__): dummy
268         cd `dirname \$@` && \$(MAKE) man
269
270 man: \$(SUBDIRS:%=%/__man__)
271
272 \$(SUBDIRS:%=%/__doc_html__): dummy
273         cd `dirname \$@` && \$(MAKE) doc-html
274
275 doc-html: \$(SUBDIRS:%=%/__doc_html__)
276
277 \$(SUBDIRS:%=%/__doc_sgml__): dummy
278         cd `dirname \$@` && \$(MAKE) doc-sgml
279
280 doc-sgml: \$(SUBDIRS:%=%/__doc_sgml__)
281
282 .PHONY: man doc-html doc-sgml implib \$(SUBDIRS:%=%/__man__) \$(SUBDIRS:%=%/__doc_html__) \$(SUBDIRS:%=%/__doc_sgml__)
283
284 # Misc rules
285
286 install install-dev:: \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT))
287         \$(MKINSTALLDIRS) \$(dlldir)
288         for f in \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT)); do \$(INSTALL_DATA) \$\$f \$(dlldir)/\$\$f; done
289
290 install install-lib:: \$(INSTALLSUBDIRS:%=%/__install__)
291
292 uninstall::
293         \$(RM) \$(IMPORT_LIBS:%=\$(dlldir)/%.\$(IMPLIBEXT))
294         -rmdir \$(dlldir)
295
296 implib: \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT))
297
298 clean::
299         \$(RM) \$(IMPORT_LIBS:%=%.a) \$(IMPORT_LIBS:%=%.def) \$(SYMLINKS)
300
301 check test:: \$(BUILDSUBDIRS:%=%/__test__)
302
303 crosstest:: \$(BUILDSUBDIRS:%=%/__crosstest__)
304
305 checklink:: \$(BUILDSUBDIRS:%=%/__checklink__)
306
307 ### Dependencies:
308 EOF
309
310 close NEWMAKE;
311 rename "Makefile.in.new", "Makefile.in";
312 printf "Successfully updated Makefile.in\n";