~ubuntu-branches/ubuntu/natty/ffc/natty

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Johannes Ring
  • Date: 2009-09-25 09:41:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090925094139-6exg632vgocv71uo
Tags: 0.7.0-1
Initial release (Closes: #502980)

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
DEB_COPYRIGHT_CHECK_IGNORE_REGEX = ^debian/(changelog|copyright(|_hints|_newhints))$
 
38
 
 
39
pre-build:: debian/stamp-copyright-check
 
40
 
 
41
debian/stamp-copyright-check:
 
42
        @echo 'Scanning upstream source for new/changed copyright notices...'
 
43
        @echo debian/licensecheck -c '$(DEB_COPYRIGHT_CHECK_REGEX)' -r --copyright -i '$(DEB_COPYRIGHT_CHECK_IGNORE_REGEX)' * \
 
44
                "| some-output-filtering..."
 
45
 
 
46
# Perl in shell in make requires extra care:
 
47
#  * Single-quoting ('...') protects against shell expansion
 
48
#  * Double-dollar ($$) expands to plain dollar ($) in make
 
49
        @debian/licensecheck -c '$(DEB_COPYRIGHT_CHECK_REGEX)' -r --copyright -i '$(DEB_COPYRIGHT_CHECK_IGNORE_REGEX)' * \
 
50
                | LC_ALL=C perl -e \
 
51
        'print "Format-Specification: http://wiki.debian.org/Proposals/CopyrightFormat?action=recall&rev=XXX\n";'\
 
52
        'print "Upstream-Name: Untrusted draft - double-check copyrights yourself!\n\n";'\
 
53
        '$$n=0; while (<>) {'\
 
54
        '       s/[^[:print:]]//g;'\
 
55
        '       if (/^([^:\s][^:]+):[\s]+(\S.*?)\s*$$/) {'\
 
56
        '               $$files[$$n]{name}=$$1;'\
 
57
        '               $$files[$$n]{license}=$$2;'\
 
58
        '       };'\
 
59
        '       if (/^\s*\[Copyright:\s*(\S.*?)\s*\]/) {'\
 
60
        '               $$files[$$n]{copyright}=$$1;'\
 
61
        '       };'\
 
62
        '       /^$$/ and $$n++;'\
 
63
        '};'\
 
64
        'foreach $$file (@files) {'\
 
65
        '       $$file->{license} =~ s/\s*\(with incorrect FSF address\)//;'\
 
66
        '       $$file->{license} =~ s/\s+\(v([^)]+) or later\)/-$$1+/;'\
 
67
        '       $$file->{license} =~ s/\s+\(v([^)]+)\)/-$$1/;'\
 
68
        '       $$file->{license} =~ s/\s*(\*No copyright\*)\s*// and $$file->{copyright} = $$1;'\
 
69
        '       $$file->{license} =~ s/^\s*(GENERATED FILE)/UNKNOWN ($$1)/;'\
 
70
        '       $$file->{license} =~ s/\s+(GENERATED FILE)/ ($$1)/;'\
 
71
        '       $$file->{copyright} =~ s/(?<=(\b\d{4}))(?{$$y=$$^N})\s*[,-]\s*((??{$$y+1}))\b/-$$2/g;'\
 
72
        '       $$file->{copyright} =~ s/(?<=\b\d{4})\s*-\s*\d{4}(?=\s*-\s*(\d{4})\b)//g;'\
 
73
        '       $$file->{copyright} =~ s/\b(\d{4})\s+([\S^\d])/$$1, $$2/g;'\
 
74
        '       $$file->{copyright} =~ s/^\W*\s+\/\s+//g;'\
 
75
        '       $$file->{copyright} =~ s/\s+\/\s+\W*$$//;'\
 
76
        '       $$file->{copyright} =~ s/\s+\/\s+/\n\t/g;'\
 
77
        '       $$pattern = "$$file->{license} [$$file->{copyright}]";'\
 
78
        '       push @{ $$patternfiles{"$$pattern"} }, $$file->{name};'\
 
79
        '};'\
 
80
        'foreach $$pattern ( sort {'\
 
81
        '                       @{$$patternfiles{$$b}} <=> @{$$patternfiles{$$a}}'\
 
82
        '                       ||'\
 
83
        '                       $$a cmp $$b'\
 
84
        '               } keys %patternfiles ) {'\
 
85
        '       ($$license, $$copyright) = $$pattern =~ /(.*) \[(.*)\]/s;'\
 
86
        '       print "Files: ", join("\n\t", sort @{ $$patternfiles{$$pattern} }), "\n";'\
 
87
        '       print "Copyright: $$copyright\n";'\
 
88
        '       print "License: $$license\n\n";'\
 
89
        '};'\
 
90
                > debian/copyright_newhints
 
91
        @patterncount="`cat debian/copyright_newhints | sed 's/^[^:]*://' | LANG=C sort -u | grep . -c -`"; \
 
92
                echo "Found $$patterncount different copyright and licensing combinations."
 
93
        @if [ ! -f debian/copyright_hints ]; then touch debian/copyright_hints; fi
 
94
        @newstrings=`diff -u debian/copyright_hints debian/copyright_newhints | sed '1,2d' | egrep '^\+' - | sed 's/^\+//'`; \
 
95
                if [ -n "$$newstrings" ]; then \
 
96
                        echo "$(if $(DEB_COPYRIGHT_CHECK_STRICT),ERROR,WARNING): The following new or changed copyright notices discovered:"; \
 
97
                        echo; \
 
98
                        echo "$$newstrings"; \
 
99
                        echo; \
 
100
                        echo "To fix the situation please do the following:"; \
 
101
                        echo "  1) Investigate the above changes and update debian/copyright as needed"; \
 
102
                        echo "  2) Replace debian/copyright_hints with debian/copyright_newhints"; \
 
103
                        $(if $(DEB_COPYRIGHT_CHECK_STRICT),exit 1,:); \
 
104
                else \
 
105
                        echo 'No new copyright notices found - assuming no news is good news...'; \
 
106
                        rm -f debian/copyright_newhints; \
 
107
                fi
 
108
        touch $@
 
109
 
 
110
clean::
 
111
        rm -f debian/stamp-copyright-check
 
112
 
 
113
endif