Cast time_t to long for printing.
[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   "d3d9"     => "OPENGLFILES",
40   "d3dx8"    => "OPENGLFILES",
41   "x11drv"   => "XFILES"
42 );
43
44 foreach my $i (split(/\s/,$makefiles))
45 {
46     my $module;
47
48     next if $i =~ /\/tests\/Makefile.in/;
49
50     open MAKE,$i;
51
52     $module = undef;
53     while (<MAKE>)
54     {
55         chop;
56         # 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
60         if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
61         {
62             $module = $1;
63             $imports{$module} = [ ];
64             ($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         }
73         if (/^(DELAYIMPORTS|IMPORTS)\s*=\s*(.*)/)
74         {
75             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);
82             $linked_dlls{$module} = \@list;
83             next;
84         }
85     }
86     close MAKE;
87     push @{$imports{$module}}, "kernel32.dll" unless !defined($module) || @{$imports{$module}} || $module eq "ntdll.dll";
88 }
89
90 open NEWMAKE,">Makefile.in.new" or die "cannot create Makefile.in.new";
91
92 ################################################################
93 # makefile header
94
95 print NEWMAKE <<EOF;
96 # Automatically generated by make_dlls; DO NOT EDIT!!
97
98 TOPSRCDIR = \@top_srcdir\@
99 TOPOBJDIR = ..
100 SRCDIR    = \@srcdir\@
101 VPATH     = \@srcdir\@
102
103 EOF
104
105 ################################################################
106 # output special dlls configure definitions
107
108 printf NEWMAKE "# special configure-dependent targets\n\n";
109 my %specials = ();
110 foreach my $mod (sort keys %special_dlls)
111 {
112     $specials{$special_dlls{$mod}} .= " " . $mod;
113 }
114 foreach my $i (sort keys %specials)
115 {
116     printf NEWMAKE "%s =%s\n", $i, $specials{$i};
117 }
118 printf NEWMAKE "EXTRADIRS =";
119 foreach my $i (sort keys %specials) { printf NEWMAKE " \@%s\@", $i; }
120 printf NEWMAKE "\n\n";
121
122
123 ################################################################
124 # output the subdirs list
125
126 print NEWMAKE "# Subdir list\n\nBASEDIRS =";
127 foreach my $dir (sort values %directories)
128 {
129     next if defined($special_dlls{$dir});  # skip special dlls
130     printf NEWMAKE " \\\n\t%s", $dir;
131 }
132
133 printf NEWMAKE "\n\nSUBDIRS = \\\n\t\$(BASEDIRS)";
134 foreach my $dir (sort keys %special_dlls)
135 {
136     printf NEWMAKE " \\\n\t%s", $dir;
137 }
138 printf NEWMAKE <<EOF;
139
140
141 BUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)
142
143 INSTALLSUBDIRS = \$(BUILDSUBDIRS)
144 EOF
145
146 ################################################################
147 # output the all: target
148
149 my %targets = ();  # use a hash to get rid of duplicate target names
150 my %targets16 = ();
151 foreach my $mod (sort keys %directories)
152 {
153     next if defined($special_dlls{$directories{$mod}});  # skip special dlls
154     $targets{sprintf("%s\$(DLLEXT)",$mod)} = 1;
155     next unless defined $altnames{$mod};
156     foreach my $i (sort @{$altnames{$mod}})
157     {
158         $targets16{sprintf("%s\$(DLLEXT)",$i)} = 1;
159     }
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 = \\
174         \$(EXTRADIRS:%=%.dll\$(DLLEXT)) \\
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)
184 EOF
185
186 ################################################################
187 # output the lib name -> directory rules
188
189 print NEWMAKE <<EOF;
190
191 # Map symlink name to the corresponding library
192
193 EOF
194
195 foreach my $mod (sort keys %directories)
196 {
197     printf NEWMAKE "%s\$(DLLEXT)", $mod;
198     if (defined $altnames{$mod})
199     {
200         my $count = 1;
201         foreach my $i (sort @{$altnames{$mod}})
202         {
203             if (!($count++ % 3)) { printf NEWMAKE " \\\n "; }
204             printf NEWMAKE " %s\$(DLLEXT)", $i;
205         }
206     }
207     printf NEWMAKE ": %s/%s\$(DLLEXT)\n", $directories{$mod}, $mod;
208     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
209 }
210
211
212 ################################################################
213 # output the import libraries rules
214
215 my @implibs = grep /\.dll$/, keys %directories;
216 push @implibs, "winspool.drv";
217
218 print NEWMAKE "\n# Import libraries\n\nIMPORT_LIBS =";
219 foreach my $mod (sort @implibs)
220 {
221     my $def = $mod;
222     $def =~ s/\.(dll|drv)$//;
223     printf NEWMAKE " \\\n\tlib%s", $def;
224 }
225 print NEWMAKE "\n\n";
226
227 foreach 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 }
239 foreach 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
248 print NEWMAKE <<EOF;
249
250 \$(SUBDIRS): \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT))
251 \$(SUBDIRS:%=%/__install__): \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT))
252 \$(SUBDIRS:%=%/__crosstest__): \$(IMPORT_LIBS:%=%.a)
253
254 EOF
255
256 ################################################################
257 # output the inter-dll dependencies and rules
258
259 print NEWMAKE "# Map library name to the corresponding directory\n\n";
260
261 foreach my $mod (sort keys %directories)
262 {
263     printf NEWMAKE "%s/%s\$(DLLEXT): %s\n", $directories{$mod}, $mod, $directories{$mod};
264 }
265
266 ################################################################
267 # output the linkable dlls special links
268
269 my %linkable_dlls = ();
270 foreach my $mod (keys %imports)
271 {
272     foreach my $i (@{$linked_dlls{$mod}}) { $linkable_dlls{$i} = 1; }
273 }
274
275 print NEWMAKE "\n# Special targets for dlls that we need to link to\n\n";
276 printf NEWMAKE "LINKABLE_DLLS = %s\n\n", join( " ", keys %linkable_dlls );
277
278 foreach my $mod (keys %linkable_dlls)
279 {
280     printf NEWMAKE "lib%s.\$(LIBEXT): %s/%s\$(DLLEXT)\n", $mod, $directories{$mod}, $mod;
281     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
282 }
283
284 foreach my $mod (keys %imports)
285 {
286     my $deps = "";
287     foreach my $i (@{$linked_dlls{$mod}}) { $deps .= " lib$i.\$(LIBEXT)"; }
288     if ($deps) { printf NEWMAKE "%s %s/__install__:%s\n", $directories{$mod}, $directories{$mod}, $deps; }
289 }
290
291 print NEWMAKE <<EOF;
292
293 uninstall::
294         \$(RM) \$(LINKABLE_DLLS:%=\$(libdir)/lib%.\$(LIBEXT))
295
296 install install-lib:: \$(INSTALLSUBDIRS:%=%/__install__)
297         \$(RM) \$(LINKABLE_DLLS:%=\$(libdir)/lib%.\$(LIBEXT))
298         cd \$(libdir) && if [ "\$(dlldir)" = "\$(libdir)/wine" ]; \\
299         then \\
300 EOF
301 foreach my $mod (keys %linkable_dlls)
302 {
303     printf NEWMAKE "\t  \$(LN_S) wine/%s\$(DLLEXT) lib%s.\$(LIBEXT); \\\n", $mod, $mod;
304 }
305 print NEWMAKE "\telse \\\n";
306 foreach my $mod (keys %linkable_dlls)
307 {
308     printf NEWMAKE "\t  \$(LN_S) \$(dlldir)/%s\$(DLLEXT) lib%s.\$(LIBEXT); \\\n", $mod, $mod;
309 }
310 print NEWMAKE "\tfi\n\n";
311
312 ################################################################
313 # makefile trailer
314
315 print NEWMAKE <<EOF;
316 # Rules for auto documentation
317
318 \$(SUBDIRS:%=%/__man__): dummy
319         cd `dirname \$@` && \$(MAKE) man
320
321 man: \$(SUBDIRS:%=%/__man__)
322
323 \$(SUBDIRS:%=%/__doc_html__): dummy
324         cd `dirname \$@` && \$(MAKE) doc-html
325
326 doc-html: \$(SUBDIRS:%=%/__doc_html__)
327
328 \$(SUBDIRS:%=%/__doc_sgml__): dummy
329         cd `dirname \$@` && \$(MAKE) doc-sgml
330
331 doc-sgml: \$(SUBDIRS:%=%/__doc_sgml__)
332
333 .PHONY: man doc-html doc-sgml \$(SUBDIRS:%=%/__man__) \$(SUBDIRS:%=%/__doc_html__) \$(SUBDIRS:%=%/__doc_sgml__)
334
335 # Misc rules
336
337 install install-dev:: \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT))
338         \$(MKINSTALLDIRS) \$(dlldir)
339         for f in \$(IMPORT_LIBS:%=%.\$(IMPLIBEXT)); do \$(INSTALL_DATA) \$\$f \$(dlldir)/\$\$f; done
340
341 uninstall::
342         \$(RM) \$(IMPORT_LIBS:%=\$(dlldir)/%.\$(IMPLIBEXT))
343         -rmdir \$(dlldir)
344
345 clean::
346         \$(RM) \$(IMPORT_LIBS:%=%.a) \$(IMPORT_LIBS:%=%.def) \$(SYMLINKS)
347
348 check test:: \$(BUILDSUBDIRS:%=%/__test__)
349
350 crosstest:: \$(BUILDSUBDIRS:%=%/__crosstest__)
351
352 checklink:: \$(BUILDSUBDIRS:%=%/__checklink__)
353
354 ### Dependencies:
355 EOF
356
357 close NEWMAKE;
358 rename "Makefile.in.new", "Makefile.in";
359 printf "Successfully updated Makefile.in\n";