head	1.1;
branch	1.1.1;
access;
symbols
	import-20090318:1.1.1.7
	import-20081205:1.1.1.7
	rel-8-1-2-sv:1.1.1.6
	import-20080404:1.1.1.6
	import-20071105:1.1.1.6
	import-20070116:1.1.1.5
	import-20061124:1.1.1.5
	rel-6-2-2-sv:1.1.1.4
	rel-6-2-1-sv:1.1.1.4
	import-20060615:1.1.1.4
	import-20060530:1.1.1.4
	import-20060516:1.1.1.4
	import-20060421:1.1.1.3
	import-20060406:1.1.1.3
	import-29mar06:1.1.1.3
	import-14mar06:1.1.1.3
	import-13mar06:1.1.1.3
	fixed-post-import-14feb06:1.1.1.2
	import-14feb06:1.1.1.2
	fixed-post-import-6feb06:1.1.1.2
	import-6feb06:1.1.1.2
	import-6sep05:1.1.1.1
	start:1.1.1.1
	freescale:1.1.1;
locks; strict;
comment	@# @;


1.1
date	2005.08.23.08.54.15;	author seh;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2005.08.23.08.54.15;	author seh;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	2006.02.06.14.20.04;	author seh;	state Exp;
branches;
next	1.1.1.3;

1.1.1.3
date	2006.03.13.17.44.08;	author seh;	state Exp;
branches;
next	1.1.1.4;

1.1.1.4
date	2006.05.16.14.20.55;	author seh;	state Exp;
branches;
next	1.1.1.5;

1.1.1.5
date	2006.11.27.11.19.19;	author seh;	state Exp;
branches;
next	1.1.1.6;

1.1.1.6
date	2007.11.06.15.44.45;	author seh;	state Exp;
branches;
next	1.1.1.7;
commitid	AdKoH3Xx8FxdUwEs;

1.1.1.7
date	2008.12.05.14.25.48;	author seh;	state Exp;
branches;
next	;
commitid	A4gB7k6PjRrWLhtt;


desc
@@


1.1
log
@Initial revision
@
text
@eval 'exec perl -w -S $0 ${1+"$@@"}'
    if $running_under_some_shell;
$running_under_some_shell = 0;

######################################################################
#
# Copyright  Freescale Semicondutor, Inc. 2004-2005. All rights reserved.
#
# Stuart Hughes, stuarth@@freescale.com,  22nd Feb 2005
#   
# This file is part of LTIB.
#
# LTIB is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# LTIB 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LTIB; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# Description:
#
# Recurse directory try and strip debug symbols
#
######################################################################
use Getopt::Std;
$opt_p = "";
$opt_h = 0;
$opt_v = 0;

$usage = "Usage stripall [ -v ] [ -p <strip_prefix> ] [ directory ]\n";

getopts('p:hv') or die($usage);
die($usage) if $opt_h;
$dir = shift || ".";

strip_rootfs();

sub strip_rootfs
{
    foreach $fn ( split( /\n/, `find $dir -type f`) ) {
        $_ = `file $fn`;
        warn("WARN: $fn statically linked\n") if m#statically#;
        if( m#not stripped#) {
            warn("stripping: $fn\n") if $opt_v;
            system($opt_p . "strip -g $fn 2>/dev/null");
        }
    }
    return 1;
}

@


1.1.1.1
log
@LTIB external initial import
@
text
@@


1.1.1.2
log
@Import from fsl 6feb06
@
text
@d10 1
a10 2
# Steve Papacharalambous, stevep@@freescale.com, 13 Sept 2005
#
d17 1
a17 1
#
d29 1
a29 1
# Recurse directory and try to strip debug symbols.
d33 1
a33 1
$opt_t = "";
a35 4
$opt_e = "";
$opt_w = "";
$ex_pattern = "";
@@dont_strip = ();
d37 1
a37 1
$usage = "Usage: stripall [ -v ] [ -t <target strip prefix> ] [ -w <workstation strip prefix> ] [ -e <exclude file> ] [ directory ]\n";
d39 1
a39 1
getopts('t:w:e:hv') or die($usage);
a41 24
$targ_objdump = ($opt_t . "objdump -f");

if( $opt_w ) {
    $host_objdump = ($opt_w . "objdump -f");
    $host_strip = ($opt_w . "strip");
} else {
    $host_objdump = "/usr/bin/objdump -f";
    $host_strip = "/usr/bin/strip";
}

local $_ = `$host_objdump --version 2> /dev/null` || die "Path to host tools not set up, aborting...\n\n";

local $_ = `$targ_objdump --version 2> /dev/null` || die "Path to target tools not set up, aborting...\n\n";

if( $opt_e ) {
    open(EXCLUDE, "< $opt_e") || die "Can't open $opt_e: $!\n\n";
    while ( <EXCLUDE> ) {
        chomp;
        push(@@dont_strip, $_);
    }
    close(EXCLUDE);
    $ex_pattern = join "|" , @@dont_strip;
    $ex_pattern = "(" . $ex_pattern . ")";
}
d43 1
a43 4
print "Host strip: $host_strip\n" if $opt_v;
print "Host objdump: $host_objdump\n" if $opt_v;
print "Target strip: ${opt_t}strip\n" if $opt_v;
print "Target objdump: $targ_objdump\n" if $opt_v;
d45 1
a45 5

strip_subdir();


sub strip_subdir
d48 5
a52 33
        if( $opt_e && $fn =~ m#$ex_pattern$#o ) {
            warn("$fn excluded from stripping, skipping.\n") if $opt_v;
            next;
        }
        $_ = `$targ_objdump $fn 2>&1`;

        # Test whether the format of the file to be stripped is one that can
        # be stripped by the target tools.
        if( ! m#(?:architecture:\s+UNKNOWN!)|(?:File\s+format\s+not\s+recognized)# ) {
            $_ = `file $fn`;
            warn("WARN: $fn statically linked\n") if m#statically#;

            # Second test whether the file format is one that can be stripped.
            if ( m#(?:not\s+stripped)|(?:Intel\s+80386\s+console\s+executable\s+not\s+relocatable)# ) {
                warn("Stripping (${opt_t}strip): $fn\n") if $opt_v;
                system($opt_t . "strip -g $fn 2> /dev/null");
            }
            next;
        }
        $_ = `$host_objdump $fn 2>&1`;

        # Test whether the format of the file to be stripped is one that can
        # be stripped by the host tools.
        if( ! m#(?:architecture:\s+UNKNOWN!)|(?:File\s+format\s+not\s+recognized)# ) {
            $_ = `file $fn`;
            warn("WARN: $fn statically linked\n") if m#statically#;

            # Second test whether the file format is one that can be stripped.
            if ( m#(?:not\s+stripped)|(?:Intel\s+80386\s+console\s+executable\s+not\s+relocatable)# ) {
                warn("Stripping ($host_strip): $fn\n") if $opt_v;
                system($host_strip . " -g $fn 2> /dev/null");
            }
            next;
@


1.1.1.3
log
@Import from fsl 13mar06
@
text
@a36 2
$opt_d = 0;
$opt_s = 0;
d42 1
a42 7
$usage = <<TXT;
Usage: stripall [ -v ] [ -d ] [ -s ] [ -t <target strip prefix> ] [ -w <workstation strip prefix> ] [ -e <exclude file> ] [ directory ]
    Where:
        -v     : verbose
        -d     : debug
        -s     : speedup (only examine xxx, xxx.exe, .o, .so, .ko, .a files)
TXT
d44 1
a44 1
getopts('t:w:e:hvds') or die($usage);
d85 1
a85 1
            warn("$fn excluded from stripping, skipping.\n") if $opt_v || $opt_d;
a87 9
        if(    $opt_s 
            && $fn =~ m,(?:/[^.]+|.\.exe|\.o|\.so|\.so[.\d]+|\.a|\.ko)$, ) {
            warn "Do  : $fn\n" if $opt_d;
        } else {
            warn "Skip: $fn\n" if $opt_d;
            next;
        }
    
        warn "running $targ_objdump $fn\n" if $opt_d;
a92 1
            warn "running file $fn\n" if $opt_d;
d98 1
a98 1
                warn("Stripping targ (${opt_t}strip): $fn\n") if $opt_v || $opt_d;
a102 1
        warn "running $host_objdump $fn\n" if $opt_d;
a107 1
            warn "running file $fn\n" if $opt_d;
d113 1
a113 1
                warn("Stripping host ($host_strip): $fn\n") if $opt_v || $opt_d;
@


1.1.1.4
log
@Import from fsl 20060516
@
text
@d7 1
a7 1
# Copyright  Freescale Semiconductor, Inc. 2004-2005. All rights reserved.
@


1.1.1.5
log
@Import from fsl 20061124
@
text
@d7 1
a7 1
# Copyright  Freescale Semiconductor, Inc. 2004-2006. All rights reserved.
a31 12
#
#------------------------------------------------------------------------------
# Permissions: http://www.oreilly.com/pub/a/oreilly/ask_tim/2001/codepolicy.html# Ref:         http://www.oreilly.com/catalog/cookbook/
# Download:    http://examples.oreilly.com/cookbook/pcookexamples.tar.gz
#
# Author:    Tom Christiansen (tchrist@@mox.perl.com)
# Book:      Perl Cookbook (example 6.9)
# Publisher: O'Reilly
# ISBN:      1-56592-243-3
#
# Modified by Steve Papacharalambous stevep@@freescale.com 03 October 2006
#
d73 1
a73 1
        push(@@dont_strip, glob2pat($_));
a83 1
print "Strip exclude pattern: $ex_pattern\n" if $opt_v;
d96 6
a101 7
        if( $opt_s ) {
            if( $fn =~ m,(?:/[^.]+|.\.exe|\.o|\.so|\.so[.\d]+|\.a|\.ko)$, ) {
                warn "Do : $fn\n" if $opt_d;
            } else {
                warn "Skip: $fn\n" if $opt_d;
                next;
            }
a141 15

# Convert four shell wildcard characters to their equivalent regular
# expression, all other characters will be quoted to render them literals.
sub glob2pat {
    my $globstr = shift;
    my %patmap = (
        '*' => '.*',
        '?' => '.',
        '[' => '[',
        ']' => ']',
    );
    $globstr =~ s{(.)} { $patmap{$1} || "\Q$1" }ge;
    return $globstr . '$';
}

@


1.1.1.6
log
@Import from fsl 20071105
@
text
@a0 1
#!/usr/bin/perl -w
d7 1
a7 1
# Copyright  Freescale Semiconductor, Inc. 2004-2007. All rights reserved.
@


1.1.1.7
log
@Import from fsl 20081205
@
text
@a51 1
$opt_a = 0;
d58 1
a58 1
Usage: stripall [ -v ] [ -d ] [ -s ] [ -a ] [ -t <target strip prefix> ] [ -w <workstation strip prefix> ] [ -e <exclude file> ] [ directory ]
a62 1
        -a     : aggressive, strip more than debug when it _should_ be safe
d65 1
a65 1
getopts('t:w:e:hvdsa') or die($usage);
a101 13
sub strip_level($)
{
    my ($fn) = @@_;

    # non-aggressive, only strip debug
    return ' -g' if !$opt_a;

    # if you totally strip a, o, so, and ko files they are useless
    return ' -g' if $fn =~ m,\.(?:a|o|so[.\d]*|ko)$,;

    # otherwise, we're going skinny dipping
    return '';
}
d111 1
a111 1
            if( $fn =~ m,(?:.\.exe|\.o|\.so[.\d]*|\.a|\.ko)$, || -x $fn ) {
d131 2
a132 3
                my $cmd = $opt_t . 'strip' . strip_level($fn);
                warn("Stripping targ ($cmd): $fn\n") if $opt_v || $opt_d;
                system("$cmd $fn 2> /dev/null");
d148 2
a149 3
                my $cmd = $host_strip . strip_level($fn);
                warn("Stripping host ($cmd): $fn\n") if $opt_v || $opt_d;
                system("$cmd $fn 2> /dev/null");
@


