Keep on moving 16 bit code out of winmm.
[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   "d3d8"     => "OPENGLFILES",
39   "x11drv"   => "XFILES"
40 );
41
42 foreach my $i (split(/\s/,$makefiles))
43 {
44     my $module;
45
46     next if $i =~ /\/tests\/Makefile.in/;
47
48     open MAKE,$i;
49
50     $module = undef;
51     while (<MAKE>)
52     {
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/);
57
58         if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
59         {
60             $module = $1;
61             $imports{$module} = [ ];
62             ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
63             next;
64         }
65         if (/^ALTNAMES\s*=\s*(.*)/)
66         {
67             my @list = split(/\s/,$1);
68             $altnames{$module} = \@list;
69             next;
70         }
71         if (/^(DELAYIMPORTS|IMPORTS)\s*=\s*(.*)/)
72         {
73             my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$2);
74             push @{$imports{$module}}, @list;
75             next;
76         }
77         if (/^LDIMPORTS\s*=\s*(.*)/)
78         {
79             my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$1);
80             $linked_dlls{$module} = \@list;
81             next;
82         }
83     }
84     close MAKE;
85     push @{$imports{$module}}, "kernel32.dll" unless !defined($module) || @{$imports{$module}} || $module eq "ntdll.dll";
86 }
87
88 open NEWMAKE,">Makefile.in.new" or die "cannot create Makefile.in.new";
89
90 ################################################################
91 # makefile header
92
93 print NEWMAKE <<EOF;
94 # Automatically generated by make_dlls; DO NOT EDIT!!
95
96 TOPSRCDIR = \@top_srcdir\@
97 TOPOBJDIR = ..
98 SRCDIR    = \@srcdir\@
99 VPATH     = \@srcdir\@
100
101 EOF
102
103 ################################################################
104 # output special dlls configure definitions
105
106 printf NEWMAKE "# special configure-dependent targets\n\n";
107 my %specials = ();
108 foreach my $mod (sort keys %special_dlls)
109 {
110     $specials{$special_dlls{$mod}} .= " " . $mod;
111 }
112 foreach my $i (sort keys %specials)
113 {
114     printf NEWMAKE "%s =%s\n", $i, $specials{$i};
115 }
116 printf NEWMAKE "EXTRADIRS =";
117 foreach my $i (sort keys %specials) { printf NEWMAKE " \@%s\@", $i; }
118 printf NEWMAKE "\n\n";
119
120
121 ################################################################
122 # output the subdirs list
123
124 print NEWMAKE "# Subdir list\n\nBASEDIRS =";
125 foreach my $dir (sort values %directories)
126 {
127     next if defined($special_dlls{$dir});  # skip special dlls
128     printf NEWMAKE " \\\n\t%s", $dir;
129 }
130
131 printf NEWMAKE "\n\nSUBDIRS = \\\n\t\$(BASEDIRS)";
132 foreach my $dir (sort keys %special_dlls)
133 {
134     printf NEWMAKE " \\\n\t%s", $dir;
135 }
136 printf NEWMAKE <<EOF;
137
138
139 BUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)
140
141 INSTALLSUBDIRS = \$(BUILDSUBDIRS)
142 EOF
143
144 ################################################################
145 # output the all: target
146
147 my %targets = ();  # use a hash to get rid of duplicate target names
148 my %targets16 = ();
149 foreach my $mod (sort keys %directories)
150 {
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}})
155     {
156         $targets16{sprintf("%s\$(DLLEXT)",$i)} = 1;
157     }
158 }
159 print NEWMAKE <<EOF;
160
161 # Main target
162
163 \@MAKE_RULES\@
164
165 WIN16_FILES = \\
166 EOF
167 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets16 );
168
169 print NEWMAKE <<EOF;
170
171 all: \\
172         \$(EXTRADIRS:%=%.dll\$(DLLEXT)) \\
173         \@WIN16_FILES\@ \\
174 EOF
175 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );
176
177
178 ################################################################
179 # output the lib name -> directory rules
180
181 print NEWMAKE <<EOF;
182
183 # Map symlink name to the corresponding library
184
185 EOF
186
187 foreach my $mod (sort keys %directories)
188 {
189     printf NEWMAKE "%s\$(DLLEXT)", $mod;
190     if (defined $altnames{$mod})
191     {
192         my $count = 1;
193         foreach my $i (sort @{$altnames{$mod}})
194         {
195             if (!($count++ % 3)) { printf NEWMAKE " \\\n "; }
196             printf NEWMAKE " %s\$(DLLEXT)", $i;
197         }
198     }
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;
201 }
202
203
204 ################################################################
205 # output the inter-dll dependencies and rules
206
207 print NEWMAKE "# Map library name to the corresponding directory\n\n";
208
209 foreach my $mod (sort keys %directories)
210 {
211     printf NEWMAKE "%s/%s\$(DLLEXT): %s\n", $directories{$mod}, $mod, $directories{$mod};
212 }
213
214 print NEWMAKE "\n# Install dependencies\n\n";
215
216 foreach my $mod (sort keys %directories)
217 {
218     printf NEWMAKE "%s/__install__: %s\$(DLLEXT)\n", $directories{$mod}, $mod;
219 }
220
221 print NEWMAKE "\n# Inter-dll dependencies\n\n";
222
223 my @depends = ();
224 foreach my $mod (sort keys %imports)
225 {
226     next unless @{$imports{$mod}};
227     my $count = 0;
228     my $dep = sprintf("%s:", $directories{$mod});
229     $dep .= " " x (8-length($directories{$mod}));
230     foreach my $i (@{$imports{$mod}})
231     {
232         if ($count++ >= 4)
233         {
234             $count = 1;
235             $dep .= " \\\n" . " " x 9;
236         }
237         $dep .= sprintf(" %s\$(DLLEXT)", $i);
238     }
239     foreach my $i (@{$linked_dlls{$mod}})
240     {
241         if ($count++ >= 4)
242         {
243             $count = 1;
244             $dep .= " \\\n" . " " x 9;
245         }
246         $dep .= sprintf(" lib%s.\$(LIBEXT)", $i);
247     }
248     push @depends, $dep . "\n";
249 }
250 print NEWMAKE sort @depends;
251
252
253 ################################################################
254 # output the linkable dlls special links
255
256 my %linkable_dlls = ();
257 foreach my $mod (keys %imports)
258 {
259     foreach my $i (@{$linked_dlls{$mod}}) { $linkable_dlls{$i} = 1; }
260 }
261
262 print NEWMAKE "\n# Special targets for dlls that we need to link to\n\n";
263 printf NEWMAKE "LINKABLE_DLLS = %s\n\n", join( " ", keys %linkable_dlls );
264
265 foreach my $mod (keys %linkable_dlls)
266 {
267     printf NEWMAKE "lib%s.\$(LIBEXT): %s/%s\$(DLLEXT)\n", $mod, $directories{$mod}, $mod;
268     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
269 }
270
271 print NEWMAKE <<EOF;
272 uninstall::
273         \$(RM) \$(LINKABLE_DLLS:%=\$(libdir)/lib%.\$(LIBEXT))
274
275 install::
276         \$(RM) \$(LINKABLE_DLLS:%=\$(libdir)/lib%.\$(LIBEXT))
277         cd \$(libdir) && if [ "\$(dlldir)" = "\$(libdir)/wine" ]; \\
278         then \\
279 EOF
280 foreach my $mod (keys %linkable_dlls)
281 {
282     printf NEWMAKE "\t  \$(LN_S) wine/%s\$(DLLEXT) lib%s.\$(LIBEXT); \\\n", $mod, $mod;
283 }
284 print NEWMAKE "\telse \\\n";
285 foreach my $mod (keys %linkable_dlls)
286 {
287     printf NEWMAKE "\t  \$(LN_S) \$(dlldir)/%s\$(DLLEXT) lib%s.\$(LIBEXT); \\\n", $mod, $mod;
288 }
289 print NEWMAKE "\tfi\n\n";
290
291 ################################################################
292 # makefile trailer
293
294 print NEWMAKE <<EOF;
295 # Misc rules
296
297 uninstall::
298         -rmdir \$(dlldir)
299
300 check test:: \$(BUILDSUBDIRS:%=%/__test__)
301
302 crosstest:: \$(BUILDSUBDIRS:%=%/__crosstest__)
303
304 checklink:: \$(BUILDSUBDIRS:%=%/__checklink__)
305
306 ### Dependencies:
307 EOF
308
309 close NEWMAKE;
310 rename "Makefile.in.new", "Makefile.in";
311 printf "Successfully updated Makefile.in\n";