Merge branch 'experimental-buffers' of git+ssh://repo.or.cz/srv/git/conkeror into...
[conkeror.git] / build.sh
blobeeb62f452934b4b902ed7bddfec8d4bc1a85a9a1
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 for x in idl/*; do
190 name="$(basename "$x")"
191 "${XPIDL}" -w -v -m typelib -I "${XPIDL_INCLUDE}" -e "$SCRATCH/components/${name%.idl}.xpt" "$x"
192 done
193 pushd "$SCRATCH" > /dev/null
194 ## begin preprocessing
196 perl -pi -e 's/\$CONKEROR_VERSION\$/'$VERSION'/g' application.ini
197 perl -pi -e 's/\$CONKEROR_BUILD_DATE\$/'$BUILD_DATE'/g' application.ini
198 perl -pi -e 's/\$CONKEROR_VERSION\$/'$VERSION'/g' components/application.js
200 ## end preprocessing
201 zip -r conkeror.xulapp * > /dev/null
202 popd > /dev/null
203 mv "$SCRATCH/conkeror.xulapp" .
204 do_cleanup
205 echo ok
209 function do_target_dist_tar () {
210 do_target_xulapp
211 get_scratch
212 ## now we have conkeror.xulapp
213 ## package it with install.sh
215 ## some other files should probably go in here.. NEWS, for example
216 mkdir "$SCRATCH/conkeror-$VERSION"
217 mv conkeror.xulapp "$SCRATCH/conkeror-$VERSION/"
218 cp install.sh "$SCRATCH/conkeror-$VERSION/"
219 pushd "$SCRATCH" > /dev/null
220 tar c conkeror-$VERSION | gzip > conkeror-$VERSION.tar.gz
221 popd > /dev/null
222 mv "$SCRATCH/conkeror-$VERSION.tar.gz" .
223 echo -n "Making conkeror-$VERSION.tar.gz ..."
224 do_cleanup
225 echo ok
229 function do_target_release () {
230 do_check_milestone_for_release
231 ## Make any and all release archives.
233 ## Right now, we just make a tar.gz archive that includes an install
234 ## script. In the future, we could consider making an OSX App, a Windows
235 ## Installer EXE, and a Mozilla XPI Installer.
237 do_target_dist_tar
238 echo -n Putting conkeror-$VERSION.tar.gz in downloads directory ...
239 mv conkeror-$VERSION.tar.gz ../downloads
240 echo ok
244 function do_target_announce () {
245 do_check_milestone_for_release
246 echo Entering ../www/ ... ok
247 pushd ../www/ > /dev/null
248 scratch=$(mktemp -d conkeror-XXXXXX)
250 perlexp='s/(?<=<!--\scontrolled\scontent\sinsertion\spoint::whatsnew\s-->\n) ()(?!.*'$VERSION'.*$)/<li>'$VERSION' released! \('"$(date '+%b %d, %Y')"'\)<\/li>\n/mxg'
251 diff_wrapper "$scratch" index.html "$perlexp"
253 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'
254 diff_wrapper "$scratch" installation.html "$perlexp"
256 rm -r "$scratch"
257 popd > /dev/null
261 function do_target_etags () {
262 if [[ -z "$ETAGSDIR" ]]; then
263 ETAGSDIR=.
265 ETAGSDIR="${ETAGSDIR%/}/TAGS"
266 echo -n "Building $ETAGSDIR ..."
267 etags -o "$ETAGSDIR" conkeror/content/*.js
268 echo ok
272 function do_target_notes () {
273 FILES=($(find conkeror -name \*.js))
274 for file in "${FILES[@]}"; do
275 fileo="${file//\//\/}"
276 perl -0777 -ne 's/## BLOCK COMMENTS
277 (.*\/\*\s*[A-Z][A-Z].*:.*$
278 (\n.*$)*?
279 (\n.*\*\/)
280 (?{ $p = pos(); })) |
281 ## LINE COMMENTS
282 (.*\/\/\s*[A-Z][A-Z].*:.*$
283 ((\n.*\/\/.*$)*)
284 (?{ $p = pos(); }))
285 /print "'$fileo':$p\n" . $& . "\n\n"/mexg' < "$file"
286 done
290 function do_target_help () {
291 echo "For this script to work, your current working directory must"
292 echo "be \`<CONKEROR>/src' where <CONKEROR> is the project root."
293 echo "This script expects to find the subdirectory structure,"
294 echo "\`conkeror/content', and VERSION in the current directory,"
295 echo "\`downloads' and \`www' in the parent directory, and possibly"
296 echo "other files."
297 echo
298 echo 'Usage: bash build.sh <TARGET>'
299 echo 'where <TARGET> is one of:'
300 echo
301 echo ' xulapp'
302 echo
303 echo ' dist-tar'
304 echo
305 echo ' release Builds a release xpi and puts it in ../downloads.'
306 echo
307 echo ' announce Modify the website in ../www to announce a release.'
308 echo
309 echo ' etags [DIR] Build TAGS file in etags format. If a'
310 echo ' directory is given, TAGS will be made in'
311 echo ' that directory.'
312 echo
313 echo ' notes Shows specially formatted comments in'
314 echo " \`conkeror/content/*.js' Modifies no files."
315 echo
316 echo ' help Shows this help message. Modifies no files.'
317 echo
325 ### MAIN
329 assert_conkeror_src
331 case "$TARGET" in
332 jar) do_target_jar ;;
333 xulapp) do_target_xulapp ;;
334 dist-tar) do_target_dist_tar ;;
335 release) do_target_release ;;
336 announce) do_target_announce ;;
337 etags) do_target_etags ;;
338 notes) do_target_notes ;;
339 help) do_target_help ;;
340 esac
342 do_cleanup