Implement describe-key-briefly (C-h c)
[conkeror.git] / build.sh
blob6db5db48f68d56f3b15ea2bcbfbaa643ec37672d
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 . -type d -and \! -name '*[~#]' -print0 ) \
104 | ( cd "$dest"; xargs -0 mkdir -p )
105 files=($( cd "$src"; find . -type f -and \! -name '*[~#]' -print ))
106 for file in "${files[@]}" ; do cp "$src/$file" "$dest/$file" ; done
107 IFS=$O
112 function do_check_milestone_for_release ()
114 if [[ "$MILESTONE" = "0" ]]; then
115 return
118 dest=VERSION
119 proposed="${VERSION%.*}".$(( ${VERSION#*.} + 1 )).0
121 echo "The version given in the file $dest does not have 0 as its last component."
122 echo -n "Shall I rewrite \`VERSION=$VERSION.$MILESTONE' to \`VERSION=$proposed'? [yN] "
123 read
124 if [[ "$REPLY" = [Yy]* ]]; then
125 perl -pi -e 's/^VERSION='$VERSION'\.'$MILESTONE'$/VERSION='$proposed'/' "$dest"
126 echo "Version changed in $dest. Please run this build program again."
127 exit
128 else
129 echo "Leaving $dest untouched. Continuing with build."
134 function diff_wrapper () {
135 scratch="$1"
136 dest="$2"
137 perlexp="$3"
139 scratchfile="${scratch}/$dest"
140 patchfile="${scratch}/$dest.patch"
142 echo -n "Processing $dest ..."
143 perl -0777 -p -e "$perlexp" "$dest" > "$scratchfile"
144 echo ok
146 if cmp "$dest" "$scratchfile" ; then
147 echo "$dest does not need to be updated"
148 else
149 diff -u "$dest" "$scratchfile" | tee "$patchfile"
150 echo -n "Apply this patch to $dest? [yN] "
151 read
152 if [[ "$REPLY" = [Yy]* ]]; then
153 patch < "$patchfile"
154 else
155 echo "Leaving $dest untouched"
164 ### TARGETS
168 function do_target_jar () {
169 echo -n Building JAR...
170 FILES=($(find content branding locale modules -type f -and \! -name '*[~#]' -print ))
171 zip "conkeror.jar" "${FILES[@]}" > /dev/null
172 echo ok
176 function do_target_xulapp () {
177 do_target_jar
178 echo -n Building XULRunner Application...
179 get_scratch
180 mkdir -p "$SCRATCH/chrome"
181 cp application.ini "$SCRATCH"
182 if [ -n "$CONKEROR_APP_NAME" ]; then
183 sed -i -e "s/Name=conkeror/Name=${CONKEROR_APP_NAME}/" "${SCRATCH}/application.ini"
185 mv conkeror.jar "$SCRATCH/chrome/"
186 cp chrome.manifest.for-jar "$SCRATCH/chrome/chrome.manifest"
187 copy_tree_sans_boring defaults "$SCRATCH/defaults"
188 copy_tree_sans_boring components "$SCRATCH/components"
189 if [ -d idl ]; then
190 for x in idl/*; do
191 name="$(basename "$x")"
192 "${XPIDL}" -w -v -m typelib -I "${XPIDL_INCLUDE}" -e "$SCRATCH/components/${name%.idl}.xpt" "$x"
193 done
195 pushd "$SCRATCH" > /dev/null
196 ## begin preprocessing
198 perl -pi -e 's/\$CONKEROR_VERSION\$/'$VERSION'/g' application.ini
199 perl -pi -e 's/\$CONKEROR_BUILD_DATE\$/'$BUILD_DATE'/g' application.ini
200 perl -pi -e 's/\$CONKEROR_VERSION\$/'$VERSION'/g' components/application.js
202 ## end preprocessing
203 zip -r conkeror.xulapp * > /dev/null
204 popd > /dev/null
205 mv "$SCRATCH/conkeror.xulapp" .
206 do_cleanup
207 echo ok
211 function do_target_dist_tar () {
212 do_target_xulapp
213 get_scratch
214 ## now we have conkeror.xulapp
215 ## package it with install.sh
217 ## some other files should probably go in here.. NEWS, for example
218 mkdir "$SCRATCH/conkeror-$VERSION"
219 mv conkeror.xulapp "$SCRATCH/conkeror-$VERSION/"
220 cp install.sh "$SCRATCH/conkeror-$VERSION/"
221 pushd "$SCRATCH" > /dev/null
222 tar c conkeror-$VERSION | gzip > conkeror-$VERSION.tar.gz
223 popd > /dev/null
224 mv "$SCRATCH/conkeror-$VERSION.tar.gz" .
225 echo -n "Making conkeror-$VERSION.tar.gz ..."
226 do_cleanup
227 echo ok
231 function do_target_release () {
232 do_check_milestone_for_release
233 ## Make any and all release archives.
235 ## Right now, we just make a tar.gz archive that includes an install
236 ## script. In the future, we could consider making an OSX App, a Windows
237 ## Installer EXE, and a Mozilla XPI Installer.
239 do_target_dist_tar
240 echo -n Putting conkeror-$VERSION.tar.gz in downloads directory ...
241 mv conkeror-$VERSION.tar.gz ../downloads
242 echo ok
246 function do_target_announce () {
247 do_check_milestone_for_release
248 echo Entering ../www/ ... ok
249 pushd ../www/ > /dev/null
250 scratch=$(mktemp -d conkeror-XXXXXX)
252 perlexp='s/(?<=<!--\scontrolled\scontent\sinsertion\spoint::whatsnew\s-->\n) ()(?!.*'$VERSION'.*$)/<li>'$VERSION' released! \('"$(date '+%b %d, %Y')"'\)<\/li>\n/mxg'
253 diff_wrapper "$scratch" index.html "$perlexp"
255 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'
256 diff_wrapper "$scratch" installation.html "$perlexp"
258 rm -r "$scratch"
259 popd > /dev/null
263 function do_target_etags () {
264 if [[ -z "$ETAGSDIR" ]]; then
265 ETAGSDIR=.
267 ETAGSDIR="${ETAGSDIR%/}/TAGS"
268 echo -n "Building $ETAGSDIR ..."
269 etags -o "$ETAGSDIR" $(find -name \*.js -and \! -name '*[~#]*')
270 echo ok
274 function do_target_notes () {
275 FILES=($(find conkeror -name \*.js))
276 for file in "${FILES[@]}"; do
277 fileo="${file//\//\/}"
278 perl -0777 -ne 's/## BLOCK COMMENTS
279 (.*\/\*\s*[A-Z][A-Z].*:.*$
280 (\n.*$)*?
281 (\n.*\*\/)
282 (?{ $p = pos(); })) |
283 ## LINE COMMENTS
284 (.*\/\/\s*[A-Z][A-Z].*:.*$
285 ((\n.*\/\/.*$)*)
286 (?{ $p = pos(); }))
287 /print "'$fileo':$p\n" . $& . "\n\n"/mexg' < "$file"
288 done
292 function do_target_help () {
293 echo "For this script to work, your current working directory must"
294 echo "be \`<CONKEROR>/src' where <CONKEROR> is the project root."
295 echo "This script expects to find the subdirectory structure,"
296 echo "\`conkeror/content', and VERSION in the current directory,"
297 echo "\`downloads' and \`www' in the parent directory, and possibly"
298 echo "other files."
299 echo
300 echo 'Usage: bash build.sh <TARGET>'
301 echo 'where <TARGET> is one of:'
302 echo
303 echo ' xulapp'
304 echo
305 echo ' dist-tar'
306 echo
307 echo ' release Builds a release xpi and puts it in ../downloads.'
308 echo
309 echo ' announce Modify the website in ../www to announce a release.'
310 echo
311 echo ' etags [DIR] Build TAGS file in etags format. If a'
312 echo ' directory is given, TAGS will be made in'
313 echo ' that directory.'
314 echo
315 echo ' notes Shows specially formatted comments in'
316 echo " \`conkeror/content/*.js' Modifies no files."
317 echo
318 echo ' help Shows this help message. Modifies no files.'
319 echo
327 ### MAIN
331 assert_conkeror_src
333 case "$TARGET" in
334 jar) do_target_jar ;;
335 xulapp) do_target_xulapp ;;
336 dist-tar) do_target_dist_tar ;;
337 release) do_target_release ;;
338 announce) do_target_announce ;;
339 etags) do_target_etags ;;
340 notes) do_target_notes ;;
341 help) do_target_help ;;
342 esac
344 do_cleanup