Home | History | Annotate | Download | only in scripts
      1 #! /usr/bin/perl -w
      2 #
      3 # CDDL HEADER START
      4 #
      5 # The contents of this file are subject to the terms of the
      6 # Common Development and Distribution License (the "License").
      7 # You may not use this file except in compliance with the License.
      8 #
      9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10 # or http://www.opensolaris.org/os/licensing.
     11 # See the License for the specific language governing permissions
     12 # and limitations under the License.
     13 #
     14 # When distributing Covered Code, include this CDDL HEADER in each
     15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16 # If applicable, add the following below this CDDL HEADER, with the
     17 # fields enclosed by brackets "[]" replaced with your own identifying
     18 # information: Portions Copyright [yyyy] [name of copyright owner]
     19 #
     20 # CDDL HEADER END
     21 #
     22 
     23 #
     24 # Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
     25 # Use is subject to license terms.
     26 #
     27 # ident	"%Z%%M%	%I%	%E% SMI"
     28 #
     29 
     30 #
     31 # Create THIRDPARTYLICENSE files using the index file in $CODEMGR_WS.
     32 #
     33 
     34 use Cwd;
     35 use Env;
     36 use strict;
     37 
     38 my $usage = "mktpl license-list-file";
     39 
     40 my $top = $ENV{"CODEMGR_WS"};
     41 if (! $top) {
     42 	die "CODEMGR_WS must be set.\n";
     43 }
     44 
     45 if (@ARGV != 1) {
     46 	die "usage: $usage\n";
     47 }
     48 
     49 my $indexfile = $ARGV[0];
     50 
     51 my $exitstatus = 0;
     52 
     53 # create a THIRDPARTYLICENSE file from the given license list and suffix.
     54 sub maketpl {
     55 	my ($suffix, @tpllist) = @_;
     56 	my $licnum = 1;
     57 	my $tplname = "$top/THIRDPARTYLICENSE.$suffix";
     58 
     59 	open(TPL, ">$tplname") or die "Can't create $tplname: $!\n";
     60 
     61 	print TPL "DO NOT TRANSLATE OR LOCALIZE.\n\n";
     62 
     63 	foreach my $licfile (@tpllist) {
     64 		my $descrip = `cat "$licfile.descrip"`;
     65 		if (! $descrip) {
     66 			warn "Missing description for $licfile\n";
     67 			$exitstatus = 1;
     68 			$descrip = "(MISSING DESCRIPTION for $licfile)\n";
     69 		}
     70 		print TPL "$licnum)  The following software may be included ",
     71 		    "in this product:\n\n";
     72 		print TPL "\t$descrip\n";
     73 		print TPL "    Use of this software is governed by the ",
     74 		    "terms of the following license:\n";
     75 		print TPL "\n";
     76 		if (open(LIC, "<$licfile")) {
     77 			while (<LIC>) {
     78 				print TPL "    " . $_;
     79 			}
     80 			close LIC;
     81 		} else {
     82 			warn "Can't open $licfile: $!\n";
     83 			$exitstatus = 1;
     84 			print TPL "    (MISSING LICENSE: $licfile)\n";
     85 		}
     86 		print TPL "\n";
     87 		$licnum++;
     88 	}
     89 
     90 	close TPL or die "I/O error on $tplname: $!\n";
     91 }
     92 
     93 #
     94 # Make file list for each TPL file.
     95 #
     96 
     97 chdir($top) or die "Can't chdir to $top: $!\n";
     98 $top = getcwd();
     99 
    100 my $isclosed = qr"^usr/closed";
    101 my $istools = qr"^usr/src/tools";
    102 
    103 my @closedlist;
    104 my @toolslist;
    105 my @bfulist;
    106 
    107 open(IX, "<$indexfile") or die "Can't open $indexfile: $!\n";
    108 while (<IX>) {
    109 	chomp;
    110 	if (/$isclosed/) {
    111 		push @closedlist, $_;
    112 	}
    113 	if (/$istools/) {
    114 		push @toolslist, $_;
    115 	} else {
    116 		push @bfulist, $_;
    117 	}
    118 }
    119 close IX;
    120 
    121 #
    122 # Generate each TPL file.
    123 #
    124 
    125 maketpl("ON-BINARIES", @closedlist) if (@closedlist);
    126 maketpl("ON-BUILD-TOOLS", @toolslist) if (@toolslist);
    127 maketpl("BFU-ARCHIVES", @bfulist) if (@bfulist);
    128 
    129 exit $exitstatus;
    130