7de772b149cc305e1a8773c7ef36d350fd7f056e
[maemo-efl] / trunk / build-all.sh
1 #!/bin/bash
2
3 source "helper-functions.sh"
4
5 ###########################################################
6 # Variable definitions
7 ###########################################################
8 __this_script=`basename $0`
9 __this_script_dir=`dirname $0`
10 __orig_path=$PATH
11
12 # Binaries
13 __date=`which date`
14 __git=`which git`
15 __head=`which head`
16 __mkdir=`which mkdir`
17 __sed=`which sed`
18 __uname=`which uname`
19
20 # git definitions
21 __git_clone="$__git clone -q"
22 __git_pull="$__git pull -q -n"
23 __git_clean="$__git clean -q -x -d"
24 __git_reset="$__git reset --hard HEAD"
25 __git_repo="git://staff.get-e.org/"
26
27 # e17 git repositories paths
28 __e17_libs="e17/libs"
29 __e17_proto="e17/proto"
30 __e17_python_efl="$__e17_proto/python-efl"
31 __e17_python_etk="users/cmarcelo"
32
33 # modules to build
34 #__lib_modules="edb eet evas ecore embryo edje efreet epeg epsilon emotion etk ewl e_dbus exml enhance"
35 __lib_modules="eet:evas:ecore:embryo:edje:epsilon:etk:e_dbus"
36 __python_modules="python-evas:python-ecore:python-edje:python-epsilon:python-e_dbus"
37 __python_etk_module="python-etk"
38
39 # dpkg definitions
40 __common_build_pkg_options="-I.svn -I.git -I.gitignore -I.cvsignore -rfakeroot -us -uc -D -tc"
41
42 # Packages dirs and log file
43 __today=`$__date +%Y%m%d`
44 __base_pkg_dir="$__this_script_dir/packages_$__today"
45 __output_file="$PWD/$__base_pkg_dir/packages_$__today.log"
46
47 # Scratchbox definitions
48 __sbox_path="/scratchbox"
49
50 # Other
51 __update_repositories=1
52
53 ###########################################################
54 # Function definitions
55 ###########################################################
56
57 function usage() {
58     cat << EOF
59
60 Usage: $__this_script [OPTIONS]
61
62 Build script for EFL debian packages for Maemo.
63
64 Options:
65     -c      Don't update source repositories.
66     -h      Show this usage guide.
67     -s PATH Specify alternate scratchbox path (default: $__sbox_path).
68
69 EOF
70 }
71
72 function create_log_file() {
73     if [ ! -r $__output_file ]; then
74         msg_begin "Creating log file"
75         touch $__output_file
76         msg_end $?
77     else
78         msg "Using existing log file: $__output_file"
79     fi
80 }
81
82 function log_to_file() {
83     local now
84     local msg
85     msg=$1
86
87     if [ ! -r $__output_file ]; then
88         error "log_to_file(): Log file does not exist"
89     fi
90
91     now=`$__date +%H:%M:%S`
92     echo "$now: $msg" >> $__output_file
93 }
94
95 function start_log() {
96     local now
97     now=`$__date -R`
98
99     echo "" >> $__output_file
100
101     if [ $? != 0 ] ; then
102         error "start_log(): Could not create $__output_file file"
103     fi
104
105     cat << EOF >> $__output_file
106 *********************************************************
107 * Started $__this_script: $now *
108 *********************************************************
109
110 EOF
111 }
112
113 function finish_log() {
114     local now
115     now=`$__date -R`
116
117     if [ ! -r $__output_file ]; then
118         error "finish_log(): Log file does not exist"
119     fi
120
121     cat << EOF >> $__output_file
122
123 * Finished $__this_script: $now
124 EOF
125 }
126
127 function clone() {
128     local repo
129     repo=$1
130     `$__git_clone $repo.git >> $__output_file 2>&1 `
131     return $?
132 }
133
134 function pull() {
135     `$__git_pull >> $__output_file 2>&1`
136     return $?
137 }
138
139 function clean() {
140     `$__git_reset >> $__output_file 2>&1`
141     `$__git_clean >> $__output_file 2>&1`
142     return $?
143 }
144
145 function build_pkg() {
146     echo "build_pkg"
147     return $?
148 }
149
150 function install_pkg() {
151     echo "install_pkg"
152     return $?
153 }
154
155 function uninstall_pkg() {
156     echo "uninstall_pkg"
157     return $?
158 }
159
160 function get_sources() {
161     local modules
162     local repo
163     modules=`echo $1|$__sed -e 's/:/ /g'`
164     repo=$2
165
166     for module in $modules; do
167         if [ -d $module/$module/.git ]; then
168             if [ ! $__update_repositories -eq 0 ]; then
169                 log_to_file "Updating existing repository at $PWD/$module/$module"
170                 cd $module/$module
171                 msg_begin "  Updating $module repository"
172                 pull
173                 msg_end $?
174                 cd - > /dev/null 2>&1
175             else
176                 log_to_file "Skipping update of $module repository"
177             fi
178         elif [ -d $module/$module ]; then
179             log_to_file "Removing invalid repository at $PWD/$module/$module"
180             rm -rf $module/$module
181         fi
182
183         if [ ! -d $module/$module ]; then
184             cd $module
185             msg_begin "  Cloning $repo/$module.git"
186             clone $repo/$module
187             msg_end $?
188             cd - > /dev/null 2>&1
189         elif [ ! -d $module ]; then
190             error "Directory $module does not exist."
191         fi
192     done
193 }
194
195 function setup_distro() {
196     local target
197     local sources_list_file
198     local target_conf_file
199     local ret
200     target=$1
201     sources_list_file=$__sbox_path/users/$USER/targets/$target/etc/apt/sources.list
202     target_conf_file=$__sbox_path/users/$USER/targets/$target.config
203     ret=1
204
205     log_to_file "setup_distro(): Target $target"
206     log_to_file "setup_distro(): sources.list file : $sources_list_file"
207     log_to_file "setup_distro(): config file: $target_conf_file"
208
209     if [ "x$target" != "x" ] && [ -r $sources_list_file ] && [ -r $target_conf_file ]; then
210         # XXX: FIXME Figure out a better way to get the distro string
211         __distro=`$__head -1 $sources_list_file|cut -d" " -f3`
212         __arch=`grep SBOX_CPU= $target_conf_file|cut -d= -f2`
213         __pkg_dir="$__base_pkg_dir/$__distro/$__arch"
214         __build_pkg_options="$__common_build_pkg_options -sa"
215         if [ "x$__arch" = "xarm" ] ; then
216             __build_pkg_options="$__common_build_pkg_options -B"
217         fi
218         ret=0
219     fi
220
221     if [ $ret -eq 0 ]; then
222         log_to_file "setup_distro(): Configuration:"
223         log_to_file "setup_distro(): distro...........: $__distro"
224         log_to_file "setup_distro(): arch.............: $__arch"
225         log_to_file "setup_distro(): build options....: $__build_pkg_options"
226         log_to_file "setup_distro(): pkg_dir..........: $__pkg_dir"
227     fi
228
229     log_to_file "setup_distro(): Returning $ret"
230
231     return $ret
232 }
233
234 function setup_sbox() {
235     if [ ! -d $__sbox_path ]; then
236         error "Invalid scratchbox path: $__sbox_path"
237     fi
238
239     __sbox="$__sbox_path/login"
240     __sbox_sb_conf="$__sbox /scratchbox/tools/bin/sb-conf"
241
242     __sbox_maemo3_debian_bin_path="/scratchbox/devkits/maemo3-debian/bin"
243     __sbox_dpkg_buildpackage="$__sbox $__sbox_maemo3_debian_bin_path/dpkg-buildpackage"
244
245     __sbox_debian_sarge_bin_path="/scratchbox/devkits/debian-sarge/bin"
246     __sbox_dch="$__sbox $__sbox_debian_sarge_bin_path/dch"
247
248     PATH="$__orig_path:$__sbox_maemo3_debian_bin_path:$__sbox_debian_sarge_bin_path"
249 }
250
251 ###########################################################
252 # Begin script
253 ###########################################################
254
255 # Parse comand line options
256 while getopts "chs:" opt ; do
257     case "$opt" in
258         c)
259             __update_repositories=0
260             ;;
261         h)
262             usage
263             exit 0
264             ;;
265         s)
266             __sbox_path=$OPTARG
267             if [ "x$__sbox_path" = "x" ] || [ ! -d $__sbox_path ]; then
268                 error "Invalid scratchbox path: $__sbox_path"
269             fi
270             ;;
271         [?])
272             usage
273             exit 1
274             ;;
275     esac
276 done
277
278 # Initial checks
279
280 # Check if we're running inside scratchbox
281 if [ -r /targets/links/scratchbox.config ]; then
282     error "You should run this script ouside the scratchbox environment."
283 fi
284
285 # Create base packages dir
286 if [ ! -d $__base_pkg_dir ]; then
287     msg_begin "Creating base packages dir $__base_pkg_dir"
288     $__mkdir -p $__base_pkg_dir
289     msg_end $?
290 fi
291
292 # Create log file
293 create_log_file
294 start_log
295
296 # Download modules under e17/libs
297 msg "Downloading e17 modules"
298 get_sources $__lib_modules $__git_repo$__e17_libs
299
300 # Download python modules under proto/python/efl
301 msg "Downloading python modules"
302 get_sources $__python_modules $__git_repo$__e17_python_efl
303
304 # Download python-etk module
305 get_sources $__python_etk_module $__git_repo$__e17_python_etk
306
307 # Setup scratchbox variables
308 setup_sbox
309
310 # For each scratchbox target
311 for target in `$__sbox_sb_conf list --targets`; do
312     msg_begin "Checking distro and arch for target $target"
313     setup_distro $target
314     msg_end $?
315
316     msg "  Distribution..: $__distro"
317     msg "  Architecture..: $__arch"
318     msg "  Build Options.: $__build_pkg_options"
319
320     if [ ! -d $__pkg_dir ]; then
321         msg_begin "Creating dir for $__distro $__arch packages"
322         $__mkdir -p $__pkg_dir
323         msg_end $?
324     fi
325
326     # For each module
327     for module in `echo $__lib_modules $__python_modules $__python_etk_module|$__sed -e 's/:/ /g'`; do
328         msg "  Building $module packages for $__distro $__arch"
329         cd $module/$module
330
331         if [ -d ./debian ]; then
332             msg_begin "  Removing existing debian directory"
333             rm -rf ./debian
334             msg_end $?
335         fi
336
337         cp -r ../debian .
338
339         # Build package
340         `$__sbox_dpkg_buildpackage $__build_pkg_options >> $__output_file 2>&1`
341
342         # Install packages
343
344         # Clean tree
345         clean
346
347         cd - > /dev/null 2>&1
348     done
349 done
350
351 # Uninstall all packages
352 # END
353 finish_log