Added support for ordinal hint in PE_FindExportedFunction.
[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     open MAKE,$i;
46
47     $module = undef;
48     while (<MAKE>)
49     {
50         chop;
51         # EPP hack to disable this DLL... the MKDLL_SKIP comment must appear
52         # at the very top of the Makefile.in
53         last if (/^\#\s*MKDLL_SKIP/);
54
55         if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
56         {
57             $module = $1;
58             $imports{$module} = [ ];
59             ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
60             next;
61         }
62         if (/^ALTNAMES\s*=\s*(.*)/)
63         {
64             my @list = split(/\s/,$1);
65             $altnames{$module} = \@list;
66             next;
67         }
68         if (/^(DELAYIMPORTS|IMPORTS)\s*=\s*(.*)/)
69         {
70             my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$2);
71             push @{$imports{$module}}, @list;
72             next;
73         }
74         if (/^LDIMPORTS\s*=\s*(.*)/)
75         {
76             my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$1);
77             $linked_dlls{$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 foreach my $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 my $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 symlink name to the corresponding library
173
174 EOF
175
176 foreach my $mod (sort keys %directories)
177 {
178     printf NEWMAKE "%s\$(DLLEXT)", $mod;
179     if (defined $altnames{$mod})
180     {
181         my $count = 1;
182         foreach my $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 "# Map library name to the corresponding directory\n\n";
197
198 foreach my $mod (sort keys %directories)
199 {
200     printf NEWMAKE "%s/%s\$(DLLEXT): %s\n", $directories{$mod}, $mod, $directories{$mod};
201 }
202
203 print NEWMAKE "\n# Install dependencies\n\n";
204
205 foreach my $mod (sort keys %directories)
206 {
207     printf NEWMAKE "%s/__install__: %s\$(DLLEXT)\n", $directories{$mod}, $mod;
208 }
209
210 print NEWMAKE "\n# Inter-dll dependencies\n\n";
211
212 my @depends = ();
213 foreach my $mod (sort keys %imports)
214 {
215     next unless @{$imports{$mod}};
216     my $count = 0;
217     my $dep = sprintf("%s:", $directories{$mod});
218     $dep .= " " x (8-length($directories{$mod}));
219     foreach my $i (@{$imports{$mod}})
220     {
221         if ($count++ >= 4)
222         {
223             $count = 1;
224             $dep .= " \\\n" . " " x 9;
225         }
226         $dep .= sprintf(" %s\$(DLLEXT)", $i);
227     }
228     foreach my $i (@{$linked_dlls{$mod}})
229     {
230         if ($count++ >= 4)
231         {
232             $count = 1;
233             $dep .= " \\\n" . " " x 9;
234         }
235         $dep .= sprintf(" lib%s.\$(LIBEXT)", $i);
236     }
237     push @depends, $dep . "\n";
238 }
239 print NEWMAKE sort @depends;
240
241
242 ################################################################
243 # output the linkable dlls special links
244
245 my %linkable_dlls = ();
246 foreach my $mod (keys %imports)
247 {
248     foreach my $i (@{$linked_dlls{$mod}}) { $linkable_dlls{$i} = 1; }
249 }
250
251 print NEWMAKE "\n# Special targets for dlls that we need to link to\n\n";
252 printf NEWMAKE "LINKABLE_DLLS = %s\n\n", join( " ", keys %linkable_dlls );
253
254 foreach my $mod (keys %linkable_dlls)
255 {
256     printf NEWMAKE "lib%s.\$(LIBEXT): %s/%s\$(DLLEXT)\n", $mod, $directories{$mod}, $mod;
257     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
258 }
259
260 print NEWMAKE <<EOF;
261 uninstall::
262         \$(RM) \$(LINKABLE_DLLS:%=\$(libdir)/lib%.\$(LIBEXT))
263
264 install::
265         \$(RM) \$(LINKABLE_DLLS:%=\$(libdir)/lib%.\$(LIBEXT))
266         cd \$(libdir) && if [ "\$(dlldir)" = "\$(libdir)/wine" ]; \\
267         then \\
268 EOF
269 foreach my $mod (keys %linkable_dlls)
270 {
271     printf NEWMAKE "\t  \$(LN_S) wine/%s\$(DLLEXT) lib%s.\$(LIBEXT); \\\n", $mod, $mod;
272 }
273 print NEWMAKE "\telse \\\n";
274 foreach my $mod (keys %linkable_dlls)
275 {
276     printf NEWMAKE "\t  \$(LN_S) \$(dlldir)/%s\$(DLLEXT) lib%s.\$(LIBEXT); \\\n", $mod, $mod;
277 }
278 print NEWMAKE "\tfi\n\n";
279
280 ################################################################
281 # makefile trailer
282
283 print NEWMAKE <<EOF;
284 # Misc rules
285
286 \$(BUILDSUBDIRS:%=%/__checklink__): dummy
287         \@cd `dirname \$\@` && \$(MAKE) checklink
288
289 uninstall::
290         -rmdir \$(dlldir)
291
292 check test:: \$(BUILDSUBDIRS:%=%/__test__)
293
294 checklink:: \$(BUILDSUBDIRS:%=%/__checklink__)
295
296 .PHONY: checklink \$(BUILDSUBDIRS:%=%/__checklink__)
297
298 ### Dependencies:
299 EOF
300
301 close NEWMAKE;
302 rename "Makefile.in.new", "Makefile.in";
303 printf "Successfully updated Makefile.in\n";