Mercurial > hg > FirefoxAddon
comparison firefoxaddon/template/build.sh @ 0:9869cf47fcf8 default tip
initial commit of Firefox addon template
author | k0s <k0scist@gmail.com> |
---|---|
date | Sun, 28 Mar 2010 16:25:58 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9869cf47fcf8 |
---|---|
1 #!/bin/bash | |
2 # build.sh -- builds JAR and XPI files for mozilla extensions | |
3 # by Nickolay Ponomarev <asqueella@gmail.com> | |
4 # (original version based on Nathan Yergler's build script) | |
5 # Most recent version is at <http://kb.mozillazine.org/Bash_build_script> | |
6 | |
7 # This script assumes the following directory structure: | |
8 # ./ | |
9 # chrome.manifest (optional - for newer extensions) | |
10 # install.rdf | |
11 # (other files listed in $ROOT_FILES) | |
12 # | |
13 # content/ | | |
14 # locale/ |} these can be named arbitrary and listed in $CHROME_PROVIDERS | |
15 # skin/ | | |
16 # | |
17 # defaults/ | | |
18 # components/ |} these must be listed in $ROOT_DIRS in order to be packaged | |
19 # ... | | |
20 # | |
21 # It uses a temporary directory ./build when building; don't use that! | |
22 # Script's output is: | |
23 # ./$APP_NAME.xpi | |
24 # ./$APP_NAME.jar (only if $KEEP_JAR=1) | |
25 # ./files -- the list of packaged files | |
26 # | |
27 # Note: It modifies chrome.manifest when packaging so that it points to | |
28 # chrome/$APP_NAME.jar!/* | |
29 | |
30 # | |
31 # default configuration file is ./config_build.sh, unless another file is | |
32 # specified in command-line. Available config variables: | |
33 APP_NAME= # short-name, jar and xpi files name. Must be lowercase with no spaces | |
34 CHROME_PROVIDERS= # which chrome providers we have (space-separated list) | |
35 CLEAN_UP= # delete the jar / "files" when done? (1/0) | |
36 ROOT_FILES= # put these files in root of xpi (space separated list of leaf filenames) | |
37 ROOT_DIRS= # ...and these directories (space separated list) | |
38 BEFORE_BUILD= # run this before building (bash command) | |
39 AFTER_BUILD= # ...and this after the build (bash command) | |
40 | |
41 if [ -z $1 ]; then | |
42 . ./config_build.sh | |
43 else | |
44 . $1 | |
45 fi | |
46 | |
47 if [ -z $APP_NAME ]; then | |
48 echo "You need to create build config file first!" | |
49 echo "Read comments at the beginning of this script for more info." | |
50 exit; | |
51 fi | |
52 | |
53 ROOT_DIR=`pwd` | |
54 TMP_DIR=build | |
55 | |
56 #uncomment to debug | |
57 #set -x | |
58 | |
59 # remove any left-over files from previous build | |
60 rm -f $APP_NAME.jar $APP_NAME.xpi files | |
61 rm -rf $TMP_DIR | |
62 | |
63 $BEFORE_BUILD | |
64 | |
65 mkdir --parents --verbose $TMP_DIR/chrome | |
66 | |
67 # generate the JAR file, excluding CVS and temporary files | |
68 JAR_FILE=$TMP_DIR/chrome/$APP_NAME.jar | |
69 echo "Generating $JAR_FILE..." | |
70 for CHROME_SUBDIR in $CHROME_PROVIDERS; do | |
71 find $CHROME_SUBDIR -path '*CVS*' -prune -o -type f -print | grep -v \~ >> files | |
72 done | |
73 | |
74 zip -0 -r $JAR_FILE `cat files` | |
75 # The following statement should be used instead if you don't wish to use the JAR file | |
76 #cp --verbose --parents `cat files` $TMP_DIR/chrome | |
77 | |
78 # prepare components and defaults | |
79 echo "Copying various files to $TMP_DIR folder..." | |
80 for DIR in $ROOT_DIRS; do | |
81 mkdir $TMP_DIR/$DIR | |
82 FILES="`find $DIR -path '*CVS*' -prune -o -type f -print | grep -v \~`" | |
83 echo $FILES >> files | |
84 cp --verbose --parents $FILES $TMP_DIR | |
85 done | |
86 | |
87 # Copy other files to the root of future XPI. | |
88 for ROOT_FILE in $ROOT_FILES install.rdf chrome.manifest; do | |
89 cp --verbose $ROOT_FILE $TMP_DIR | |
90 if [ -f $ROOT_FILE ]; then | |
91 echo $ROOT_FILE >> files | |
92 fi | |
93 done | |
94 | |
95 cd $TMP_DIR | |
96 | |
97 if [ -f "chrome.manifest" ]; then | |
98 echo "Preprocessing chrome.manifest..." | |
99 # You think this is scary? | |
100 #s/^(content\s+\S*\s+)(\S*\/)$/\1jar:chrome\/$APP_NAME\.jar!\/\2/ | |
101 #s/^(skin|locale)(\s+\S*\s+\S*\s+)(.*\/)$/\1\2jar:chrome\/$APP_NAME\.jar!\/\3/ | |
102 # | |
103 # Then try this! (Same, but with characters escaped for bash :) | |
104 sed -i -r s/^\(content\\s+\\S*\\s+\)\(\\S*\\/\)$/\\1jar:chrome\\/$APP_NAME\\.jar!\\/\\2/ chrome.manifest | |
105 sed -i -r s/^\(skin\|locale\)\(\\s+\\S*\\s+\\S*\\s+\)\(.*\\/\)$/\\1\\2jar:chrome\\/$APP_NAME\\.jar!\\/\\3/ chrome.manifest | |
106 | |
107 # (it simply adds jar:chrome/whatever.jar!/ at appropriate positions of chrome.manifest) | |
108 fi | |
109 | |
110 # generate the XPI file | |
111 echo "Generating $APP_NAME.xpi..." | |
112 zip -r ../$APP_NAME.xpi * | |
113 | |
114 cd "$ROOT_DIR" | |
115 | |
116 echo "Cleanup..." | |
117 if [ $CLEAN_UP = 0 ]; then | |
118 # save the jar file | |
119 mv $TMP_DIR/chrome/$APP_NAME.jar . | |
120 else | |
121 rm ./files | |
122 fi | |
123 | |
124 # remove the working files | |
125 rm -rf $TMP_DIR | |
126 echo "Done!" | |
127 | |
128 $AFTER_BUILD |