16b5e5868SGarrett D'Amore#! /usr/perl5/bin/perl 26b5e5868SGarrett D'Amore# 36b5e5868SGarrett D'Amore# This file and its contents are supplied under the terms of the 46b5e5868SGarrett D'Amore# Common Development and Distribution License ("CDDL"), version 1.0. 56b5e5868SGarrett D'Amore# You may only use this file in accordance with the terms version 66b5e5868SGarrett D'Amore# 1.0 of the CDDL. 76b5e5868SGarrett D'Amore# 86b5e5868SGarrett D'Amore# A full copy of the text of the CDDL should have accompanied this 96b5e5868SGarrett D'Amore# source. A copy is of the CDDL is also available via the Internet 106b5e5868SGarrett D'Amore# at http://www.illumos.org/license/CDDL. 116b5e5868SGarrett D'Amore# 126b5e5868SGarrett D'Amore 136b5e5868SGarrett D'Amore# 146b5e5868SGarrett D'Amore# Copyright 2010 Nexenta Systems, Inc. All rights reserved. 15cec7ac1bSJosef 'Jeff' Sipek# Copyright 2016 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> 166b5e5868SGarrett D'Amore# 176b5e5868SGarrett D'Amore 186b5e5868SGarrett D'Amore# 196b5e5868SGarrett D'Amore# This extracts all the BSD copyrights (excluding the CDDL licenses) 206b5e5868SGarrett D'Amore# for use in a THIRDPARTYLICENSE file. It tries hard to avoid duplicates. 216b5e5868SGarrett D'Amore# 226b5e5868SGarrett D'Amore 236b5e5868SGarrett D'Amoreuse strict; 246b5e5868SGarrett D'Amoreuse warnings; 256b5e5868SGarrett D'Amoreuse File::Find; 266b5e5868SGarrett D'Amore 276b5e5868SGarrett D'Amoremy %LICENSE = (); 286b5e5868SGarrett D'Amore 296b5e5868SGarrett D'Amoresub dofile 306b5e5868SGarrett D'Amore{ 316b5e5868SGarrett D'Amore my $file = shift; 326b5e5868SGarrett D'Amore my $comment = 0; 336b5e5868SGarrett D'Amore my @license = (); 346b5e5868SGarrett D'Amore my @block = ();; 356b5e5868SGarrett D'Amore my $copyr = 0; 366b5e5868SGarrett D'Amore open(FILE, $file); 376b5e5868SGarrett D'Amore while (<FILE>) { 386b5e5868SGarrett D'Amore if (/^\/\*$/) { 396b5e5868SGarrett D'Amore $comment = 1; 406b5e5868SGarrett D'Amore $copyr = 0; 416b5e5868SGarrett D'Amore @block = (); 426b5e5868SGarrett D'Amore next; 436b5e5868SGarrett D'Amore } 446b5e5868SGarrett D'Amore if (!$comment) { 456b5e5868SGarrett D'Amore next; 466b5e5868SGarrett D'Amore } 476b5e5868SGarrett D'Amore # 486b5e5868SGarrett D'Amore # We don't want to know about CDDL files. They don't 496b5e5868SGarrett D'Amore # require an explicit THIRDPARTYLICENSE file. 506b5e5868SGarrett D'Amore # 516b5e5868SGarrett D'Amore if (/CDDL/) { 526b5e5868SGarrett D'Amore #print "$file is CDDL.\n"; 536b5e5868SGarrett D'Amore close(FILE); 546b5e5868SGarrett D'Amore return; 556b5e5868SGarrett D'Amore } 566b5e5868SGarrett D'Amore if (/Copyright/) { 576b5e5868SGarrett D'Amore $copyr = 1; 586b5e5868SGarrett D'Amore } 596b5e5868SGarrett D'Amore if (!/^ \*\//) { 606b5e5868SGarrett D'Amore push(@block, $_); 616b5e5868SGarrett D'Amore next; 626b5e5868SGarrett D'Amore } 636b5e5868SGarrett D'Amore # 646b5e5868SGarrett D'Amore # We have reached the end of the comment now. 656b5e5868SGarrett D'Amore # 666b5e5868SGarrett D'Amore $comment = 0; 676b5e5868SGarrett D'Amore 686b5e5868SGarrett D'Amore # Check to see if we saw a copyright. 696b5e5868SGarrett D'Amore if (!$copyr) { 706b5e5868SGarrett D'Amore next; 716b5e5868SGarrett D'Amore } 726b5e5868SGarrett D'Amore my $line; 736b5e5868SGarrett D'Amore foreach $line (@block) { 746b5e5868SGarrett D'Amore chomp $line; 756b5e5868SGarrett D'Amore $line =~ s/^ \* //; 766b5e5868SGarrett D'Amore $line =~ s/^ \*//; 776b5e5868SGarrett D'Amore $line =~ s/^ \*$//; 786b5e5868SGarrett D'Amore push(@license, $line); 796b5e5868SGarrett D'Amore } 806b5e5868SGarrett D'Amore } 816b5e5868SGarrett D'Amore 826b5e5868SGarrett D'Amore if ($#license > 0) { 836b5e5868SGarrett D'Amore my $lic = join "\n", @license; 846b5e5868SGarrett D'Amore push (@{$LICENSE{$lic}}, $file); 856b5e5868SGarrett D'Amore } 866b5e5868SGarrett D'Amore 876b5e5868SGarrett D'Amore close(FILE); 886b5e5868SGarrett D'Amore} 896b5e5868SGarrett D'Amore 906b5e5868SGarrett D'Amoremy @FILES; 916b5e5868SGarrett D'Amore 926b5e5868SGarrett D'Amoresub wanted { 936b5e5868SGarrett D'Amore my $path = $File::Find::name; 946b5e5868SGarrett D'Amore 956b5e5868SGarrett D'Amore if (!-f $path) { 96*5d9d9091SRichard Lowe if ($path =~ /\.[chsS]$/) { 976b5e5868SGarrett D'Amore push(@FILES, $path); 986b5e5868SGarrett D'Amore } 996b5e5868SGarrett D'Amore } 1006b5e5868SGarrett D'Amore 1016b5e5868SGarrett D'Amore} 1026b5e5868SGarrett D'Amoreforeach $a (@ARGV) { 1036b5e5868SGarrett D'Amore if (-d $a) { 1046b5e5868SGarrett D'Amore find(\&wanted, $a); 1056b5e5868SGarrett D'Amore } elsif (-f $a) { 1066b5e5868SGarrett D'Amore push(@FILES, $a); 1076b5e5868SGarrett D'Amore } 1086b5e5868SGarrett D'Amore} 1096b5e5868SGarrett D'Amore 110cec7ac1bSJosef 'Jeff' Sipek# sort files to get a stable ordering to aid wsdiff(1onbld) 111cec7ac1bSJosef 'Jeff' Sipek@FILES = sort @FILES; 112cec7ac1bSJosef 'Jeff' Sipek 1136b5e5868SGarrett D'Amoreforeach $a (@FILES) { 1146b5e5868SGarrett D'Amore dofile($a); 1156b5e5868SGarrett D'Amore} 1166b5e5868SGarrett D'Amore 117e2fb2b65SMarcel Telkaforeach my $lic (sort keys %LICENSE) { 1186b5e5868SGarrett D'Amore my @files = @{$LICENSE{$lic}}; 1196b5e5868SGarrett D'Amore print "\nThe following files from the C library:\n"; 1206b5e5868SGarrett D'Amore foreach my $f (@files) { 1216b5e5868SGarrett D'Amore print(" $f\n"); 1226b5e5868SGarrett D'Amore } 1236b5e5868SGarrett D'Amore print "are provided under the following terms:\n\n"; 1246b5e5868SGarrett D'Amore print "$lic\n"; 1256b5e5868SGarrett D'Amore} 126