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)(\..*)?)$
38
pre-build:: debian/stamp-copyright-check
40
debian/stamp-copyright-check:
41
@echo 'Scanning upstream source for new/changed copyright notices (except debian subdir!)...'
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)' * \
48
'$$n=0; while (<>) {'\
49
' s/[^[:print:]]//g;'\
50
' if (/^([^:\s][^:]+):[\s]+(\S.*?)\s*$$/) {'\
51
' $$files[$$n]{name}=$$1;'\
52
' $$files[$$n]{license}=$$2;'\
54
' if (/^\s*\[Copyright:\s*(\S.*?)\s*\]/) {'\
55
' $$files[$$n]{copyright}=$$1;'\
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};'\
67
'foreach $$pattern ( sort {'\
68
' @{$$patternfiles{$$b}} <=> @{$$patternfiles{$$a}}'\
71
' } keys %patternfiles ) {'\
72
' print "$$pattern: ", join("\n\t", sort @{ $$patternfiles{$$pattern} }), "\n";'\
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:"; \
82
echo "$$newstrings"; \
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,:); \
89
echo 'No new copyright notices found - assuming no news is good news...'; \
90
rm -f debian/copyright_newhints; \
95
rm -f debian/stamp-copyright-check