blob: 6f01d1a1e9816dde747e39f87ee202211c911dc7 [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001#!/usr/bin/perl
2###############################################################################
3#
4# Copyright 2015 Broadcom Corporation
5#
6# This program is the proprietary software of Broadcom Corporation
7# and/or its licensors, and may only be used, duplicated, modified or
8# distributed pursuant to the terms and conditions of a separate,
9# written license agreement executed between you and Broadcom (an
10# "Authorized License"). Except as set forth in an Authorized License,
11# Broadcom grants no license (express or implied), right to use, or
12# waiver of any kind with respect to the Software, and Broadcom
13# expressly reserves all rights in and to the Software and all
14# intellectual property rights therein. IF YOU HAVE NO AUTHORIZED
15# LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND
16# SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE
17# SOFTWARE.
18#
19# Except as expressly set forth in the Authorized License,
20#
21# 1. This program, including its structure, sequence and organization,
22# constitutes the valuable trade secrets of Broadcom, and you shall use
23# all reasonable efforts to protect the confidentiality thereof, and to
24# use this information only in connection with your use of Broadcom
25# integrated circuit products.
26#
27# 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED
28# "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES,
29# REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR
30# OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY
31# DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
32# NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES,
33# ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
34# CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT
35# OF USE OR PERFORMANCE OF THE SOFTWARE.
36#
37# 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM
38# OR ITS LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL,
39# INDIRECT, OR EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY
40# RELATING TO YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF
41# BROADCOM HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR (ii)
42# ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE SOFTWARE
43# ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE LIMITATIONS SHALL APPLY
44# NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF ANY LIMITED
45# REMEDY.
46#
47###############################################################################
48#
49# Script: insert_copyright.pl
50#
51# Purpose: This script inserts a copyright header into the beginning
52# of a c/c++, shell script, and Makefiles.
53#
54# Usage: ./insert_copyright.pl -l <license file> [-t <type>] <source file>
55# Options:
56#
57# -l <file> Specifies the license/copyright file to be inserted into the file
58# -t <type> Specifies the type of copyright to insert...
59# 's' - shell script
60# 'm' - Makefile
61# 'c' - (default) c/c++ file
62#
63###############################################################################
64use Getopt::Long;
65my $licfile = "";
66my $srcfile = "";
67my $type = "";
68$result = GetOptions ("license_file=s" => \$licfile,
69 "type=s" => \$type);
70
71$srcfile = shift;
72
73## printf "$licfile, $type, $srcfile\n";
74
75sub InsertCfileCopyright
76{
77 my $lic = shift;
78 my $src = shift;
79
80 print "/******************************************************************************\n";
81 print " *\n";
82
83 open( LICF, "< $lic" ) or die "Can't open $lic : $!";
84 while( $line = <LICF> ) {
85 print " * $line";
86 }
87 close LICF;
88
89 print " *\n";
90 print " *****************************************************************************/\n";
91 print " \n";
92
93 if (length($srcfile) > 0) {
94 open( SRCF, "< $src" ) or die "Can't open $src : $!";
95 while( $line = <SRCF> ) {
96 print "$line";
97 }
98 close SRCF;
99 }
100}
101
102sub InsertMakefileCopyright
103{
104 my $lic = shift;
105 my $src = shift;
106
107 print "###############################################################################\n";
108 print "#\n";
109
110 open( LICF, "< $lic" ) or die "Can't open $lic : $!";
111 while( $line = <LICF> ) {
112 print "# $line";
113 }
114 close LICF;
115
116 print "#\n";
117 print "###############################################################################\n";
118
119 if (length($srcfile) > 0) {
120 open( SRCF, "< $src" ) or die "Can't open $src : $!";
121 while( $line = <SRCF> ) {
122 print "$line";
123 }
124 close SRCF;
125 }
126}
127
128sub InsertShCopyright
129{
130 my $lic = shift;
131 my $src = shift;
132
133 if (length($srcfile) > 0) {
134 open( SRCF, "< $src" ) or die "Can't open $src : $!";
135 $line = <SRCF>;
136 print "$line";
137 }
138
139 print "###############################################################################\n";
140 print "#\n";
141
142 open( LICF, "< $lic" ) or die "Can't open $lic : $!";
143 while( $line = <LICF> ) {
144 print "# $line";
145 }
146 close LICF;
147
148 print "#\n";
149 print "###############################################################################\n";
150
151 if (length($srcfile) > 0) {
152 while( $line = <SRCF> ) {
153 print "$line";
154 }
155 close SRCF;
156 }
157}
158
159if ($type eq "s") {
160 InsertShCopyright($licfile, $srcfile);
161} elsif ($type eq "m") {
162 InsertMakefileCopyright($licfile, $srcfile);
163} elsif ($type eq "c" || $type == "") {
164 InsertCfileCopyright($licfile, $srcfile);
165}
166
167exit;
168
169