2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
25 #a prebuilt toolchain package is only used if found in cache
26 if [ ! -d $BASEDIR/cache
]; then
27 exiterror
"Use make.sh downloadsrc first!"
29 cd $BASEDIR/cache
/toolchains
30 PACKAGE
=`ls -v -r $TOOLCHAINNAME.tar.bz2 2> /dev/null | head -n 1`
31 #only restore on a clean disk
33 echo -ne "Building for ${BOLD}${MACHINE} on ${MACHINE_REAL}${NORMAL}\n"
35 if [ -f $BASEDIR/log_
${MACHINE}/02_base
/stage2-LFS
]; then
37 echo "Using installed toolchain" >> $LOGFILE
38 beautify message DONE
"Stage toolchain already built or extracted"
40 if [ -z "$PACKAGE" ]; then
41 echo "Full toolchain compilation" |
tee -a $LOGFILE
44 .
$BASEDIR/tools
/make-check
47 beautify build_stage
"Building toolchain"
50 echo "Restore from $PACKAGE" |
tee -a $LOGFILE
51 if [ `md5sum $BASEDIR/cache/toolchains/$PACKAGE | awk '{print $1}'` == `cat $BASEDIR/cache/toolchains/$TOOLCHAINNAME.md5 | awk '{print $1}'` ]; then
52 cd $BASEDIR && tar jxf
$BASEDIR/cache
/toolchains
/$PACKAGE
55 exiterror
"$TOOLCHAINNAME md5 did not match, check downloaded package"
60 beautify build_stage
"Building base"
63 beautify build_stage
"Building $SNAME"
66 beautify build_stage
"Building miscellaneous"
69 beautify build_stage
"Building installer"
72 beautify build_stage
"Building packages"
76 echo "... and all this hard work for this:"
77 du
-bsh $BASEDIR/${SNAME}-${VERSION}.${MACHINE}.iso
81 # enter a shell inside LFS chroot
82 # may be used to change kernel settings
88 echo -ne "Cleaning ${BOLD}$MACHINE${NORMAL} buildtree"
89 for i
in `mount | grep $BASEDIR | sed 's/^.*loop=\(.*\))/\1/'`
91 $LOSETUP -d $i 2>/dev
/null
94 for i
in `mount | grep $BASEDIR | cut -d " " -f 1`
103 if ( losetup
/dev
/loop
${i} 2>/dev
/null |
grep -q "/install/images" ); then
104 umount
/dev
/loop
${i} 2>/dev
/null
;
105 losetup
-d /dev
/loop
${i} 2>/dev
/null
;
109 rm -rf $BASEDIR/build_
${MACHINE}
110 rm -rf $BASEDIR/log_
${MACHINE}
111 rm -rf $BASEDIR/packages
113 if [ -h $TOOLS_DIR ]; then
116 beautify message DONE
120 LOGFILE
=$BASEDIR/log_
${MACHINE}/_build.preparation.log
122 if [ ! -d $BASEDIR/cache
]; then
125 mkdir
-p $BASEDIR/log_
${MACHINE}
126 echo -e "${BOLD}Preload all source files${NORMAL}" |
tee -a $LOGFILE
129 if [ -f "$i" -a "$i" != "Config" ]; then
130 echo -ne "Loading $i"
131 make -s -f $i LFS_BASEDIR
=$BASEDIR MESSAGE
="$i\t" download
>> $LOGFILE 2>&1
132 if [ $?
-ne 0 ]; then
133 beautify message FAIL
135 beautify message DONE
144 # Check if host can build the toolchain
145 check_toolchain_prerequisites
147 echo "Create toolchain tar.bz for $MACHINE" |
tee -a $LOGFILE
148 # Safer inside the chroot
149 echo -ne "Stripping lib"
150 chroot
$LFS $TOOLS_DIR/bin
/find $TOOLS_DIR/lib \
151 -type f \
( -name '*.so' -o -name '*.so[\.0-9]*' \
) \
152 -exec $TOOLS_DIR/bin
/strip
--strip-debug {} \
; 2>/dev
/null
153 beautify message DONE
154 echo -ne "Stripping binaries"
155 chroot
$LFS $TOOLS_DIR/bin
/find /usr
/local /usr
/src
/binutils-build
$TOOLS_DIR/bin
$TOOLS_DIR/sbin \
157 -exec $TOOLS_DIR/bin
/strip
--strip-all {} \
; 2> /dev
/null
158 beautify message DONE
160 echo -ne "Tar creation "
161 [ -d cache
/toolchains
] || mkdir cache
/toolchains
162 cd $BASEDIR && tar cj \
163 --exclude='log_${MACHINE}/_build.*.log' \
164 --file=cache
/toolchains
/$TOOLCHAINNAME.
tar.bz2 \
166 log_
${MACHINE} >> $LOGFILE
167 beautify message DONE
168 echo `ls -sh cache/toolchains/$TOOLCHAINNAME.tar.bz2`
169 md5sum cache
/toolchains
/$TOOLCHAINNAME.
tar.bz2 \
170 > cache
/toolchains
/$TOOLCHAINNAME.md5
176 if [ ! -f $BASEDIR/cache
/toolchains
/$TOOLCHAINNAME.
tar.bz2
]; then
177 URL_TOOLCHAIN
=`grep URL_TOOLCHAIN lfs/Config | awk '{ print $3 }'`
178 test -d $BASEDIR/cache
/toolchains || mkdir
$BASEDIR/cache
/toolchains
179 echo "Loading toolchain for $MACHINE"
180 cd $BASEDIR/cache
/toolchains
181 wget
-c -nv $URL_TOOLCHAIN/$TOOLCHAINNAME.
tar.bz2
$URL_TOOLCHAIN/$TOOLCHAINNAME.md5
182 if [ $?
-ne 0 ]; then
183 echo -n "ERROR: Downloading toolchain for $MACHINE machine"
184 beautify message FAIL
185 echo "Precompiled toolchain not always available for every machine"
187 if [ "`md5sum $TOOLCHAINNAME.tar.bz2 | awk '{print $1}'`" = "`cat $TOOLCHAINNAME.md5 | awk '{print $1}'`" ]; then
188 beautify message DONE
189 echo "Toolchain md5 ok"
191 exiterror
"$TOOLCHAINNAME.md5 did not match, check downloaded package"
195 echo -n "Toolchain for $MACHINE is already existing"
196 beautify message SKIP
202 echo -ne "`date -u '+%b %e %T'`: Build sources iso for $MACHINE" |
tee -a $LOGFILE
203 chroot
$LFS /tools
/bin
/env
-i HOME
=/root \
204 TERM
=$TERM PS1
='\u:\w\$ ' \
205 PATH
=/usr
/local
/bin
:/bin
:/usr
/bin
:/sbin
:/usr
/sbin \
206 VERSION
=$VERSION NAME
="$NAME" SNAME
="$SNAME" MACHINE
=$MACHINE \
207 /bin
/bash
-x -c "cd /usr/src/lfs && make -f sources-iso LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
208 mv $LFS/install
/images
/ipfire-
* $BASEDIR >> $LOGFILE 2>&1
209 if [ $?
-eq "0" ]; then
210 beautify message DONE
212 beautify message FAIL
218 .
$BASEDIR/tools
/make-subversion
243 echo -e "Uploading cache to ftp server:"
245 echo "${i}" | fgrep
-q .md5
&& continue
246 [ -e ${i}.md5
] && continue
247 md5sum ${i} |
tee ${i}.md5
249 ncftpls
-u $FTP_CACHE_USER -p $FTP_CACHE_PASS ftp://$FTP_CACHE_URL/$FTP_CACHE_PATH/ > /tmp
/ftplist
251 if [ "$(basename $i)" == "toolchains" ]; then continue; fi
252 grep -q $
(basename $i) /tmp
/ftplist
253 if [ "$?" -ne "0" ]; then
254 echo -ne "$(basename $i)"
255 ncftpput
-u $FTP_CACHE_USER -p $FTP_CACHE_PASS $FTP_CACHE_URL $FTP_CACHE_PATH/ $
(basename $i)
256 if [ "$?" -ne "0" ]; then
257 beautify message FAIL
267 FTP_ISO_PORT
=`echo "$FTP_ISO_URL" | awk -F: '{ print $2 }'`
268 FTP_ISO_URL
=`echo "$FTP_ISO_URL" | awk -F: '{ print $1 }'`
269 if [ -z $FTP_ISO_PORT ]; then
272 cat <<EOF > .ftp-commands
273 mkdir -p $FTP_ISO_PATH$SVN_REVISION
274 mkdir -p $FTP_ISO_PATH$SVN_REVISION/paks
277 ncftp
-u $FTP_ISO_USER -p $FTP_ISO_PASS -P $FTP_ISO_PORT $FTP_ISO_URL < .ftp-commands
282 echo -e "Uploading the iso to $FTP_ISO_PATH/$SVN_REVISION."
284 md5sum ipfire-
$VERSION.
$MACHINE-full.iso
> ipfire-
$VERSION.
$MACHINE-full.iso.md5
285 for i
in svn_status ipfire-source-r
$SVN_REVISION.
tar.gz ipfire-
$VERSION.
$MACHINE-full.iso ipfire-
$VERSION.
$MACHINE-full.iso.md5 ipfire-
$VERSION.
$MACHINE-devel.iso ipfire-
$VERSION.
$MACHINE-devel.iso.md5
; do
287 ncftpput
-u $FTP_ISO_USER -p $FTP_ISO_PASS -P $FTP_ISO_PORT $FTP_ISO_URL $FTP_ISO_PATH$SVN_REVISION/ $i
288 if [ "$?" -eq "0" ]; then
289 echo "The file with name $i was successfully uploaded to $FTP_ISO_URL$FTP_ISO_PATH$SVN_REVISION/."
291 echo "There was an error while uploading the file $i to the ftp server."
296 rm -f ipfire-
$VERSION.
$MACHINE-full.iso.md5
297 if [ "$3" = "--with-sources-cd" ]; then
298 ncftpput
-u $FTP_ISO_USER -p $FTP_ISO_PASS -P $FTP_ISO_PORT $FTP_ISO_URL $FTP_ISO_PATH/$SVN_REVISION/ ipfire-sources-cd-
$VERSION.
$MACHINE.iso
302 ncftpput
-u $FTP_ISO_USER -p $FTP_ISO_PASS -P $FTP_ISO_PORT $FTP_ISO_URL $FTP_ISO_PATH$SVN_REVISION/paks packages
/*
303 if [ "$?" -eq "0" ]; then
304 echo -e "The packages were successfully uploaded to $FTP_ISO_URL$FTP_ISO_PATH$SVN_REVISION/."
306 echo -e "There was an error while uploading the packages to the ftp server."
314 if [ "$2" = "--background" ]; then
318 if [ `screen -ls | grep -q ipfire` ]; then
319 echo "Build is already running, sorry!"
322 if [ "$2" = "--rebuild" ]; then
323 export IPFIRE_REBUILD
=1
326 export IPFIRE_REBUILD
=0
328 echo -en "${BOLD}***IPFire-Batch-Build is starting...${NORMAL}"
329 screen
-dmS ipfire
$0 batch --background
340 .
$BASEDIR/tools
/make-compilers
345 cat doc
/make.sh-usage