xref: /onnv-gate/usr/src/cmd/sgs/tools/lint_hdr.pl (revision 7008:8f7bd4ba8aeb)
16951Sab196087#!/usr/bin/perl
26951Sab196087
36951Sab196087#
46951Sab196087# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
56951Sab196087# Use is subject to license terms.
66951Sab196087#
76951Sab196087# CDDL HEADER START
86951Sab196087#
96951Sab196087# The contents of this file are subject to the terms of the
106951Sab196087# Common Development and Distribution License (the "License").
116951Sab196087# You may not use this file except in compliance with the License.
126951Sab196087#
136951Sab196087# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
146951Sab196087# or http://www.opensolaris.org/os/licensing.
156951Sab196087# See the License for the specific language governing permissions
166951Sab196087# and limitations under the License.
176951Sab196087#
186951Sab196087# When distributing Covered Code, include this CDDL HEADER in each
196951Sab196087# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
206951Sab196087# If applicable, add the following below this CDDL HEADER, with the
216951Sab196087# fields enclosed by brackets "[]" replaced with your own identifying
226951Sab196087# information: Portions Copyright [yyyy] [name of copyright owner]
236951Sab196087#
246951Sab196087# CDDL HEADER END
256951Sab196087#
266951Sab196087#ident	"%Z%%M%	%I%	%E% SMI"
276951Sab196087
286951Sab196087
296951Sab196087#
306951Sab196087# Generate a header for lint output for subdirectories of
316951Sab196087# usr/src/cmd/sgs, of the form:
326951Sab196087#
336951Sab196087#	lint_hdr [-s] target_file [elfclass]
346951Sab196087#
356951Sab196087# where:
366951Sab196087#	target - Name of main target (library or program name)
376951Sab196087#	elfclass - If present, 32 or 64, giving the ELFCLASS of
386951Sab196087#		the code being linted.
396951Sab196087#
406951Sab196087# The resulting header looks like the following:
416951Sab196087#
426951Sab196087#	[elfclass - ]target [sgssubdir]
436951Sab196087#       ----------------------------------------------------
446951Sab196087#
456951Sab196087# If the elfclass is omitted, then the header does not include
466951Sab196087# it. If the target matches 'dirname sgssubdir', then sgssubdir
476951Sab196087# is displayed without the target and without the square brackets.
486951Sab196087#
496951Sab196087# The -s option specifies that this is a sub-header, used when
506951Sab196087# multiple lints are done within a single target. If -s is specified,
516951Sab196087# the sgssubdir is not shown (presumably it was already shown in an earlier
526951Sab196087# call to link_hdr), and a shorter dashed line is used:
536951Sab196087#
546951Sab196087#	[elfclass - ]target
556951Sab196087#	========================
566951Sab196087#
576951Sab196087
586951Sab196087use warnings;
596951Sab196087use strict;
606951Sab196087use Cwd;
616951Sab196087
626951Sab196087use vars qw($script $usage $dir $argc $target $elfclass);
636951Sab196087use vars qw($sub);
646951Sab196087
656951Sab196087$script = 'lint_hdr';
666951Sab196087$usage = "usage: $script target [elfclass]\n";
676951Sab196087
686951Sab196087$sub = 0;
69*7008Sab196087die $usage if (scalar(@ARGV) == 0);
706951Sab196087while ($_ = $ARGV[0],/^-/) {
716951Sab196087	ARG: {
726951Sab196087	    if (/^-s$/) {
736951Sab196087		$sub = 1;
746951Sab196087		last ARG;
756951Sab196087	    }
766951Sab196087
776951Sab196087	    # If it gets here, it's an unknown option
786951Sab196087	    die $usage;
796951Sab196087	}
806951Sab196087	shift;
816951Sab196087}
826951Sab196087
836951Sab196087$argc = scalar(@ARGV);
846951Sab196087die $usage if (($argc < 1) || ($argc > 2));
856951Sab196087$target = $ARGV[0];
866951Sab196087$elfclass = ($argc == 2) ? "Elf$ARGV[1] - " : '';
876951Sab196087
886951Sab196087if ($sub) {
896951Sab196087    print "\n$elfclass$target\n========================\n";
906951Sab196087    exit 0;
916951Sab196087}
926951Sab196087
936951Sab196087# Clip the path up through ..sgs/, leaving the path from sgs to current dir
946951Sab196087$dir = getcwd();
956951Sab196087$dir = "$1" if $dir =~ /\/sgs\/(.*)$/;
966951Sab196087
976951Sab196087# Normally, we format the target and directory like this:
986951Sab196087#	target [dir]
996951Sab196087# However, if this is the special case where $dir is equal to
1006951Sab196087#	prog/mach
1016951Sab196087# and prog matches our target name, then just show dir without brackets.
1026951Sab196087if (($dir =~ /^([^\/]+)\/[^\/]+$/) && ($1 eq $target)) {
1036951Sab196087    $target = '';
1046951Sab196087} else {
1056951Sab196087    $dir = " [$dir]";
1066951Sab196087}
1076951Sab196087
1086951Sab196087print "\n$elfclass$target$dir\n";
1096951Sab196087print "------------------------------------------------------------\n";
1106951Sab196087
1116951Sab196087exit 0;
112