delibtoolize.pl revision 98
98N/A#! /usr/perl5/bin/perl
98N/A#
98N/A# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
98N/A# Use is subject to license terms.
98N/A#
98N/A# ident "@(#)delibtoolize.pl 1.3 07/01/30 SMI"
98N/A#
98N/A
98N/A#
98N/A# Undo libtool damage to makefiles to allow us to control the linker
98N/A# settings that libtool tries to force on us.
98N/A#
98N/A
98N/Ause strict;
98N/Ause warnings;
98N/Ause integer;
98N/A
98N/Ause File::Find;
98N/A
98N/Asub process_file {
98N/A if ($_ eq "Makefile" && -f $_) {
98N/A print "delibtoolizing $File::Find::name...\n";
98N/A my $old_file = $_ . "~";
98N/A my $new_file = $_;
98N/A rename($new_file, $old_file) or
98N/A die "Can't rename $new_file to $old_file: $!\n";
98N/A
98N/A open(OLD, "<$old_file") or die "Can't open $old_file for reading: $!\n";
98N/A open(NEW, ">$new_file") or die "Can't open $new_file for writing: $!\n";
98N/A
98N/A my $compiler;
98N/A my $l;
98N/A my @inlines = ();
98N/A my %so_versions = ();
98N/A
98N/A # Read in original file and preprocess for data we'll need later
98N/A while ($l = <OLD>) {
98N/A if ($l =~ m%^\s*CC\s*=\s*(\S*)%) {
98N/A $compiler = $1;
98N/A }
98N/A
98N/A # TODO: handle line continuation
98N/A if ($l =~ m%^(\S*)_la_LDFLAGS\s=.*-version-number (\d+)[:\d]+%) {
98N/A $so_versions{$1} = $2;
98N/A $l =~ s%-version-number (\d+)[:\d]+%-G%;
98N/A }
98N/A if ($l =~ m%^(\S*)_la_LDFLAGS\s=.*\s*-avoid-version\b%) {
98N/A $so_versions{$1} = "none";
98N/A $l =~ s%-avoid-version\b%%;
98N/A }
98N/A
98N/A push @inlines, $l;
98N/A }
98N/A close(OLD) or die;
98N/A
98N/A my $picflags = "-Kpic -DPIC";
98N/A
98N/A if ($compiler =~ m/gcc/) {
98N/A $picflags = "-fpic -DPIC";
98N/A }
98N/A
98N/A my $curtarget = "";
98N/A
98N/A foreach $l (@inlines) {
98N/A # Remove libtool script from compile & link steps
98N/A $l =~ s%\$\(LIBTOOL\)( --tag=CC)? --mode=(compile|link)\s*%%;
98N/A
98N/A # Add -KPIC & -DPIC flags that libtool normally provides
98N/A $l =~ s%(LTCOMPILE\s*=\s*\$\(CC\))%$1 $picflags%;
98N/A $l =~ s%(LTCCASCOMPILE\s*=\s*\$\(CCAS\))%$1 $picflags%;
98N/A
98N/A # Change -rpath to -R in link arguments
98N/A $l =~ s%(\s*)-rpath(\s*)%$1-R$2%g;
98N/A
98N/A # Change flags for building shared object from arguments to libtool
98N/A # script into arguments to linker
98N/A $l =~ s%(_la_LDFLAGS\s*=.*) -module%$1 -G%;
98N/A $l =~ s%(_la_LDFLAGS\s*=.*) -no-undefined%$1 -z defs%;
98N/A
98N/A # Change file names
98N/A my $so;
98N/A foreach $so (keys %so_versions) {
98N/A if ($so_versions{$so} eq "none") {
98N/A $l =~ s%$so\.la\b%$so.so%g;
98N/A } else {
98N/A $l =~ s%$so\.la\b%$so.so.$so_versions{$so}%g;
98N/A }
98N/A }
98N/A $l =~ s%\.la\b%.a%g;
98N/A
98N/A if ($l =~ m%^(\S+):%) {
98N/A $curtarget = $1;
98N/A } elsif ($l =~ m%^\s*$%) {
98N/A $curtarget = "";
98N/A }
98N/A
98N/A if ($curtarget =~ m%^.*\.a$%) {
98N/A $l =~ s%\$\(LINK\)%\$(AR) cru $curtarget%;
98N/A }
98N/A
98N/A print NEW $l;
98N/A }
98N/A close(NEW) or die;
98N/A }
98N/A}
98N/A
98N/Afind(\&process_file, @ARGV);