google-search-results.js: also add binding for return
[conkeror.git] / build.sh
blobb0d6718768347c55163961a6db5fd3c6b96f6c11
1 #! /bin/bash
3 source VERSION
5 SDK_DIR="/usr/lib/xulrunner"
7 XPIDL="${SDK_DIR}/xpidl"
8 XPIDL_INCLUDE="${SDK_DIR}/idl"
10 TARGET='help'
12 ## ETAGSDIR
14 ## This variable is for target `etags'. It specifies the destination
15 ## directory for the TAGS file.
17 ETAGSDIR=""
19 case "$1" in
20 jar)
21 TARGET=jar ;;
22 xulapp)
23 TARGET=xulapp ;;
24 dist-tar)
25 TARGET=dist-tar ;;
26 release)
27 TARGET=release ;;
28 announce)
29 TARGET=announce ;;
30 etags)
31 TARGET=etags
32 ETAGSDIR="$2"
33 shift ;;
34 notes)
35 TARGET=notes ;;
36 help|-help|--help)
37 TARGET=help ;;
39 echo 'bad usage. please read the source.'
40 exit 1
41 esac
42 shift
45 #build the spawn-process-helper
46 make
49 ## if this is not an official release, tag on a build date.
51 ## if this is an official release, strip the subminor.
53 MILESTONE="${VERSION##*.}"
54 BUILD_DATE=$(date +%Y%m%d)
55 SHORT_VERSION="$VERSION"
57 case "$TARGET" in
58 release|announce)
59 VERSION="${VERSION%.*}" ;;
61 VERSION="$VERSION.$BUILD_DATE"
62 esac
63 echo "build target: $TARGET, $VERSION"
66 ### UTILITIES
67 ###
68 ###
72 ## SCRATCH
74 ## Temporary directory for build process.
76 SCRATCH=""
78 function get_scratch () {
79 if [[ -z "$SCRATCH" ]]; then
80 SCRATCH=$(mktemp -d conkeror-XXXXXX)
85 function do_cleanup () {
86 if [[ -n "$SCRATCH" ]]; then
87 rm -r "$SCRATCH"
88 SCRATCH=""
93 function assert_conkeror_src () {
94 if [[ ! -e application.ini ]]; then
95 echo "The current directory does not appear to contain the Conkeror source code."
96 exit 1
101 function copy_tree_sans_boring () {
102 src="$1"
103 dest="$2"
104 mkdir -p "$dest"
105 O=$IFS
106 IFS=$'\n'
107 ( cd "$src"; find . -type d -and \! -name '*[~#]' -print0 ) \
108 | ( cd "$dest"; xargs -0 mkdir -p )
109 files=($( cd "$src"; find . -type f -and \! -name '*[~#]' -print ))
110 for file in "${files[@]}" ; do cp "$src/$file" "$dest/$file" ; done
111 IFS=$O
116 function do_check_milestone_for_release ()
118 if [[ "$MILESTONE" = "0" ]]; then
119 return
122 dest=VERSION
123 proposed="${VERSION%.*}".$(( ${VERSION#*.} + 1 )).0
125 echo "The version given in the file $dest does not have 0 as its last component."
126 echo -n "Shall I rewrite \`VERSION=$VERSION.$MILESTONE' to \`VERSION=$proposed'? [yN] "
127 read
128 if [[ "$REPLY" = [Yy]* ]]; then
129 perl -pi -e 's/^VERSION='$VERSION'\.'$MILESTONE'$/VERSION='$proposed'/' "$dest"
130 echo "Version changed in $dest. Please run this build program again."
131 exit
132 else
133 echo "Leaving $dest untouched. Continuing with build."
138 function diff_wrapper () {
139 scratch="$1"
140 dest="$2"
141 perlexp="$3"
143 scratchfile="${scratch}/$dest"
144 patchfile="${scratch}/$dest.patch"
146 echo -n "Processing $dest ..."
147 perl -0777 -p -e "$perlexp" "$dest" > "$scratchfile"
148 echo ok
150 if cmp "$dest" "$scratchfile" ; then
151 echo "$dest does not need to be updated"
152 else
153 diff -u "$dest" "$scratchfile" | tee "$patchfile"
154 echo -n "Apply this patch to $dest? [yN] "
155 read
156 if [[ "$REPLY" = [Yy]* ]]; then
157 patch < "$patchfile"
158 else
159 echo "Leaving $dest untouched"
168 ### TARGETS
172 function do_target_jar () {
173 echo -n Building JAR...
174 FILES=($(find content branding locale modules -type f -and \! -name '*[~#]' -print ))
175 zip "conkeror.jar" "${FILES[@]}" > /dev/null
176 echo ok
180 function do_target_xulapp () {
181 do_target_jar
182 echo -n Building XULRunner Application...
183 get_scratch
184 mkdir -p "$SCRATCH/chrome"
185 cp application.ini "$SCRATCH"
186 if [ -n "$CONKEROR_APP_NAME" ]; then
187 sed -i -e "s/Name=conkeror/Name=${CONKEROR_APP_NAME}/" "${SCRATCH}/application.ini"
189 mv conkeror.jar "$SCRATCH/chrome/"
190 cp chrome.manifest.for-jar "$SCRATCH/chrome/chrome.manifest"
191 copy_tree_sans_boring defaults "$SCRATCH/defaults"
192 copy_tree_sans_boring components "$SCRATCH/components"
193 if [ -d idl ]; then
194 for x in idl/*; do
195 name="$(basename "$x")"
196 "${XPIDL}" -w -v -m typelib -I "${XPIDL_INCLUDE}" -e "$SCRATCH/components/${name%.idl}.xpt" "$x"
197 done
199 pushd "$SCRATCH" > /dev/null
200 ## begin preprocessing
202 perl -pi -e 's/\$CONKEROR_VERSION\$/'$VERSION'/g' application.ini
203 perl -pi -e 's/\$CONKEROR_BUILD_DATE\$/'$BUILD_DATE'/g' application.ini
204 perl -pi -e 's/\$CONKEROR_VERSION\$/'$VERSION'/g' components/application.js
206 ## end preprocessing
207 zip -r conkeror.xulapp * > /dev/null
208 popd > /dev/null
209 mv "$SCRATCH/conkeror.xulapp" .
210 do_cleanup
211 echo ok
215 function do_target_dist_tar () {
216 do_target_xulapp
217 get_scratch
218 ## now we have conkeror.xulapp
219 ## package it with install.sh
221 ## some other files should probably go in here.. NEWS, for example
222 mkdir "$SCRATCH/conkeror-$VERSION"
223 mv conkeror.xulapp "$SCRATCH/conkeror-$VERSION/"
224 cp install.sh "$SCRATCH/conkeror-$VERSION/"
225 pushd "$SCRATCH" > /dev/null
226 tar c conkeror-$VERSION | gzip > conkeror-$VERSION.tar.gz
227 popd > /dev/null
228 mv "$SCRATCH/conkeror-$VERSION.tar.gz" .
229 echo -n "Making conkeror-$VERSION.tar.gz ..."
230 do_cleanup
231 echo ok
235 function do_target_release () {
236 do_check_milestone_for_release
237 ## Make any and all release archives.
239 ## Right now, we just make a tar.gz archive that includes an install
240 ## script. In the future, we could consider making an OSX App, a Windows
241 ## Installer EXE, and a Mozilla XPI Installer.
243 do_target_dist_tar
244 echo -n Putting conkeror-$VERSION.tar.gz in downloads directory ...
245 mv conkeror-$VERSION.tar.gz ../downloads
246 echo ok
250 function do_target_announce () {
251 do_check_milestone_for_release
252 echo Entering ../www/ ... ok
253 pushd ../www/ > /dev/null
254 scratch=$(mktemp -d conkeror-XXXXXX)
256 perlexp='s/(?<=<!--\scontrolled\scontent\sinsertion\spoint::whatsnew\s-->\n) ()(?!.*'$VERSION'.*$)/<li>'$VERSION' released! \('"$(date '+%b %d, %Y')"'\)<\/li>\n/mxg'
257 diff_wrapper "$scratch" index.html "$perlexp"
259 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'
260 diff_wrapper "$scratch" installation.html "$perlexp"
262 rm -r "$scratch"
263 popd > /dev/null
267 function do_target_etags () {
268 if [[ -z "$ETAGSDIR" ]]; then
269 ETAGSDIR=.
271 ETAGSDIR="${ETAGSDIR%/}/TAGS"
272 echo -n "Building $ETAGSDIR ..."
273 etags -o "$ETAGSDIR" $(find -name \*.js -and \! -name '*[~#]*')
274 echo ok
278 function do_target_notes () {
279 FILES=($(find conkeror -name \*.js))
280 for file in "${FILES[@]}"; do
281 fileo="${file//\//\/}"
282 perl -0777 -ne 's/## BLOCK COMMENTS
283 (.*\/\*\s*[A-Z][A-Z].*:.*$
284 (\n.*$)*?
285 (\n.*\*\/)
286 (?{ $p = pos(); })) |
287 ## LINE COMMENTS
288 (.*\/\/\s*[A-Z][A-Z].*:.*$
289 ((\n.*\/\/.*$)*)
290 (?{ $p = pos(); }))
291 /print "'$fileo':$p\n" . $& . "\n\n"/mexg' < "$file"
292 done
296 function do_target_help () {
297 echo "For this script to work, your current working directory must"
298 echo "be \`<CONKEROR>/src' where <CONKEROR> is the project root."
299 echo "This script expects to find the subdirectory structure,"
300 echo "\`conkeror/content', and VERSION in the current directory,"
301 echo "\`downloads' and \`www' in the parent directory, and possibly"
302 echo "other files."
303 echo
304 echo 'Usage: bash build.sh <TARGET>'
305 echo 'where <TARGET> is one of:'
306 echo
307 echo ' xulapp'
308 echo
309 echo ' dist-tar'
310 echo
311 echo ' release Builds a release xpi and puts it in ../downloads.'
312 echo
313 echo ' announce Modify the website in ../www to announce a release.'
314 echo
315 echo ' etags [DIR] Build TAGS file in etags format. If a'
316 echo ' directory is given, TAGS will be made in'
317 echo ' that directory.'
318 echo
319 echo ' notes Shows specially formatted comments in'
320 echo " \`conkeror/content/*.js' Modifies no files."
321 echo
322 echo ' help Shows this help message. Modifies no files.'
323 echo
331 ### MAIN
335 assert_conkeror_src
337 case "$TARGET" in
338 jar) do_target_jar ;;
339 xulapp) do_target_xulapp ;;
340 dist-tar) do_target_dist_tar ;;
341 release) do_target_release ;;
342 announce) do_target_announce ;;
343 etags) do_target_etags ;;
344 notes) do_target_notes ;;
345 help) do_target_help ;;
346 esac
348 do_cleanup