summaryrefslogtreecommitdiff
path: root/src/xpi.mk
blob: 35cd0373331018d902911c06c2399d22c7d94e63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# -*- mode: makefile; coding: utf-8 -*-

# Copyright (c) 2008-2009 Canonical Ltd.
# Author(s): Alexander Sack <asac@ubuntu.com>
#            Fabien Tassin <fta@sofaraway.org>
#            Benjamin Drung <bdrung@ubuntu.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


#
# Usage: include this file in your cdbs debian/rules file and define the
#        following variables:
#
#        MOZ_EXTENSION_PKG (OPTIONAL):
#        	if defined the given binary package name is used to ship this
#        	xpi; otherwise the first binary package listed in debian/control
#        	is used
#
#        MOZ_XPI_FILE (OPTIONAL):
#        	if defined the given .xpi file is used; otherwise we try to
#        	guess one using wildcard (*.xpi)
#
#        MOZ_XPI_EMID (OPTIONAL):
#        	if defined the given id is used to determine the link name
#        	in the firefox extensions directory. if not defined we try
#        	our best to extract the em:id from the install.rdf file shipped
#        	by any xpi
#
#        MOZ_XPI_BUILD_COMMAND (OPTIONAL):
#               if defined the given command will be run _before_ the extension
#               gets packaged up the standard .xpi way. Thus, the build command
#               should produce an .xpi in top level directory. Note: If this
#               command is specified, all .xpi files in the top level directory
#               will be removed during |clean|. If the xpi file will not be
#               build from source, you have to set this variable to nothing.
#
#        MOZ_XPI_MOZILLA_EXTRA_DIRS (OPTIONAL):
#               XXX: implement this!
#               defines extra directories to link the extension in.
#               usually xpi.mk creates the right links based on targetApplication
#               parsed in install.rdf; if you need more directories, use this.
#
#        MOZ_XPI_DOCUMENTED_LICENSE_FILES (OPTIONAL):
#               defines extra license files which need to be excluded during
#               the installation of the XPI file to the packaging tree. When
#               using parameter, be sure that you documented _all_ excluded
#               license files in debian/copyright appropriately. If not defined
#               the common license file names are tried.
#
#        Deprecated variables:
#
#        MOZ_XPI_MOZILLA_DIRS /deprecated/ (OPTIONAL/NODEFAULT - see "Note:"):
#               defines in which directories to create links for this extension.
#               the default is "firefox-addons", which means that
#               the extension will be linked appropriately to the
#               /usr/lib/firefox-addons/extensions directory.
#               '''Note''': this variable is deprecated and will go away; the
#               default is already empty; if you still need this variable, migrate
#               your code to MOZ_XPI_MOZILLA_EXTRA_DIRS
#

# data for XPI_RECOMMENDS/CHECK_VERSION magic - start/end of life of binary packages
abrowser-3.0_sol := 3.0a8
abrowser-3.0_eol := 3.0.*
abrowser-3.5_sol := 3.5b4
abrowser-3.5_eol := 3.5.*
abrowser-3.6_sol := 3.6a1pre
abrowser-3.6_eol := 3.6.*
abrowser-3.7_sol := 3.7a1pre
abrowser-3.7_eol := 3.7.*
firefox-3.0_sol := 3.0a8
firefox-3.0_eol := 3.0.*
firefox-3.5_sol := 3.5b4
firefox-3.5_eol := 3.5.*
firefox-3.6_sol := 3.6a1pre
firefox-3.6_eol := 3.6.*
firefox-3.7_sol := 3.7a1pre
firefox-3.7_eol := 3.7.*
iceweasel_sol := 2.0
iceweasel_eol := *

icedove_sol := 1.5.0.7
icedove_eol := *
thunderbird_sol := 2.0
thunderbird_eol := 2.0.0.*
thunderbird-3.0_sol := 3.0a1pre
thunderbird-3.0_eol := 3.0.*

iceape_sol := 1.0.6
iceape_eol := *
seamonkey_sol := 1.1.6
seamonkey_eol := *

conkeror_sol := 0.9
conkeror_eol := *

prism_sol := 0.8
prism_eol := *

sunbird_sol := 0.5
sunbird_eol := *

xulrunner-1.9_sol := 1.9a1pre
xulrunner-1.9_eol := 1.9.0.*
xulrunner-1.9.1_sol := 1.9.1a1pre
xulrunner-1.9.1_eol := 1.9.1.*
xulrunner-1.9.2_sol := 1.9.2a1pre
xulrunner-1.9.2_eol := 1.9.2.*
xulrunner-1.9.3_sol := 1.9.3a1pre
xulrunner-1.9.3_eol := 1.9.3.*

# data for XPI_RECOMMENDS/CHECK_VERSION magic - targetApplication packages
packages_{ec8030f7-c20a-464f-9b0e-13a3a9e97384} := abrowser-3.0 abrowser-3.5 abrowser-3.6 abrowser-3.7 firefox-3.0 firefox-3.5 firefox-3.6 firefox-3.7 iceweasel
packages_{3550f703-e582-4d05-9a08-453d09bdfdc6} := icedove thunderbird thunderbird-3.0
packages_{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a} := iceape seamonkey
packages_{a79fe89b-6662-4ff4-8e88-09950ad4dfde} := conkeror
packages_prism@developer.mozilla.org := prism
packages_toolkit@mozilla.org := xulrunner-1.9 xulrunner-1.9.1 xulrunner-1.9.2 xulrunner-1.9.3

# distribution package list
Debian_packages := iceweasel icedove iceape conkeror xulrunner-1.9 xulrunner-1.9.1
Ubuntu_packages := abrowser-3.5 firefox-3.0 firefox-3.5 thunderbird seamonkey conkeror prism xulrunner-1.9 xulrunner-1.9.1

# data for XPI_RECOMMENDS/CHECK_VERSION magic - targetApplication min-/maxVersions
# call parameters_
#   1- target app id
#   2- maxVersion | minVersion
#   3- extension dir
TARGET_VERSION = $(shell xpath -q -e '//em:targetApplication/Description[em:id="$(1)" or @em:id="$(1)"]/em:$(2)/text() | //em:targetApplication/Description[em:id="$(1)" or @em:id="$(1)"]/@em:$(2)' $(3)/install.rdf)

# call parameters_
#   1- target app id
#   2- package name
CHECK_VERSION = $(shell \
	moz-version -cs "$($(2)_eol)" ge $(call TARGET_VERSION,$(1),minVersion,$(TEMPDIR)) && \
	moz-version -cs "$($(2)_sol)" le $(call TARGET_VERSION,$(1),maxVersion,$(TEMPDIR)) && \
	echo $(2))

MOZ_EXTENSION_PKG ?= $(strip $(shell grep ^Package: debian/control | head -n 1 | sed "s/^Package://"))

MOZ_XPI_ARCH := $(strip $(shell egrep '^Package:|^Architecture:' debian/control | grep -A1 '^Package:[ \t]*$(MOZ_EXTENSION_PKG)[ \t]*$$' | grep ^Architecture: | sed -e 's/Architecture://'))

MOZ_XPI_BUILD_COMMAND ?= med-xpi-pack $(CURDIR) $(MOZ_EXTENSION_PKG).xpi;

ALL_XPI_RECOMMENDS = $(sort $(foreach id,$(call XPI_TARGET_EMIDs,$(TEMPDIR)), \
	$(foreach package,$(packages_$(id)),$(call CHECK_VERSION,$(id),$(package)))))

# list only packages, which are available in the distribution
DISTRIBUTION := $(shell lsb_release -si)
ifneq ($($(DISTRIBUTION)_packages),)
XPI_RECOMMENDS = $(filter $($(DISTRIBUTION)_packages),$(ALL_XPI_RECOMMENDS))
else
XPI_RECOMMENDS = ALL_XPI_RECOMMENDS
endif

strip_version = $(sort $(foreach package,$(1),$(shell echo $(package) | sed "s/-[0-9.]*$$//")))
XPI_PROVIDES = $(addsuffix -$(patsubst xul-ext-%,%,$(MOZ_EXTENSION_PKG)),$(call strip_version,$(XPI_RECOMMENDS)))

TEMPDIR := temp-xpi-unpacked

ifneq (,$(MOZ_XPI_FILE))
XPI_FILE = $(wildcard $(MOZ_XPI_FILE))
else
XPI_FILE = $(wildcard *.xpi)
endif

XPI_BASE_FILE = $(notdir $(XPI_FILE))
XPI_DIR       = $(dir $(XPI_FILE))

ifneq (,$(MOZ_XPI_EMID))
XPI_EMID = $(MOZ_XPI_EMID)
else
XPI_EMID = $(shell xpath -e '/node()/Description/em:id/text()' $(1)/install.rdf 2>/dev/null)
endif

ifeq (,$(MOZ_XPI_DISABLE_AUTOLINKS))
XPI_TARGET_EMIDs = \
		$(shell xpath -q -e '//em:targetApplication//@em:id' $(1)/install.rdf | sed -e 's/.*"\(.*\)"/\1/') \
		$(shell xpath -q -e '//em:targetApplication//em:id/text()' $(1)/install.rdf)
endif

# local vars
# + lib_share_dir - for arch all this is "share"; otherwise "lib"
ifeq (all, $(MOZ_XPI_ARCH))
lib_share_dir = share
else
lib_share_dir = lib
endif

# ### cdbs hooks
# build xpi using MOZ_XPI_BUILD_COMMAND if defined
build/$(MOZ_EXTENSION_PKG)::
ifneq (,$(MOZ_XPI_BUILD_COMMAND))
	$(MOZ_XPI_BUILD_COMMAND)
endif

install/$(MOZ_EXTENSION_PKG):: xpi-install

# ### general helper targets
unzip-%-stamp: $(XPI_FILE)
	mkdir -p $(TEMPDIR)
ifneq (,$(MOZ_XPI_DOCUMENTED_LICENSE_FILES))
	unzip -o -d $(TEMPDIR) $(XPI_DIR)$* -x $(MOZ_XPI_DOCUMENTED_LICENSE_FILES)
else
	unzip -o -d $(TEMPDIR) $(XPI_DIR)$*
ifeq ($(origin MOZ_XPI_DOCUMENTED_LICENSE_FILES),undefined)
	cd $(TEMPDIR) && find \( -iname copying -o -iname gpl.txt -o -iname licen[cs]e -o -iname licen[cs]e.txt \) -printf "xpi.mk: deleted %p\n" -delete
endif
endif
	touch $@

installlinks-%-stamp: unzip-$(XPI_BASE_FILE)-stamp
	dh_link -p$(MOZ_EXTENSION_PKG) /usr/$(lib_share_dir)/$(MOZ_EXTENSION_PKG) /usr/lib/$*/extensions/$(call XPI_EMID,$(TEMPDIR))
	touch $@

autolinks-stamp: unzip-$(XPI_BASE_FILE)-stamp $(foreach mozilla,$(MOZ_XPI_MOZILLA_DIRS),installlinks-$(mozilla)-stamp)
	$(foreach id,$(call XPI_TARGET_EMIDs,$(TEMPDIR)),dh_link -p$(MOZ_EXTENSION_PKG) /usr/$(lib_share_dir)/$(MOZ_EXTENSION_PKG) /usr/lib/mozilla/extensions/$(id)/$(call XPI_EMID,$(TEMPDIR));)
	touch $@

install-%-stamp: unzip-%-stamp
	dh_install -p$(MOZ_EXTENSION_PKG) $(wildcard $(TEMPDIR)/*) /usr/$(lib_share_dir)/$(MOZ_EXTENSION_PKG)
	touch $@

xpi-recommends-stamp: unzip-$(XPI_BASE_FILE)-stamp
	if test -f debian/$(MOZ_EXTENSION_PKG).substvars; then sed -i '/^xpi:Recommends=/d' debian/$(MOZ_EXTENSION_PKG).substvars; fi
	echo "xpi:Recommends=$(XPI_RECOMMENDS)" | sed "s/ / | /g" >> debian/$(MOZ_EXTENSION_PKG).substvars
ifneq ($(shell grep '$${xpi:Depends}' debian/control),)
	@echo 'xpi.mk: $${xpi:Depends} is deprecated, please use $${xpi:Recommends} instead.'
	if test -f debian/$(MOZ_EXTENSION_PKG).substvars; then sed -i '/^xpi:Depends=/d' debian/$(MOZ_EXTENSION_PKG).substvars; fi
	echo "xpi:Depends=$(XPI_RECOMMENDS)" | sed "s/ / | /g" >> debian/$(MOZ_EXTENSION_PKG).substvars
endif
	if test -f debian/$(MOZ_EXTENSION_PKG).substvars; then sed -i '/^xpi:Provides=/d' debian/$(MOZ_EXTENSION_PKG).substvars; fi
	echo "xpi:Provides=$(XPI_PROVIDES)" | sed "s/ /, /g" >> debian/$(MOZ_EXTENSION_PKG).substvars
	if test -f debian/$(MOZ_EXTENSION_PKG).substvars; then sed -i '/^xpi:Enhances=/d' debian/$(MOZ_EXTENSION_PKG).substvars; fi
	echo "xpi:Enhances=$(XPI_RECOMMENDS)" | sed "s/ /, /g" >> debian/$(MOZ_EXTENSION_PKG).substvars
	touch $@

xpi-install: install-$(XPI_BASE_FILE)-stamp autolinks-stamp xpi-recommends-stamp

# clean build and remove all .xpi in top-level if a MOZ_XPI_BUILD_COMMAND is defined
clean::
	dh_testdir
	dh_clean
	rm -rf $(TEMPDIR)
ifeq ($(shell expr $(shell cat debian/compat) '<' 7),1)
	rm -f *-stamp
endif
ifneq (,$(MOZ_XPI_BUILD_COMMAND))
	rm -f *.xpi
endif

.PHONY: clean xpi-install