Added support for multiple mixers.
[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 %implib_dirs = ();
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             if ($module =~ /^lib.*\.a$/)
65             {
66                 ($implib_dirs{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
67             }
68             else
69             {
70                 ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
71             }
72             next;
73         }
74         if (/^SPEC_SRCS16\s*=\s*(.*)/)
75         {
76             my $specs = $1;
77             while ($specs =~ /\s*(.*)\\$/) { $specs = $1 . <MAKE>; }
78             my @list = split(/\s+/,$specs);
79             @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @list;
80             $altnames{$module} = \@list;
81             printf "\"$specs\" -> %s\n", join(',',@list);
82             next;
83         }
84     }
85     close MAKE;
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, values %implib_dirs))
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{$mod . ".so"} = 1;
153     next unless defined $altnames{$mod};
154     foreach my $i (sort @{$altnames{$mod}})
155     {
156         $targets16{sprintf("%s.so",$i)} = 1;
157     }
158 }
159 foreach my $mod (sort keys %implib_dirs) { $targets{$mod} = 1; }
160
161 print NEWMAKE <<EOF;
162
163 \@MAKE_RULES\@
164
165 # Symbolic links
166
167 WIN16_FILES = \\
168 EOF
169 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets16 );
170
171 print NEWMAKE <<EOF;
172
173 SYMLINKS_SO = \\
174         \$(EXTRADIRS:%=%.dll.so) \\
175         \@WIN16_FILES\@ \\
176 EOF
177 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );
178
179 print NEWMAKE <<EOF;
180
181 # Main target
182
183 all: symlinks\$(DLLEXT)
184
185 .PHONY: symlinks symlinks.so implib
186
187 symlinks.so: \$(SYMLINKS_SO)
188
189 symlinks: \$(BUILDSUBDIRS)
190
191 EOF
192
193 ################################################################
194 # output the lib name -> directory rules
195
196 print NEWMAKE <<EOF;
197
198 # Map symlink name to the corresponding library
199
200 EOF
201
202 foreach my $mod (sort keys %directories)
203 {
204     printf NEWMAKE "%s.so: %s/%s.so\n", $mod, $directories{$mod}, $mod;
205     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s.so \$@\n\n", $directories{$mod}, $mod;
206
207     if (defined $altnames{$mod})
208     {
209         my $count = 0;
210         foreach my $i (sort @{$altnames{$mod}})
211         {
212             if ($count++ == 3) { printf NEWMAKE "\\\n  "; $count = 1; }
213             printf NEWMAKE "%s.so ", $i;
214         }
215         printf NEWMAKE ": %s.so\n", $mod;
216         printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s.so \$@\n\n", $mod;
217     }
218 }
219 foreach my $mod (sort keys %implib_dirs)
220 {
221     printf NEWMAKE "%s: %s/%s\n", $mod, $implib_dirs{$mod}, $mod;
222     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $implib_dirs{$mod}, $mod;
223 }
224
225 ################################################################
226 # output the import libraries rules
227
228 my @implibs = grep /\.dll$/, keys %directories;
229 push @implibs, "winspool.drv";
230
231 print NEWMAKE "\n# Import libraries\n\nIMPORT_LIBS =";
232 foreach my $mod (sort @implibs)
233 {
234     my $def = $mod;
235     $def =~ s/\.(dll|drv)$//;
236     printf NEWMAKE " \\\n\tlib%s.\$(IMPLIBEXT)", $def;
237 }
238 foreach my $mod (sort keys %implib_dirs)
239 {
240     printf NEWMAKE " \\\n\t%s", $mod;
241 }
242 print NEWMAKE "\n\n";
243 print NEWMAKE "implib: \$(IMPORT_LIBS)\n\n";
244
245 foreach my $mod (sort @implibs)
246 {
247     my $dir = $directories{$mod};
248     my $def = $mod;
249     my $spec = $mod;
250     $spec =~ s/\.dll$//;
251     $def =~ s/\.(dll|drv)$//;
252     printf NEWMAKE "lib%s.def: %s/%s.spec.def\n", $def, $dir, $spec;
253     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s.spec.def \$@\n", $dir, $spec;
254     printf NEWMAKE "lib%s.a: %s/%s.spec.def\n", $def, $dir, $spec;
255     printf NEWMAKE "\t\$(DLLTOOL) -k -l \$@ -d %s/%s.spec.def\n\n", $dir, $spec;
256 }
257 foreach my $mod (sort @implibs)
258 {
259     my $dir = $directories{$mod};
260     my $spec = $mod;
261     $spec =~ s/\.dll$//;
262     printf NEWMAKE "%s/%s.spec.def: \$(WINEBUILD)\n", $dir, $spec;
263 }
264
265
266 print NEWMAKE <<EOF;
267
268 \$(BUILDSUBDIRS): \$(IMPORT_LIBS)
269 \$(INSTALLSUBDIRS:%=%/__install__): \$(IMPORT_LIBS)
270
271 EOF
272
273 ################################################################
274 # output the inter-dll dependencies and rules
275
276 print NEWMAKE "# Map library name to the corresponding directory\n\n";
277
278 foreach my $mod (sort keys %directories)
279 {
280     printf NEWMAKE "%s/%s.so: %s\n", $directories{$mod}, $mod, $directories{$mod};
281 }
282 foreach my $mod (sort keys %implib_dirs)
283 {
284     printf NEWMAKE "%s/%s: %s\n", $implib_dirs{$mod}, $mod, $implib_dirs{$mod};
285 }
286
287 ################################################################
288 # makefile trailer
289
290 print NEWMAKE <<EOF;
291
292 # Rules for auto documentation
293
294 \$(SUBDIRS:%=%/__man__): dummy
295         cd `dirname \$@` && \$(MAKE) man
296
297 man: \$(SUBDIRS:%=%/__man__)
298
299 \$(SUBDIRS:%=%/__doc_html__): dummy
300         cd `dirname \$@` && \$(MAKE) doc-html
301
302 doc-html: \$(SUBDIRS:%=%/__doc_html__)
303
304 \$(SUBDIRS:%=%/__doc_sgml__): dummy
305         cd `dirname \$@` && \$(MAKE) doc-sgml
306
307 doc-sgml: \$(SUBDIRS:%=%/__doc_sgml__)
308
309 .PHONY: man doc-html doc-sgml \$(SUBDIRS:%=%/__man__) \$(SUBDIRS:%=%/__doc_html__) \$(SUBDIRS:%=%/__doc_sgml__)
310
311 # Misc rules
312
313 install install-dev:: \$(IMPORT_LIBS)
314         \$(MKINSTALLDIRS) \$(dlldir)
315         for f in \$(IMPORT_LIBS); do \$(INSTALL_DATA) \$\$f \$(dlldir)/\$\$f; done
316
317 install install-lib:: \$(INSTALLSUBDIRS:%=%/__install__)
318
319 uninstall::
320         -cd \$(dlldir) && \$(RM) \$(IMPORT_LIBS)
321         -rmdir \$(dlldir)
322
323 clean::
324         \$(RM) \$(IMPORT_LIBS) \$(SYMLINKS)
325
326 check test:: \$(BUILDSUBDIRS:%=%/__test__)
327
328 crosstest:: \$(BUILDSUBDIRS:%=%/__crosstest__)
329
330 checklink:: \$(BUILDSUBDIRS:%=%/__checklink__)
331
332 ### Dependencies:
333 EOF
334
335 close NEWMAKE;
336 rename "Makefile.in.new", "Makefile.in";
337 printf "Successfully updated Makefile.in\n";