Initial step of large code reorganization to improve buffer and minibuffer interface
[conkeror.git] / build.sh
blob6de12b7e198910ee8a77ee462fa3b2b649b11ceb
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 ## if this is not an official release, tag on a build date.
47 ## if this is an official release, strip the subminor.
49 MILESTONE="${VERSION##*.}"
50 BUILD_DATE=$(date +%Y%m%d)
51 SHORT_VERSION="$VERSION"
53 case "$TARGET" in
54 release|announce)
55 VERSION="${VERSION%.*}" ;;
57 VERSION="$VERSION.$BUILD_DATE"
58 esac
59 echo "build target: $TARGET, $VERSION"
62 ### UTILITIES
63 ###
64 ###
68 ## SCRATCH
70 ## Temporary directory for build process.
72 SCRATCH=""
74 function get_scratch () {
75 if [[ -z "$SCRATCH" ]]; then
76 SCRATCH=$(mktemp -d conkeror-XXXXXX)
81 function do_cleanup () {
82 if [[ -n "$SCRATCH" ]]; then
83 rm -r "$SCRATCH"
84 SCRATCH=""
89 function assert_conkeror_src () {
90 if [[ ! -e application.ini ]]; then
91 echo "The current directory does not appear to contain the Conkeror source code."
92 exit 1
97 function copy_tree_sans_boring () {
98 src="$1"
99 dest="$2"
100 mkdir -p "$dest"
101 O=$IFS
102 IFS=$'\n'
103 ( cd "$src"; find . -name CVS -prune -or \( -type d -and \
104 \! -name '*[~#]' -print0 \) ) \
105 | ( cd "$dest"; xargs -0 mkdir -p )
106 files=($( cd "$src"; find . -name CVS -prune -or \( -type f -and \
107 \! -name '*[~#]' -print \) ))
108 for file in "${files[@]}" ; do cp "$src/$file" "$dest/$file" ; done
109 IFS=$O
114 function do_check_milestone_for_release ()
116 if [[ "$MILESTONE" = "0" ]]; then
117 return
120 dest=VERSION
121 proposed="${VERSION%.*}".$(( ${VERSION#*.} + 1 )).0
123 echo "The version given in the file $dest does not have 0 as its last component."
124 echo -n "Shall I rewrite \`VERSION=$VERSION.$MILESTONE' to \`VERSION=$proposed'? [yN] "
125 read
126 if [[ "$REPLY" = [Yy]* ]]; then
127 perl -pi -e 's/^VERSION='$VERSION'\.'$MILESTONE'$/VERSION='$proposed'/' "$dest"
128 echo "Version changed in $dest. Please run this build program again."
129 exit
130 else
131 echo "Leaving $dest untouched. Continuing with build."
136 function diff_wrapper () {
137 scratch="$1"
138 dest="$2"
139 perlexp="$3"
141 scratchfile="${scratch}/$dest"
142 patchfile="${scratch}/$dest.patch"
144 echo -n "Processing $dest ..."
145 perl -0777 -p -e "$perlexp" "$dest" > "$scratchfile"
146 echo ok
148 if cmp "$dest" "$scratchfile" ; then
149 echo "$dest does not need to be updated"
150 else
151 diff -u "$dest" "$scratchfile" | tee "$patchfile"
152 echo -n "Apply this patch to $dest? [yN] "
153 read
154 if [[ "$REPLY" = [Yy]* ]]; then
155 patch < "$patchfile"
156 else
157 echo "Leaving $dest untouched"
166 ### TARGETS
170 function do_target_jar () {
171 echo -n Building JAR...
172 get_scratch
173 jarbuild="$SCRATCH/jar-build"
174 mkdir "$jarbuild"
175 cp -r conkeror "$jarbuild/conkeror"
176 pushd "$jarbuild" > /dev/null
177 FILES=($(find conkeror -name CVS -prune -or \( -type f -and \! -name '*[~#]' -print \)))
178 zip conkeror.jar "${FILES[@]}" > /dev/null
179 popd > /dev/null
180 mv "$jarbuild/conkeror.jar" .
181 echo ok
182 do_cleanup
186 function do_target_xulapp () {
187 do_target_jar
188 echo -n Building XULRunner Application...
189 get_scratch
190 mkdir -p "$SCRATCH/chrome"
191 cp application.ini "$SCRATCH"
192 mv conkeror.jar "$SCRATCH/chrome/"
193 cp chrome.manifest.for-jar "$SCRATCH/chrome/chrome.manifest"
194 copy_tree_sans_boring defaults "$SCRATCH/defaults"
195 copy_tree_sans_boring components "$SCRATCH/components"
196 for x in idl/*; do
197 name="$(basename "$x")"
198 "${XPIDL}" -w -v -m typelib -I "${XPIDL_INCLUDE}" -e "$SCRATCH/components/${name%.idl}.xpt" "$x"
199 done
200 pushd "$SCRATCH" > /dev/null
201 ## begin preprocessing
203 perl -pi -e 's/\$CONKEROR_VERSION\$/'$VERSION'/g' application.ini
204 perl -pi -e 's/\$CONKEROR_BUILD_DATE\$/'$BUILD_DATE'/g' application.ini
205 perl -pi -e 's/\$CONKEROR_VERSION\$/'$VERSION'/g' components/application.js
207 ## end preprocessing
208 zip -r conkeror.xulapp * > /dev/null
209 popd > /dev/null
210 mv "$SCRATCH/conkeror.xulapp" .
211 do_cleanup
212 echo ok
216 function do_target_dist_tar () {
217 do_target_xulapp
218 get_scratch
219 ## now we have conkeror.xulapp
220 ## package it with install.sh
222 ## some other files should probably go in here.. NEWS, for example
223 mkdir "$SCRATCH/conkeror-$VERSION"
224 mv conkeror.xulapp "$SCRATCH/conkeror-$VERSION/"
225 cp install.sh "$SCRATCH/conkeror-$VERSION/"
226 pushd "$SCRATCH" > /dev/null
227 tar c conkeror-$VERSION | gzip > conkeror-$VERSION.tar.gz
228 popd > /dev/null
229 mv "$SCRATCH/conkeror-$VERSION.tar.gz" .
230 echo -n "Making conkeror-$VERSION.tar.gz ..."
231 do_cleanup
232 echo ok
236 function do_target_release () {
237 do_check_milestone_for_release
238 ## Make any and all release archives.
240 ## Right now, we just make a tar.gz archive that includes an install
241 ## script. In the future, we could consider making an OSX App, a Windows
242 ## Installer EXE, and a Mozilla XPI Installer.
244 do_target_dist_tar
245 echo -n Putting conkeror-$VERSION.tar.gz in downloads directory ...
246 mv conkeror-$VERSION.tar.gz ../downloads
247 echo ok
251 function do_target_announce () {
252 do_check_milestone_for_release
253 echo Entering ../www/ ... ok
254 pushd ../www/ > /dev/null
255 scratch=$(mktemp -d conkeror-XXXXXX)
257 perlexp='s/(?<=<!--\scontrolled\scontent\sinsertion\spoint::whatsnew\s-->\n) ()(?!.*'$VERSION'.*$)/<li>'$VERSION' released! \('"$(date '+%b %d, %Y')"'\)<\/li>\n/mxg'
258 diff_wrapper "$scratch" index.html "$perlexp"
260 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'
261 diff_wrapper "$scratch" installation.html "$perlexp"
263 rm -r "$scratch"
264 popd > /dev/null
268 function do_target_etags () {
269 if [[ -z "$ETAGSDIR" ]]; then
270 ETAGSDIR=.
272 ETAGSDIR="${ETAGSDIR%/}/TAGS"
273 echo -n "Building $ETAGSDIR ..."
274 etags -o "$ETAGSDIR" conkeror/content/*.js
275 echo ok
279 function do_target_notes () {
280 FILES=($(find conkeror -name \*.js))
281 for file in "${FILES[@]}"; do
282 fileo="${file//\//\/}"
283 perl -0777 -ne 's/## BLOCK COMMENTS
284 (.*\/\*\s*[A-Z][A-Z].*:.*$
285 (\n.*$)*?
286 (\n.*\*\/)
287 (?{ $p = pos(); })) |
288 ## LINE COMMENTS
289 (.*\/\/\s*[A-Z][A-Z].*:.*$
290 ((\n.*\/\/.*$)*)
291 (?{ $p = pos(); }))
292 /print "'$fileo':$p\n" . $& . "\n\n"/mexg' < "$file"
293 done
297 function do_target_help () {
298 echo "For this script to work, your current working directory must"
299 echo "be \`<CONKEROR>/src' where <CONKEROR> is the project root."
300 echo "This script expects to find the subdirectory structure,"
301 echo "\`conkeror/content', and VERSION in the current directory,"
302 echo "\`downloads' and \`www' in the parent directory, and possibly"
303 echo "other files."
304 echo
305 echo 'Usage: bash build.sh <TARGET>'
306 echo 'where <TARGET> is one of:'
307 echo
308 echo ' xulapp'
309 echo
310 echo ' dist-tar'
311 echo
312 echo ' release Builds a release xpi and puts it in ../downloads.'
313 echo
314 echo ' announce Modify the website in ../www to announce a release.'
315 echo
316 echo ' etags [DIR] Build TAGS file in etags format. If a'
317 echo ' directory is given, TAGS will be made in'
318 echo ' that directory.'
319 echo
320 echo ' notes Shows specially formatted comments in'
321 echo " \`conkeror/content/*.js' Modifies no files."
322 echo
323 echo ' help Shows this help message. Modifies no files.'
324 echo
332 ### MAIN
336 assert_conkeror_src
338 case "$TARGET" in
339 jar) do_target_jar ;;
340 xulapp) do_target_xulapp ;;
341 dist-tar) do_target_dist_tar ;;
342 release) do_target_release ;;
343 announce) do_target_announce ;;
344 etags) do_target_etags ;;
345 notes) do_target_notes ;;
346 help) do_target_help ;;
347 esac
349 do_cleanup