New version of build scripts
[maemo-efl] / trunk / scripts / package-functions.sh
1 #!/bin/sh
2
3 ###########################################################
4 # Maemo-efl building script
5 # Package functions definitions
6 #
7 # Note: var-definitions.sh needed.
8 ###########################################################
9
10 function configure_pkg() {
11     local dir
12     dir=$1
13
14     cd $dir/`basename $dir`
15
16     if [ -x ./autogen.sh ]; then
17         NOCONFIGURE=1 ./autogen.sh >> $dir/sbox_build_pkgs.log 2>&1 || return 1
18     fi
19
20     cd - > /dev/null 2>&1
21
22     return 0
23 }
24
25 function build_pkg() {
26     local dir
27     dir=$1
28
29     configure_pkg $dir || return 1
30
31     local DEB_BUILD_OPTIONS=n8x0
32     if [ "x$__distro" = "xgregale" ]; then
33         DEB_BUILD_OPTIONS=n770
34     fi
35
36     cat << EOF > $dir/sbox_build_pkgs
37 #!/bin/sh
38
39 export DEBFULLNAME="$DEBFULLNAME"
40 export DEBEMAIL="$DEBEMAIL"
41 export DEB_BUILD_OPTIONS="$DEB_BUILD_OPTIONS"
42
43 cd $dir/`basename $dir`
44
45 #VERSION=\`$__sbox_dpkg_parsechangelog | grep Version: | cut -d" " -f2 | cut -d- -f1 >> $dir/sbox_build_pkgs.log 2>&1 || exit 1\`
46 #REVISION=\`$__sbox_dpkg_parsechangelog | grep Version: | cut -d- -f2 >> $dir/sbox_build_pkgs.log 2>&1 || exit 1\`
47
48 VERSION=\`$__sbox_dpkg_parsechangelog | grep Version: | cut -d" " -f2 | cut -d- -f1\`
49 REVISION=\`$__sbox_dpkg_parsechangelog | grep Version: | cut -d- -f2\`
50
51 TO_REPLACE=\`grep -o -E '@([A-Z]|[0-9])+(-|_)*([A-Z]|[0-9])+_VERSION@' ./debian/control.in | cut -d @ -f 2 | sort -u\`
52
53 # Test if we should process control.in file or not.
54 if [ -z $__not_all_pkgs ]; then
55     cp ./debian/control.in ./debian/control.temp
56
57     for replacement in \$TO_REPLACE
58     do
59         replacement_lowercase=\`echo \$replacement | tr "[:upper:]" "[:lower:]"\`
60         version_file=$__versions_dir/\$replacement_lowercase
61         version_number=\`cat \$version_file\`
62         sed -i s/@\$replacement@/\$version_number/g ./debian/control.temp
63     done
64
65     mv ./debian/control.temp ./debian/control
66 else
67     builddeps=\`$__sbox_dpkg_checkbuilddeps ./debian/control 2>&1 | grep Unmet | cut -d: -f3\`
68     target_lowercase=\`echo $target | cut -d_ -f1 | tr "[:upper:]" "[:lower:]"\`
69
70     if [ -z $__pkgslist_updated ];then
71
72         has_extras_rep=\`grep 'deb http://repository.maemo.org/extras' $__srclist_file\`
73         if [ -z "\$has_extras_rep" ];then
74             echo "deb http://repository.maemo.org/extras \$target_lowercase free non-free" >> $__srclist_file
75         fi
76
77         has_extras_rep=\`grep 'deb-src http://repository.maemo.org/extras' $__srclist_file\`
78         if [ -z "\$has_extras_rep" ];then
79             echo "deb-src http://repository.maemo.org/extras \$target_lowercase free non-free" >> $__srclist_file
80         fi
81
82         apt-get update >> $dir/sbox_apt_update.log 2>&1
83         __pkgslist_updated=1
84     fi
85
86     if [ -n "\$builddeps" ];then
87         echo \$builddeps | while read line
88         do
89             pkg_name=\`echo \$line | cut -d'(' -f1 | tr -d "[:blank:]"\`
90             pkg_version=\`echo \$line | cut -d= -f2 | cut -d')' -f1 | tr -d "[:blank:]"\`
91             apt-get -y install \$pkg_name=\$pkg_version >> $dir/sbox_builddeps.log 2>&1
92         done
93     fi
94 fi
95
96 # $__sbox_dch -v \$VERSION+cvs$__today-\$REVISION -D $__distro "Snapshot CVS release of $__today" >> $dir/sbox_build_pkgs.log 2>&1 || exit 1
97 $__sbox_dpkg_buildpackage $__build_pkg_options >> $dir/sbox_build_pkgs.log 2>&1
98
99 if [ -z \$REVISION ]
100 then
101     echo "\$VERSION" > $__versions_dir/`basename $dir`_version
102 else
103     echo "\$VERSION-\$REVISION" >  $__versions_dir/`basename $dir`_version
104 fi
105
106 exit \$?
107 EOF
108
109     $__chmod 755 $dir/sbox_build_pkgs
110     $__sbox $dir/sbox_build_pkgs
111     return $?
112 }
113
114 function install_pkgs() {
115     local dir
116     dir=$1
117
118     cat << EOF > $dir/sbox_install_pkgs
119 #!/bin/sh
120
121 cd $dir
122 $__sbox_dpkg --install *.deb >> $dir/sbox_install_pkgs.log 2>&1
123 exit \$?
124 EOF
125
126     $__chmod 755 $dir/sbox_install_pkgs
127     $__sbox $dir/sbox_install_pkgs || return 1
128
129     for package in $dir/*.deb; do
130         pkg=`basename $package | cut -d_ -f1`
131         echo $__installed_packages | tr " " "\n" | sort -u | $__egrep "\^$pkg\$" > /dev/null 2>&1
132
133         if [ ! $? -eq 0 ]; then
134             __installed_packages="$__installed_packages $pkg"
135         fi
136     done
137
138     return 0
139 }
140
141 function uninstall_pkgs() {
142
143     cat << EOF > $__tmp_dir/sbox_uninstall_pkgs
144 #!/bin/sh
145
146 cd $__tmp_dir
147 $__sbox_dpkg --purge $__installed_packages >> $__tmp_dir/sbox_uninstall_pkgs.log 2>&1
148 exit \$?
149 EOF
150
151     __installed_packages=""
152     $__chmod 755 $__tmp_dir/sbox_uninstall_pkgs
153     #$__sbox $__tmp_dir/sbox_uninstall_pkgs
154     return $?
155 }
156
157 function sign_pkgs() {
158     local dir
159     dir=$1
160
161     cd $dir
162     $__debsign *.changes >> $dir/sign_pkgs.log 2>&1 || return 1
163
164     cd - > /dev/null 2>&1
165
166     return 0
167 }
168