- Introduce a significant design decision.
[wine/dcerpc.git] / dlls / make_dlls
blob7a51bb0d96f2a2746493d5047a00e26508309274
1 #!/usr/bin/perl -w
3 # Update the dll dependencies in the dlls main Makefile.in.
4 # Must be run in the dlls/ directory of the Wine tree.
6 # Copyright 2001 Alexandre Julliard
9 $makefiles = `find . -name Makefile.in -print`;
11 %imports = ();
12 %directories = ();
13 %altnames = ();
15 # list of special dlls that can be switched on or off by configure
16 %special_dlls =
18 "ddraw" => "XFILES",
19 "glu32" => "GLU32FILES",
20 "opengl32" => "OPENGLFILES",
21 "x11drv" => "XFILES"
24 foreach $i (split(/\s/,$makefiles))
26 open MAKE,$i;
27 while (<MAKE>)
29 chop;
30 if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
32 $module = $1;
33 ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
34 next;
36 if (/^ALTNAMES\s*=\s*(.*)/)
38 my @list = split(/\s/,$1);
39 $altnames{$module} = \@list;
40 next;
45 foreach $mod (sort keys %directories)
47 my $spec = sprintf("%s/%s.spec", $directories{$mod}, $mod);
48 open SPEC,$spec or die "cannot open $spec";
49 $imports{$mod} = [ ];
50 while (<SPEC>)
52 if (/^\#?import\s+(-delay\s+)?([a-zA-Z0-9_]+)\.dll/)
54 my $imp = $2;
55 push @{$imports{$mod}}, $imp;
56 next;
58 if (/^\#?import\s+(-delay\s+)?([a-zA-Z0-9_.]+)/)
60 my $imp = $2;
61 push @{$imports{$mod}}, $imp;
62 next;
67 open NEWMAKE,">Makefile.in.new" or die "cannot create Makefile.in.new";
69 ################################################################
70 # makefile header
72 print NEWMAKE <<EOF;
73 # Automatically generated by make_dlls; DO NOT EDIT!!
75 TOPSRCDIR = \@top_srcdir\@
76 TOPOBJDIR = ..
77 SRCDIR = \@srcdir\@
78 VPATH = \@srcdir\@
79 LIBEXT = \@LIBEXT\@
81 EOF
83 ################################################################
84 # output special dlls configure definitions
86 printf NEWMAKE "# special configure-dependent targets\n\n";
87 my %specials = ();
88 foreach $mod (sort keys %special_dlls)
90 $specials{$special_dlls{$mod}} .= " " . $mod;
92 foreach $i (sort keys %specials)
94 printf NEWMAKE "%s =%s\n", $i, $specials{$i};
96 printf NEWMAKE "EXTRADIRS =";
97 foreach $i (sort keys %specials) { printf NEWMAKE " \@%s\@", $i; }
98 printf NEWMAKE "\n\n";
101 ################################################################
102 # output the subdirs list
104 print NEWMAKE <<EOF;
105 # Subdir list
107 SUBDIRS = \\
109 printf NEWMAKE "\t\$(EXTRADIRS)";
110 foreach $dir (sort values %directories)
112 next if defined($special_dlls{$dir}); # skip special dlls
113 printf NEWMAKE " \\\n\t%s", $dir;
115 printf NEWMAKE "\n";
118 ################################################################
119 # output the all: target
121 my %targets = (); # use a hash to get rid of duplicate target names
122 foreach $mod (sort keys %directories)
124 next if defined($special_dlls{$mod}); # skip special dlls
125 $targets{sprintf("lib%s.\$(LIBEXT)",$mod)} = 1;
126 next unless defined $altnames{$mod};
127 foreach $i (sort @{$altnames{$mod}})
129 $targets{sprintf("lib%s.\$(LIBEXT)",$i)} = 1;
132 print NEWMAKE <<EOF;
134 # Main target
136 all: \\
137 \$(EXTRADIRS:%=lib%.\$(LIBEXT)) \\
139 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );
142 ################################################################
143 # output the lib name -> directory rules
145 print NEWMAKE <<EOF;
147 \@MAKE_RULES\@
149 # Map library name to directory
153 foreach $mod (sort keys %directories)
155 printf NEWMAKE "lib%s.\$(LIBEXT)", $mod;
156 if (defined $altnames{$mod})
158 my $count = 1;
159 foreach $i (sort @{$altnames{$mod}})
161 if (!($count++ % 3)) { printf NEWMAKE " \\\n "; }
162 printf NEWMAKE " lib%s.\$(LIBEXT)", $i;
165 printf NEWMAKE ": %s/lib%s.\$(LIBEXT)\n", $directories{$mod}, $mod;
166 printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/lib%s.\$(LIBEXT) \$@\n\n", $directories{$mod}, $mod;
170 ################################################################
171 # output the inter-dll dependencies and rules
173 print NEWMAKE "# Inter-dll dependencies\n\n";
175 my @depends = ();
176 foreach $mod (sort keys %imports)
178 my $count = 1;
179 my $dep = sprintf("%s/lib%s.\$(LIBEXT): dummy", $directories{$mod}, $mod);
180 foreach $i (@{$imports{$mod}})
182 if ($count++ >= 3)
184 $count = 0;
185 $dep .= " \\\n ";
187 $dep .= sprintf(" lib%s.\$(LIBEXT)", $i);
189 $dep .= sprintf("\n\t\@cd %s && \$(MAKE) lib%s.\$(LIBEXT)\n\n",$directories{$mod}, $mod);
190 push @depends, $dep;
192 print NEWMAKE sort @depends;
195 ################################################################
196 # makefile trailer
198 print NEWMAKE <<EOF;
199 # Misc rules
201 \$(SUBDIRS:%=%/__test__): dummy
202 \@cd `dirname \$\@` && \$(MAKE) test
204 \$(SUBDIRS:%=%/__checklink__): dummy
205 \@cd `dirname \$\@` && \$(MAKE) checklink
207 \$(SUBDIRS:%=%/__debug_channels__): dummy
208 \@cd `dirname \$\@` && \$(MAKE) debug_channels
210 install:: \$(SUBDIRS:%=%/__install__)
212 uninstall:: \$(SUBDIRS:%=%/__uninstall__)
214 test:: \$(SUBDIRS:%=%/__test__)
216 checklink:: \$(SUBDIRS:%=%/__checklink__)
218 debug_channels:: \$(SUBDIRS:%=%/__debug_channels__)
221 close NEWMAKE;
222 rename "Makefile.in.new", "Makefile.in";
223 printf "Successfully updated Makefile.in\n";