1
# -*- mode: makefile; coding: utf-8 -*-
2
# Copyright © 2007-2008 Jonas Smedegaard <dr@jones.dk>
3
# Description: Convenience rules for dealing with upstream tarballs
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_upstream_tarball
25
_cdbs_rules_upstream_tarball := 1
27
include $(_cdbs_rules_path)/buildvars.mk$(_cdbs_makefile_suffix)
29
CDBS_BUILD_DEPENDS := $(CDBS_BUILD_DEPENDS), cdbs (>= 0.4.39)
31
# Prefix for upstream location of all upstream tarballs (mandatory!)
34
DEB_UPSTREAM_PACKAGE = $(DEB_SOURCE_PACKAGE)
35
DEB_UPSTREAM_TARBALL_VERSION = $(if $(strip $(DEB_UPSTREAM_REPACKAGE_EXCLUDE)),$(DEB_UPSTREAM_VERSION:$(DEB_UPSTREAM_REPACKAGE_DELIMITER)$(DEB_UPSTREAM_REPACKAGE_TAG)=),$(DEB_UPSTREAM_VERSION))
36
DEB_UPSTREAM_TARBALL_EXTENSION = tar.gz
37
# Checksum to ensure integrity of downloadeds using get-orig-source (optional)
38
#DEB_UPSTREAM_TARBALL_MD5 =
40
DEB_UPSTREAM_WORKDIR = ../tarballs
42
# Perl regexp to change locally used string into that in upstream URL and srcdir
43
#DEB_UPSTREAM_TARBALL_VERSION_MANGLE
44
cdbs_upstream_tarball_version_mangled = $(if $(strip $(DEB_UPSTREAM_TARBALL_VERSION_MANGLE)),$(shell echo '$(DEB_UPSTREAM_TARBALL_VERSION)' | perl -pe '$(DEB_UPSTREAM_TARBALL_VERSION_MANGLE)'),$(DEB_UPSTREAM_TARBALL_VERSION))
46
# Base filename (without extension) as used in upstream URL
47
DEB_UPSTREAM_TARBALL_BASENAME = $(DEB_UPSTREAM_PACKAGE)-$(cdbs_upstream_tarball_version_mangled)
49
# Base directory within tarball
50
DEB_UPSTREAM_TARBALL_SRCDIR = $(DEB_UPSTREAM_PACKAGE)-$(cdbs_upstream_tarball_version_mangled)
52
# Space-delimited list of directories and files to strip (optional)
53
#DEB_UPSTREAM_REPACKAGE_EXCLUDE = CVS .cvsignore doc/rfc*.txt doc/draft*.txt
54
DEB_UPSTREAM_REPACKAGE_TAG = dfsg
55
DEB_UPSTREAM_REPACKAGE_DELIMITER = ~
57
cdbs_upstream_tarball = $(DEB_UPSTREAM_TARBALL_BASENAME).$(DEB_UPSTREAM_TARBALL_EXTENSION)
58
cdbs_upstream_local_tarball = $(DEB_SOURCE_PACKAGE)_$(DEB_UPSTREAM_TARBALL_VERSION).orig.$(if $(findstring $(DEB_UPSTREAM_TARBALL_EXTENSION),tgz),tar.gz,$(DEB_UPSTREAM_TARBALL_EXTENSION))
59
cdbs_upstream_repackaged_basename = $(DEB_SOURCE_PACKAGE)_$(DEB_UPSTREAM_TARBALL_VERSION)$(DEB_UPSTREAM_REPACKAGE_DELIMITER)$(DEB_UPSTREAM_REPACKAGE_TAG).orig
60
cdbs_upstream_uncompressed_tarball = $(DEB_SOURCE_PACKAGE)_$(DEB_UPSTREAM_TARBALL_VERSION).orig.tar
62
# # These variables are deprecated
63
_cdbs_deprecated_vars += DEB_UPSTREAM_TARBALL DEB_UPSTREAM_LOCAL_TARBALL DEB_UPSTREAM_REPACKAGE_TARBALL
64
_cdbs_deprecated_vars += DEB_UPSTREAM_REPACKAGE_EXCLUDES
65
DEB_UPSTREAM_REPACKAGE_EXCLUDE += $(DEB_UPSTREAM_REPACKAGE_EXCLUDES)
68
@@echo "Debian version: $(DEB_VERSION)"
69
@@echo "Upstream version: $(DEB_UPSTREAM_TARBALL_VERSION)"
73
@@mkdir -p "$(DEB_UPSTREAM_WORKDIR)"
75
@if [ ! -s "$(DEB_UPSTREAM_WORKDIR)/$(cdbs_upstream_local_tarball)" ] ; then \
76
if [ -f "$(DEB_UPSTREAM_WORKDIR)/$(cdbs_upstream_local_tarball)" ] ; then \
77
rm "$(DEB_UPSTREAM_WORKDIR)/$(cdbs_upstream_local_tarball)" ; \
79
echo "Downloading $(cdbs_upstream_local_tarball) from $(DEB_UPSTREAM_URL)/$(cdbs_upstream_tarball) ..." ; \
80
wget -nv -T10 -t3 -O "$(DEB_UPSTREAM_WORKDIR)/$(cdbs_upstream_local_tarball)" "$(DEB_UPSTREAM_URL)/$(cdbs_upstream_tarball)" ; \
82
echo "Upstream source tarball have been already downloaded: $(DEB_UPSTREAM_WORKDIR)/$(cdbs_upstream_local_tarball)" ; \
85
@md5current=`md5sum "$(DEB_UPSTREAM_WORKDIR)/$(cdbs_upstream_local_tarball)" | sed -e 's/ .*//'`; \
86
if [ -n "$(DEB_UPSTREAM_TARBALL_MD5)" ] ; then \
87
if [ "$$md5current" != "$(DEB_UPSTREAM_TARBALL_MD5)" ] ; then \
88
echo "Expecting upstream tarball md5sum $(DEB_UPSTREAM_TARBALL_MD5), but $$md5current found" ; \
89
echo "Upstream tarball md5sum is NOT trusted! Possible upstream tarball forge!" ; \
90
echo "Purging downloaded file. Try new download." ; \
91
rm -f "$(DEB_UPSTREAM_WORKDIR)/$(cdbs_upstream_local_tarball)" ; \
94
echo "Upstream tarball is trusted!" ; \
97
echo "Upstream tarball NOT trusted (current md5sum is $$md5current)!" ; \
100
# TODO: Rewrite using make variables like cdbs_upstream_unpack_cmd and
101
# DEB_UPSTREAM_SUPPORTED_COMPRESSIONS (recent dpkg supports bz2)
102
@untar="tar -x -C"; \
103
case "$(cdbs_upstream_local_tarball)" in \
104
*.tar.gz) unpack="gunzip -c";; \
105
*.tar.bz2) unpack="bunzip2 -c"; uncompress="bunzip2";; \
106
*.tar.Z) unpack="uncompress -c"; uncompress="uncompress";; \
107
*.zip) unpack="unzip -q"; uncompress="false"; untar="-d"; nopipe="true";; \
108
*.tar) unpack="cat"; uncompress="true";; \
109
*) echo "Unknown extension for upstream tarball $(cdbs_upstream_local_tarball)"; false;; \
111
if [ -n "$(strip $(DEB_UPSTREAM_REPACKAGE_EXCLUDE))" ] || [ "$$uncompress" = "false" ]; then \
112
echo "Repackaging tarball ..." && \
113
mkdir -p "$(DEB_UPSTREAM_WORKDIR)/$(DEB_UPSTREAM_REPACKAGE_TAG)" && \
114
if [ -n "$$nopipe" ]; then \
115
$$unpack "$(DEB_UPSTREAM_WORKDIR)/$(cdbs_upstream_local_tarball)" \
116
$$untar "$(DEB_UPSTREAM_WORKDIR)/$(DEB_UPSTREAM_REPACKAGE_TAG)" $(patsubst %,--exclude='%',$(DEB_UPSTREAM_REPACKAGE_EXCLUDE)); \
118
$$unpack "$(DEB_UPSTREAM_WORKDIR)/$(cdbs_upstream_local_tarball)" \
119
| $$untar "$(DEB_UPSTREAM_WORKDIR)/$(DEB_UPSTREAM_REPACKAGE_TAG)" $(patsubst %,--exclude='%',$(DEB_UPSTREAM_REPACKAGE_EXCLUDE)); \
121
if [ "$(DEB_UPSTREAM_TARBALL_SRCDIR)" != "$(cdbs_upstream_repackaged_basename)" ]; then \
122
mv -T "$(DEB_UPSTREAM_WORKDIR)/$(DEB_UPSTREAM_REPACKAGE_TAG)/$(DEB_UPSTREAM_TARBALL_SRCDIR)" "$(DEB_UPSTREAM_WORKDIR)/$(DEB_UPSTREAM_REPACKAGE_TAG)/$(cdbs_upstream_repackaged_basename)"; \
124
if [ -n "$(strip $(DEB_UPSTREAM_REPACKAGE_EXCLUDE))" ]; then \
125
GZIP=-9 tar -b1 -czf "$(DEB_UPSTREAM_WORKDIR)/$(cdbs_upstream_repackaged_basename).tar.gz" -C "$(DEB_UPSTREAM_WORKDIR)/$(DEB_UPSTREAM_REPACKAGE_TAG)" "$(cdbs_upstream_repackaged_basename)"; \
127
GZIP=-9 tar -b1 -czf "$(DEB_UPSTREAM_WORKDIR)/$(cdbs_upstream_uncompressed_tarball).gz" -C "$(DEB_UPSTREAM_WORKDIR)/$(DEB_UPSTREAM_REPACKAGE_TAG)" "$(cdbs_upstream_repackaged_basename)"; \
129
echo "Cleaning up" && \
130
rm -rf "$(DEB_UPSTREAM_WORKDIR)/$(DEB_UPSTREAM_REPACKAGE_TAG)"; \
131
elif [ -n "$$uncompress" ]; then \
132
echo "Recompressing tarball ..." && \
133
$$uncompress "$(DEB_UPSTREAM_WORKDIR)/$(cdbs_upstream_local_tarball)"; \
134
gzip -9 "$(DEB_UPSTREAM_WORKDIR)/$(cdbs_upstream_uncompressed_tarball)"; \
137
DEB_PHONY_RULES += print-version get-orig-source