~ubuntu-branches/ubuntu/maverick/libhtml-wikiconverter-kwiki-perl/maverick

« back to all changes in this revision

Viewing changes to debian/cdbs/1/rules/copyright-check.mk

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-28 23:26:44 UTC
  • Revision ID: james.westby@ubuntu.com-20080628232644-duno7aunkwu486nw
Tags: 0.51-1
Initial official release. Closes: bug#448912.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- mode: makefile; coding: utf-8 -*-
 
2
# Copyright © 2005-2008 Jonas Smedegaard <dr@jones.dk>
 
3
# Description: Check for changes to copyright notices in source
 
4
#
 
5
# This program is free software; you can redistribute it and/or
 
6
# modify it under the terms of the GNU General Public License as
 
7
# published by the Free Software Foundation; either version 2, or (at
 
8
# your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful, but
 
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
# General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 
18
# 02111-1307 USA.
 
19
 
 
20
_cdbs_scripts_path ?= /usr/lib/cdbs
 
21
_cdbs_rules_path ?= /usr/share/cdbs/1/rules
 
22
_cdbs_class_path ?= /usr/share/cdbs/1/class
 
23
 
 
24
ifndef _cdbs_rules_copyright-check
 
25
_cdbs_rules_copyright-check := 1
 
26
 
 
27
include $(_cdbs_rules_path)/buildcore.mk$(_cdbs_makefile_suffix)
 
28
 
 
29
CDBS_BUILD_DEPENDS := $(CDBS_BUILD_DEPENDS), devscripts (>= 2.10.7)
 
30
 
 
31
# Set to yes to fail on changed/new hints are found
 
32
#DEB_COPYRIGHT_CHECK_STRICT := yes
 
33
 
 
34
# Single regular expression for files to include or ignore
 
35
DEB_COPYRIGHT_CHECK_REGEX = .*
 
36
DEB_COPYRIGHT_CHECK_IGNORE_REGEX = ^(debian/.*|(.*/)?config\.(guess|sub|rpath)(\..*)?)$
 
37
 
 
38
pre-build:: debian/stamp-copyright-check
 
39
 
 
40
debian/stamp-copyright-check:
 
41
        @echo 'Scanning upstream source for new/changed copyright notices (except debian subdir!)...'
 
42
 
 
43
# Perl in shell in make requires extra care:
 
44
#  * Single-quoting ('...') protects against shell expansion
 
45
#  * Double-dollar ($$) expands to plain dollar ($) in make
 
46
        licensecheck -c '$(DEB_COPYRIGHT_CHECK_REGEX)' -r --copyright -i '$(DEB_COPYRIGHT_CHECK_IGNORE_REGEX)' * \
 
47
                | LC_ALL=C perl -e \
 
48
        '$$n=0; while (<>) {'\
 
49
        '       s/[^[:print:]]//g;'\
 
50
        '       if (/^([^:\s][^:]+):[\s]+(\S.*?)\s*$$/) {'\
 
51
        '               $$files[$$n]{name}=$$1;'\
 
52
        '               $$files[$$n]{license}=$$2;'\
 
53
        '       };'\
 
54
        '       if (/^\s*\[Copyright:\s*(\S.*?)\s*\]/) {'\
 
55
        '               $$files[$$n]{copyright}=$$1;'\
 
56
        '       };'\
 
57
        '       /^$$/ and $$n++;'\
 
58
        '};'\
 
59
        'foreach $$file (@files) {'\
 
60
        '       $$file->{license} =~ s/\s*\(with incorrect FSF address\)//;'\
 
61
        '       $$file->{license} =~ s/\s+\(v([^)]+) or later\)/-$$1+/;'\
 
62
        '       $$file->{copyright} =~ s/(?<=(\b\d{4}))(?{$$y=$$^N})\s*[,-]\s*((??{$$y+1}))\b/-$$2/g;'\
 
63
        '       $$file->{copyright} =~ s/(?<=\b\d{4})\s*-\s*\d{4}(?=\s*-\s*(\d{4})\b)//g;'\
 
64
        '       $$pattern = "$$file->{license} [$$file->{copyright}]";'\
 
65
        '       push @{ $$patternfiles{"$$pattern"} }, $$file->{name};'\
 
66
        '};'\
 
67
        'foreach $$pattern ( sort {'\
 
68
        '                       @{$$patternfiles{$$b}} <=> @{$$patternfiles{$$a}}'\
 
69
        '                       ||'\
 
70
        '                       $$a cmp $$b'\
 
71
        '               } keys %patternfiles ) {'\
 
72
        '       print "$$pattern: ", join("\n\t", sort @{ $$patternfiles{$$pattern} }), "\n";'\
 
73
        '};'\
 
74
                > debian/copyright_newhints
 
75
        @patterncount="`cat debian/copyright_newhints | sed 's/^[^:]*://' | LANG=C sort -u | grep . -c -`"; \
 
76
                echo "Found $$patterncount different copyright and licensing combinations."
 
77
        @if [ ! -f debian/copyright_hints ]; then touch debian/copyright_hints; fi
 
78
        @newstrings=`diff -u debian/copyright_hints debian/copyright_newhints | sed '1,2d' | egrep '^\+' - | sed 's/^\+//'`; \
 
79
                if [ -n "$$newstrings" ]; then \
 
80
                        echo "$(if $(DEB_COPYRIGHT_CHECK_STRICT),ERROR,WARNING): The following new or changed copyright notices discovered:"; \
 
81
                        echo; \
 
82
                        echo "$$newstrings"; \
 
83
                        echo; \
 
84
                        echo "To fix the situation please do the following:"; \
 
85
                        echo "  1) Investigate the above changes and update debian/copyright as needed"; \
 
86
                        echo "  2) Replace debian/copyright_hints with debian/copyright_newhints"; \
 
87
                        $(if $(DEB_COPYRIGHT_CHECK_STRICT),exit 1,:); \
 
88
                else \
 
89
                        echo 'No new copyright notices found - assuming no news is good news...'; \
 
90
                        rm -f debian/copyright_newhints; \
 
91
                fi
 
92
        touch $@
 
93
 
 
94
clean::
 
95
        rm -f debian/stamp-copyright-check
 
96
 
 
97
endif