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
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.
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.
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
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
24
ifndef _cdbs_rules_copyright_check
25
_cdbs_rules_copyright_check := 1
27
include $(_cdbs_rules_path)/buildcore.mk$(_cdbs_makefile_suffix)
29
CDBS_BUILD_DEPENDS := $(CDBS_BUILD_DEPENDS), devscripts (>= 2.10.7)
31
# Set to yes to fail on changed/new hints are found
32
#DEB_COPYRIGHT_CHECK_STRICT := yes
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))$
39
pre-build:: debian/stamp-copyright-check
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..."
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)' * \
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;'\
59
' if (/^\s*\[Copyright:\s*(\S.*?)\s*\]/) {'\
60
' $$files[$$n]{copyright}=$$1;'\
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};'\
80
'foreach $$pattern ( sort {'\
81
' @{$$patternfiles{$$b}} <=> @{$$patternfiles{$$a}}'\
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";'\
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:"; \
98
echo "$$newstrings"; \
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,:); \
105
echo 'No new copyright notices found - assuming no news is good news...'; \
106
rm -f debian/copyright_newhints; \
111
rm -f debian/stamp-copyright-check