summaryrefslogtreecommitdiff
path: root/src/mozclient.mk.in
blob: 9f7369ca20605cbb84cb7f7937fbf7e971a4edcf (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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# -*- mode: makefile; coding: utf-8 -*-

# Copyright (c) 2007-2008 Fabien Tassin <fta@sofaraway.org>
# Description: The 'mozclient' module of mozilla-devscripts
#
# 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.

#####################################################################

# Don't include this file directly, include one of the project.mk
# file instead, which will include this file for you.

# The caller could specify the following parameters:
# DEBIAN_DATE in the form YYYYMMDDtHHMM
#  ex: DEBIAN_DATE=20070911t1711
# or
# DEBIAN_TAG in the form CVS_TAG=debian_version
#  ex: DEBIAN_TAG=FIREFOX_3_0b2_RC1=3.0~b2~rc1
# Optionally:
# DEBIAN_KEEP_VCS to preserve the VCS files (*/CVS, .hg, ...)
#  ex: DEBIAN_KEEP_VCS=1

# The following targets are available to the caller:
# - get-orig-source
#    Build a tarball according to parameters from project.mk
#    and optionally using either DEBIAN_DATE or DEBIAN_TAG
# - list-tags
#    List all the registered CVS tags from upstream server

# project.mk contains the following parameters
# - MOZCLIENT_TARGET (mandatory): a label, usually 'project-orig'
# - MOZCLIENT_APPNAME (mandatory): package name
# - MOZCLIENT_MODULES (optional): list of modules/directories for direct checkout
# - MOZCLIENT_VCS (optional): VCS (hg, git, cvs, svn..). (default: cvs)
# - MOZCLIENT_PROJECT (mandatory): VCS project name. If $(NULL), then
#   $(MOZCLIENT_MODULES) becomes mandatory
# - MOZCLIENT_BRANCH (optional): VCS branch name
# - MOZCLIENT_POSTCOCMD (optional): a shell command that is executed after checkout
# - MOZCLIENT_FILE (mandatory): source file containing the version
# - MOZCLIENT_GETVERSION (mandatory): how to transform the version
# - MOZCLIENT_URL (mandatory): an URL (usually on Bonsai) listing commits
# - MOZCLIENT_GETDATE (mandatory): get the last commit date for the project
# - MOZCLIENT_EMBEDDED (optional): create an embedded tarball (default: 0)
# - MOZCLIENT_WANTMOZDIR (optional): should the root dir be 'mozilla'?
#   (default: 0 unless MOZCLIENT_EMBEDDED=1)
# - MOZCLIENT_WANTPATCH (optional): should we use the patch system? (default: 0)

# Example with firefox-3.0:
#
# - in debian/control, add mozilla-devscripts to Build-Depends
# - in debian/rules, add:
#    include /usr/share/mozilla-devscripts/firefox-3.0.mk
#
# That's it. You've gained get-orig-source.
#
# You can now call it:
# - debian/rules get-orig-source
#   => firefox-3.0_3.0~b2~cvs20071120t1456+nobinonly.orig.tar.gz
#
# - debian/rules get-orig-source DEBIAN_DATE=20070914t1713
#   => firefox-3.0_3.0~a8~cvs20070914t1713+nobinonly.orig.tar.gz
#
# - debian/rules get-orig-source DEBIAN_TAG=FIREFOX_3_0b2_RC1=3.0~b2~rc1
#   => firefox-3.0_3.0~b2~rc1+nobinonly.orig.tar.gz

# Notes:
# - the script 'remove.binonly.sh' is applied to all projects, in order
#   to remove binary-only files before packing. Traces of the cleaning
#   are preserved inside that resulting tarball in REMOVED+nobinonly.txt.
#   If nothing has been removed, the log and the "+nobinonly" signature
#   are both dropped.

MOZ_CLIENT        = mozilla/client.mk
MOZCLIENT_CVS_LOC = :pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot
MOZCLIENT_HG_LOC  = http://hg.mozilla.org/

MOZCLIENT_STAMP  ?= stamped
MOZCLIENT_TMP    := mozclient-tmp

MOZCLIENT_VCS    ?= cvs

MOZCLIENT_PATCHES        := ../patches
MOZCLIENT_EXCLUDE_SCRIPT := ../../remove.binonly.sh
NOBINONLY                := nobinonly

TAR_EXCLUDE      := $(NULL)
ifeq (,$(DEBIAN_KEEP_VCS))
ifeq ($(MOZCLIENT_VCS),cvs)
TAR_EXCLUDE      := --exclude=CVS --exclude=.cvsignore
else
ifeq ($(MOZCLIENT_VCS),hg)
TAR_EXCLUDE      := --exclude=.hg
endif
endif
endif

DATE_FILTER      := sed -e 's,\(....\)\(..\)\(..\)[rt]\(..\)\(..\),\1/\2/\3 \4:\5 PST,'
REVISION_FILTER  := sed -e 's,^\([0-9]*\).*,\1,'

ifdef DEBIAN_TAG
DEBIAN_DATE       = $(NULL)
DEBIAN_LTAG       = $(shell echo $(DEBIAN_TAG) | sed -e 's/=.*//')
DEBIAN_DTAG       = $(shell echo $(DEBIAN_TAG) | sed -e 's/.*=//')
DEBIAN_CO_TAG     = -r $(DEBIAN_LTAG)
DEBIAN_MOZ_CO_TAG = MOZ_CO_TAG=$(DEBIAN_LTAG)
else
DEBIAN_MOZ_CO_TAG = $(NULL)
ifdef DEBIAN_DATE
DEBIAN_CO_DATE    = $(shell echo "-D \"$(DEBIAN_DATE)\"" | $(DATE_FILTER))
endif
ifdef DEBIAN_BRANCH
DEBIAN_CO_TAG     = -r $(DEBIAN_BRANCH)
endif
endif

############################################################################

mozclient-deps:
	@if [ ! -f /usr/bin/cvs ]   ; then echo "**ERROR** Depends on missing cvs. Abort"; exit 1; fi
	@if [ ! -f /usr/bin/hg ]    ; then echo "**ERROR** Depends on missing mercurial. Abort"; exit 1; fi
	@if [ ! -f /usr/bin/quilt ] ; then echo "**ERROR** Depends on missing quilt. Abort"; exit 1; fi
	@if [ ! -f /usr/bin/wget ]  ; then echo "**ERROR** Depends on missing wget. Abort"; exit 1; fi

mozclient-dir:
	rm -rf $(MOZCLIENT_TMP)
	mkdir $(MOZCLIENT_TMP)

# Get the client
ifneq (,$(MOZCLIENT_BRANCH))
$(MOZ_CLIENT): MOZCLIENT_TBRANCH = -r $(MOZCLIENT_BRANCH)
else
$(MOZ_CLIENT): MOZCLIENT_TBRANCH = $(NULL)
endif
$(MOZ_CLIENT): mozclient-deps mozclient-dir
ifeq ($(MOZCLIENT_VCS),cvs)
	cd $(MOZCLIENT_TMP) && cvs -d $(MOZCLIENT_CVS_LOC) co $(MOZCLIENT_TBRANCH) $(DEBIAN_CO_DATE) $(DEBIAN_CO_TAG) $@
endif

mozclient-client: $(MOZCLIENT_TMP)/$(MOZCLIENT_STAMP)

# List all tags
mozclient-status: list-tags
list-tags: mozclient-deps mozclient-dir
ifeq ($(MOZCLIENT_VCS),cvs)
	cd $(MOZCLIENT_TMP) && cvs -d $(MOZCLIENT_CVS_LOC) co $(MOZCLIENT_FILE)
	cd $(MOZCLIENT_TMP)/mozilla && cvs status -v $(subst mozilla/,,$(MOZCLIENT_FILE))
else
	$(error '$@' not supported for '$(MOZCLIENT_VCS)' yet)
endif
	rm -rf $(MOZCLIENT_TMP)

# Patch
#  - don't patch when a branch name is specified
mozclient-patch: $(MOZCLIENT_TMP)/$(MOZCLIENT_STAMP)

$(MOZCLIENT_TMP)/$(MOZCLIENT_STAMP): $(MOZ_CLIENT)
ifneq (,$(MOZCLIENT_WANTPATCH))
ifeq (,$(MOZCLIENT_BRANCH))
	if [ ! -L $(MOZCLIENT_TMP)/patches ] ; then ln -s $(MOZCLIENT_PATCHES) $(MOZCLIENT_TMP)/patches ; fi
	cd $(MOZCLIENT_TMP) && quilt --quiltrc /dev/null push -a || test $$? = 2
endif
endif
	touch $(MOZCLIENT_TMP)/$(MOZCLIENT_STAMP)

# Unpatch
mozclient-unpatch:
ifeq (,$(MOZCLIENT_BRANCH))
	cd $(MOZCLIENT_TMP) && quilt --quiltrc /dev/null pop -a -R || test $$? = 2
endif
	rm -rf $(MOZCLIENT_TMP)/.pc $(MOZCLIENT_TMP)/$(MOZCLIENT_STAMP) $(MOZCLIENT_TMP)/patches

# Clean
mozclient-clean:
	rm -rf $(MOZCLIENT_TMP)

# Checkout using either a TAG, a date or nothing (last commit date)
# Use mozclient.mk if $(MOZCLIENT_PROJECT) is specified, otherwise, do a direct cvs checkout
# using $(MOZCLIENT_MODULES)
ifneq (,$(MOZCLIENT_PROJECT))
ifneq (,$(DEBIAN_TAG))
mozclient-checkout: MOZCLIENT_DATE = $(NULL)
else
ifeq (,$(DEBIAN_DATE))
mozclient-checkout: DEBIAN_DATE    = $(shell $(MOZCLIENT_GETDATE))
endif
ifeq ($(MOZCLIENT_VCS),cvs)
mozclient-checkout: MOZCLIENT_DATE = MOZ_CO_DATE="$(shell echo $(DEBIAN_DATE) | $(DATE_FILTER))"
else
ifeq ($(MOZCLIENT_VCS),hg)
mozclient-checkout: MOZCLIENT_DATE = -r $(shell echo $(DEBIAN_DATE) | $(REVISION_FILTER))
else
mozclient-checkout:
	$(error '$@' not supported for '$(MOZCLIENT_VCS)' yet)
endif
endif
endif
mozclient-checkout:
	@if [ "Z$(DEBIAN_TAG)" = "Z" ] && [ "Z$(DEBIAN_DATE)" = "Z" ] ; then echo "*Error* DEBIAN_DATE is empty, MOZCLIENT_GETDATE failed ?" ; exit 1 ; fi
ifeq ($(MOZCLIENT_VCS),cvs)
	cd $(MOZCLIENT_TMP) && make -f $(MOZ_CLIENT) checkout MOZ_CO_PROJECT=$(MOZCLIENT_PROJECT) $(MOZCLIENT_DATE) $(DEBIAN_MOZ_CO_TAG)
else
ifeq ($(MOZCLIENT_VCS),hg)
	cd $(MOZCLIENT_TMP) && hg clone $(MOZCLIENT_DATE) $(MOZCLIENT_HG_LOC)$(MOZCLIENT_PROJECT)/ mozilla
else
	$(error '$@' not supported for '$(MOZCLIENT_VCS)' yet)
endif
endif
	echo $(DEBIAN_DATE) > $(MOZCLIENT_TMP)/.date
else
ifneq (,$(DEBIAN_TAG))
mozclient-checkout: MOZCLIENT_DATE = $(NULL)
else
ifeq (,$(DEBIAN_DATE))
mozclient-checkout: DEBIAN_DATE    = $(shell $(MOZCLIENT_GETDATE))
endif
ifeq ($(MOZCLIENT_VCS),cvs)
mozclient-checkout: MOZCLIENT_DATE = -D "$(shell echo $(DEBIAN_DATE) | $(DATE_FILTER))"
else
ifeq ($(MOZCLIENT_VCS),hg)
mozclient-checkout: MOZCLIENT_DATE = -r $(shell echo $(DEBIAN_DATE) | $(REVISION_FILTER))
else
mozclient-checkout:
	$(error '$@' not supported for '$(MOZCLIENT_VCS)' yet)
endif
endif
endif
mozclient-checkout:
	@if [ "Z$(DEBIAN_TAG)" = "Z" ] && [ "Z$(DEBIAN_DATE)" = "Z" ] ; then echo "*Error* DEBIAN_DATE is empty, MOZCLIENT_GETDATE failed ?" ; exit 1 ; fi
ifeq ($(MOZCLIENT_VCS),cvs)
	cd $(MOZCLIENT_TMP) && cvs -d $(MOZCLIENT_CVS_LOC) -q -z 3 co -P -A $(MOZCLIENT_DATE) $(DEBIAN_CO_TAG) $(MOZCLIENT_MODULES)
else
ifeq ($(MOZCLIENT_VCS),hg)
	cd $(MOZCLIENT_TMP) && hg clone $(MOZCLIENT_DATE) $(foreach module,$(MOZCLIENT_MODULES),$(MOZCLIENT_HG_LOC)$(MOZCLIENT_PROJECT)/$(module)/) mozilla
else
	$(error '$@' not supported for '$(MOZCLIENT_VCS)' yet)
endif
endif
	echo $(DEBIAN_DATE) > $(MOZCLIENT_TMP)/.date
endif
ifneq (,$(MOZCLIENT_POSTCOCMD))
	cd $(MOZCLIENT_TMP) && $(MOZCLIENT_POSTCOCMD)
endif

# Remove bin-only files using the remove.binonly.sh script.
# Keep a log in REMOVED+nobinonly.txt
mozclient-remove-bin:
	cd $(MOZCLIENT_TMP)/mozilla && sh $(MOZCLIENT_EXCLUDE_SCRIPT) > REMOVED+$(NOBINONLY).txt 2>&1
	if [ ! -s $(MOZCLIENT_TMP)/mozilla/REMOVED+$(NOBINONLY).txt ] ; then rm $(MOZCLIENT_TMP)/mozilla/REMOVED+$(NOBINONLY).txt ; fi

# Pack
# - only use the +nobinonly suffix is something has been deleted
# - for embedded tarballs (bzipped), use MOZCLIENT_EMBEDDED=1
# - to preserve the mozilla root dir, use MOZCLIENT_WANTMOZDIR=1
ifneq (,$(DEBIAN_TAG))
mozclient-pack: MOZCLIENT_TVERSION = $(DEBIAN_DTAG)
else
mozclient-pack: MOZCLIENT_TVERSION = $(shell cd $(MOZCLIENT_TMP) && $(MOZCLIENT_GETVERSION))~$(MOZCLIENT_VCS)$(shell cat $(MOZCLIENT_TMP)/.date)
endif
mozclient-pack: MOZCLIENT_VERSION  = $(MOZCLIENT_TVERSION)$(shell test -f $(MOZCLIENT_TMP)/mozilla/REMOVED+$(NOBINONLY).txt && echo "+$(NOBINONLY)")
mozclient-pack:
	rm -rf $(MOZCLIENT_TMP)/$(MOZCLIENT_APPNAME)-$(MOZCLIENT_VERSION)
ifneq (,$(findstring 1,$(MOZCLIENT_WANTMOZDIR)$(MOZCLIENT_EMBEDDED)))
	mkdir $(MOZCLIENT_TMP)/$(MOZCLIENT_APPNAME)-$(MOZCLIENT_VERSION)
endif
ifeq (1,$(MOZCLIENT_EMBEDDED))
	cd $(MOZCLIENT_TMP) && tar jcf $(MOZCLIENT_APPNAME)-$(MOZCLIENT_VERSION)/$(MOZCLIENT_PROJECT)-$(MOZCLIENT_TVERSION)-source.tar.bz2 $(TAR_EXCLUDE) mozilla
else
	mv $(MOZCLIENT_TMP)/mozilla $(MOZCLIENT_TMP)/$(MOZCLIENT_APPNAME)-$(MOZCLIENT_VERSION)
endif
	rm -f $(MOZCLIENT_APPNAME)_$(MOZCLIENT_VERSION).orig.tar.gz
	cd $(MOZCLIENT_TMP) && tar zcf ../$(MOZCLIENT_APPNAME)_$(MOZCLIENT_VERSION).orig.tar.gz $(TAR_EXCLUDE) $(MOZCLIENT_APPNAME)-$(MOZCLIENT_VERSION)
	rm -rf $(MOZCLIENT_TMP)
	-ls -l $(MOZCLIENT_APPNAME)_$(MOZCLIENT_VERSION).orig.tar.gz

# The real target
ifneq (,$(MOZCLIENT_PROJECT))
$(MOZCLIENT_TARGET): $(MOZ_CLIENT) $(MOZCLIENT_TMP)/$(MOZCLIENT_STAMP) mozclient-checkout mozclient-remove-bin mozclient-pack
else
$(MOZCLIENT_TARGET): mozclient-deps mozclient-dir mozclient-checkout mozclient-remove-bin mozclient-pack
endif

get-orig-source: $(MOZCLIENT_TARGET)

.PHONY: mozclient-deps mozclient-dir mozclient-patch mozclient-unpatch mozclient-checkout mozclient-remove-bin mozclient-pack $(MOZCLIENT_TARGET) get-orig-source

.NOTPARALLEL: