# -*- mode: makefile; coding: utf-8 -*- # Copyright (c) 2008-2009 Canonical Ltd. # Author(s): Alexander Sack # Fabien Tassin # # 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| # # 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. # # # 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_DEPENDS/CHECK_VERSION magic - targetApplication to package mapping target_packages_{ec8030f7-c20a-464f-9b0e-13a3a9e97384}_3.0 := abrowser-3.0 firefox-3.0 iceweasel target_packages_{ec8030f7-c20a-464f-9b0e-13a3a9e97384}_3.5 := abrowser-3.5 firefox-3.5 iceweasel target_packages_{ec8030f7-c20a-464f-9b0e-13a3a9e97384}_3.6 := abrowser-3.6 firefox-3.6 target_packages_{3550f703-e582-4d05-9a08-453d09bdfdc6}_2.0 := icedove thunderbird target_packages_{3550f703-e582-4d05-9a08-453d09bdfdc6}_3.0 := icedove thunderbird-3.0 target_packages_prism@developer.mozilla.org_1.0 := prism # data for XPI_DEPENDS/CHECK_VERSION magic - targetApplication versions target_versions_{ec8030f7-c20a-464f-9b0e-13a3a9e97384} := 3.0 3.5 3.6 target_versions_{3550f703-e582-4d05-9a08-453d09bdfdc6} := 2.0 3.0 target_versions_prism@developer.mozilla.org := 1.0 # data for XPI_DEPENDS/CHECK_VERSION magic - targetApplication min-/maxVersions # FIXME: find a way to get this information # 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) # TODO: Use correct comparison CHECK_VERSION = $(shell moz-version-compare $(call TARGET_VERSION,$(1),minVersion,$(TEMPDIR)) le $(2) && moz-version-compare $(2) le $(call TARGET_VERSION,$(1),maxVersion,$(TEMPDIR)) && echo $(target_packages_$(1)_$(2))) MOZ_XPI_BUILD_COMMAND ?= med-xpi-pack $(CURDIR) $(MOZ_EXTENSION_PKG).xpi; XPI_DEPENDS = $(sort $(foreach id,$(call XPI_TARGET_EMIDs,$(TEMPDIR)), \ $(foreach version,$(target_versions_$(id)),$(call CHECK_VERSION,$(id),$(version))))) 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 # ### 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-%: $(XPI_FILE) [ -d $(TEMPDIR) ] || mkdir -p $(TEMPDIR) unzip -d $(TEMPDIR) $(XPI_DIR)$* touch $@ stamp-installlinks-%: dh_link -p$(MOZ_EXTENSION_PKG) /usr/share/$(MOZ_EXTENSION_PKG) /usr/lib/$*/extensions/$(call XPI_EMID,$(TEMPDIR)) touch $@ stamp-autolinks: $(foreach mozilla,$(MOZ_XPI_MOZILLA_DIRS),stamp-installlinks-$(mozilla)) $(foreach id,$(call XPI_TARGET_EMIDs,$(TEMPDIR)),dh_link -p$(MOZ_EXTENSION_PKG) /usr/share/$(MOZ_EXTENSION_PKG) /usr/lib/mozilla/extensions/$(id)/$(call XPI_EMID,$(TEMPDIR));) stamp-install-%: stamp-autolinks dh_install -p$(MOZ_EXTENSION_PKG) $(wildcard $(TEMPDIR)/*) /usr/share/$(MOZ_EXTENSION_PKG) touch $@ stamp-extension-install: stamp-unzip-$(XPI_BASE_FILE) stamp-install-$(XPI_BASE_FILE) touch $@ stamp-xpi-depends: if test -f debian/$(MOZ_EXTENSION_PKG).substvars; then grep -v ^xpi:Depends= debian/$(MOZ_EXTENSION_PKG).substvars > debian/$(MOZ_EXTENSION_PKG).substvars~; fi echo "xpi:Depends=$(XPI_DEPENDS)" | sed "s/ / | /g" >> debian/$(MOZ_EXTENSION_PKG).substvars~ mv debian/$(MOZ_EXTENSION_PKG).substvars~ debian/$(MOZ_EXTENSION_PKG).substvars touch $@ # only attempt to do things if a pkg was provided; otherwise error out ifneq (,$(MOZ_EXTENSION_PKG)) xpi-install: stamp-extension-install stamp-xpi-depends xpi-clean: dh_clean -p$(MOZ_EXTENSION_PKG) -rm -f stamp-extension-install \ stamp-* \ $(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