Import from 1.9a8 tarball
[mozilla-extra.git] / extensions / venkman / xpi / makexpi.sh
blob78dc6ceb71a0cacafc72df2f79cf08d159e9c142
1 #!/bin/bash
3 # Set up paths for finding files.
4 if [ -z "$FEDIR" ]; then FEDIR=$PWD/../resources; fi
5 if [ -z "$CONFIGDIR" ]; then CONFIGDIR=$FEDIR/../../config; fi
6 if [ -z "$XPIFILES" ]; then XPIFILES=$PWD/resources; fi
7 if [ -z "$XPIROOT" ]; then XPIROOT=$PWD/xpi-tree; fi
8 if [ -z "$JARROOT" ]; then JARROOT=$PWD/jar-tree; fi
9 if [ -z "$PERL" ]; then PERL=perl; fi
10 if [ -z "$DEBUG" ]; then DEBUG=0; fi
13 function showParams()
15 I=0
16 for P in "$@"; do
17 I=$((I+1))
18 echo PARAM $I: "$P"
19 done
22 ## Call this with lots of parameters to run a command, log errors, and abort
23 ## if it fails. Supports redirection if '>' and '<' are passed as arguments,
24 ## e.g.:
25 ## safeCommand cmd arg1 arg2 '<' input.file '>' output-file
27 ## Note: only a single input and single output redirection is supported.
29 function safeCommand()
31 local -a CMD
32 CMD_COUNT=$((0))
33 INF=""
34 OUTF=""
35 LASTP=""
36 for P in "$@"; do
37 if [ "$LASTP" = "<" ]; then
38 if [ -n "$INF" ]; then
39 echo "ERROR: Multiple input files passed to safeCommand()." >&2
40 exit 2
42 INF="$P"
43 elif [ "$LASTP" = ">" ]; then
44 if [ -n "$OUTF" ]; then
45 echo "ERROR: Multiple output files passed to safeCommand()." >&2
46 exit 2
48 OUTF="$P"
49 elif [ "$P" = ">" -o "$P" = "<" ]; then
50 echo >/dev/null
51 else
52 CMD[$CMD_COUNT]="$P"
53 CMD_COUNT=$((CMD_COUNT+1))
55 LASTP="$P"
56 done
58 if [ $DEBUG -gt 0 ]; then
59 echo
60 showParams "${CMD[@]}"
61 echo 'INPUT :' "$INF"
62 echo 'OUTPUT :' "$OUTF"
65 touch log.stdout log.stderr
66 if [ -z "$INF" -a -z "$OUTF" ]; then
67 "${CMD[@]}" 1>log.stdout 2>log.stderr
68 elif [ -z "$INF" ]; then
69 "${CMD[@]}" 1> "$OUTF" 2>log.stderr
70 elif [ -z "$OUTF" ]; then
71 "${CMD[@]}" < "$INF" 1>log.stdout 2>log.stderr
72 else
73 "${CMD[@]}" < "$INF" 1> "$OUTF" 2>log.stderr
76 EC=$?
77 if [ $DEBUG -gt 0 ]; then
78 echo 'RESULT :' $EC
80 if [ "$EC" != "0" ]; then
81 echo "ERROR ($EC)"
82 cat log.stdout
83 cat log.stderr
84 rm -f log.stdout log.stderr
85 exit 1
87 rm -f log.stdout log.stderr
88 return $EC
92 ## Begin real program ##
95 if [ "$1" = "clean" ]; then
96 echo -n "Cleaning up files"
97 echo -n .
98 rm -rf "$XPIROOT"
99 echo -n .
100 rm -rf "$JARROOT"
101 echo ". done."
103 exit
107 # Check setup.
108 if ! [ -d "$FEDIR" ]; then
109 echo "ERROR: Base JavaScript Debugger directory (FEDIR) not found."
110 exit 1
112 if ! [ -d "$CONFIGDIR" ]; then
113 echo "ERROR: mozilla/config directory (CONFIGDIR) not found."
114 exit 1
118 # Extract version number.
119 VERSION=`cat $FEDIR/../version.txt`
121 if [ -z "$VERSION" ]; then
122 echo "ERROR: Unable to get version number."
123 exit 1
126 echo Beginning build of JavaScript Debugger $VERSION...
129 # Check for existing.
130 if [ -r "venkman-$VERSION.xpi" ]; then
131 echo " WARNING: output XPI will be overwritten."
135 # Check for required directory layouts.
136 echo -n " Checking XPI structure"
137 echo -n .
138 if ! [ -d xpi-tree ]; then mkdir xpi-tree; fi
139 echo -n .
140 if ! [ -d xpi-tree/chrome ]; then mkdir xpi-tree/chrome; fi
141 echo -n .
142 if ! [ -d xpi-tree/components ]; then mkdir xpi-tree/components; fi
143 echo ". done"
145 echo -n " Checking JAR structure"
146 echo -n .
147 if ! [ -d jar-tree ]; then mkdir jar-tree; fi
148 echo ". done"
151 # Make Toolkit updates.
152 echo -n " Updating Toolkit Extension files"
153 echo -n .
154 safeCommand $PERL $CONFIGDIR/preprocessor.pl -DVENKMAN_VERSION=$VERSION "$XPIFILES/install.rdf" '>' "$XPIROOT/install.rdf"
155 echo ". done"
158 # Make Mozilla Suite / SeaMonkey 1.x updates.
159 echo -n " Updating XPFE Extension files"
160 echo -n .
161 safeCommand sed "s|@REVISION@|$VERSION|g" '<' "$XPIFILES/install.js" '>' "$XPIROOT/install.js"
162 echo -n .
163 safeCommand mv "$FEDIR/content/contents.rdf" "$FEDIR/content/contents.rdf.in"
164 echo -n .
165 safeCommand sed "s|@MOZILLA_VERSION@|vnk-$VERSION|g;s|\(chrome:displayName=\)\"[^\"]\{1,\}\"|\1\"JavaScript Debugger $VERSION\"|g" '<' "$FEDIR/content/contents.rdf.in" '>' "$FEDIR/content/contents.rdf"
166 echo -n .
167 safeCommand rm "$FEDIR/content/contents.rdf.in"
168 echo -n .
169 safeCommand mv "$FEDIR/locale/en-US/contents.rdf" "$FEDIR/locale/en-US/contents.rdf.in"
170 echo -n .
171 safeCommand sed "s|@MOZILLA_VERSION@|vnk-$VERSION|g" '<' "$FEDIR/locale/en-US/contents.rdf.in" '>' "$FEDIR/locale/en-US/contents.rdf"
172 echo -n .
173 safeCommand rm "$FEDIR/locale/en-US/contents.rdf.in"
174 echo ". done"
177 # Create JAR.
178 echo -n " Constructing JAR package"
179 echo -n .
180 OLDPWD=`pwd`
181 cd "$CONFIGDIR"
182 echo -n .
183 safeCommand $PERL make-jars.pl -v -z zip -p preprocessor.pl -s "$FEDIR" -d "$JARROOT" -- -DVENKMAN_VERSION=$VERSION '<' "$FEDIR/jar.mn"
184 echo -n .
185 cd "$OLDPWD"
186 echo ". done"
189 # Make XPI.
190 echo -n " Constructing XPI package"
191 echo -n .
192 safeCommand cp -v "$JARROOT/venkman.jar" "$XPIROOT/chrome/"
193 echo -n .
194 safeCommand cp -v "$FEDIR/../js/venkman-service.js" "$XPIROOT/components/"
195 echo -n .
196 safeCommand chmod 664 "$XPIROOT/chrome/venkman.jar"
197 echo -n .
198 safeCommand chmod 664 "$XPIROOT/components/venkman-service.js"
199 echo -n .
200 OLDPWD=`pwd`
201 cd "$XPIROOT"
202 safeCommand zip -vr ../venkman-$VERSION.xpi . -i "*" -x "log*"
203 cd "$OLDPWD"
204 echo ". done"
207 echo "Build of JavaScript Debugger $VERSION... ALL DONE"