xref: /titanic_50/usr/src/cmd/sgs/tools/lint_hdr.pl (revision b9bd317cda1afb3a01f4812de73e8cec888cbbd7)
11dd08564Sab196087#!/usr/bin/perl
21dd08564Sab196087
31dd08564Sab196087#
41dd08564Sab196087# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
51dd08564Sab196087# Use is subject to license terms.
61dd08564Sab196087#
71dd08564Sab196087# CDDL HEADER START
81dd08564Sab196087#
91dd08564Sab196087# The contents of this file are subject to the terms of the
101dd08564Sab196087# Common Development and Distribution License (the "License").
111dd08564Sab196087# You may not use this file except in compliance with the License.
121dd08564Sab196087#
131dd08564Sab196087# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
141dd08564Sab196087# or http://www.opensolaris.org/os/licensing.
151dd08564Sab196087# See the License for the specific language governing permissions
161dd08564Sab196087# and limitations under the License.
171dd08564Sab196087#
181dd08564Sab196087# When distributing Covered Code, include this CDDL HEADER in each
191dd08564Sab196087# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
201dd08564Sab196087# If applicable, add the following below this CDDL HEADER, with the
211dd08564Sab196087# fields enclosed by brackets "[]" replaced with your own identifying
221dd08564Sab196087# information: Portions Copyright [yyyy] [name of copyright owner]
231dd08564Sab196087#
241dd08564Sab196087# CDDL HEADER END
251dd08564Sab196087#
261dd08564Sab196087#ident	"%Z%%M%	%I%	%E% SMI"
271dd08564Sab196087
281dd08564Sab196087
291dd08564Sab196087#
301dd08564Sab196087# Generate a header for lint output for subdirectories of
311dd08564Sab196087# usr/src/cmd/sgs, of the form:
321dd08564Sab196087#
331dd08564Sab196087#	lint_hdr [-s] target_file [elfclass]
341dd08564Sab196087#
351dd08564Sab196087# where:
361dd08564Sab196087#	target - Name of main target (library or program name)
371dd08564Sab196087#	elfclass - If present, 32 or 64, giving the ELFCLASS of
381dd08564Sab196087#		the code being linted.
391dd08564Sab196087#
401dd08564Sab196087# The resulting header looks like the following:
411dd08564Sab196087#
421dd08564Sab196087#	[elfclass - ]target [sgssubdir]
431dd08564Sab196087#       ----------------------------------------------------
441dd08564Sab196087#
451dd08564Sab196087# If the elfclass is omitted, then the header does not include
461dd08564Sab196087# it. If the target matches 'dirname sgssubdir', then sgssubdir
471dd08564Sab196087# is displayed without the target and without the square brackets.
481dd08564Sab196087#
491dd08564Sab196087# The -s option specifies that this is a sub-header, used when
501dd08564Sab196087# multiple lints are done within a single target. If -s is specified,
511dd08564Sab196087# the sgssubdir is not shown (presumably it was already shown in an earlier
521dd08564Sab196087# call to link_hdr), and a shorter dashed line is used:
531dd08564Sab196087#
541dd08564Sab196087#	[elfclass - ]target
551dd08564Sab196087#	========================
561dd08564Sab196087#
571dd08564Sab196087
581dd08564Sab196087use warnings;
591dd08564Sab196087use strict;
601dd08564Sab196087use Cwd;
611dd08564Sab196087
621dd08564Sab196087use vars qw($script $usage $dir $argc $target $elfclass);
631dd08564Sab196087use vars qw($sub);
641dd08564Sab196087
651dd08564Sab196087$script = 'lint_hdr';
661dd08564Sab196087$usage = "usage: $script target [elfclass]\n";
671dd08564Sab196087
681dd08564Sab196087$sub = 0;
69*b9bd317cSab196087die $usage if (scalar(@ARGV) == 0);
701dd08564Sab196087while ($_ = $ARGV[0],/^-/) {
711dd08564Sab196087	ARG: {
721dd08564Sab196087	    if (/^-s$/) {
731dd08564Sab196087		$sub = 1;
741dd08564Sab196087		last ARG;
751dd08564Sab196087	    }
761dd08564Sab196087
771dd08564Sab196087	    # If it gets here, it's an unknown option
781dd08564Sab196087	    die $usage;
791dd08564Sab196087	}
801dd08564Sab196087	shift;
811dd08564Sab196087}
821dd08564Sab196087
831dd08564Sab196087$argc = scalar(@ARGV);
841dd08564Sab196087die $usage if (($argc < 1) || ($argc > 2));
851dd08564Sab196087$target = $ARGV[0];
861dd08564Sab196087$elfclass = ($argc == 2) ? "Elf$ARGV[1] - " : '';
871dd08564Sab196087
881dd08564Sab196087if ($sub) {
891dd08564Sab196087    print "\n$elfclass$target\n========================\n";
901dd08564Sab196087    exit 0;
911dd08564Sab196087}
921dd08564Sab196087
931dd08564Sab196087# Clip the path up through ..sgs/, leaving the path from sgs to current dir
941dd08564Sab196087$dir = getcwd();
951dd08564Sab196087$dir = "$1" if $dir =~ /\/sgs\/(.*)$/;
961dd08564Sab196087
971dd08564Sab196087# Normally, we format the target and directory like this:
981dd08564Sab196087#	target [dir]
991dd08564Sab196087# However, if this is the special case where $dir is equal to
1001dd08564Sab196087#	prog/mach
1011dd08564Sab196087# and prog matches our target name, then just show dir without brackets.
1021dd08564Sab196087if (($dir =~ /^([^\/]+)\/[^\/]+$/) && ($1 eq $target)) {
1031dd08564Sab196087    $target = '';
1041dd08564Sab196087} else {
1051dd08564Sab196087    $dir = " [$dir]";
1061dd08564Sab196087}
1071dd08564Sab196087
1081dd08564Sab196087print "\n$elfclass$target$dir\n";
1091dd08564Sab196087print "------------------------------------------------------------\n";
1101dd08564Sab196087
1111dd08564Sab196087exit 0;
112