summaryrefslogtreecommitdiff
path: root/copyright
blob: 3c8488b326fbb6d2c7858a88afa76d1422caf4be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /usr/bin/env bash

# Manage build2 toolchain copyright.
#
# Usage: copyright
#
usage="usage: $0"

old=2015
new=2016

# In extras we just grep for the old date.
#
modules="libbutl build2 libbpkg bpkg brep build2-toolchain"
extras="etc private"

owd=`pwd`
trap "{ cd $owd; exit 1; }" ERR
set -o errtrace # Trap in functions.

function info () { echo "$*" 1>&2; }
function error () { info "$*"; exit 1; }


# In-place sed.
#
function ised () # <regex> <file>
{
  local r=$1
  local f=$2
  local o=$f.orig

  mv $f $o
  cp -p $o $f # Keep owner, permissions.

  if ! sed -e "$r" $o >$f; then
    mv $o $f
    return 1
  fi

  if cmp -s $o $f; then
    mv $o $f
  else
    rm $o
  fi
}

for m in $modules; do
  # Top-level directories inside the module to exclude.
  #
  exclude=.git

  # Exclude submodules in build2-toolchain.
  #
  if [ $m = "build2-toolchain" ]; then
    exclude="$exclude bpkg build2 libbutl libbpkg"
  fi

  fo=
  if [ "$exclude" ]; then
    fo="-type d ("
    for e in $exclude; do
      fo="$fo -path $m/$e -o"
    done
    fo="$fo -false ) -prune -o"
  fi
  fo="$fo -type f -print"

  for f in `find $m $fo`; do
    ised "s/\(Copyright (c) [0-9]*\)-$old \(Code Synthesis\)/\1-$new \2/" $f
    grep --color=auto --with-filename $old $f || true
  done
done

for m in $extras; do
  for f in `find $m -type d -path $m/.git -prune -o -type f -print`; do
    grep --color=auto --with-filename $old $f || true
  done
done