blob: 69b7f91d1717a84b12a76747b6b8719310ef77a3 [file] [log] [blame]
Alexandre Julliardf33f7f02001-09-17 20:09:08 +00001#!/usr/bin/perl -w
Alexandre Julliard7c3dec92001-06-08 19:09:44 +00002#
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#
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00008# 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#
Alexandre Julliard7c3dec92001-06-08 19:09:44 +000022
Eric Pouechc0d955e2002-05-21 18:29:31 +000023use strict;
Alexandre Julliard7c3dec92001-06-08 19:09:44 +000024
Eric Pouechc0d955e2002-05-21 18:29:31 +000025my $makefiles = `find . -name Makefile.in -print`;
26
27my %imports = ();
28my %directories = ();
29my %altnames = ();
30my %linked_dlls = ();
Alexandre Julliard7c3dec92001-06-08 19:09:44 +000031
Alexandre Julliardf33f7f02001-09-17 20:09:08 +000032# list of special dlls that can be switched on or off by configure
Eric Pouechc0d955e2002-05-21 18:29:31 +000033my %special_dlls =
Alexandre Julliardf33f7f02001-09-17 20:09:08 +000034(
35 "ddraw" => "XFILES",
36 "glu32" => "GLU32FILES",
37 "opengl32" => "OPENGLFILES",
Alexandre Julliard7cbb3402002-09-29 18:07:25 +000038 "d3d8" => "OPENGLFILES",
Alexandre Julliardaa1bdc42003-07-01 01:11:13 +000039 "d3d9" => "OPENGLFILES",
Raphael Junqueirae31ae922002-12-17 01:15:15 +000040 "d3dx8" => "OPENGLFILES",
Alexandre Julliardf33f7f02001-09-17 20:09:08 +000041 "x11drv" => "XFILES"
42);
43
Eric Pouechc0d955e2002-05-21 18:29:31 +000044foreach my $i (split(/\s/,$makefiles))
Alexandre Julliard7c3dec92001-06-08 19:09:44 +000045{
Eric Pouechc0d955e2002-05-21 18:29:31 +000046 my $module;
47
Alexandre Julliardedeee892002-08-09 01:22:40 +000048 next if $i =~ /\/tests\/Makefile.in/;
49
Alexandre Julliard7c3dec92001-06-08 19:09:44 +000050 open MAKE,$i;
Eric Pouechc0d955e2002-05-21 18:29:31 +000051
52 $module = undef;
Alexandre Julliard7c3dec92001-06-08 19:09:44 +000053 while (<MAKE>)
54 {
55 chop;
Eric Pouechc0d955e2002-05-21 18:29:31 +000056 # EPP hack to disable this DLL... the MKDLL_SKIP comment must appear
57 # at the very top of the Makefile.in
58 last if (/^\#\s*MKDLL_SKIP/);
59
Alexandre Julliard7c3dec92001-06-08 19:09:44 +000060 if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
61 {
62 $module = $1;
Alexandre Julliardec329ab2002-05-14 20:42:52 +000063 $imports{$module} = [ ];
Alexandre Julliard7c3dec92001-06-08 19:09:44 +000064 ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
65 next;
66 }
67 if (/^ALTNAMES\s*=\s*(.*)/)
68 {
69 my @list = split(/\s/,$1);
70 $altnames{$module} = \@list;
71 next;
72 }
Alexandre Julliardec329ab2002-05-14 20:42:52 +000073 if (/^(DELAYIMPORTS|IMPORTS)\s*=\s*(.*)/)
Alexandre Julliardc1bfca02002-03-20 22:19:06 +000074 {
Alexandre Julliardec329ab2002-05-14 20:42:52 +000075 my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$2);
76 push @{$imports{$module}}, @list;
77 next;
78 }
79 if (/^LDIMPORTS\s*=\s*(.*)/)
80 {
81 my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$1);
Alexandre Julliardc1bfca02002-03-20 22:19:06 +000082 $linked_dlls{$module} = \@list;
83 next;
84 }
Alexandre Julliard7c3dec92001-06-08 19:09:44 +000085 }
Eric Pouechc0d955e2002-05-21 18:29:31 +000086 close MAKE;
87 push @{$imports{$module}}, "kernel32.dll" unless !defined($module) || @{$imports{$module}} || $module eq "ntdll.dll";
Alexandre Julliard7c3dec92001-06-08 19:09:44 +000088}
89
Alexandre Julliard7c3dec92001-06-08 19:09:44 +000090open NEWMAKE,">Makefile.in.new" or die "cannot create Makefile.in.new";
91
Alexandre Julliardf33f7f02001-09-17 20:09:08 +000092################################################################
93# makefile header
Alexandre Julliard7c3dec92001-06-08 19:09:44 +000094
Alexandre Julliardf33f7f02001-09-17 20:09:08 +000095print NEWMAKE <<EOF;
96# Automatically generated by make_dlls; DO NOT EDIT!!
Alexandre Julliard7c3dec92001-06-08 19:09:44 +000097
Alexandre Julliardf33f7f02001-09-17 20:09:08 +000098TOPSRCDIR = \@top_srcdir\@
99TOPOBJDIR = ..
100SRCDIR = \@srcdir\@
101VPATH = \@srcdir\@
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000102
103EOF
104
105################################################################
106# output special dlls configure definitions
107
108printf NEWMAKE "# special configure-dependent targets\n\n";
109my %specials = ();
Eric Pouechc0d955e2002-05-21 18:29:31 +0000110foreach my $mod (sort keys %special_dlls)
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000111{
112 $specials{$special_dlls{$mod}} .= " " . $mod;
113}
Eric Pouechc0d955e2002-05-21 18:29:31 +0000114foreach my $i (sort keys %specials)
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000115{
116 printf NEWMAKE "%s =%s\n", $i, $specials{$i};
117}
118printf NEWMAKE "EXTRADIRS =";
Eric Pouechc0d955e2002-05-21 18:29:31 +0000119foreach my $i (sort keys %specials) { printf NEWMAKE " \@%s\@", $i; }
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000120printf NEWMAKE "\n\n";
121
122
123################################################################
124# output the subdirs list
125
Alexandre Julliard5852f7a2002-05-23 02:47:16 +0000126print NEWMAKE "# Subdir list\n\nBASEDIRS =";
Eric Pouechc0d955e2002-05-21 18:29:31 +0000127foreach my $dir (sort values %directories)
Alexandre Julliard7c3dec92001-06-08 19:09:44 +0000128{
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000129 next if defined($special_dlls{$dir}); # skip special dlls
Alexandre Julliard7c3dec92001-06-08 19:09:44 +0000130 printf NEWMAKE " \\\n\t%s", $dir;
131}
Alexandre Julliard7c3dec92001-06-08 19:09:44 +0000132
Alexandre Julliard5852f7a2002-05-23 02:47:16 +0000133printf NEWMAKE "\n\nSUBDIRS = \\\n\t\$(BASEDIRS)";
134foreach my $dir (sort keys %special_dlls)
135{
136 printf NEWMAKE " \\\n\t%s", $dir;
137}
138printf NEWMAKE <<EOF;
139
140
141BUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)
Alexandre Julliardf673b712002-06-14 23:48:27 +0000142
143INSTALLSUBDIRS = \$(BUILDSUBDIRS)
Alexandre Julliard5852f7a2002-05-23 02:47:16 +0000144EOF
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000145
146################################################################
147# output the all: target
148
149my %targets = (); # use a hash to get rid of duplicate target names
Alexandre Julliardc728efc2002-10-02 02:34:09 +0000150my %targets16 = ();
Eric Pouechc0d955e2002-05-21 18:29:31 +0000151foreach my $mod (sort keys %directories)
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000152{
Alexandre Julliardc1bfca02002-03-20 22:19:06 +0000153 next if defined($special_dlls{$directories{$mod}}); # skip special dlls
154 $targets{sprintf("%s\$(DLLEXT)",$mod)} = 1;
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000155 next unless defined $altnames{$mod};
Eric Pouechc0d955e2002-05-21 18:29:31 +0000156 foreach my $i (sort @{$altnames{$mod}})
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000157 {
Alexandre Julliardc728efc2002-10-02 02:34:09 +0000158 $targets16{sprintf("%s\$(DLLEXT)",$i)} = 1;
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000159 }
160}
161print NEWMAKE <<EOF;
162
Alexandre Julliardc1bfca02002-03-20 22:19:06 +0000163\@MAKE_RULES\@
164
Alexandre Julliard23829be2003-05-15 04:30:46 +0000165# Symbolic links
166
Alexandre Julliardc728efc2002-10-02 02:34:09 +0000167WIN16_FILES = \\
168EOF
169printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets16 );
170
171print NEWMAKE <<EOF;
172
Alexandre Julliard23829be2003-05-15 04:30:46 +0000173SYMLINKS = \\
Alexandre Julliardc1bfca02002-03-20 22:19:06 +0000174 \$(EXTRADIRS:%=%.dll\$(DLLEXT)) \\
Alexandre Julliardc728efc2002-10-02 02:34:09 +0000175 \@WIN16_FILES\@ \\
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000176EOF
177printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );
178
Alexandre Julliard23829be2003-05-15 04:30:46 +0000179print NEWMAKE <<EOF;
180
181# Main target
182
183all: \$(SYMLINKS)
184EOF
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000185
186################################################################
187# output the lib name -> directory rules
188
Alexandre Julliard7c3dec92001-06-08 19:09:44 +0000189print NEWMAKE <<EOF;
190
Alexandre Julliard45a795c2002-05-23 19:13:22 +0000191# Map symlink name to the corresponding library
Alexandre Julliard7c3dec92001-06-08 19:09:44 +0000192
193EOF
194
Eric Pouechc0d955e2002-05-21 18:29:31 +0000195foreach my $mod (sort keys %directories)
Alexandre Julliard7c3dec92001-06-08 19:09:44 +0000196{
Alexandre Julliardc1bfca02002-03-20 22:19:06 +0000197 printf NEWMAKE "%s\$(DLLEXT)", $mod;
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000198 if (defined $altnames{$mod})
Alexandre Julliard7c3dec92001-06-08 19:09:44 +0000199 {
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000200 my $count = 1;
Eric Pouechc0d955e2002-05-21 18:29:31 +0000201 foreach my $i (sort @{$altnames{$mod}})
Alexandre Julliard7c3dec92001-06-08 19:09:44 +0000202 {
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000203 if (!($count++ % 3)) { printf NEWMAKE " \\\n "; }
Alexandre Julliardc1bfca02002-03-20 22:19:06 +0000204 printf NEWMAKE " %s\$(DLLEXT)", $i;
Alexandre Julliard7c3dec92001-06-08 19:09:44 +0000205 }
Alexandre Julliard7c3dec92001-06-08 19:09:44 +0000206 }
Alexandre Julliard45a795c2002-05-23 19:13:22 +0000207 printf NEWMAKE ": %s/%s\$(DLLEXT)\n", $directories{$mod}, $mod;
Alexandre Julliardc1bfca02002-03-20 22:19:06 +0000208 printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
Alexandre Julliard7c3dec92001-06-08 19:09:44 +0000209}
210
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000211
212################################################################
Alexandre Julliardada5e652002-12-12 22:03:14 +0000213# output the import libraries rules
214
215my @implibs = grep /\.dll$/, keys %directories;
216push @implibs, "winspool.drv";
217
218print NEWMAKE "\n# Import libraries\n\nIMPORT_LIBS =";
219foreach my $mod (sort @implibs)
220{
221 my $def = $mod;
Alexandre Julliardf1b48192002-12-15 01:20:54 +0000222 $def =~ s/\.(dll|drv)$//;
Alexandre Julliardada5e652002-12-12 22:03:14 +0000223 printf NEWMAKE " \\\n\tlib%s", $def;
224}
225print NEWMAKE "\n\n";
226
227foreach my $mod (sort @implibs)
228{
229 my $dir = $directories{$mod};
230 my $def = $mod;
231 my $spec = $mod;
232 $spec =~ s/\.dll$//;
233 $def =~ s/\.(dll|drv)$//;
234 printf NEWMAKE "lib%s.def: %s/%s.spec.def\n", $def, $dir, $spec;
235 printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s.spec.def \$@\n", $dir, $spec;
236 printf NEWMAKE "lib%s.a: %s/%s.spec.def\n", $def, $dir, $spec;
237 printf NEWMAKE "\t\$(DLLTOOL) -k -l \$@ -d %s/%s.spec.def\n\n", $dir, $spec;
238}
239foreach my $mod (sort @implibs)
240{
241 my $dir = $directories{$mod};
242 my $spec = $mod;
243 $spec =~ s/\.dll$//;
244 printf NEWMAKE "%s/%s.spec.def: \$(WINEBUILD)\n", $dir, $spec;
245}
246
247
248print NEWMAKE <<EOF;
249
Alexandre Julliardf1b48192002-12-15 01:20:54 +0000250\$(SUBDIRS): \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT))
Alexandre Julliard635b09f2003-06-23 18:16:20 +0000251\$(SUBDIRS:%=%/__install__): \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT))
Alexandre Julliardf1b48192002-12-15 01:20:54 +0000252\$(SUBDIRS:%=%/__crosstest__): \$(IMPORT_LIBS:%=%.a)
Alexandre Julliardada5e652002-12-12 22:03:14 +0000253
254EOF
255
256################################################################
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000257# output the inter-dll dependencies and rules
258
Alexandre Julliard45a795c2002-05-23 19:13:22 +0000259print NEWMAKE "# Map library name to the corresponding directory\n\n";
260
261foreach my $mod (sort keys %directories)
262{
263 printf NEWMAKE "%s/%s\$(DLLEXT): %s\n", $directories{$mod}, $mod, $directories{$mod};
264}
265
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000266################################################################
Alexandre Julliardc1bfca02002-03-20 22:19:06 +0000267# output the linkable dlls special links
268
Eric Pouechc0d955e2002-05-21 18:29:31 +0000269my %linkable_dlls = ();
270foreach my $mod (keys %imports)
Alexandre Julliardc1bfca02002-03-20 22:19:06 +0000271{
Eric Pouechc0d955e2002-05-21 18:29:31 +0000272 foreach my $i (@{$linked_dlls{$mod}}) { $linkable_dlls{$i} = 1; }
Alexandre Julliardc1bfca02002-03-20 22:19:06 +0000273}
274
Alexandre Julliard5852f7a2002-05-23 02:47:16 +0000275print NEWMAKE "\n# Special targets for dlls that we need to link to\n\n";
Alexandre Julliard1c404262002-06-14 02:09:08 +0000276printf NEWMAKE "LINKABLE_DLLS = %s\n\n", join( " ", keys %linkable_dlls );
277
Eric Pouechc0d955e2002-05-21 18:29:31 +0000278foreach my $mod (keys %linkable_dlls)
Alexandre Julliardc1bfca02002-03-20 22:19:06 +0000279{
Alexandre Julliard5b80ce32002-07-01 18:23:38 +0000280 printf NEWMAKE "lib%s.\$(LIBEXT): %s/%s\$(DLLEXT)\n", $mod, $directories{$mod}, $mod;
Alexandre Julliardc1bfca02002-03-20 22:19:06 +0000281 printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
282}
283
Alexandre Julliardada5e652002-12-12 22:03:14 +0000284foreach my $mod (keys %imports)
285{
286 my $deps = "";
287 foreach my $i (@{$linked_dlls{$mod}}) { $deps .= " lib$i.\$(LIBEXT)"; }
Alexandre Julliard717e8f42003-06-24 19:30:25 +0000288 if ($deps) { printf NEWMAKE "%s %s/__install__:%s\n", $directories{$mod}, $directories{$mod}, $deps; }
Alexandre Julliardada5e652002-12-12 22:03:14 +0000289}
290
Alexandre Julliard1c404262002-06-14 02:09:08 +0000291print NEWMAKE <<EOF;
Alexandre Julliardada5e652002-12-12 22:03:14 +0000292
Alexandre Julliardf673b712002-06-14 23:48:27 +0000293uninstall::
Alexandre Julliard1c404262002-06-14 02:09:08 +0000294 \$(RM) \$(LINKABLE_DLLS:%=\$(libdir)/lib%.\$(LIBEXT))
295
Alexandre Julliard76c30652003-02-19 22:11:37 +0000296install install-lib:: \$(INSTALLSUBDIRS:%=%/__install__)
Alexandre Julliardf673b712002-06-14 23:48:27 +0000297 \$(RM) \$(LINKABLE_DLLS:%=\$(libdir)/lib%.\$(LIBEXT))
Alexandre Julliard1c404262002-06-14 02:09:08 +0000298 cd \$(libdir) && if [ "\$(dlldir)" = "\$(libdir)/wine" ]; \\
299 then \\
300EOF
301foreach my $mod (keys %linkable_dlls)
302{
303 printf NEWMAKE "\t \$(LN_S) wine/%s\$(DLLEXT) lib%s.\$(LIBEXT); \\\n", $mod, $mod;
304}
305print NEWMAKE "\telse \\\n";
306foreach my $mod (keys %linkable_dlls)
307{
308 printf NEWMAKE "\t \$(LN_S) \$(dlldir)/%s\$(DLLEXT) lib%s.\$(LIBEXT); \\\n", $mod, $mod;
309}
310print NEWMAKE "\tfi\n\n";
311
Alexandre Julliardc1bfca02002-03-20 22:19:06 +0000312################################################################
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000313# makefile trailer
314
Alexandre Julliard7c3dec92001-06-08 19:09:44 +0000315print NEWMAKE <<EOF;
Alexandre Julliard78e33112003-04-12 00:05:27 +0000316# Rules for auto documentation
317
318\$(SUBDIRS:%=%/__man__): dummy
319 cd `dirname \$@` && \$(MAKE) man
320
321man: \$(SUBDIRS:%=%/__man__)
322
323\$(SUBDIRS:%=%/__doc_html__): dummy
324 cd `dirname \$@` && \$(MAKE) doc-html
325
326doc-html: \$(SUBDIRS:%=%/__doc_html__)
327
328\$(SUBDIRS:%=%/__doc_sgml__): dummy
329 cd `dirname \$@` && \$(MAKE) doc-sgml
330
331doc-sgml: \$(SUBDIRS:%=%/__doc_sgml__)
332
333.PHONY: man doc-html doc-sgml \$(SUBDIRS:%=%/__man__) \$(SUBDIRS:%=%/__doc_html__) \$(SUBDIRS:%=%/__doc_sgml__)
334
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000335# Misc rules
Alexandre Julliard7c3dec92001-06-08 19:09:44 +0000336
Alexandre Julliardf1b48192002-12-15 01:20:54 +0000337install install-dev:: \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT))
Alexandre Julliardada5e652002-12-12 22:03:14 +0000338 \$(MKINSTALLDIRS) \$(dlldir)
Alexandre Julliardf1b48192002-12-15 01:20:54 +0000339 for f in \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT)); do \$(INSTALL_DATA) \$\$f \$(dlldir)/\$\$f; done
Alexandre Julliardada5e652002-12-12 22:03:14 +0000340
Alexandre Julliardf673b712002-06-14 23:48:27 +0000341uninstall::
Alexandre Julliardf1b48192002-12-15 01:20:54 +0000342 \$(RM) \$(IMPORT_LIBS:%=\$(dlldir)/%.\$(IMPLIBEXT))
Alexandre Julliardc1bfca02002-03-20 22:19:06 +0000343 -rmdir \$(dlldir)
Alexandre Julliardf33f7f02001-09-17 20:09:08 +0000344
Alexandre Julliardada5e652002-12-12 22:03:14 +0000345clean::
Alexandre Julliard23829be2003-05-15 04:30:46 +0000346 \$(RM) \$(IMPORT_LIBS:%=%.a) \$(IMPORT_LIBS:%=%.def) \$(SYMLINKS)
Alexandre Julliardada5e652002-12-12 22:03:14 +0000347
Alexandre Julliard5852f7a2002-05-23 02:47:16 +0000348check test:: \$(BUILDSUBDIRS:%=%/__test__)
Alexandre Julliard93841842002-01-14 19:56:46 +0000349
Alexandre Julliardc3c587e2002-09-06 19:46:00 +0000350crosstest:: \$(BUILDSUBDIRS:%=%/__crosstest__)
351
Alexandre Julliard5852f7a2002-05-23 02:47:16 +0000352checklink:: \$(BUILDSUBDIRS:%=%/__checklink__)
Alexandre Julliardf673b712002-06-14 23:48:27 +0000353
Alexandre Julliardf673b712002-06-14 23:48:27 +0000354### Dependencies:
Alexandre Julliard7c3dec92001-06-08 19:09:44 +0000355EOF
356
357close NEWMAKE;
358rename "Makefile.in.new", "Makefile.in";
359printf "Successfully updated Makefile.in\n";