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; 69while ($_ = $ARGV[0],/^-/) { 70 ARG: { 71 if (/^-s$/) { 72 $sub = 1; 73 last ARG; 74 } 75 76 # If it gets here, it's an unknown option 77 die $usage; 78 } 79 shift; 80} 81 82$argc = scalar(@ARGV); 83die $usage if (($argc < 1) || ($argc > 2)); 84$target = $ARGV[0]; 85$elfclass = ($argc == 2) ? "Elf$ARGV[1] - " : ''; 86 87if ($sub) { 88 print "\n$elfclass$target\n========================\n"; 89 exit 0; 90} 91 92# Clip the path up through ..sgs/, leaving the path from sgs to current dir 93$dir = getcwd(); 94$dir = "$1" if $dir =~ /\/sgs\/(.*)$/; 95 96# Normally, we format the target and directory like this: 97# target [dir] 98# However, if this is the special case where $dir is equal to 99# prog/mach 100# and prog matches our target name, then just show dir without brackets. 101if (($dir =~ /^([^\/]+)\/[^\/]+$/) && ($1 eq $target)) { 102 $target = ''; 103} else { 104 $dir = " [$dir]"; 105} 106 107print "\n$elfclass$target$dir\n"; 108print "------------------------------------------------------------\n"; 109 110exit 0; 111