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