- revert some optimisations breaking some games
[wine/hacks.git] / dlls / make_dlls
blobfddb3cdda4a23c426df7244f9122b01988285341
1 #!/usr/bin/perl -w
3 # Update the dll dependencies in the dlls main Makefile.in.
4 # Must be run in the dlls/ directory of the Wine tree.
6 # Copyright 2001 Alexandre Julliard
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.
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.
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
23 use strict;
25 my $makefiles = `find . -name Makefile.in -print`;
27 my %imports = ();
28 my %directories = ();
29 my %altnames = ();
30 my %linked_dlls = ();
32 # list of special dlls that can be switched on or off by configure
33 my %special_dlls =
35 "ddraw" => "XFILES",
36 "glu32" => "GLU32FILES",
37 "opengl32" => "OPENGLFILES",
38 "d3d8" => "OPENGLFILES",
39 "x11drv" => "XFILES"
42 foreach my $i (split(/\s/,$makefiles))
44 my $module;
46 next if $i =~ /\/tests\/Makefile.in/;
48 open MAKE,$i;
50 $module = undef;
51 while (<MAKE>)
53 chop;
54 # EPP hack to disable this DLL... the MKDLL_SKIP comment must appear
55 # at the very top of the Makefile.in
56 last if (/^\#\s*MKDLL_SKIP/);
58 if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
60 $module = $1;
61 $imports{$module} = [ ];
62 ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
63 next;
65 if (/^ALTNAMES\s*=\s*(.*)/)
67 my @list = split(/\s/,$1);
68 $altnames{$module} = \@list;
69 next;
71 if (/^(DELAYIMPORTS|IMPORTS)\s*=\s*(.*)/)
73 my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$2);
74 push @{$imports{$module}}, @list;
75 next;
77 if (/^LDIMPORTS\s*=\s*(.*)/)
79 my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$1);
80 $linked_dlls{$module} = \@list;
81 next;
84 close MAKE;
85 push @{$imports{$module}}, "kernel32.dll" unless !defined($module) || @{$imports{$module}} || $module eq "ntdll.dll";
88 open NEWMAKE,">Makefile.in.new" or die "cannot create Makefile.in.new";
90 ################################################################
91 # makefile header
93 print NEWMAKE <<EOF;
94 # Automatically generated by make_dlls; DO NOT EDIT!!
96 TOPSRCDIR = \@top_srcdir\@
97 TOPOBJDIR = ..
98 SRCDIR = \@srcdir\@
99 VPATH = \@srcdir\@
103 ################################################################
104 # output special dlls configure definitions
106 printf NEWMAKE "# special configure-dependent targets\n\n";
107 my %specials = ();
108 foreach my $mod (sort keys %special_dlls)
110 $specials{$special_dlls{$mod}} .= " " . $mod;
112 foreach my $i (sort keys %specials)
114 printf NEWMAKE "%s =%s\n", $i, $specials{$i};
116 printf NEWMAKE "EXTRADIRS =";
117 foreach my $i (sort keys %specials) { printf NEWMAKE " \@%s\@", $i; }
118 printf NEWMAKE "\n\n";
121 ################################################################
122 # output the subdirs list
124 print NEWMAKE "# Subdir list\n\nBASEDIRS =";
125 foreach my $dir (sort values %directories)
127 next if defined($special_dlls{$dir}); # skip special dlls
128 printf NEWMAKE " \\\n\t%s", $dir;
131 printf NEWMAKE "\n\nSUBDIRS = \\\n\t\$(BASEDIRS)";
132 foreach my $dir (sort keys %special_dlls)
134 printf NEWMAKE " \\\n\t%s", $dir;
136 printf NEWMAKE <<EOF;
139 BUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)
141 INSTALLSUBDIRS = \$(BUILDSUBDIRS)
144 ################################################################
145 # output the all: target
147 my %targets = (); # use a hash to get rid of duplicate target names
148 my %targets16 = ();
149 foreach my $mod (sort keys %directories)
151 next if defined($special_dlls{$directories{$mod}}); # skip special dlls
152 $targets{sprintf("%s\$(DLLEXT)",$mod)} = 1;
153 next unless defined $altnames{$mod};
154 foreach my $i (sort @{$altnames{$mod}})
156 $targets16{sprintf("%s\$(DLLEXT)",$i)} = 1;
159 print NEWMAKE <<EOF;
161 # Main target
163 \@MAKE_RULES\@
165 WIN16_FILES = \\
167 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets16 );
169 print NEWMAKE <<EOF;
171 all: \\
172 \$(EXTRADIRS:%=%.dll\$(DLLEXT)) \\
173 \@WIN16_FILES\@ \\
175 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );
178 ################################################################
179 # output the lib name -> directory rules
181 print NEWMAKE <<EOF;
183 # Map symlink name to the corresponding library
187 foreach my $mod (sort keys %directories)
189 printf NEWMAKE "%s\$(DLLEXT)", $mod;
190 if (defined $altnames{$mod})
192 my $count = 1;
193 foreach my $i (sort @{$altnames{$mod}})
195 if (!($count++ % 3)) { printf NEWMAKE " \\\n "; }
196 printf NEWMAKE " %s\$(DLLEXT)", $i;
199 printf NEWMAKE ": %s/%s\$(DLLEXT)\n", $directories{$mod}, $mod;
200 printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
204 ################################################################
205 # output the import libraries rules
207 my @implibs = grep /\.dll$/, keys %directories;
208 push @implibs, "winspool.drv";
210 print NEWMAKE "\n# Import libraries\n\nIMPORT_LIBS =";
211 foreach my $mod (sort @implibs)
213 my $def = $mod;
214 $def =~ s/\.(dll|drv)$//;
215 printf NEWMAKE " \\\n\tlib%s", $def;
217 print NEWMAKE "\n\n";
219 foreach my $mod (sort @implibs)
221 my $dir = $directories{$mod};
222 my $def = $mod;
223 my $spec = $mod;
224 $spec =~ s/\.dll$//;
225 $def =~ s/\.(dll|drv)$//;
226 printf NEWMAKE "lib%s.def: %s/%s.spec.def\n", $def, $dir, $spec;
227 printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s.spec.def \$@\n", $dir, $spec;
228 printf NEWMAKE "lib%s.a: %s/%s.spec.def\n", $def, $dir, $spec;
229 printf NEWMAKE "\t\$(DLLTOOL) -k -l \$@ -d %s/%s.spec.def\n\n", $dir, $spec;
231 foreach my $mod (sort @implibs)
233 my $dir = $directories{$mod};
234 my $spec = $mod;
235 $spec =~ s/\.dll$//;
236 printf NEWMAKE "%s/%s.spec.def: \$(WINEBUILD)\n", $dir, $spec;
240 print NEWMAKE <<EOF;
242 \$(SUBDIRS): \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT))
243 \$(SUBDIRS:%=%/__crosstest__): \$(IMPORT_LIBS:%=%.a)
247 ################################################################
248 # output the inter-dll dependencies and rules
250 print NEWMAKE "# Map library name to the corresponding directory\n\n";
252 foreach my $mod (sort keys %directories)
254 printf NEWMAKE "%s/%s\$(DLLEXT): %s\n", $directories{$mod}, $mod, $directories{$mod};
257 print NEWMAKE "\n# Install dependencies\n\n";
259 foreach my $mod (sort keys %directories)
261 printf NEWMAKE "%s/__install__: %s\$(DLLEXT)\n", $directories{$mod}, $mod;
264 ################################################################
265 # output the linkable dlls special links
267 my %linkable_dlls = ();
268 foreach my $mod (keys %imports)
270 foreach my $i (@{$linked_dlls{$mod}}) { $linkable_dlls{$i} = 1; }
273 print NEWMAKE "\n# Special targets for dlls that we need to link to\n\n";
274 printf NEWMAKE "LINKABLE_DLLS = %s\n\n", join( " ", keys %linkable_dlls );
276 foreach my $mod (keys %linkable_dlls)
278 printf NEWMAKE "lib%s.\$(LIBEXT): %s/%s\$(DLLEXT)\n", $mod, $directories{$mod}, $mod;
279 printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
282 foreach my $mod (keys %imports)
284 my $deps = "";
285 foreach my $i (@{$linked_dlls{$mod}}) { $deps .= " lib$i.\$(LIBEXT)"; }
286 if ($deps) { printf NEWMAKE "%s:%s\n", $directories{$mod}, $deps; }
289 print NEWMAKE <<EOF;
291 uninstall::
292 \$(RM) \$(LINKABLE_DLLS:%=\$(libdir)/lib%.\$(LIBEXT))
294 install install-lib::
295 \$(RM) \$(LINKABLE_DLLS:%=\$(libdir)/lib%.\$(LIBEXT))
296 cd \$(libdir) && if [ "\$(dlldir)" = "\$(libdir)/wine" ]; \\
297 then \\
299 foreach my $mod (keys %linkable_dlls)
301 printf NEWMAKE "\t \$(LN_S) wine/%s\$(DLLEXT) lib%s.\$(LIBEXT); \\\n", $mod, $mod;
303 print NEWMAKE "\telse \\\n";
304 foreach my $mod (keys %linkable_dlls)
306 printf NEWMAKE "\t \$(LN_S) \$(dlldir)/%s\$(DLLEXT) lib%s.\$(LIBEXT); \\\n", $mod, $mod;
308 print NEWMAKE "\tfi\n\n";
310 ################################################################
311 # makefile trailer
313 print NEWMAKE <<EOF;
314 # Misc rules
316 install install-dev:: \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT))
317 \$(MKINSTALLDIRS) \$(dlldir)
318 for f in \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT)); do \$(INSTALL_DATA) \$\$f \$(dlldir)/\$\$f; done
320 install install-lib:: \$(INSTALLSUBDIRS:%=%/__install__)
322 uninstall::
323 \$(RM) \$(IMPORT_LIBS:%=\$(dlldir)/%.\$(IMPLIBEXT))
324 -rmdir \$(dlldir)
326 clean::
327 \$(RM) \$(IMPORT_LIBS:%=%.a) \$(IMPORT_LIBS:%=%.def)
329 check test:: \$(BUILDSUBDIRS:%=%/__test__)
331 crosstest:: \$(BUILDSUBDIRS:%=%/__crosstest__)
333 checklink:: \$(BUILDSUBDIRS:%=%/__checklink__)
335 ### Dependencies:
338 close NEWMAKE;
339 rename "Makefile.in.new", "Makefile.in";
340 printf "Successfully updated Makefile.in\n";