summaryrefslogtreecommitdiff
path: root/src/xpi.mk.in
blob: 595d0d8b5f8befa37034e93a11f12512b24e0b94 (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
# -*- mode: makefile; coding: utf-8 -*-

# Copyright (c) 2008 Canonical Ltd.
# Author(s): Alexander Sack <asac@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 (MANDATORY):
#        	define the binary package name used to ship this xpi
#
#        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|
#

TEMPDIR := $(shell rm -rf temp-xpi-*; mktemp -d temp-xpi-XXXXXXXX)

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

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

# ### 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

# clean build and remove all .xpi in top-level if a MOZ_XPI_BUILD_COMMAND is defined
clean:: xpi-clean
ifneq (,$(MOZ_XPI_BUILD_COMMAND))
	rm -f *.xpi
endif

# ### general helper targets
stamp-unzip-%:
	unzip -d $(TEMPDIR) $*
	touch $@

stamp-install-%:
	dh_installdirs -p$(MOZ_EXTENSION_PKG) /usr/lib/firefox-addons/extensions
	dh_install -p$(MOZ_EXTENSION_PKG) $(wildcard $(TEMPDIR)/*) /usr/share/$(MOZ_EXTENSION_PKG)
	dh_link -p$(MOZ_EXTENSION_PKG) /usr/share/$(MOZ_EXTENSION_PKG) /usr/lib/firefox-addons/extensions/$(call XPI_EMID,$(TEMPDIR))
	touch $@

stamp-extension-install: $(XPI_FILE) stamp-unzip-$(XPI_FILE) stamp-install-$(XPI_FILE)
	touch stamp-extension-install


# only attempt to do things if a pkg was provided; otherwise error out
ifneq (,$(MOZ_EXTENSION_PKG))
xpi-install: stamp-extension-install

xpi-clean:
	dh_clean -p$(MOZ_EXTENSION_PKG)
	-rm -f stamp-extension-install \
		unzip-* \
		install-* \
		$(NULL)
	-rm -rf $(TEMPDIR)


else
xpi-install:
	echo "*** need to define MOZ_EXTENSION_PKG"
	exit 2

xpi-clean:
	echo "*** need to define MOZ_EXTENSION_PKG"
	exit 2
endif