xref: /freebsd-src/contrib/cortex-strings/scripts/add-license.sh (revision 8c4282b370bd66908b45b6a223226a9fc2b69d57)
1*09a53ad8SAndrew Turner#!/bin/bash
2*09a53ad8SAndrew Turner#
3*09a53ad8SAndrew Turner# Add the modified BSD license to a file
4*09a53ad8SAndrew Turner#
5*09a53ad8SAndrew Turner
6*09a53ad8SAndrew Turnerf=`mktemp -d`
7*09a53ad8SAndrew Turnertrap "rm -rf $f" EXIT
8*09a53ad8SAndrew Turner
9*09a53ad8SAndrew Turneryear=`date +%Y`
10*09a53ad8SAndrew Turnercat > $f/original <<EOF
11*09a53ad8SAndrew TurnerCopyright (c) $year, Linaro Limited
12*09a53ad8SAndrew TurnerAll rights reserved.
13*09a53ad8SAndrew Turner
14*09a53ad8SAndrew TurnerRedistribution and use in source and binary forms, with or without
15*09a53ad8SAndrew Turnermodification, are permitted provided that the following conditions are met:
16*09a53ad8SAndrew Turner    * Redistributions of source code must retain the above copyright
17*09a53ad8SAndrew Turner      notice, this list of conditions and the following disclaimer.
18*09a53ad8SAndrew Turner    * Redistributions in binary form must reproduce the above copyright
19*09a53ad8SAndrew Turner      notice, this list of conditions and the following disclaimer in the
20*09a53ad8SAndrew Turner      documentation and/or other materials provided with the distribution.
21*09a53ad8SAndrew Turner    * Neither the name of the Linaro nor the
22*09a53ad8SAndrew Turner      names of its contributors may be used to endorse or promote products
23*09a53ad8SAndrew Turner      derived from this software without specific prior written permission.
24*09a53ad8SAndrew Turner
25*09a53ad8SAndrew TurnerTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26*09a53ad8SAndrew TurnerANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27*09a53ad8SAndrew TurnerWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28*09a53ad8SAndrew TurnerDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
29*09a53ad8SAndrew TurnerDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30*09a53ad8SAndrew Turner(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31*09a53ad8SAndrew TurnerLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32*09a53ad8SAndrew TurnerON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33*09a53ad8SAndrew Turner(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34*09a53ad8SAndrew TurnerSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35*09a53ad8SAndrew TurnerEOF
36*09a53ad8SAndrew Turner
37*09a53ad8SAndrew Turner# Translate it to C style
38*09a53ad8SAndrew Turnerecho "/*" > $f/c
39*09a53ad8SAndrew Turnersed -r 's/(.*)/ * \1/' $f/original | sed -r 's/ +$//' >> $f/c
40*09a53ad8SAndrew Turnerecho " */" >> $f/c
41*09a53ad8SAndrew Turnerecho >> $f/c
42*09a53ad8SAndrew Turner
43*09a53ad8SAndrew Turner# ...and shell style
44*09a53ad8SAndrew Turnersed -r 's/(.*)/# \1/' $f/original | sed -r 's/ +$//' >> $f/shell
45*09a53ad8SAndrew Turnerecho '#' >> $f/shell
46*09a53ad8SAndrew Turnerecho >> $f/shell
47*09a53ad8SAndrew Turner
48*09a53ad8SAndrew Turnerfor name in $@; do
49*09a53ad8SAndrew Turner    if grep -q Copyright $name; then
50*09a53ad8SAndrew Turner	echo $name already has some type of copyright
51*09a53ad8SAndrew Turner	continue
52*09a53ad8SAndrew Turner    fi
53*09a53ad8SAndrew Turner
54*09a53ad8SAndrew Turner    case $name in
55*09a53ad8SAndrew Turner	# These files don't have an explicit license
56*09a53ad8SAndrew Turner        *autogen.sh*)
57*09a53ad8SAndrew Turner	    continue;;
58*09a53ad8SAndrew Turner	*reference/newlib/*)
59*09a53ad8SAndrew Turner	    continue;;
60*09a53ad8SAndrew Turner	*reference/newlib-xscale/*)
61*09a53ad8SAndrew Turner	    continue;;
62*09a53ad8SAndrew Turner	*/dhry/*)
63*09a53ad8SAndrew Turner	    continue;;
64*09a53ad8SAndrew Turner
65*09a53ad8SAndrew Turner	*.c)
66*09a53ad8SAndrew Turner	    src=$f/c
67*09a53ad8SAndrew Turner	    ;;
68*09a53ad8SAndrew Turner	*.sh|*.am|*.ac)
69*09a53ad8SAndrew Turner	    src=$f/shell
70*09a53ad8SAndrew Turner	    ;;
71*09a53ad8SAndrew Turner	*)
72*09a53ad8SAndrew Turner	    echo Unrecognied extension on $name
73*09a53ad8SAndrew Turner	    continue
74*09a53ad8SAndrew Turner    esac
75*09a53ad8SAndrew Turner
76*09a53ad8SAndrew Turner    cat $src $name > $f/next
77*09a53ad8SAndrew Turner    mv $f/next $name
78*09a53ad8SAndrew Turner    echo Updated $name
79*09a53ad8SAndrew Turnerdone
80