Better implementation of GetCalendarInfo{A,W}, not perfect.
[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 $makefiles = `find . -name Makefile.in -print`;
24
25 %imports = ();
26 %directories = ();
27 %altnames = ();
28 %linked_dlls = ();
29
30 # list of special dlls that can be switched on or off by configure
31 %special_dlls =
32 (
33   "ddraw"    => "XFILES",
34   "glu32"    => "GLU32FILES",
35   "opengl32" => "OPENGLFILES",
36   "x11drv"   => "XFILES"
37 );
38
39 foreach $i (split(/\s/,$makefiles))
40 {
41     open MAKE,$i;
42     while (<MAKE>)
43     {
44         chop;
45         if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
46         {
47             $module = $1;
48             $imports{$module} = [ ];
49             ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
50             next;
51         }
52         if (/^ALTNAMES\s*=\s*(.*)/)
53         {
54             my @list = split(/\s/,$1);
55             $altnames{$module} = \@list;
56             next;
57         }
58         if (/^(DELAYIMPORTS|IMPORTS)\s*=\s*(.*)/)
59         {
60             my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$2);
61             push @{$imports{$module}}, @list;
62             next;
63         }
64         if (/^LDIMPORTS\s*=\s*(.*)/)
65         {
66             my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$1);
67             $linked_dlls{$module} = \@list;
68             next;
69         }
70     }
71 }
72
73 open NEWMAKE,">Makefile.in.new" or die "cannot create Makefile.in.new";
74
75 ################################################################
76 # makefile header
77
78 print NEWMAKE <<EOF;
79 # Automatically generated by make_dlls; DO NOT EDIT!!
80
81 TOPSRCDIR = \@top_srcdir\@
82 TOPOBJDIR = ..
83 SRCDIR    = \@srcdir\@
84 VPATH     = \@srcdir\@
85
86 EOF
87
88 ################################################################
89 # output special dlls configure definitions
90
91 printf NEWMAKE "# special configure-dependent targets\n\n";
92 my %specials = ();
93 foreach $mod (sort keys %special_dlls)
94 {
95     $specials{$special_dlls{$mod}} .= " " . $mod;
96 }
97 foreach $i (sort keys %specials)
98 {
99     printf NEWMAKE "%s =%s\n", $i, $specials{$i};
100 }
101 printf NEWMAKE "EXTRADIRS =";
102 foreach $i (sort keys %specials) { printf NEWMAKE " \@%s\@", $i; }
103 printf NEWMAKE "\n\n";
104
105
106 ################################################################
107 # output the subdirs list
108
109 print NEWMAKE <<EOF;
110 # Subdir list
111
112 SUBDIRS = \\
113 EOF
114 printf NEWMAKE "\t\$(EXTRADIRS)";
115 foreach $dir (sort values %directories)
116 {
117     next if defined($special_dlls{$dir});  # skip special dlls
118     printf NEWMAKE " \\\n\t%s", $dir;
119 }
120 printf NEWMAKE "\n";
121
122
123 ################################################################
124 # output the all: target
125
126 my %targets = ();  # use a hash to get rid of duplicate target names
127 foreach $mod (sort keys %directories)
128 {
129     next if defined($special_dlls{$directories{$mod}});  # skip special dlls
130     $targets{sprintf("%s\$(DLLEXT)",$mod)} = 1;
131     next unless defined $altnames{$mod};
132     foreach $i (sort @{$altnames{$mod}})
133     {
134         $targets{sprintf("%s\$(DLLEXT)",$i)} = 1;
135     }
136 }
137 print NEWMAKE <<EOF;
138
139 # Main target
140
141 \@MAKE_RULES\@
142
143 all: \\
144         \$(EXTRADIRS:%=%.dll\$(DLLEXT)) \\
145 EOF
146 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );
147
148
149 ################################################################
150 # output the lib name -> directory rules
151
152 print NEWMAKE <<EOF;
153
154 # Map library name to directory
155
156 EOF
157
158 foreach $mod (sort keys %directories)
159 {
160     printf NEWMAKE "%s\$(DLLEXT)", $mod;
161     if (defined $altnames{$mod})
162     {
163         my $count = 1;
164         foreach $i (sort @{$altnames{$mod}})
165         {
166             if (!($count++ % 3)) { printf NEWMAKE " \\\n "; }
167             printf NEWMAKE " %s\$(DLLEXT)", $i;
168         }
169     }
170     printf NEWMAKE ": %s/%s\$(DLLEXT)\n", $directories{$mod}, $mod;
171     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
172 }
173
174
175 ################################################################
176 # output the inter-dll dependencies and rules
177
178 print NEWMAKE "# Inter-dll dependencies\n\n";
179
180 my @depends = ();
181 foreach $mod (sort keys %imports)
182 {
183     my $count = 1;
184     my $dep = sprintf("%s/%s\$(DLLEXT): dummy", $directories{$mod}, $mod);
185     foreach $i (@{$imports{$mod}})
186     {
187         if ($count++ >= 3)
188         {
189             $count = 0;
190             $dep .= " \\\n ";
191         }
192         $dep .= sprintf(" %s\$(DLLEXT)", $i);
193     }
194     foreach $i (@{$linked_dlls{$mod}})
195     {
196         if ($count++ >= 3)
197         {
198             $count = 0;
199             $dep .= " \\\n ";
200         }
201         $dep .= sprintf(" lib%s.\$(LIBEXT)", $i);
202     }
203     $dep .= sprintf("\n\t\@cd %s && \$(MAKE) %s\$(DLLEXT)\n\n",$directories{$mod}, $mod);
204     push @depends, $dep;
205 }
206 print NEWMAKE sort @depends;
207
208
209 ################################################################
210 # output the linkable dlls special links
211
212 %linkable_dlls = ();
213 foreach $mod (keys %imports)
214 {
215     foreach $i (@{$linked_dlls{$mod}}) { $linkable_dlls{$i} = 1; }
216 }
217
218 print NEWMAKE "# Special targets for dlls that we need to link to\n\n";
219 foreach $mod (keys %linkable_dlls)
220 {
221     printf NEWMAKE "lib%s.\$(LIBEXT): %s/%s\$(DLLEXT)\n", $mod, $directories{$mod}, $mod;
222     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
223 }
224
225 ################################################################
226 # makefile trailer
227
228 print NEWMAKE <<EOF;
229 # Misc rules
230
231 \$(SUBDIRS:%=%/__checklink__): dummy
232         \@cd `dirname \$\@` && \$(MAKE) checklink
233
234 install:: \$(SUBDIRS:%=%/__install__)
235
236 uninstall:: \$(SUBDIRS:%=%/__uninstall__)
237         -rmdir \$(dlldir)
238
239 check test:: \$(SUBDIRS:%=%/__test__)
240
241 checklink:: \$(SUBDIRS:%=%/__checklink__)
242 EOF
243
244 close NEWMAKE;
245 rename "Makefile.in.new", "Makefile.in";
246 printf "Successfully updated Makefile.in\n";