Magellan Linux

Contents of /trunk/mage-buildroot/mage-buildroot.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 720 - (show annotations) (download) (as text)
Wed Apr 23 16:07:00 2008 UTC (16 years ago) by niro
File MIME type: application/x-sh
File size: 6542 byte(s)
-several fixups

1 #!/bin/bash
2 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage-buildroot/mage-buildroot.sh,v 1.4 2008-04-23 16:07:00 niro Exp $
3 #
4 # mage buildroot
5 # creates a buildroot to compile programms
6 # may get later into mage
7 #
8 # Niels Rogalla <niro@magellan-linux.de>
9 #
10
11 # default die function
12 die()
13 {
14 echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT}
15 echo -e ${COLRED}"$@"${COLDEFAULT}
16 exit 1
17 }
18
19 installrc()
20 {
21 local var="$1"
22
23 # sanity checks
24 [ -z "${MROOT}" ] && die "\$MROOT not given."
25 echo "${var}" >> ${MROOT}/.installrc || die "add_initrc() adding \$var"
26 }
27
28 enter_chroot()
29 {
30 [ ! -d ${MROOT}/proc ] && install -d ${MROOT}/proc
31 [ ! -d ${MROOT}/dev ] && install -d ${MROOT}/dev
32 [ ! -d ${MROOT}/sys ] && install -d ${MROOT}/sys
33
34 mount -t proc proc ${MROOT}/proc
35 mount -t sysfs sysfs ${MROOT}/sys
36 mount -o bind /dev ${MROOT}/dev
37
38 if [[ ${SMAGE_USE_CCACHE} = true ]] || [[ -f ${MROOT}/.ccache_enabled ]]
39 then
40 [ ! -d ${MROOT}/root/.ccache ] && install -d ${MROOT}/root/.ccache
41 mount -o bind /root/.ccache ${MROOT}/root/.ccache
42 fi
43
44 chroot ${MROOT} /usr/bin/env -i \
45 HOME=/root \
46 TERM="${TERM}" \
47 PS1='\u:\w\$ ' \
48 PATH=/bin:/usr/bin:/sbin:/usr/sbin \
49 /bin/bash /.installrc #|| die "chr00ting"
50
51 umount ${MROOT}/dev
52 umount ${MROOT}/proc
53 umount ${MROOT}/sys
54
55 [ -f ${MROOT}/.installrc ] && rm ${MROOT}/.installrc
56 }
57
58 # some sane defaults
59 MROOT="$1"
60 TARGET_PKG="$2"
61 MAGERC="/etc/mage.rc"
62 #MAGERC="/home/tjoke/mage.rc-buildroot"
63 MAGE_PROFILE="$(basename $(readlink /etc/mage-profile))"
64 TOOLCHAIN=toolchain
65 BASESYSTEM=common-devutils
66
67 [[ $(id -u ) != 0 ]] && die "you must be root"
68
69 # i need some settings and functions from mage
70 [ -f /etc/rc.d/init.d/functions ] && \
71 source /etc/rc.d/init.d/functions || \
72 die "Your /etc/mage.rc is missing. Aborting."
73
74 [ -f /etc/mage.rc.global ] && \
75 source /etc/mage.rc.global || \
76 die "/etc/mage.rc.global missing"
77
78 [ -f ${MAGERC} ] && source ${MAGERC} || \
79 die "Your /etc/mage.rc is missing. Aborting."
80
81 [ -f ${MLIBDIR}/mage4.functions.sh ] && \
82 source ${MLIBDIR}/mage4.functions.sh || \
83 die "mage functions missing"
84
85 # sanity checks
86 [[ -z ${MROOT} ]] && die "\$MROOT not given."
87 [[ -z ${TARGET_PKG} ]] && die "\$TARGET_PKG not given."
88
89 # first install a toolchain and some common dev-utils using bootstrap2
90 # only if not already builded
91 if [ ! -f ${MROOT}/.buildroot_build_ok-${TOOLCHAIN}-${BASESYSTEM} ]
92 then
93 mage-bootstrap \
94 --root "${MROOT}" \
95 --magerc "${MAGERC}" \
96 --profile "${MAGE_PROFILE}" \
97 --toolchain "${TOOLCHAIN}" \
98 --basesystem "${BASESYSTEM}" \
99 || die "bootstrapping toolchain"
100
101 # mark this as builded
102 touch ${MROOT}/.buildroot_build_ok-${TOOLCHAIN}-${BASESYSTEM} || die "touch ok"
103
104 # enable ccache
105 [[ ${SMAGE_USE_CCACHE} = true ]] && touch ${MROOT}/.ccache_enabled
106 fi
107
108 #####################################################
109 # setup a chroot environment #
110 #####################################################
111 :> ${MROOT}/.installrc || die
112
113 # some needed env-vars and functions
114 installrc 'unset MROOT'
115 installrc 'env-rebuild'
116 installrc 'source /etc/profile'
117 installrc 'die() { echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT};echo -e ${COLRED}"$@"${COLDEFAULT}; exit 1; }'
118 installrc '[ -f /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions' # || die "Your /etc/mage.rc is missing. Aborting."'
119 installrc '[ -f /etc/mage.rc.global ] && . /etc/mage.rc.global' # || die "/etc/mage.rc.global missing"'
120 installrc '[ -f /etc/mage.rc ] && . /etc/mage.rc' # || die "Your /etc/mage.rc is missing. Aborting."'
121 installrc '[ -f ${MLIBDIR}/mage4.functions.sh ] && . ${MLIBDIR}/mage4.functions.sh' # || die "mage functions missing"'
122 installrc "export FAKE_MROOT=\"${MROOT}\""
123 installrc "export TARGET_PKG=\"${TARGET_PKG}\""
124
125 # update mage only if buildroot already exists
126 [ -f ${MROOT}/.buildroot_build_ok-${TOOLCHAIN}-${BASESYSTEM} ] && installrc 'mage update'
127 installrc 'smage2 update'
128
129 # run part
130 cat >> ${MROOT}/.installrc << "EOF"
131
132 #####################################################
133 # now calculate the src-dependencies for TARGET_PKG #
134 #####################################################
135
136 # before anything run mage_setup
137 mage_setup || die "error in mage_setup()"
138
139 # first of all get the right pkg which going to be installed
140 PCAT="$(pname2pcat ${TARGET_PKG})"
141
142 # package does not exists
143 [ -z "${PCAT}" ] && die "Package '${TARGET_PKG}' does not exist."
144
145 # source the highest magefile of this pkg
146 PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${TARGET_PKG}))
147
148 # convert PKGNAME to PNAME/PVER/PBUILD
149 # we're working *only* with these three vars from here on
150 PNAME="$(pkgname2pname ${PKGNAME})"
151 PVER="$(pkgname2pver ${PKGNAME})"
152 PBUILD="$(pkgname2pbuild ${PKGNAME})"
153
154 if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD}
155 then
156 echo -en "Package "
157 echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
158 echo -e " already installed."
159 exit 3
160 fi
161
162 # get all dependencies of this package
163 echo
164 echo -n "Calculating dependencies ... "
165 ALLDEPS="$(${MLIBDIR}/depwalker.sh \
166 --method srcinstall \
167 --pcat ${PCAT} \
168 --pname ${PNAME} \
169 --pver ${PVER} \
170 --pbuild ${PBUILD})"
171 echo "done"
172
173 # remove TARGET_PKG from list
174 SRC_INSTALL_DEPS="$(get_highest_magefile ${PCAT} ${TARGET_PKG})"
175 INSTALL_DEPS="${ALLDEPS/${SRC_INSTALL_DEPS}/}"
176
177 echo
178 echo "---- environment -----"
179 echo "MROOT: ${FAKE_MROOT}"
180 echo "PKGDIR: ${PKGDIR}"
181 echo "BUILDDIR: ${BUILDDIR}"
182 echo "BINDIR: ${BINDIR}"
183 echo "----------------------"
184 echo
185 echo "---- dependencies ----"
186 echo "SRC_INSTALL_DEPS:"
187 for i in ${SRC_INSTALL_DEPS}
188 do
189 echo " * ${i}"
190 done
191 echo "INSTALL_DEPS:"
192 for i in ${INSTALL_DEPS}
193 do
194 echo " * ${i}"
195 done
196 echo "----------------------"
197
198 #read
199
200 # now install the packages (no srcinstall, when the user not explcitly want this)
201 fetch_packages ${INSTALL_DEPS} || die "fetching packages"
202 md5sum_packages ${INSTALL_DEPS} || die "md5 sum packages"
203 unpack_packages ${INSTALL_DEPS} || die "unpacking packages"
204 install_packages ${INSTALL_DEPS} || die "installing packages"
205
206 # whipe out all packages
207 mage clean
208
209 # now src-install TARGET_PKG
210 install_packages --src-install ${SRC_INSTALL_DEPS} || die "src-installing packages"
211
212 # done
213 [[ ! -d /BUILDED ]] && install -d /BUILDED
214 mv ${PKGDIR}/${PNAME}-${PVER}-${ARCH}-${PBUILD}.mpk /BUILDED || die "pkg move"
215 echo -e "Package ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT} successfully builded."
216 echo "You will find this in ${FAKE_MROOT}/BUILDED."
217 EOF
218
219 # run this stuff
220 enter_chroot

Properties

Name Value
svn:executable *