Debian package: Use more debhelper magic
[conkeror.git] / contrib / build.sh
blob2bd831c64acf6912123e332cc21f003df80d8568
1 #! /bin/bash
3 # (C) Copyright 2004-2007 Shawn Betts
4 # (C) Copyright 2007-2008 John J. Foerch
5 # (C) Copyright 2007-2008 Jeremy Maitin-Shepard
7 # Use, modification, and distribution are subject to the terms specified in the
8 # COPYING file.
10 SDK_DIR="/usr/lib/xulrunner"
12 XPIDL="${SDK_DIR}/xpidl"
13 XPIDL_INCLUDE="${SDK_DIR}/idl"
15 TARGET='help'
17 ## ETAGSDIR
19 ## This variable is for target `etags'. It specifies the destination
20 ## directory for the TAGS file.
22 ETAGSDIR=""
24 case "$1" in
25 xulapp)
26 TARGET=xulapp ;;
27 dist-tar)
28 TARGET=dist-tar ;;
29 release)
30 TARGET=release ;;
31 announce)
32 TARGET=announce ;;
33 etags)
34 TARGET=etags
35 ETAGSDIR="$2"
36 shift ;;
37 notes)
38 TARGET=notes ;;
39 help|-help|--help)
40 TARGET=help ;;
42 echo 'bad usage. please read the source.'
43 exit 1
44 esac
45 shift
48 VERSION=$(grep '^Version=' application.ini | cut -d '=' -f 2)
51 ## if this is not an official release, tag on a build date.
53 ## if this is an official release, strip the subminor.
55 MILESTONE="${VERSION##*.}"
56 BUILD_DATE=$(date +%Y%m%d)
57 SHORT_VERSION="$VERSION"
59 case "$TARGET" in
60 release|announce)
61 VERSION="${VERSION%.*}" ;;
63 VERSION="$VERSION.$BUILD_DATE"
64 esac
65 echo "build target: $TARGET, $VERSION"
68 ### UTILITIES
69 ###
70 ###
74 ## SCRATCH
76 ## Temporary directory for build process.
78 SCRATCH=""
80 function get_scratch () {
81 if [[ -z "$SCRATCH" ]]; then
82 SCRATCH=$(mktemp -d conkeror-XXXXXX)
87 function do_cleanup () {
88 if [[ -n "$SCRATCH" ]]; then
89 rm -r "$SCRATCH"
90 SCRATCH=""
95 function assert_conkeror_src () {
96 if [[ ! -e application.ini ]]; then
97 echo "The current directory does not appear to contain the Conkeror source code."
98 exit 1
103 function copy_tree_sans_boring () {
104 src="$1"
105 dest="$2"
106 mkdir -p "$dest"
107 O=$IFS
108 IFS=$'\n'
109 ( cd "$src"; find . -type d -and \! -name '*[~#]' -print0 ) \
110 | ( cd "$dest"; xargs -0 mkdir -p )
111 files=($( cd "$src"; find . -type f -and \! -name '*[~#]' -print ))
112 for file in "${files[@]}" ; do cp "$src/$file" "$dest/$file" ; done
113 IFS=$O
118 function do_check_milestone_for_release ()
120 if [[ "$MILESTONE" = "0" ]]; then
121 return
124 dest=VERSION
125 proposed="${VERSION%.*}".$(( ${VERSION#*.} + 1 )).0
127 echo "The version given in the file $dest does not have 0 as its last component."
128 echo -n "Shall I rewrite \`VERSION=$VERSION.$MILESTONE' to \`VERSION=$proposed'? [yN] "
129 read
130 if [[ "$REPLY" = [Yy]* ]]; then
131 perl -pi -e 's/^VERSION='$VERSION'\.'$MILESTONE'$/VERSION='$proposed'/' "$dest"
132 echo "Version changed in $dest. Please run this build program again."
133 exit
134 else
135 echo "Leaving $dest untouched. Continuing with build."
140 function diff_wrapper () {
141 scratch="$1"
142 dest="$2"
143 perlexp="$3"
145 scratchfile="${scratch}/$dest"
146 patchfile="${scratch}/$dest.patch"
148 echo -n "Processing $dest ..."
149 perl -0777 -p -e "$perlexp" "$dest" > "$scratchfile"
150 echo ok
152 if cmp "$dest" "$scratchfile" ; then
153 echo "$dest does not need to be updated"
154 else
155 diff -u "$dest" "$scratchfile" | tee "$patchfile"
156 echo -n "Apply this patch to $dest? [yN] "
157 read
158 if [[ "$REPLY" = [Yy]* ]]; then
159 patch < "$patchfile"
160 else
161 echo "Leaving $dest untouched"
170 ### TARGETS
174 function do_target_xulapp () {
175 echo -n Building XULRunner Application...
177 #build the conkeror-spawn-helper
178 make
180 get_scratch
181 mkdir -p "$SCRATCH/chrome"
182 cp application.ini "$SCRATCH"
183 if [ -n "$CONKEROR_APP_NAME" ]; then
184 sed -i -e "s/Name=conkeror/Name=${CONKEROR_APP_NAME}/" "${SCRATCH}/application.ini"
186 for x in branding chrome components content defaults locale modules search-engines help style; do
187 copy_tree_sans_boring "$x" "$SCRATCH/$x"
188 done
189 cp conkeror-spawn-helper "${SCRATCH}"
190 if [ -d idl ]; then
191 for x in idl/*; do
192 name="$(basename "$x")"
193 "${XPIDL}" -w -v -m typelib -I "${XPIDL_INCLUDE}" -e "$SCRATCH/components/${name%.idl}.xpt" "$x"
194 done
196 BUILD_ID=$(git rev-parse HEAD 2> /dev/null)
197 if [ "$?" != 0 ]; then
198 BUILD_ID="git"
200 pushd "$SCRATCH" > /dev/null
201 ## begin preprocessing
203 perl -pi -e 's/BuildID=git/BuildID='${BUILD_ID}'/g' application.ini
205 ## end preprocessing
206 zip -r ../conkeror.xulapp * > /dev/null
207 popd > /dev/null
208 do_cleanup
209 echo ok
213 function do_target_dist_tar () {
214 do_target_xulapp
215 get_scratch
216 ## now we have conkeror.xulapp
217 ## package it with install.sh
219 ## some other files should probably go in here.. NEWS, for example
220 mkdir "$SCRATCH/conkeror-$VERSION"
221 mv conkeror.xulapp "$SCRATCH/conkeror-$VERSION/"
222 cp install.sh "$SCRATCH/conkeror-$VERSION/"
223 pushd "$SCRATCH" > /dev/null
224 tar c conkeror-$VERSION | gzip > conkeror-$VERSION.tar.gz
225 popd > /dev/null
226 mv "$SCRATCH/conkeror-$VERSION.tar.gz" .
227 echo -n "Making conkeror-$VERSION.tar.gz ..."
228 do_cleanup
229 echo ok
233 function do_target_release () {
234 do_check_milestone_for_release
235 ## Make any and all release archives.
237 ## Right now, we just make a tar.gz archive that includes an install
238 ## script. In the future, we could consider making an OSX App, a Windows
239 ## Installer EXE, and a Mozilla XPI Installer.
241 do_target_dist_tar
242 echo -n Putting conkeror-$VERSION.tar.gz in downloads directory ...
243 mv conkeror-$VERSION.tar.gz ../downloads
244 echo ok
248 function do_target_announce () {
249 do_check_milestone_for_release
250 echo Entering ../www/ ... ok
251 pushd ../www/ > /dev/null
252 scratch=$(mktemp -d conkeror-XXXXXX)
254 perlexp='s/(?<=<!--\scontrolled\scontent\sinsertion\spoint::whatsnew\s-->\n) ()(?!.*'$VERSION'.*$)/<li>'$VERSION' released! \('"$(date '+%b %d, %Y')"'\)<\/li>\n/mxg'
255 diff_wrapper "$scratch" index.html "$perlexp"
257 perlexp='s/(?<=<!-- begin controlled content. do not edit manually. id:newestlink -->).*?(?=<!-- end controlled content. -->)/<a href="http:\/\/downloads.mozdev.org\/conkeror\/conkeror-'$VERSION'.tar.gz">conkeror-'$VERSION'.tar.gz<\/a>/g'
258 diff_wrapper "$scratch" installation.html "$perlexp"
260 rm -r "$scratch"
261 popd > /dev/null
265 function do_target_etags () {
266 if [[ -z "$ETAGSDIR" ]]; then
267 ETAGSDIR=.
269 ETAGSDIR="${ETAGSDIR%/}/TAGS"
270 echo -n "Building $ETAGSDIR ..."
271 etags -o "$ETAGSDIR" $(find -name \*.js -and \! -name '*[~#]*')
272 echo ok
276 function do_target_notes () {
277 FILES=($(find conkeror -name \*.js))
278 for file in "${FILES[@]}"; do
279 fileo="${file//\//\/}"
280 perl -0777 -ne 's/## BLOCK COMMENTS
281 (.*\/\*\s*[A-Z][A-Z].*:.*$
282 (\n.*$)*?
283 (\n.*\*\/)
284 (?{ $p = pos(); })) |
285 ## LINE COMMENTS
286 (.*\/\/\s*[A-Z][A-Z].*:.*$
287 ((\n.*\/\/.*$)*)
288 (?{ $p = pos(); }))
289 /print "'$fileo':$p\n" . $& . "\n\n"/mexg' < "$file"
290 done
294 function do_target_help () {
295 echo "For this script to work, your current working directory must"
296 echo "be \`<CONKEROR>/src' where <CONKEROR> is the project root."
297 echo "This script expects to find the subdirectory structure,"
298 echo "\`conkeror/content', and VERSION in the current directory,"
299 echo "\`downloads' and \`www' in the parent directory, and possibly"
300 echo "other files."
301 echo
302 echo 'Usage: bash build.sh <TARGET>'
303 echo 'where <TARGET> is one of:'
304 echo
305 echo ' xulapp'
306 echo
307 echo ' dist-tar'
308 echo
309 echo ' release Builds a release xpi and puts it in ../downloads.'
310 echo
311 echo ' announce Modify the website in ../www to announce a release.'
312 echo
313 echo ' etags [DIR] Build TAGS file in etags format. If a'
314 echo ' directory is given, TAGS will be made in'
315 echo ' that directory.'
316 echo
317 echo ' notes Shows specially formatted comments in'
318 echo " \`conkeror/content/*.js' Modifies no files."
319 echo
320 echo ' help Shows this help message. Modifies no files.'
321 echo
329 ### MAIN
333 assert_conkeror_src
335 case "$TARGET" in
336 xulapp) do_target_xulapp ;;
337 dist-tar) do_target_dist_tar ;;
338 release) do_target_release ;;
339 announce) do_target_announce ;;
340 etags) do_target_etags ;;
341 notes) do_target_notes ;;
342 help) do_target_help ;;
343 esac
345 do_cleanup