xref: /titanic_41/usr/src/cmd/sgs/tools/lint_hdr.pl (revision 66ea84940ca8687745ad2a165ef9bf49ec13996f)
1#!/usr/bin/perl
2
3#
4# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
5# Use is subject to license terms.
6#
7# CDDL HEADER START
8#
9# The contents of this file are subject to the terms of the
10# Common Development and Distribution License (the "License").
11# You may not use this file except in compliance with the License.
12#
13# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
14# or http://www.opensolaris.org/os/licensing.
15# See the License for the specific language governing permissions
16# and limitations under the License.
17#
18# When distributing Covered Code, include this CDDL HEADER in each
19# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
20# If applicable, add the following below this CDDL HEADER, with the
21# fields enclosed by brackets "[]" replaced with your own identifying
22# information: Portions Copyright [yyyy] [name of copyright owner]
23#
24# CDDL HEADER END
25#
26#ident	"%Z%%M%	%I%	%E% SMI"
27
28
29#
30# Generate a header for lint output for subdirectories of
31# usr/src/cmd/sgs, of the form:
32#
33#	lint_hdr [-s] target_file [elfclass]
34#
35# where:
36#	target - Name of main target (library or program name)
37#	elfclass - If present, 32 or 64, giving the ELFCLASS of
38#		the code being linted.
39#
40# The resulting header looks like the following:
41#
42#	[elfclass - ]target [sgssubdir]
43#       ----------------------------------------------------
44#
45# If the elfclass is omitted, then the header does not include
46# it. If the target matches 'dirname sgssubdir', then sgssubdir
47# is displayed without the target and without the square brackets.
48#
49# The -s option specifies that this is a sub-header, used when
50# multiple lints are done within a single target. If -s is specified,
51# the sgssubdir is not shown (presumably it was already shown in an earlier
52# call to link_hdr), and a shorter dashed line is used:
53#
54#	[elfclass - ]target
55#	========================
56#
57
58use warnings;
59use strict;
60use Cwd;
61
62use vars qw($script $usage $dir $argc $target $elfclass);
63use vars qw($sub);
64
65$script = 'lint_hdr';
66$usage = "usage: $script target [elfclass]\n";
67
68$sub = 0;
69die $usage if (scalar(@ARGV) == 0);
70while ($_ = $ARGV[0],/^-/) {
71	ARG: {
72	    if (/^-s$/) {
73		$sub = 1;
74		last ARG;
75	    }
76
77	    # If it gets here, it's an unknown option
78	    die $usage;
79	}
80	shift;
81}
82
83$argc = scalar(@ARGV);
84die $usage if (($argc < 1) || ($argc > 2));
85$target = $ARGV[0];
86$elfclass = ($argc == 2) ? "Elf$ARGV[1] - " : '';
87
88if ($sub) {
89    print "\n$elfclass$target\n========================\n";
90    exit 0;
91}
92
93# Clip the path up through ..sgs/, leaving the path from sgs to current dir
94$dir = getcwd();
95$dir = "$1" if $dir =~ /\/sgs\/(.*)$/;
96
97# Normally, we format the target and directory like this:
98#	target [dir]
99# However, if this is the special case where $dir is equal to
100#	prog/mach
101# and prog matches our target name, then just show dir without brackets.
102if (($dir =~ /^([^\/]+)\/[^\/]+$/) && ($1 eq $target)) {
103    $target = '';
104} else {
105    $dir = " [$dir]";
106}
107
108print "\n$elfclass$target$dir\n";
109print "------------------------------------------------------------\n";
110
111exit 0;
112