include: Win64 fix in TBBUTTON.
[wine] / dlls / make_dlls
1 #!/usr/bin/perl -w
2 #
3 # Update the dll dependencies in the dlls main Makefile.in.
4 #
5 # Copyright 2001 Alexandre Julliard
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #
21
22 use strict;
23
24 my %directories = ();
25 my %testdirs = ();
26 my %importlibs = ();
27 my %static_implibs = ();
28 my %staticlib_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   "glu32"    => "GLU32FILES",
35   "glut32"   => "GLUT32FILES",
36   "opengl32" => "OPENGLFILES",
37   "wined3d"  => "OPENGLFILES",
38   "winex11.drv" => "XFILES"
39 );
40
41 sub needs_symlink($)
42 {
43     (my $mod = $_[0]) =~ s/\.dll$//;
44     return $mod ne $directories{$_[0]};
45 }
46
47 sub update_file($)
48 {
49     my $file = shift;
50     if (!system "cmp $file $file.new >/dev/null")
51     {
52         unlink "$file.new";
53         print "$file is unchanged\n";
54     }
55     else
56     {
57         rename "$file.new", "$file";
58         print "$file updated\n";
59         if (-x "./config.status" && $file =~ /(.*Makefile)\.in$/)
60         {
61             system "./config.status", $1;
62         }
63     }
64 }
65
66 # if we are inside the dlls dir, go up one level
67 if (! -f "configure.ac" && -f "../configure.ac") { chdir(".."); }
68
69 my @args = @ARGV;
70 if (!@args) { @args = map { s/^(.*)\.in/$1/; $_; } split(/\s/,`find dlls -name Makefile.in -print`); }
71
72 foreach my $i (@args)
73 {
74     if ($i =~ /dlls\/(.*)\/tests\/Makefile/)
75     {
76         $testdirs{$1} = "$1/tests";
77         next;
78     }
79
80     open MAKE, "$i.in" or die "cannot open $i.in\n";
81
82     my $module = undef;
83     my $dir = $i;
84
85     while (<MAKE>)
86     {
87         chop;
88         # EPP hack to disable this DLL... the MKDLL_SKIP comment must appear
89         # at the very top of the Makefile.in
90         last if (/^\#\s*MKDLL_SKIP/);
91
92         if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
93         {
94             $module = $1;
95             if ($module =~ /^lib.*\.a$/)
96             {
97                 ($staticlib_dirs{$module} = $i) =~ s/^dlls\/(.*)\/[^\/]+$/$1/;
98                 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "lib$staticlib_dirs{$module}.a" ne $module;
99             }
100             else
101             {
102                 ($directories{$module} = $i) =~ s/^dlls\/(.*)\/[^\/]+$/$1/;
103             }
104             next;
105         }
106         if (/^IMPORTLIB\s*=\s*([a-zA-Z0-9_.]+)\.\$\(IMPLIBEXT\)/)
107         {
108             $importlibs{$module} = $1;
109             next;
110         }
111         if (/^IMPLIB_SRCS\s*=/)
112         {
113             $static_implibs{$module} = 1;
114             next;
115         }
116         if (/^SPEC_SRCS16\s*=\s*(.*)/)
117         {
118             my $specs = $1;
119             while ($specs =~ /\s*(.*)\\$/) { $specs = $1 . <MAKE>; }
120             my @list = split(/\s+/,$specs);
121             @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @list;
122             $altnames{$module} = \@list;
123             next;
124         }
125     }
126     close MAKE;
127 }
128
129 open NEWMAKE,">dlls/Makefile.in.new" or die "cannot create dlls/Makefile.in.new";
130
131 ################################################################
132 # makefile header
133
134 print NEWMAKE <<EOF;
135 # Automatically generated by make_dlls; DO NOT EDIT!!
136
137 TOPSRCDIR = \@top_srcdir\@
138 TOPOBJDIR = ..
139 SRCDIR    = \@srcdir\@
140 VPATH     = \@srcdir\@
141
142 EOF
143
144 ################################################################
145 # output special dlls configure definitions
146
147 printf NEWMAKE "# special configure-dependent targets\n\n";
148 my %specials = ();
149 foreach my $mod (sort keys %special_dlls)
150 {
151     $specials{$special_dlls{$mod}} .= " " . $mod;
152 }
153 foreach my $i (sort keys %specials)
154 {
155     printf NEWMAKE "%s =%s\n", $i, $specials{$i};
156 }
157 printf NEWMAKE "EXTRADIRS =";
158 foreach my $i (sort keys %specials) { printf NEWMAKE " \@%s\@", $i; }
159 printf NEWMAKE "\n\n";
160
161
162 ################################################################
163 # output the subdirs list
164
165 print NEWMAKE "# Subdir list\n\nBASEDIRS =";
166 foreach my $dir (sort values %directories)
167 {
168     next if defined($special_dlls{$dir});  # skip special dlls
169     printf NEWMAKE " \\\n\t%s", $dir;
170 }
171
172 print NEWMAKE "\n\nIMPLIBSUBDIRS = \\\n\t";
173 print NEWMAKE join " \\\n\t", sort values %staticlib_dirs;
174
175 print NEWMAKE "\n\nTESTSUBDIRS = \\\n\t";
176 print NEWMAKE join " \\\n\t", sort values %testdirs;
177
178 print NEWMAKE "\n\nSUBDIRS = \\\n\t";
179 print NEWMAKE join " \\\n\t", "\$(BASEDIRS)", "\$(IMPLIBSUBDIRS)", "\$(TESTSUBDIRS)",
180                               sort keys %special_dlls;
181 print NEWMAKE <<EOF;
182
183
184 BUILDSUBDIRS   = \$(BASEDIRS) \$(EXTRADIRS) \$(TESTSUBDIRS)
185 INSTALLSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(IMPLIBSUBDIRS)
186 DOCSUBDIRS     = \$(BASEDIRS) \$(EXTRADIRS)
187 EOF
188
189 ################################################################
190 # output the all: target
191
192 my %targets = ();  # use a hash to get rid of duplicate target names
193 my %targets16 = ();
194 foreach my $mod (sort keys %directories)
195 {
196     next if defined($special_dlls{$directories{$mod}});  # skip special dlls
197     $targets{$mod . ".so"} = 1 if needs_symlink($mod);
198     next unless defined $altnames{$mod};
199     foreach my $i (sort @{$altnames{$mod}})
200     {
201         $targets16{$i . "16"} = $mod;
202     }
203 }
204
205 print NEWMAKE <<EOF;
206
207 \@MAKE_RULES\@
208
209 # Symbolic links
210
211 WIN16_FILES = \\
212 EOF
213 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets16 );
214
215 print NEWMAKE <<EOF;
216
217 SYMLINKS_SO = \\
218         \@WIN16_FILES\@ \\
219 EOF
220 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );
221
222 print NEWMAKE <<EOF;
223
224 # Main target
225
226 all: \$(BUILDSUBDIRS) symlinks\$(DLLEXT)
227
228 .PHONY: symlinks symlinks.so implib
229
230 symlinks.so: \$(SYMLINKS_SO)
231
232 symlinks: \$(BUILDSUBDIRS)
233
234 EOF
235
236 ################################################################
237 # output the lib name -> directory rules
238
239 print NEWMAKE "# Map symlink name to the corresponding library\n\n";
240 foreach my $mod (sort keys %directories)
241 {
242     next unless needs_symlink($mod);
243     printf NEWMAKE "%s.so: %s/%s.so\n", $mod, $directories{$mod}, $mod;
244     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s.so \$@\n\n", $directories{$mod}, $mod;
245 }
246
247 print NEWMAKE "# Placeholders for 16-bit libraries\n\n";
248 foreach my $mod (sort keys %directories)
249 {
250     next unless defined $altnames{$mod};
251     printf NEWMAKE "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
252     printf NEWMAKE "\techo \"%s\" >\$\@\n\n", $mod;
253 }
254
255 ################################################################
256 # output the import libraries rules
257
258 print NEWMAKE "# Import libraries\n\n";
259 print NEWMAKE "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
260
261 my @lib_symlinks = ();
262 foreach my $mod (sort keys %importlibs)
263 {
264     my $dir = $directories{$mod};
265     my $lib = $importlibs{$mod};
266     if ($lib ne "lib" . $dir) { push @lib_symlinks, $mod; }
267 }
268 print NEWMAKE "IMPORT_SYMLINKS =";
269 foreach my $mod (sort @lib_symlinks)
270 {
271     printf NEWMAKE " \\\n\t%s.\$(IMPLIBEXT)", $importlibs{$mod};
272 }
273
274 print NEWMAKE "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
275 foreach my $mod (sort keys %staticlib_dirs)
276 {
277     printf NEWMAKE " \\\n\t%s/%s", $staticlib_dirs{$mod}, $mod;
278 }
279 foreach my $mod (sort keys %importlibs)
280 {
281     my $dir = $directories{$mod};
282     my $def = $mod;
283     $def =~ s/\.(dll|drv)$//;
284     printf NEWMAKE " \\\n\t%s/lib%s.\$(IMPLIBEXT)", $dir, $def;
285     printf NEWMAKE " \\\n\t%s/lib%s.\$(STATIC_IMPLIBEXT)", $dir, $def if $static_implibs{$mod};
286 }
287 print NEWMAKE "\n\n";
288 print NEWMAKE "implib: \$(IMPORT_LIBS)\n\n";
289
290 foreach my $mod (sort keys %importlibs)
291 {
292     my $dir = $directories{$mod};
293     my $lib = $importlibs{$mod};
294     my $spec = $mod;
295     $spec =~ s/\.dll$//;
296     printf NEWMAKE "%s/%s.\$(IMPLIBEXT): %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
297     printf NEWMAKE "\t\@cd %s && \$(MAKE) %s.\$(IMPLIBEXT)\n\n", $dir, $lib;
298     next unless $static_implibs{$mod};
299     printf NEWMAKE "%s/%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
300     printf NEWMAKE "\t\@cd %s && \$(MAKE) %s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
301 }
302 foreach my $mod (sort @lib_symlinks)
303 {
304     my $dir = $directories{$mod};
305     my $lib = $importlibs{$mod} . ".\$(IMPLIBEXT)";
306     printf NEWMAKE "%s: %s/%s\n", $lib, $dir, $lib;
307     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $dir, $lib;
308 }
309
310 print NEWMAKE <<EOF;
311 \$(BUILDSUBDIRS): \$(IMPORT_LIBS)
312 \$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)
313
314 EOF
315
316 ################################################################
317 # output the inter-dll dependencies and rules
318
319 print NEWMAKE "# Map library name to the corresponding directory\n\n";
320
321 foreach my $mod (sort keys %directories)
322 {
323     next unless needs_symlink($mod);
324     printf NEWMAKE "%s/%s.so: %s\n", $directories{$mod}, $mod, $directories{$mod};
325 }
326 foreach my $mod (sort keys %staticlib_dirs)
327 {
328     printf NEWMAKE "%s/%s: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
329 }
330
331 ################################################################
332 # makefile trailer
333
334 print NEWMAKE <<EOF;
335
336 # Misc rules
337
338 install-lib:: \$(INSTALLSUBDIRS:%=%/__install-lib__)
339
340 install-dev:: \$(INSTALLSUBDIRS:%=%/__install-dev__)
341
342 uninstall::
343         -rmdir \$(DESTDIR)\$(dlldir)
344
345 clean::
346         \$(RM) \$(IMPORT_SYMLINKS) \$(WIN16_FILES)
347 EOF
348
349 close NEWMAKE;
350 update_file("dlls/Makefile.in");
351
352 ################################################################
353 # .gitignore file
354
355 open GITIGNORE, ">dlls/.gitignore.new" or die "cannot create dlls/.gitignore.new";
356 print GITIGNORE "# Automatically generated by make_dlls; DO NOT EDIT!!\n";
357
358 my @ignores =
359 (
360  "/Makedll.rules",
361  "/Makeimplib.rules",
362  "/Maketest.rules",
363  "*/tests/testlist.c",
364  "*/tests/*.ok",
365 );
366
367 foreach my $mod (sort @lib_symlinks)
368 {
369     push @ignores, "/$importlibs{$mod}.def";
370 }
371 foreach my $mod (sort keys %directories)
372 {
373     next unless defined $altnames{$mod};
374     push @ignores, map { "/" . $_ . "16"; } @{$altnames{$mod}};
375 }
376 foreach my $mod (sort keys %importlibs)
377 {
378     my $dir = $directories{$mod};
379     my $def = $mod;
380     $def =~ s/\.(dll|drv)$//;
381     push @ignores, "$dir/lib$def.def";
382 }
383
384 print GITIGNORE join("\n", sort @ignores) . "\n";
385
386 close GITIGNORE;
387 update_file("dlls/.gitignore");