conkeror.xml (makeBrowser): move to frame.js
[conkeror.git] / build.sh
blobbdad26d4ff67723c66efb5913e139aaa5f0ac56a
1 #! /bin/bash
3 source VERSION
5 TARGET='help'
7 ## ETAGSDIR
8 ##
9 ## This variable is for target `etags'. It specifies the destination
10 ## directory for the TAGS file.
12 ETAGSDIR=""
14 case "$1" in
15 jar)
16 TARGET=jar ;;
17 xulapp)
18 TARGET=xulapp ;;
19 dist-tar)
20 TARGET=dist-tar ;;
21 release)
22 TARGET=release ;;
23 announce)
24 TARGET=announce ;;
25 etags)
26 TARGET=etags
27 ETAGSDIR="$2"
28 shift ;;
29 notes)
30 TARGET=notes ;;
31 help|-help|--help)
32 TARGET=help ;;
34 echo 'bad usage. please read the source.'
35 exit 1
36 esac
37 shift
40 ## if this is not an official release, tag on a build date.
42 ## if this is an official release, strip the subminor.
44 MILESTONE="${VERSION##*.}"
45 BUILD_DATE=$(date +%Y%m%d)
46 SHORT_VERSION="$VERSION"
48 case "$TARGET" in
49 release|announce)
50 VERSION="${VERSION%.*}" ;;
52 VERSION="$VERSION.$BUILD_DATE"
53 esac
54 echo "build target: $TARGET, $VERSION"
57 ### UTILITIES
58 ###
59 ###
63 ## SCRATCH
65 ## Temporary directory for build process.
67 SCRATCH=""
69 function get_scratch () {
70 if [[ -z "$SCRATCH" ]]; then
71 SCRATCH=$(mktemp -d conkeror-XXXXXX)
76 function do_cleanup () {
77 if [[ -n "$SCRATCH" ]]; then
78 rm -r "$SCRATCH"
79 SCRATCH=""
84 function assert_conkeror_src () {
85 if [[ ! -e application.ini ]]; then
86 echo "The current directory does not appear to contain the Conkeror source code."
87 exit 1
92 function copy_tree_sans_boring () {
93 src="$1"
94 dest="$2"
95 mkdir -p "$dest"
96 O=$IFS
97 IFS=$'\n'
98 ( cd "$src"; find . -name CVS -prune -or \( -type d -and \
99 \! -name '*[~#]' -print0 \) ) \
100 | ( cd "$dest"; xargs -0 mkdir -p )
101 files=($( cd "$src"; find . -name CVS -prune -or \( -type f -and \
102 \! -name '*[~#]' -print \) ))
103 for file in "${files[@]}" ; do cp "$src/$file" "$dest/$file" ; done
104 IFS=$O
109 function do_check_milestone_for_release ()
111 if [[ "$MILESTONE" = "0" ]]; then
112 return
115 dest=VERSION
116 proposed="${VERSION%.*}".$(( ${VERSION#*.} + 1 )).0
118 echo "The version given in the file $dest does not have 0 as its last component."
119 echo -n "Shall I rewrite \`VERSION=$VERSION.$MILESTONE' to \`VERSION=$proposed'? [yN] "
120 read
121 if [[ "$REPLY" = [Yy]* ]]; then
122 perl -pi -e 's/^VERSION='$VERSION'\.'$MILESTONE'$/VERSION='$proposed'/' "$dest"
123 echo "Version changed in $dest. Please run this build program again."
124 exit
125 else
126 echo "Leaving $dest untouched. Continuing with build."
131 function diff_wrapper () {
132 scratch="$1"
133 dest="$2"
134 perlexp="$3"
136 scratchfile="${scratch}/$dest"
137 patchfile="${scratch}/$dest.patch"
139 echo -n "Processing $dest ..."
140 perl -0777 -p -e "$perlexp" "$dest" > "$scratchfile"
141 echo ok
143 if cmp "$dest" "$scratchfile" ; then
144 echo "$dest does not need to be updated"
145 else
146 diff -u "$dest" "$scratchfile" | tee "$patchfile"
147 echo -n "Apply this patch to $dest? [yN] "
148 read
149 if [[ "$REPLY" = [Yy]* ]]; then
150 patch < "$patchfile"
151 else
152 echo "Leaving $dest untouched"
161 ### TARGETS
165 function do_target_jar () {
166 echo -n Building JAR...
167 get_scratch
168 jarbuild="$SCRATCH/jar-build"
169 mkdir "$jarbuild"
170 cp -r conkeror "$jarbuild/conkeror"
171 pushd "$jarbuild" > /dev/null
172 FILES=($(find conkeror -name CVS -prune -or \( -type f -and \! -name '*[~#]' -print \)))
173 zip conkeror.jar "${FILES[@]}" > /dev/null
174 popd > /dev/null
175 mv "$jarbuild/conkeror.jar" .
176 echo ok
177 do_cleanup
181 function do_target_xulapp () {
182 do_target_jar
183 echo -n Building XULRunner Application...
184 get_scratch
185 mkdir -p "$SCRATCH/chrome"
186 cp application.ini "$SCRATCH"
187 mv conkeror.jar "$SCRATCH/chrome/"
188 cp chrome.manifest.for-jar "$SCRATCH/chrome/chrome.manifest"
189 copy_tree_sans_boring defaults "$SCRATCH/defaults"
190 copy_tree_sans_boring components "$SCRATCH/components"
191 pushd "$SCRATCH" > /dev/null
192 ## begin preprocessing
194 perl -pi -e 's/\$CONKEROR_VERSION\$/'$VERSION'/g' application.ini
195 perl -pi -e 's/\$CONKEROR_BUILD_DATE\$/'$BUILD_DATE'/g' application.ini
196 perl -pi -e 's/\$CONKEROR_VERSION\$/'$VERSION'/g' components/application.js
198 ## end preprocessing
199 zip -r conkeror.xulapp * > /dev/null
200 popd > /dev/null
201 mv "$SCRATCH/conkeror.xulapp" .
202 do_cleanup
203 echo ok
207 function do_target_dist_tar () {
208 do_target_xulapp
209 get_scratch
210 ## now we have conkeror.xulapp
211 ## package it with install.sh
213 ## some other files should probably go in here.. NEWS, for example
214 mkdir "$SCRATCH/conkeror-$VERSION"
215 mv conkeror.xulapp "$SCRATCH/conkeror-$VERSION/"
216 cp install.sh "$SCRATCH/conkeror-$VERSION/"
217 pushd "$SCRATCH" > /dev/null
218 tar c conkeror-$VERSION | gzip > conkeror-$VERSION.tar.gz
219 popd > /dev/null
220 mv "$SCRATCH/conkeror-$VERSION.tar.gz" .
221 echo -n "Making conkeror-$VERSION.tar.gz ..."
222 do_cleanup
223 echo ok
227 function do_target_release () {
228 do_check_milestone_for_release
229 ## Make any and all release archives.
231 ## Right now, we just make a tar.gz archive that includes an install
232 ## script. In the future, we could consider making an OSX App, a Windows
233 ## Installer EXE, and a Mozilla XPI Installer.
235 do_target_dist_tar
236 echo -n Putting conkeror-$VERSION.tar.gz in downloads directory ...
237 mv conkeror-$VERSION.tar.gz ../downloads
238 echo ok
242 function do_target_announce () {
243 do_check_milestone_for_release
244 echo Entering ../www/ ... ok
245 pushd ../www/ > /dev/null
246 scratch=$(mktemp -d conkeror-XXXXXX)
248 perlexp='s/(?<=<!--\scontrolled\scontent\sinsertion\spoint::whatsnew\s-->\n) ()(?!.*'$VERSION'.*$)/<li>'$VERSION' released! \('"$(date '+%b %d, %Y')"'\)<\/li>\n/mxg'
249 diff_wrapper "$scratch" index.html "$perlexp"
251 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'
252 diff_wrapper "$scratch" installation.html "$perlexp"
254 rm -r "$scratch"
255 popd > /dev/null
259 function do_target_etags () {
260 if [[ -z "$ETAGSDIR" ]]; then
261 ETAGSDIR=.
263 ETAGSDIR="${ETAGSDIR%/}/TAGS"
264 echo -n "Building $ETAGSDIR ..."
265 etags -o "$ETAGSDIR" conkeror/content/*.js
266 echo ok
270 function do_target_notes () {
271 FILES=($(find conkeror -name \*.js))
272 for file in "${FILES[@]}"; do
273 fileo="${file//\//\/}"
274 perl -0777 -ne 's/## BLOCK COMMENTS
275 (.*\/\*\s*[A-Z][A-Z].*:.*$
276 (\n.*$)*?
277 (\n.*\*\/)
278 (?{ $p = pos(); })) |
279 ## LINE COMMENTS
280 (.*\/\/\s*[A-Z][A-Z].*:.*$
281 ((\n.*\/\/.*$)*)
282 (?{ $p = pos(); }))
283 /print "'$fileo':$p\n" . $& . "\n\n"/mexg' < "$file"
284 done
288 function do_target_help () {
289 echo "For this script to work, your current working directory must"
290 echo "be \`<CONKEROR>/src' where <CONKEROR> is the project root."
291 echo "This script expects to find the subdirectory structure,"
292 echo "\`conkeror/content', and VERSION in the current directory,"
293 echo "\`downloads' and \`www' in the parent directory, and possibly"
294 echo "other files."
295 echo
296 echo 'Usage: bash build.sh <TARGET>'
297 echo 'where <TARGET> is one of:'
298 echo
299 echo ' xulapp'
300 echo
301 echo ' dist-tar'
302 echo
303 echo ' release Builds a release xpi and puts it in ../downloads.'
304 echo
305 echo ' announce Modify the website in ../www to announce a release.'
306 echo
307 echo ' etags [DIR] Build TAGS file in etags format. If a'
308 echo ' directory is given, TAGS will be made in'
309 echo ' that directory.'
310 echo
311 echo ' notes Shows specially formatted comments in'
312 echo " \`conkeror/content/*.js' Modifies no files."
313 echo
314 echo ' help Shows this help message. Modifies no files.'
315 echo
323 ### MAIN
327 assert_conkeror_src
329 case "$TARGET" in
330 jar) do_target_jar ;;
331 xulapp) do_target_xulapp ;;
332 dist-tar) do_target_dist_tar ;;
333 release) do_target_release ;;
334 announce) do_target_announce ;;
335 etags) do_target_etags ;;
336 notes) do_target_notes ;;
337 help) do_target_help ;;
338 esac
340 do_cleanup