make_dlls 10.3 KB
Newer Older
1
#!/usr/bin/perl -w
2 3 4 5 6 7
#
# Update the dll dependencies in the dlls main Makefile.in.
# Must be run in the dlls/ directory of the Wine tree.
#
# Copyright 2001 Alexandre Julliard
#
8 9 10 11 12 13 14 15 16 17 18 19
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
20
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21
#
22

23
use strict;
24

25 26 27
my $makefiles = `find . -name Makefile.in -print`;

my %directories = ();
28 29 30
my %importlibs = ();
my %static_implibs = ();
my %staticlib_dirs = ();
31
my %altnames = ();
32

33
# list of special dlls that can be switched on or off by configure
34
my %special_dlls =
35 36
(
  "glu32"    => "GLU32FILES",
Jacek Caban's avatar
Jacek Caban committed
37
  "glut32"   => "GLUT32FILES",
38
  "opengl32" => "OPENGLFILES",
39
  "wined3d"  => "OPENGLFILES",
40
  "winex11.drv" => "XFILES"
41 42
);

43 44 45 46 47 48
sub needs_symlink($)
{
    (my $mod = $_[0]) =~ s/\.dll$//;
    return $mod ne $directories{$_[0]};
}

49
foreach my $i (split(/\s/,$makefiles))
50
{
51 52
    my $module;

53 54
    next if $i =~ /\/tests\/Makefile.in/;

55
    open MAKE,$i;
56 57

    $module = undef;
58 59 60
    while (<MAKE>)
    {
        chop;
61 62 63 64
        # EPP hack to disable this DLL... the MKDLL_SKIP comment must appear
        # at the very top of the Makefile.in
        last if (/^\#\s*MKDLL_SKIP/);

65 66 67
        if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
        {
            $module = $1;
68 69
            if ($module =~ /^lib.*\.a$/)
            {
70
                ($staticlib_dirs{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
71
                die "invalid module $module in dir $staticlib_dirs{$module}\n" if "lib$staticlib_dirs{$module}.a" ne $module;
72 73 74 75 76
            }
            else
            {
                ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
            }
77 78
            next;
        }
79 80 81 82 83 84 85 86 87 88
        if (/^IMPORTLIB\s*=\s*([a-zA-Z0-9_.]+)\.\$\(IMPLIBEXT\)/)
        {
            $importlibs{$module} = $1;
            next;
        }
        if (/^IMPLIB_SRCS\s*=/)
        {
            $static_implibs{$module} = 1;
            next;
        }
89
        if (/^SPEC_SRCS16\s*=\s*(.*)/)
90
        {
91 92 93 94
            my $specs = $1;
            while ($specs =~ /\s*(.*)\\$/) { $specs = $1 . <MAKE>; }
            my @list = split(/\s+/,$specs);
            @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @list;
95 96 97 98
            $altnames{$module} = \@list;
            next;
        }
    }
99
    close MAKE;
100 101 102 103
}

open NEWMAKE,">Makefile.in.new" or die "cannot create Makefile.in.new";

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
################################################################
# makefile header

print NEWMAKE <<EOF;
# Automatically generated by make_dlls; DO NOT EDIT!!

TOPSRCDIR = \@top_srcdir\@
TOPOBJDIR = ..
SRCDIR    = \@srcdir\@
VPATH     = \@srcdir\@

EOF

################################################################
# output special dlls configure definitions

printf NEWMAKE "# special configure-dependent targets\n\n";
my %specials = ();
122
foreach my $mod (sort keys %special_dlls)
123
{
124
    $specials{$special_dlls{$mod}} .= " " . $mod;
125
}
126
foreach my $i (sort keys %specials)
127
{
128
    printf NEWMAKE "%s =%s\n", $i, $specials{$i};
129
}
130
printf NEWMAKE "EXTRADIRS =";
131
foreach my $i (sort keys %specials) { printf NEWMAKE " \@%s\@", $i; }
132 133 134 135 136
printf NEWMAKE "\n\n";


################################################################
# output the subdirs list
137

138
print NEWMAKE "# Subdir list\n\nBASEDIRS =";
139
foreach my $dir (sort values %directories)
140
{
141
    next if defined($special_dlls{$dir});  # skip special dlls
142 143 144
    printf NEWMAKE " \\\n\t%s", $dir;
}

145 146 147 148 149 150 151 152
printf NEWMAKE "\n\nIMPLIBSUBDIRS =";
foreach my $dir (sort values %staticlib_dirs)
{
    printf NEWMAKE " \\\n\t%s", $dir;
}

printf NEWMAKE "\n\nSUBDIRS = \\\n\t\$(BASEDIRS) \\\n\t\$(IMPLIBSUBDIRS)";
foreach my $dir (sort keys %special_dlls)
153 154 155 156 157 158 159
{
    printf NEWMAKE " \\\n\t%s", $dir;
}
printf NEWMAKE <<EOF;


BUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)
160

161
INSTALLSUBDIRS = \$(BUILDSUBDIRS) \$(IMPLIBSUBDIRS)
162
EOF
163 164 165 166 167

################################################################
# output the all: target

my %targets = ();  # use a hash to get rid of duplicate target names
168
my %targets16 = ();
169
foreach my $mod (sort keys %directories)
170
{
171
    next if defined($special_dlls{$directories{$mod}});  # skip special dlls
172
    $targets{$mod . ".so"} = 1 if needs_symlink($mod);
173
    next unless defined $altnames{$mod};
174
    foreach my $i (sort @{$altnames{$mod}})
175
    {
176
        $targets16{$i . "16"} = $mod;
177 178
    }
}
179

180 181
print NEWMAKE <<EOF;

182 183
\@MAKE_RULES\@

184 185
# Symbolic links

186 187 188 189 190 191
WIN16_FILES = \\
EOF
printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets16 );

print NEWMAKE <<EOF;

192
SYMLINKS_SO = \\
193
	\@WIN16_FILES\@ \\
194 195 196
EOF
printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );

197 198 199 200
print NEWMAKE <<EOF;

# Main target

201
all: \$(BUILDSUBDIRS) symlinks\$(DLLEXT)
202 203 204 205 206 207 208

.PHONY: symlinks symlinks.so implib

symlinks.so: \$(SYMLINKS_SO)

symlinks: \$(BUILDSUBDIRS)

209
EOF
210 211 212 213

################################################################
# output the lib name -> directory rules

214
print NEWMAKE "# Map symlink name to the corresponding library\n\n";
215
foreach my $mod (sort keys %directories)
216
{
217
    next unless needs_symlink($mod);
218 219
    printf NEWMAKE "%s.so: %s/%s.so\n", $mod, $directories{$mod}, $mod;
    printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s.so \$@\n\n", $directories{$mod}, $mod;
220
}
221

222 223 224 225
print NEWMAKE "# Placeholders for 16-bit libraries\n\n";
foreach my $mod (sort keys %directories)
{
    next unless defined $altnames{$mod};
226
    printf NEWMAKE "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
227
    printf NEWMAKE "\techo \"%s\" >\$\@\n\n", $mod;
228
}
229

230 231 232
################################################################
# output the import libraries rules

233
print NEWMAKE "# Import libraries\n\n";
234
print NEWMAKE "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
235

236
my @lib_symlinks = ();
237
foreach my $mod (sort keys %importlibs)
238
{
239 240 241
    my $dir = $directories{$mod};
    my $lib = $importlibs{$mod};
    if ($lib ne "lib" . $dir) { push @lib_symlinks, $mod; }
242
}
243 244 245 246 247
print NEWMAKE "IMPORT_SYMLINKS =";
foreach my $mod (sort @lib_symlinks)
{
    printf NEWMAKE " \\\n\t%s.\$(IMPLIBEXT)", $importlibs{$mod};
}
248 249

print NEWMAKE "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
250
foreach my $mod (sort keys %staticlib_dirs)
251
{
252
    printf NEWMAKE " \\\n\t%s/%s", $staticlib_dirs{$mod}, $mod;
253
}
254 255 256 257 258 259 260 261
foreach my $mod (sort keys %importlibs)
{
    my $dir = $directories{$mod};
    my $def = $mod;
    $def =~ s/\.(dll|drv)$//;
    printf NEWMAKE " \\\n\t%s/lib%s.\$(IMPLIBEXT)", $dir, $def;
    printf NEWMAKE " \\\n\t%s/lib%s.\$(STATIC_IMPLIBEXT)", $dir, $def if $static_implibs{$mod};
}
262
print NEWMAKE "\n\n";
263
print NEWMAKE "implib: \$(IMPORT_LIBS)\n\n";
264

265
foreach my $mod (sort keys %importlibs)
266 267
{
    my $dir = $directories{$mod};
268
    my $lib = $importlibs{$mod};
269 270
    my $spec = $mod;
    $spec =~ s/\.dll$//;
271 272 273 274 275 276 277 278 279 280 281 282
    printf NEWMAKE "%s/%s.\$(IMPLIBEXT): %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
    printf NEWMAKE "\t\@cd %s && \$(MAKE) %s.\$(IMPLIBEXT)\n\n", $dir, $lib;
    next unless $static_implibs{$mod};
    printf NEWMAKE "%s/%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
    printf NEWMAKE "\t\@cd %s && \$(MAKE) %s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
}
foreach my $mod (sort @lib_symlinks)
{
    my $dir = $directories{$mod};
    my $lib = $importlibs{$mod} . ".\$(IMPLIBEXT)";
    printf NEWMAKE "%s: %s/%s\n", $lib, $dir, $lib;
    printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $dir, $lib;
283 284 285
}

print NEWMAKE <<EOF;
286
\$(BUILDSUBDIRS): \$(IMPORT_LIBS)
287
\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)
288 289 290

EOF

291 292 293
################################################################
# output the inter-dll dependencies and rules

294 295 296 297
print NEWMAKE "# Map library name to the corresponding directory\n\n";

foreach my $mod (sort keys %directories)
{
298
    next unless needs_symlink($mod);
299
    printf NEWMAKE "%s/%s.so: %s\n", $directories{$mod}, $mod, $directories{$mod};
300
}
301
foreach my $mod (sort keys %staticlib_dirs)
302
{
303
    printf NEWMAKE "%s/%s: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
304
}
305

306 307
################################################################
# makefile trailer
308

309
print NEWMAKE <<EOF;
310

311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
# Rules for auto documentation

\$(SUBDIRS:%=%/__man__): dummy
	cd `dirname \$@` && \$(MAKE) man

man: \$(SUBDIRS:%=%/__man__)

\$(SUBDIRS:%=%/__doc_html__): dummy
	cd `dirname \$@` && \$(MAKE) doc-html

doc-html: \$(SUBDIRS:%=%/__doc_html__)

\$(SUBDIRS:%=%/__doc_sgml__): dummy
	cd `dirname \$@` && \$(MAKE) doc-sgml

doc-sgml: \$(SUBDIRS:%=%/__doc_sgml__)

328
.PHONY: man doc-html doc-sgml \$(SUBDIRS:%=%/__man__) \$(SUBDIRS:%=%/__doc_html__) \$(SUBDIRS:%=%/__doc_sgml__)
329

330
# Misc rules
331

332
install-lib:: \$(INSTALLSUBDIRS:%=%/__install-lib__)
333

334
install-dev:: \$(INSTALLSUBDIRS:%=%/__install-dev__)
335

336
uninstall::
337
	-rmdir \$(DESTDIR)\$(dlldir)
338

339
clean::
340
	\$(RM) \$(IMPORT_SYMLINKS) \$(WIN16_FILES)
341

342
check test:: \$(BUILDSUBDIRS:%=%/__test__)
343

344 345
crosstest:: \$(BUILDSUBDIRS:%=%/__crosstest__)

346
checklink:: \$(BUILDSUBDIRS:%=%/__checklink__)
347 348

### Dependencies:
349 350 351 352 353
EOF

close NEWMAKE;
rename "Makefile.in.new", "Makefile.in";
printf "Successfully updated Makefile.in\n";
354 355 356 357 358 359 360 361 362 363 364 365

################################################################
# .gitignore file

open GITIGNORE, ">.gitignore.new" or die "cannot create .gitignore.new";
print GITIGNORE "# Automatically generated by make_dlls; DO NOT EDIT!!\n";

my @ignores =
(
 "/Makedll.rules",
 "/Makeimplib.rules",
 "/Maketest.rules",
366
 "*/tests/testlist.c",
367
 "*/tests/*.ok",
368 369 370 371 372 373 374 375 376 377 378
);

foreach my $mod (sort @lib_symlinks)
{
    push @ignores, "/$importlibs{$mod}.def";
}
foreach my $mod (sort keys %directories)
{
    next unless defined $altnames{$mod};
    push @ignores, map { "/" . $_ . "16"; } @{$altnames{$mod}};
}
379 380 381 382 383 384 385 386
foreach my $mod (sort keys %importlibs)
{
    my $dir = $directories{$mod};
    my $def = $mod;
    $def =~ s/\.(dll|drv)$//;
    push @ignores, "$dir/lib$def.def";
}

387 388 389 390 391
print GITIGNORE join("\n", sort @ignores) . "\n";

close GITIGNORE;
rename ".gitignore.new", ".gitignore";
printf "Successfully updated .gitignore\n";