-#!/bin/bash
+#!/bin/sh
source "helper-functions.sh"
+
+###########################################################
+# Variable definitions
+###########################################################
__this_script=`basename $0`
__this_script_dir=`dirname $0`
+__orig_path=$PATH
-# git definitions
+# Binaries
+__date=`which date`
__git=`which git`
-__git_clone="$__git clone"
-__git_pull="$__git pull"
-__git_clean="$__git clean"
+__head=`which head`
+__mkdir=`which mkdir`
+__sed=`which sed`
+__uname=`which uname`
+__chmod=`which chmod`
+__grep=`which grep`
+__egrep=`which egrep`
+__debsign=`which debsign`
+
+# git definitions
+__git_clone="$__git clone -q"
+__git_pull="$__git pull -q"
+__git_clean="$__git clean -q -x -d -f"
+__git_reset="$__git reset --hard HEAD"
__git_repo="git://staff.get-e.org/"
-# e17 repositories paths
+# e17 git repositories paths
__e17_libs="e17/libs"
__e17_proto="e17/proto"
__e17_python_efl="$__e17_proto/python-efl"
-__users="users"
-
-# modules
-__lib_modules="edb eet evas ecore embryo edje efreet epeg epsilon emotion etk ewl e_dbus exml enhance"
-__python_modules="python-evas python-ecore python-edje python-epsilon python-e_dbus"
-__user_modules="python-etk"
+__e17_python_etk="users/cmarcelo"
+__e17_python_efl_utils="users/barbieri"
+#__e17_python_dispatcher="users/ulisses"
+
+# modules to build
+#__lib_modules="edb eet evas ecore embryo edje efreet epeg epsilon emotion etk ewl e_dbus exml enhance"
+__lib_modules="eet:evas:ecore:embryo:edje:imlib2:epeg:epsilon:etk:e_dbus"
+__other_modules="himf-ecore:himf-ecore-chinook:lightmediascanner:python-lightmediascanner"
+__python_modules="python-evas:python-ecore:python-edje:python-epsilon:python-e_dbus"
+__python_etk_module="python-etk"
+__python_efl_utils_module="python-efl_utils"
+#__python_dispatcher_module="python-dispatcher"
+__virtual_packages="efl-core python-efl-core"
# dpkg definitions
-__uname=`which uname`
-__arch=`$__uname -m`
__common_build_pkg_options="-rfakeroot -us -uc -D"
-__build_pkg_options="$__common_build_pkg_options -sa"
-if [ "x$__arch" = "xarm" ] ; then
- __build_pkg_options="$__common_build_pkg_options -B"
-fi
-# other definitions
-__date=`which date`
+# Packages dirs and log file
__today=`$__date +%Y%m%d`
-
-__head=`which head`
-__distro=`$__head -1 /etc/apt/sources.list|cut -d" " -f3`
-
__base_pkg_dir="$__this_script_dir/packages_$__today"
-__pkg_dir="$__base_pkg_dir/$__distro/$__arch"
+__output_file="$PWD/$__base_pkg_dir/packages_$__today.log"
-__output_file="$__base_pkg_dir/packages_$__today.log"
+# Scratchbox definitions
+__sbox_path="/scratchbox"
+# Other
+__update_repositories=1
+__installed_packages=""
-function clone() {
- local repo
- repo=$1
- `$__git_clone $repo 2>&1 >> $__output_file`
- return $?
-}
+###########################################################
+# Function definitions
+###########################################################
-function pull() {
- `$__git_pull 2>&1 >> $__output_file`
- return $?
-}
+function usage() {
+ cat << EOF
-function clean() {
- echo "clean"
- return $?
-}
+Usage: $__this_script [OPTIONS]
-function build_pkg() {
- echo "build_pkg"
- return $?
-}
+Build script for EFL debian packages for Maemo.
-function install_pkg() {
- echo "install_pkg"
- return $?
+Options:
+ -c Don't update source repositories.
+ -h Show this usage guide.
+ -s PATH Specify alternate scratchbox path (default: $__sbox_path).
+
+EOF
}
-function uninstall_pkg() {
- echo "uninstall_pkg"
- return $?
+function create_log_file() {
+ if [ ! -r $__output_file ]; then
+ msg_begin "Creating log file"
+ touch $__output_file
+ msg_end $?
+ else
+ msg "Using existing log file: $__output_file"
+ fi
}
function log_to_file() {
msg=$1
if [ ! -r $__output_file ]; then
- error "Log file $__output_file does not exist"
+ error "log_to_file(): Log file does not exist"
fi
now=`$__date +%H:%M:%S`
local now
now=`$__date -R`
- if [ ! -r $__output_file ]; then
- touch $__output_file
- fi
+ echo "" >> $__output_file
if [ $? != 0 ] ; then
- error "Could not create log file $__output_file"
+ error "start_log(): Could not create $__output_file file"
fi
- echo "*********************************************************" >> $__output_file
- echo "* Started $__this_script: $now *" >> $__output_file
- echo "*********************************************************" >> $__output_file
- echo "" >> $__output_file
- echo "Configuration:" >> $__output_file
- echo " Distro.: $__distro" >> $__output_file
- echo " Arch...: $__arch" >> $__output_file
- echo "" >> $__output_file
+ cat << EOF >> $__output_file
+*********************************************************
+* Started $__this_script: $now *
+*********************************************************
+
+EOF
}
function finish_log() {
now=`$__date -R`
if [ ! -r $__output_file ]; then
- error "Log file $__output_file does not exist"
+ error "finish_log(): Log file does not exist"
fi
- echo "" >> $__output_file
- echo "* Finished $__this_script: $now" >> $__output_file
- echo "" >> $__output_file
+ cat << EOF >> $__output_file
+
+* Finished $__this_script: $now
+EOF
+}
+
+function clone_repository() {
+ local repo
+ repo=$1
+ $__git_clone $repo.git >> $__output_file 2>&1
+ return $?
+}
+
+function update_repository() {
+ local repo
+ repo=$1
+
+ if [ ! -d $repo ]; then
+ error " Trying to update invalid repository"
+ fi
+
+ cd $repo
+ $__git_pull >> $__output_file 2>&1 || return 1
+ cd - > /dev/null 2>&1
+
+ return 0
+}
+
+function clean_repository() {
+ local repo
+ repo=$1
+
+ if [ ! -d $repo ]; then
+ error " Trying to clean invalid repository"
+ fi
+
+ cd $repo
+ $__git_reset >> $__output_file 2>&1 || return 1
+ $__git_clean >> $__output_file 2>&1 || return 1
+ cd - > /dev/null 2>&1
+
+ return 0
+}
+
+function configure_pkg() {
+ local dir
+ dir=$1
+
+ cd $dir/`basename $dir`
+
+ if [ -x ./autogen.sh ]; then
+ NOCONFIGURE=1 ./autogen.sh >> $dir/sbox_build_pkgs.log 2>&1 || return 1
+ fi
+
+ cd - > /dev/null 2>&1
+
+ return 0
}
+function build_pkg() {
+ local dir
+ dir=$1
+
+ configure_pkg $dir || return 1
+
+ local DEB_BUILD_OPTIONS=n8x0
+ if [ "x$__distro" = "xgregale" ]; then
+ DEB_BUILD_OPTIONS=n770
+ fi
+
+ cat << EOF > $dir/sbox_build_pkgs
+#!/bin/sh
+
+export DEBFULLNAME="$DEBFULLNAME"
+export DEBEMAIL="$DEBEMAIL"
+export DEB_BUILD_OPTIONS="$DEB_BUILD_OPTIONS"
+
+cd $dir/`basename $dir`
+
+VERSION=\`$__sbox_dpkg_parsechangelog | grep Version: | cut -d" " -f2 | cut -d- -f1 >> $dir/sbox_build_pkgs.log 2>&1 || exit 1\`
+REVISION=\`$__sbox_dpkg_parsechangelog | grep Version: | cut -d- -f2 >> $dir/sbox_build_pkgs.log 2>&1 || exit 1\`
+
+# $__sbox_dch -v \$VERSION+cvs$__today-\$REVISION -D $__distro "Snapshot CVS release of $__today" >> $dir/sbox_build_pkgs.log 2>&1 || exit 1
+$__sbox_dpkg_buildpackage $__build_pkg_options >> $dir/sbox_build_pkgs.log 2>&1
+exit \$?
+EOF
+
+ $__chmod 755 $dir/sbox_build_pkgs
+ $__sbox $dir/sbox_build_pkgs
+ return $?
+}
+
+function install_pkgs() {
+ local dir
+ dir=$1
+
+ cat << EOF > $dir/sbox_install_pkgs
+#!/bin/sh
+
+cd $dir
+$__sbox_dpkg --install *.deb >> $dir/sbox_install_pkgs.log 2>&1
+exit \$?
+EOF
+
+ $__chmod 755 $dir/sbox_install_pkgs
+ $__sbox $dir/sbox_install_pkgs || return 1
+
+ for package in $dir/*.deb; do
+ pkg=`basename $package | cut -d_ -f1`
+ echo $__installed_packages | tr " " "\n" | sort -u | $__egrep "\^$pkg\$" > /dev/null 2>&1
+
+ if [ ! $? -eq 0 ]; then
+ __installed_packages="$__installed_packages $pkg"
+ fi
+ done
+
+ return 0
+}
+
+function uninstall_pkgs() {
+
+ cat << EOF > /tmp/sbox_uninstall_pkgs
+#!/bin/sh
+
+cd /tmp
+$__sbox_dpkg --purge $__installed_packages >> /tmp/sbox_uninstall_pkgs.log 2>&1
+exit \$?
+EOF
+
+ __installed_packages=""
+ $__chmod 755 /tmp/sbox_uninstall_pkgs
+ #$__sbox /tmp/sbox_uninstall_pkgs
+ return $?
+}
+
+function sign_pkgs() {
+ local dir
+ dir=$1
+
+ cd $dir
+ $__debsign *.changes >> $dir/sign_pkgs.log 2>&1 || return 1
+
+ cd - > /dev/null 2>&1
+
+ return 0
+}
+
+function get_sources() {
+ local modules
+ local repo
+ modules=`echo $1|$__sed -e 's/:/ /g'`
+ repo=$2
+
+ for module in $modules; do
+
+ if [ ! -d $module ]; then
+ error "Directory $module does not exist."
+ fi
+
+ cd $module
+
+ if [ -d $module/.git ]; then
+ if [ ! $__update_repositories -eq 0 ]; then
+ log_to_file "Updating existing repository at $PWD/$module"
+
+ msg_begin " Updating $module repository"
+ update_repository $module
+ msg_end $?
+ else
+ log_to_file "Skipping update of $module repository"
+ fi
+ elif [ -d $module ]; then
+ log_to_file "Removing invalid repository at $PWD/$module"
+ rm -rf $module
+ fi
+
+ if [ ! -d $module ]; then
+ msg_begin " Cloning $repo/$module.git"
+ clone_repository $repo/$module
+ msg_end $?
+ fi
+
+ cd ..
+ done
+}
+
+function setup_distro() {
+ local target
+ local sources_list_file
+ local target_conf_file
+ local ret
+ target=$1
+ sources_list_file=$__sbox_path/users/$USER/targets/$target/etc/apt/sources.list
+ target_conf_file=$__sbox_path/users/$USER/targets/$target.config
+ ret=1
+
+ log_to_file "setup_distro(): Target $target"
+ log_to_file "setup_distro(): sources.list file : $sources_list_file"
+ log_to_file "setup_distro(): config file: $target_conf_file"
+
+ if [ "x$target" != "x" ] && [ -r $sources_list_file ] && [ -r $target_conf_file ]; then
+ # XXX: FIXME Figure out a better way to get the distro string
+ __distro=`$__head -1 $sources_list_file | cut -d" " -f3`
+ __arch=`$__grep SBOX_CPU= $target_conf_file | cut -d= -f2`
+ __pkg_dir="$__base_pkg_dir/$__distro/$__arch"
+ if [ "x$__arch" = "xarm" ] ; then
+ __build_pkg_options="$__common_build_pkg_options -B"
+ else
+ __build_pkg_options="$__common_build_pkg_options -I.svn -I.git -I.gitignore -I.cvsignore -sa"
+ fi
+ ret=0
+ fi
+
+ if [ $ret -eq 0 ]; then
+ log_to_file "setup_distro(): Configuration:"
+ log_to_file "setup_distro(): distro...........: $__distro"
+ log_to_file "setup_distro(): arch.............: $__arch"
+ log_to_file "setup_distro(): build options....: $__build_pkg_options"
+ log_to_file "setup_distro(): pkg_dir..........: $__pkg_dir"
+ fi
+
+ return $ret
+}
+
+function setup_sbox() {
+ if [ ! -d $__sbox_path ]; then
+ error "Invalid scratchbox path: $__sbox_path"
+ fi
+
+ __sbox="$__sbox_path/login"
+ __sbox_tools_bin_path="$__sbox_path/tools/bin"
+ __sbox_sb_conf="$__sbox_tools_bin_path/sb-conf"
+
+ __sbox_maemo3_debian_bin_path="/scratchbox/devkits/maemo3-debian/bin"
+ __sbox_dpkg="$__sbox_maemo3_debian_bin_path/dpkg"
+ __sbox_dpkg_buildpackage="$__sbox_dpkg-buildpackage"
+ __sbox_dpkg_parsechangelog="$__sbox_dpkg-parsechangelog"
+
+ __sbox_debian_sarge_bin_path="/scratchbox/devkits/debian-sarge/bin"
+ __sbox_dch="$__sbox_debian_sarge_bin_path/dch"
+}
+
+function change_sbox_target() {
+ local target
+ target=$1
+
+ $__sbox_sb_conf select $target >> $__output_file 2>&1
+ return $?
+}
+
+###########################################################
+# Begin script
+###########################################################
+
+# Parse comand line options
+while getopts "chs:" opt ; do
+ case "$opt" in
+ c)
+ __update_repositories=0
+ ;;
+ h)
+ usage
+ exit 0
+ ;;
+ s)
+ __sbox_path=$OPTARG
+ if [ "x$__sbox_path" = "x" ] || [ ! -d $__sbox_path ]; then
+ error "Invalid scratchbox path: $__sbox_path"
+ fi
+ ;;
+ [?])
+ usage
+ exit 1
+ ;;
+ esac
+done
+
# Initial checks
+
# Check if we're running inside scratchbox
-msg_begin "Checking for scratchbox environment"
-test -r /targets/links/scratchbox.config
-msg_end $?
+if [ -r /targets/links/scratchbox.config ]; then
+ error "You should run this script ouside the scratchbox environment."
+fi
-# Begin
-mkdir -p $__pkg_dir
+# Create base packages dir
+if [ ! -d $__base_pkg_dir ]; then
+ msg_begin "Creating base packages dir $__base_pkg_dir"
+ $__mkdir -p $__base_pkg_dir
+ msg_end $?
+fi
+
+# Create log file
+create_log_file
start_log
-log_to_file "Created $__pkg_dir"
-# Check for fakeroot
+# Download modules under e17/libs
+msg "Downloading e17 modules"
+get_sources $__lib_modules $__git_repo$__e17_libs
+
+# Download python modules under proto/python/efl
+msg "Downloading python modules"
+get_sources $__python_modules $__git_repo$__e17_python_efl
-# Download official modules
+# Download python-etk module
+get_sources $__python_etk_module $__git_repo$__e17_python_etk
-# Build package
+# Download python-efl-utils module
+get_sources $__python_efl_utils_module $__git_repo$__e17_python_efl_utils
-# Install package
+# Download python-dispatcher module
+#get_sources $__python_dispatcher_module $__git_repo$__e17_python_dispatcher
-# Download user modules (python-etk)
+# Setup scratchbox variables
+setup_sbox
-# Build package
+###########################################################
+# ARCHITECTURE DEPENDENT MODULES
+###########################################################
+# For each scratchbox target
+for target in `$__sbox_sb_conf list --targets`; do
+ msg_begin "Checking distro and arch for target $target"
+ setup_distro $target
+ msg_end $?
-# Install package
+ msg " Distribution..: $__distro"
+ msg " Architecture..: $__arch"
+ msg " Build Options.: $__build_pkg_options"
+
+ if [ ! -d $__pkg_dir ]; then
+ msg_begin " Creating dir for $__distro $__arch packages"
+ $__mkdir -p $__pkg_dir
+ msg_end $?
+ fi
+
+ msg_begin " Changing current sbox target to $target"
+ change_sbox_target $target
+ msg_end $?
+
+ # For each module
+ for module in `echo $__lib_modules:$__python_modules:$__python_etk_module|$__sed -e 's/:/ /g'`; do
+ msg " Building $module packages for $__distro $__arch"
+
+ if [ -d ./$module/$module/debian ]; then
+ msg_begin " Removing existing debian directory"
+ rm -rf ./$module/$module/debian
+ msg_end $?
+ fi
+
+ msg_begin " Copying specific debian directory"
+ if [ -d ./$module/debian ]; then
+ cp -r ./$module/debian ./$module/$module/
+
+ if [ -d ./$module/debian_$__distro ]; then
+ cp -r ./$module/debian_$__distro/* ./$module/$module/debian/
+ fi
+ else
+ if [ -d ./$module/debian_$__distro ]; then
+ cp -r ./$module/debian_$__distro ./$module/$module/debian
+ else
+ echo ""
+ warn "Missing debian directory for $module. Ignoring"
+ continue
+ fi
+ fi
+ msg_end $?
+
+ if [ -d /tmp/$module/$module ]; then
+ msg_begin " Removing temporary $module"
+ rm -rf /tmp/$module/$module
+ msg_end $?
+ fi
+
+ msg_begin " Copying $module dir to /tmp"
+ cp -u -r $module /tmp
+ msg_end $?
+
+ msg_begin " Cleaning $module repository"
+ clean_repository $module/$module
+ msg_end $?
+
+ msg_begin " Building $module packages"
+ build_pkg /tmp/$module
+ msg_end $?
+
+ msg_begin " Signing $module packages"
+ sign_pkgs /tmp/$module
+ msg_end $?
+
+ msg_begin " Installing $module packages"
+ install_pkgs /tmp/$module
+ msg_end $?
+
+ msg_begin " Copying $module packages"
+ if [ "x$__arch" != "xarm" ]; then
+ mv /tmp/$module/*.dsc /tmp/$module/*.tar.gz $__pkg_dir
+ fi
+ mv /tmp/$module/*.deb /tmp/$module/*.changes $__pkg_dir
+ msg_end $?
+
+ msg_begin " Removing temporary $module"
+ rm -rf /tmp/$module/$module
+ msg_end $?
+ done
+
+ msg_begin " Uninstalling packages $__installed_packages"
+ uninstall_pkgs
+ msg_end $?
+done
+
+exit 0
+###########################################################
+# ARCHITECTURE INDEPENDENT MODULES
+###########################################################
+# For each scratchbox target
+for target in `$__sbox_sb_conf list --targets`; do
+ msg_begin "Checking distro and arch for target $target"
+ setup_distro $target
+ msg_end $?
+
+ msg " Distribution..: $__distro"
+ msg " Architecture..: $__arch"
+ msg " Build Options.: $__build_pkg_options"
+
+ if [ "x$__arch" = "xarm" ]; then
+ warn "Skipping target $target for architecture independent packages"
+ continue
+ fi
+
+ __arch="all"
+ __pkg_dir=`dirname $__pkg_dir`/$__arch
+
+ if [ ! -d $__pkg_dir ]; then
+ msg_begin " Creating dir for $__distro $__arch packages"
+ $__mkdir -p $__pkg_dir
+ msg_end $?
+ fi
+
+ msg_begin " Changing current sbox target to $target"
+ change_sbox_target $target
+ msg_end $?
+
+ # For each module
+ for module in $__python_efl_utils_module; do
+ msg " Building $module packages for $__distro $__arch"
+
+ if [ ! -d /tmp/$module ]; then
+ mkdir /tmp/$module
+ fi
+
+ if [ -d /tmp/$module/$module ]; then
+ msg_begin " Removing temporary $module"
+ rm -rf /tmp/$module/$module
+ msg_end $?
+ fi
+
+ msg_begin " Copying specific debian directory"
+ if [ -d ./$module/debian ]; then
+ cp -r ./$module/debian ./$module/$module/
+
+ if [ -d ./$module/debian_$__distro ]; then
+ cp -r ./$module/debian_$__distro/* ./$module/$module/debian/
+ fi
+ else
+ echo ""
+ warn " Missing debian directory for $module. Ignoring"
+ continue
+ fi
+ msg_end $?
+
+ msg_begin " Copying $module dir to /tmp"
+ cp -u -r $module /tmp
+ msg_end $?
+
+ msg_begin " Cleaning $module repository"
+ clean_repository $module/$module
+ msg_end $?
+
+ msg_begin " Building $module packages"
+ build_pkg /tmp/$module
+ msg_end $?
+
+ msg_begin " Signing $module packages"
+ sign_pkgs /tmp/$module
+ msg_end $?
+
+ msg_begin " Installing $module packages"
+ install_pkgs /tmp/$module
+ msg_end $?
+
+ msg_begin " Copying $module packages"
+ mv /tmp/$module/*.dsc /tmp/$module/*.tar.gz /tmp/$module/*.deb /tmp/$module/*.changes $__pkg_dir
+ msg_end $?
+
+ msg_begin " Removing temporary $module"
+ rm -rf /tmp/$module/$module
+ msg_end $?
+ done
+
+ msg_begin " Uninstalling packages $__installed_packages"
+ uninstall_pkgs
+ msg_end $?
+done
+
+###########################################################
+# VIRTUAL PACKAGES
+###########################################################
+# For each scratchbox target
+for target in `$__sbox_sb_conf list --targets`; do
+ msg_begin "Checking distro and arch for target $target"
+ setup_distro $target
+ msg_end $?
+
+ msg " Distribution..: $__distro"
+ msg " Architecture..: $__arch"
+ msg " Build Options.: $__build_pkg_options"
+
+ if [ "x$__arch" = "xarm" ]; then
+ warn "Skipping target $target for architecture independent packages"
+ continue
+ fi
+
+ __arch="all"
+ __pkg_dir=`dirname $__pkg_dir`/$__arch
+
+ if [ ! -d $__pkg_dir ]; then
+ msg_begin " Creating dir for $__distro $__arch packages"
+ $__mkdir -p $__pkg_dir
+ msg_end $?
+ fi
-# Uninstall all packages
+ msg_begin " Changing current sbox target to $target"
+ change_sbox_target $target
+ msg_end $?
+
+ # For each module
+ for module in $__virtual_packages; do
+ msg " Building $module packages for $__distro $__arch"
+
+ if [ ! -d /tmp/$module ]; then
+ mkdir /tmp/$module
+ fi
+
+ if [ -d /tmp/$module/$module ]; then
+ msg_begin " Removing temporary $module"
+ rm -rf /tmp/$module/$module
+ msg_end $?
+ fi
+
+ msg_begin " Copying $module dir to /tmp"
+ cp -u -r $module /tmp/$module
+ msg_end $?
+
+ msg_begin " Building $module packages"
+ build_pkg /tmp/$module
+ msg_end $?
+
+ msg_begin " Signing $module packages"
+ sign_pkgs /tmp/$module
+ msg_end $?
+
+ msg_begin " Installing $module packages"
+ install_pkgs /tmp/$module
+ msg_end $?
+
+ msg_begin " Copying $module packages"
+ mv /tmp/$module/*.dsc /tmp/$module/*.tar.gz /tmp/$module/*.deb /tmp/$module/*.changes $__pkg_dir
+ msg_end $?
+
+ msg_begin " Removing temporary $module"
+ rm -rf /tmp/$module/$module
+ msg_end $?
+ done
+
+ msg_begin " Uninstalling packages $__installed_packages"
+ uninstall_pkgs
+ msg_end $?
+done
# END
finish_log