]> git.ipfire.org Git - ipfire-3.x.git/blob - tools/make-include
Merge branch 'master' of git://git.ipfire.org/ipfire-3.x
[ipfire-3.x.git] / tools / make-include
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2008 Michael Tremer & Christian Schmidt #
6 # #
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. #
11 # #
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. #
16 # #
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/>. #
19 # #
20 ###############################################################################
21 ###############################################################################
22 #
23 # System variables
24 #
25 ###############################################################################
26
27 CONFIG_ROOT=/etc/$SNAME # Configuration rootdir
28 NICE=10 # Nice level
29 TARGET=i686 # Default target
30 KVER=`grep --max-count=1 VER lfs/linux | awk '{ print $3 }' | tr -d '\n'; grep --max-count=1 LOCALVERSION lfs/linux | awk '{ print $3 }' | tail -1`
31 MACHINE_REAL=`uname -m`
32 GIT_TAG=$(git tag | tail -1)
33
34 # Security options
35 SSP=1
36 PIE=1
37 PAX=1
38
39 # Embedded build
40 EMB=0
41
42 # Parallelism flag
43 PARALLELISMFLAGS=-j$(( $(grep processor < /proc/cpuinfo | wc -l) * 2 + 1 ))
44 DISTCC_HOSTS=localhost
45
46 PWD=`pwd`
47 BASENAME=`basename $0`
48
49 # Debian specific settings
50 if [ ! -e /etc/debian_version ]; then
51 FULLPATH=`which $0`
52 else
53 if [ -x /usr/bin/realpath ]; then
54 FULLPATH=`/usr/bin/realpath $0`
55 else
56 echo "ERROR: Need to do apt-get install realpath"
57 exit 1
58 fi
59 fi
60
61 BASEDIR=`echo $FULLPATH | sed "s/\/$BASENAME//g"`
62 export BASEDIR
63
64 HOSTNAME=${HOSTNAME-$(hostname -f || hostname)}
65
66 . $BASEDIR/tools/make-beautify # Load this very early
67
68 ###############################################################################
69 #
70 # Read the local configuration to override the environment variables
71 #
72 ###############################################################################
73
74 if ! [ -e .config ]; then
75 sed -e "s/@UUID@/$(uuidgen 2>/dev/null || cat /proc/sys/kernel/random/uuid)/" \
76 -e "s/^#UUID=/UUID=/" < $BASEDIR/.config-default > $BASEDIR/.config
77 fi
78
79 . $BASEDIR/.config
80
81 ###############################################################################
82 #
83 # Variables that are not modifyable by .config
84 #
85 ###############################################################################
86
87 if [ 'i686' = $MACHINE_REAL \
88 -o 'i586' = $MACHINE_REAL \
89 -o 'i486' = $MACHINE_REAL \
90 -o 'x86_64' = $MACHINE_REAL ]; then
91 IFS_HOST="$(echo $MACHTYPE | sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")"
92 else
93 beautify message FAIL
94 echo "Can't determine your architecture - $MACHINE_REAL"
95 exit 1
96 fi
97
98 if [ 'i686' = $TARGET -o 'i586' = $TARGET \
99 -o 'i486' = $TARGET ]; then
100 MACHINE=${TARGET}
101 MACHINE_REAL=${MACHINE_REAL}
102 LINKER=/lib/ld-linux.so.2
103 IFS_TARGET="${MACHINE}-pc-linux-gnu"
104 CFLAGS="-march=${MACHINE} -O2 -pipe -fomit-frame-pointer"
105 CXXFLAGS="${CFLAGS}"
106 UCLIBC_TARGET=${MACHINE}-pc-linux-uclibc
107 UCLIBC_CFLAGS="-march=${MACHINE} -Os -pipe"
108 elif [ 'via-c7' = $TARGET ]; then
109 MACHINE=i686
110 MACHINE_REAL=${MACHINE_REAL}
111 LINKER=/lib/ld-linux.so.2
112 IFS_TARGET="${MACHINE}-pc-linux-gnu"
113 CFLAGS="-march=${MACHINE} -mmmx -msse -msse2 -msse3 -O2 -pipe"
114 CXXFLAGS="${CFLAGS}"
115 UCLIBC_TARGET=${MACHINE}-pc-linux-uclibc
116 UCLIBC_CFLAGS="-march=i386 -Os -pipe"
117 elif [ 'via-c3' = $TARGET ]; then
118 MACHINE=i586
119 MACHINE_REAL=${MACHINE_REAL}
120 LINKER=/lib/ld-linux.so.2
121 IFS_TARGET="${MACHINE}-pc-linux-gnu"
122 CFLAGS="-march=c3 -m3dnow -O2 -pipe -fomit-frame-pointer"
123 CXXFLAGS="${CFLAGS}"
124 UCLIBC_TARGET=${MACHINE}-pc-linux-uclibc
125 UCLIBC_CFLAGS="-march=${MACHINE} -Os -pipe"
126 elif [ 'geodelx' = $TARGET ]; then
127 MACHINE=i586
128 MACHINE_REAL=${MACHINE_REAL}
129 LINKER=/lib/ld-linux.so.2
130 IFS_TARGET="${MACHINE}-pc-linux-gnu"
131 CFLAGS="-march=geode -Os -pipe -fomit-frame-pointer"
132 CXXFLAGS="${CFLAGS}"
133 UCLIBC_TARGET=${MACHINE}-pc-linux-uclibc
134 UCLIBC_CFLAGS="-march=geode -Os -pipe"
135 else
136 beautify message FAIL
137 echo "Not a valid target arch (i686|i586|i486|via-c7|via-c3|geodelx) - $TARGET"
138 exit 1
139 fi
140
141 mkdir $BASEDIR/log_${MACHINE}/ 2>/dev/null
142
143 # Set up what used to be /tools
144 TOOLS_DIR=/tools_${MACHINE}
145
146 # Set up /installer
147 INSTALLER_DIR=/installer
148
149 # A place to build the iso
150 CDROM_DIR=/cdrom
151
152 # A place to keep the images
153 IMAGES_DIR=/images
154
155 # include machine in TOOLCHAINNAME
156 TOOLCHAINNAME=$SNAME-$TOOLCHAINVERSION-toolchain-t${TARGET}-m${MACHINE}
157
158 # The place where all uclibc files are stored in
159 UCLIBC_DIR=/usr/${UCLIBC_TARGET}
160 UCLIBC_CC_CORE_STATIC_DIR=${UCLIBC_DIR}/gcc-core-static
161
162 #UCLIBC_SYSROOT_DIR=${UCLIBC_DIR}/${UCLIBC_TARGET}/sys-root
163 UCLIBC_SYSROOT_DIR=${INSTALLER_DIR}
164
165 # Files that indicates that we are running or failed
166 RUNNING=$BASEDIR/.running
167 FAILED=$BASEDIR/.failed
168
169 ################################################################################
170 # #
171 # Necessary shell functions #
172 # #
173 ################################################################################
174
175 . $BASEDIR/tools/make-buildspy
176 . $BASEDIR/tools/make-check
177 . $BASEDIR/tools/make-batch
178 . $BASEDIR/tools/make-compilers
179 . $BASEDIR/tools/make-git
180
181 evaluate() {
182 RETVAL=$?
183 if [ "$RETVAL" -eq "0" ]; then
184 beautify message DONE
185 else
186 beautify message FAIL
187 fi
188 (exit $RETVAL)
189 }
190
191 stdumount() {
192 sleep 0.3 # Wait one second for finish of processes
193 for fs in `mount | grep $BASEDIR/build_${MACHINE} | awk '{print $3}'`; do
194 umount $fs #2>/dev/null;
195 done
196 } # End of stdumount()
197
198 exiterror() {
199 stdumount
200 dialogerror $*
201 build_spy error
202 touch $FAILED
203 rm -f $RUNNING 2>/dev/null
204 exit 1
205 } # End of exiterror()
206
207 ################################################################################
208 # This is the function that sets the environment of a chroot and enters it #
209 ################################################################################
210 entershell() {
211 PATH=${TOOLS_DIR}/usr/bin:/bin:/usr/bin:/sbin:/usr/sbin:${TOOLS_DIR}/bin:/usr/${MACHINE_REAL}-linux/bin
212
213 if [ ! -e $LFS/usr/src/lfs/ ]; then
214 exiterror "No such file or directory: $LFS/usr/src/lfs/"
215 fi
216
217 echo -ne "Entering ${BOLD}$MACHINE${NORMAL} LFS chroot, type exit to return to host environment\n"
218
219 chroot $LFS $TOOLS_DIR/bin/env -i \
220 HOME=/root \
221 TERM=$TERM \
222 PS1="${BOLD}[chroot-${TARGET}(${MACHINE})]${NORMAL} \u:\w\$ " \
223 PATH=$PATH \
224 CONFIG_ROOT=${CONFIG_ROOT} \
225 VERSION=${VERSION} \
226 NAME=${NAME} \
227 SNAME=${SNAME} \
228 SLOGAN="$SLOGAN" \
229 CCACHE_DIR=/usr/src/ccache \
230 CCACHE_PREFIX=${CCACHE_PREFIX} \
231 CCACHE_HASHDIR=${CCACHE_HASHDIR} \
232 DISTCC_DIR=/usr/src/distcc \
233 PARALLELISMFLAGS=$PARALLELISMFLAGS \
234 LINKER=$LINKER \
235 TOOLS_DIR=$TOOLS_DIR \
236 INSTALLER_DIR=$INSTALLER_DIR \
237 MACHINE="$MACHINE" \
238 MACHINE_REAL="$MACHINE_REAL" \
239 CFLAGS="$CFLAGS" \
240 CXXFLAGS="$CXXFLAGS" \
241 IFS_HOST="$IFS_HOST" \
242 IFS_TARGET="$IFS_TARGET" \
243 KVER=$KVER \
244 STAGE=$STAGE \
245 STAGE_ORDER=$STAGE_ORDER \
246 LOGFILE=`echo $LOGFILE | sed "s,$BASEDIR,/usr/src,g"` \
247 bash
248
249 if [ $? -ne 0 ]; then
250 exiterror "chroot error"
251 else
252 stdumount
253 fi
254 } # End of entershell()
255
256
257
258 ################################################################################
259 # Common checking before entering the chroot and compilling #
260 # Return:0 caller can continue #
261 # :1 skip (nothing to do) #
262 # or fail if no script file found #
263 ################################################################################
264 lfsmakecommoncheck()
265 {
266 # Script present?
267 if [ ! -f $BASEDIR/lfs/$1 ]; then
268 exiterror "No such file or directory: $BASEDIR/lfs/$1"
269 fi
270
271 local PKG_VER=`get_pkg_ver $BASEDIR/lfs/$1`
272 beautify make_pkg "$PKG_VER $*"
273
274 # Script slipped?
275 local i
276 for i in $SKIP_PACKAGE_LIST
277 do
278 if [ "$i" == "$1" ]; then
279 beautify result SKIP
280 return 1;
281 fi
282 done
283
284 echo -e "`date -u '+%b %e %T'`: Building $* " >> $LOGFILE
285
286 cd $BASEDIR/lfs && make -s -f $* MACHINE=$MACHINE LFS_BASEDIR=$BASEDIR MESSAGE="$1\t " download >> $LOGFILE 2>&1
287 if [ $? -ne 0 ]; then
288 exiterror "Download error in $1"
289 fi
290
291 build_spy set package $1 &
292
293 return 0 # pass all!
294 } # End of lfsmakecommoncheck()
295
296 ################################################################################
297 # This is the function that builds every package in stage "toolchain" #
298 ################################################################################
299 toolchain_make() {
300 lfsmakecommoncheck $*
301 [ $? == 1 ] && return 0
302
303 local PKG_VER=`get_pkg_ver $BASEDIR/lfs/$1`
304
305 local EXTRA_MAKE=$EXTRA_MAKE
306
307 local PKG_TIME_START=`date +%s`
308 cd $BASEDIR/lfs && $EXTRA_MAKE make -f $* \
309 CONFIG_ROOT=$CONFIG_ROOT \
310 LINKER=$LINKER \
311 TOOLS_DIR=$TOOLS_DIR \
312 MACHINE="$MACHINE" \
313 MACHINE_REAL="$MACHINE_REAL" \
314 IFS_HOST="$IFS_HOST" \
315 IFS_TARGET="$IFS_TARGET" \
316 LFS_BASEDIR=$BASEDIR \
317 LFS=$LFS \
318 INSTALLER_DIR=$INSTALLER_DIR \
319 PARALLELISMFLAGS=$PARALLELISMFLAGS \
320 KVER=$KVER \
321 STAGE=$STAGE \
322 STAGE_ORDER=$STAGE_ORDER \
323 SSP=$SSP \
324 PIE=$PIE \
325 PAX=$PAX \
326 install >> $LOGFILE 2>&1
327
328 local COMPILE_SUCCESS=$?
329 local PKG_TIME_END=`date +%s`
330
331 if [ $COMPILE_SUCCESS -ne 0 ]; then
332 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ] $1 $PKG_VER $STAGE_ORDER $STAGE
333 exiterror "Building $*";
334 else
335 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ] $1 $PKG_VER $STAGE_ORDER $STAGE
336 fi
337
338 return 0
339 } # End of toolchain_make()
340
341 ################################################################################
342 # This is the function that builds every package in stage "base" and "ipfire" #
343 ################################################################################
344 ipfire_make() {
345 lfsmakecommoncheck $*
346 [ $? == 1 ] && return 0
347
348 local PKG_VER=`get_pkg_ver $BASEDIR/lfs/$1`
349
350 local EXTRA_MAKE=$EXTRA_MAKE
351 # When cross-compiling, make sure the kernel is compiled for the target
352 [ "$MACHINE" != "$MACHINE_REAL" -a "$1" == "linux" ] && unset EXTRA_MAKE
353
354 # Also, make sure external kernel modules are compiled 64bit
355 if grep -qEi 'KERNEL_MOD = yes' $1 ; then
356 unset EXTRA_MAKE
357 fi
358
359 local MYCFLAGS MYCXXFLAGS
360 if [ "${STAGE}" = "installer" ]; then
361 MYCFLAGS=${UCLIBC_CFLAGS}
362 MYCXXFLAGS=${UCLIBC_CFLAGS}
363 else
364 MYCFLAGS=${CFLAGS}
365 MYCXXFLAGS=${CXXFLAGS}
366 fi
367
368 local PKG_TIME_START=`date +%s`
369 chroot $LFS $TOOLS_DIR/bin/env -i \
370 HOME=/root \
371 TERM=$TERM \
372 PS1='\u:\w\$ ' \
373 PATH=$PATH \
374 CONFIG_ROOT=${CONFIG_ROOT} \
375 VERSION=${VERSION} \
376 NAME=${NAME} \
377 SNAME=${SNAME} \
378 SLOGAN="$SLOGAN" \
379 CCACHE_DIR=/usr/src/ccache \
380 CCACHE_PREFIX=${CCACHE_PREFIX} \
381 CCACHE_HASHDIR=${CCACHE_HASHDIR} \
382 DISTCC_DIR=/usr/src/distcc \
383 PARALLELISMFLAGS=$PARALLELISMFLAGS \
384 LINKER=$LINKER \
385 TOOLS_DIR=$TOOLS_DIR \
386 INSTALLER_DIR=$INSTALLER_DIR \
387 CDROM_DIR=$CDROM_DIR \
388 IMAGES_DIR=$IMAGES_DIR \
389 UCLIBC_DIR=$UCLIBC_DIR \
390 UCLIBC_SYSROOT_DIR=$UCLIBC_SYSROOT_DIR \
391 UCLIBC_TARGET=$UCLIBC_TARGET \
392 UCLIBC_CC_CORE_STATIC_DIR=${UCLIBC_CC_CORE_STATIC_DIR} \
393 MACHINE="$MACHINE" \
394 MACHINE_REAL="$MACHINE_REAL" \
395 CFLAGS="$MYCFLAGS" \
396 CXXFLAGS="$MYCXXFLAGS" \
397 IFS_HOST="$IFS_HOST" \
398 IFS_TARGET="$IFS_TARGET" \
399 KVER=$KVER \
400 STAGE=$STAGE \
401 STAGE_ORDER=$STAGE_ORDER \
402 SSP=$SSP \
403 PIE=$PIE \
404 PAX=$PAX \
405 EMB=$EMB \
406 LOGFILE=`echo $LOGFILE | sed "s,$BASEDIR,/usr/src,g"` \
407 bash -x -c "cd /usr/src/lfs && \
408 $EXTRA_MAKE make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
409
410 local COMPILE_SUCCESS=$?
411 local PKG_TIME_END=`date +%s`
412
413 if [ $COMPILE_SUCCESS -ne 0 ]; then
414 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ] $1 $PKG_VER $STAGE_ORDER $STAGE
415 exiterror "Building $*";
416 else
417 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ] $1 $PKG_VER $STAGE_ORDER $STAGE
418 fi
419
420 return 0
421 } # End of ipfire_make()
422
423 ################################################################################
424 # This prepares the build environment #
425 ################################################################################
426 prepareenv() {
427 LOGFILE=$BASEDIR/log_${MACHINE}/_build.00-preparation.log
428 export LOGFILE
429 mkdir -p $BASEDIR/log_${MACHINE}/01_toolchain 2>/dev/null
430 mkdir -p $BASEDIR/log_${MACHINE}/02_base 2>/dev/null
431 mkdir -p $BASEDIR/log_${MACHINE}/03_${SNAME} 2>/dev/null
432 mkdir -p $BASEDIR/log_${MACHINE}/04_misc 2>/dev/null
433 mkdir -p $BASEDIR/log_${MACHINE}/05_installer 2>/dev/null
434 mkdir -p $BASEDIR/log_${MACHINE}/06_packages 2>/dev/null
435
436 #############################################################################
437 # Are we running the right shell? #
438 #############################################################################
439
440 if [ ! "$BASH" ]; then
441 exiterror "BASH environment variable is not set. You're probably running the wrong shell."
442 fi
443
444 if [ -z "${BASH_VERSION}" ]; then
445 exiterror "Not running BASH shell."
446 fi
447
448 #############################################################################
449 # Trap on emergency exit #
450 #############################################################################
451 trap "exiterror 'Build process interrupted'" SIGINT SIGTERM SIGKILL SIGSTOP SIGQUIT
452
453
454 #############################################################################
455 # Resetting our nice level #
456 #############################################################################
457 echo -ne "Resetting our nice level to $NICE"
458 renice $NICE $$ > /dev/null
459 if [ `nice` != "$NICE" ]; then
460 beautify message FAIL
461 exiterror "Failed to set correct nice level"
462 else
463 beautify message DONE
464 fi
465
466 # Set SCHED_BATCH
467 if [ -x /usr/bin/schedtool ]; then
468 echo -ne "Setting kernel schedular to SCHED_BATCH"
469 /usr/bin/schedtool -B $$
470 if [ $? -eq 0 ]; then
471 beautify message DONE
472 else
473 beautify message FAIL
474 fi
475 fi
476
477 ##############################################################################
478 # Checking if running as root user #
479 ##############################################################################
480 echo -ne "Checking if we're running as root user"
481 if [ `id -u` != 0 ]; then
482 beautify message FAIL
483 exiterror "Not building as root"
484 else
485 beautify message DONE
486 fi
487
488
489 ##############################################################################
490 # Checking for necessary temporary space #
491 ##############################################################################
492 echo -ne "Checking for necessary space on disk $BASE_DEV"
493 BASE_DEV=`df -P -k $BASEDIR | tail -n 1 | awk '{ print $1 }'`
494 BASE_ASPACE=`df -P -k $BASEDIR | tail -n 1 | awk '{ print $4 }'`
495 if (( 2048000 > $BASE_ASPACE )); then
496 BASE_USPACE=`du -skx $BASEDIR | awk '{print $1}'`
497 if (( 2048000 - $BASE_USPACE > $BASE_ASPACE )); then
498 beautify message FAIL
499 exiterror "Not enough temporary space available, need at least 2GB on $BASE_DEV"
500 fi
501 beautify message DONE
502 else
503 beautify message DONE
504 fi
505
506 ##############################################################################
507 # Setting security features #
508 ##############################################################################
509
510 echo -ne "Stack smashing protector (SSP)"
511 if [ $SSP -eq 1 ]; then
512 beautify message ON
513 else
514 beautify message OFF
515 fi
516
517 echo -ne "Position independent executeables (PIE)"
518 if [ $PIE -eq 1 ]; then
519 beautify message ON
520 else
521 beautify message OFF
522 fi
523
524 echo -ne "GRSecurity (PAX)"
525 if [ $PAX -eq 1 ]; then
526 beautify message ON
527 else
528 beautify message OFF
529 fi
530
531 export SSP PIE PAX
532
533 ##############################################################################
534 # Embedded build #
535 ##############################################################################
536
537 echo -ne "Embedded build"
538 if [ $EMB -eq 1 ]; then
539 beautify message ON
540 check_loop || exiterror "Can't build flash images on this machine."
541 else
542 beautify message OFF
543 fi
544
545 export EMB
546
547 ##############################################################################
548 # Building Linux From Scratch system configuration #
549 ##############################################################################
550
551 # Set umask
552 umask 022
553
554 # Set LFS Directory
555 LFS=$BASEDIR/build_${MACHINE}/${SNAME}
556
557 # Check /tools symlink
558 if [ -h $TOOLS_DIR ]; then
559 rm -f $TOOLS_DIR
560 fi
561 if [ ! -a $TOOLS_DIR ]; then
562 ln -s $BASEDIR/build_${MACHINE}/$TOOLS_DIR /
563 fi
564 if [ ! -h $TOOLS_DIR ]; then
565 exiterror "Could not create $TOOLS_DIR symbolic link."
566 fi
567
568 # Setup environment
569 set +h
570 LC_ALL=POSIX
571 export LFS LC_ALL
572 unset CC CXX CPP LD_LIBRARY_PATH LD_PRELOAD
573
574 # Make some extra directories
575 mkdir -p $BASEDIR/build_${MACHINE}/{$TOOLS_DIR,cdrom} 2>/dev/null
576 mkdir -p $BASEDIR/{cache,ccache,distcc} 2>/dev/null
577 mkdir -p $BASEDIR/cache/{toolchains,patches,tarballs} 2>/dev/null
578 mkdir -p $LFS/{$TOOLS_DIR,usr/src} 2>/dev/null
579 mkdir -p $LFS/dev/pts
580 mkdir -p $LFS/proc
581 mkdir -p $LFS/usr/src/{cache,config,doc,lfs,log_${MACHINE},src,ccache,distcc}
582 mkdir -p $LFS/{$INSTALLER_DIR,cdrom,images}
583 mkdir -p $LFS/etc
584
585 mknod -m 600 $BASEDIR/build/dev/console c 5 1 2>/dev/null
586 mknod -m 666 $BASEDIR/build/dev/null c 1 3 2>/dev/null
587
588 # Make all sources and proc available under lfs build
589 mount --bind /dev $LFS/dev
590 mount --bind /proc $LFS/proc
591 mount --bind $BASEDIR/cache $LFS/usr/src/cache
592 mount --bind $BASEDIR/ccache $LFS/usr/src/ccache
593 mount --bind $BASEDIR/distcc $LFS/usr/src/distcc
594 mount --bind $BASEDIR/config $LFS/usr/src/config
595 mount --bind $BASEDIR/doc $LFS/usr/src/doc
596 mount --bind $BASEDIR/lfs $LFS/usr/src/lfs
597 mount --bind $BASEDIR/log_${MACHINE} $LFS/usr/src/log_${MACHINE}
598 mount --bind $BASEDIR/src $LFS/usr/src/src
599 mount --bind $BASEDIR/build_${MACHINE}/$TOOLS_DIR $LFS/$TOOLS_DIR
600 mount --bind $BASEDIR/build_${MACHINE}/$CDROM_DIR $LFS/$CDROM_DIR
601
602 # Run LFS static binary creation scripts one by one
603 export CCACHE_DIR=$BASEDIR/ccache
604 export CCACHE_HASHDIR=1
605 if [ ! -z "$DISTCC_HOSTS" ]; then
606 export CCACHE_PREFIX="distcc"
607 export DISTCC_DIR=$BASEDIR/distcc
608 fi
609
610 [ -z "$DISTCC_HOSTS" ] || echo "$DISTCC_HOSTS" > $DISTCC_DIR/hosts
611
612 # Remove pre-install list of installed files in case user erase some files before rebuild
613 rm -f $LFS/usr/src/lsalr 2>/dev/null
614 }
615
616 build() {
617 clear
618 #a prebuilt toolchain package is only used if found in cache
619 if [ ! -d $BASEDIR/cache ]; then
620 exiterror "Use make.sh downloadsrc first!"
621 fi
622 cd $BASEDIR/cache/toolchains
623 PACKAGE=`ls -v -r $TOOLCHAINNAME.tar.bz2 2> /dev/null | head -n 1`
624 #only restore on a clean disk
625
626 local BLD_TIME_START=`date +%s`
627 touch $RUNNING; rm -f $FAILED 2>/dev/null
628
629 echo -ne "Building for ${BOLD}${TARGET} (${MACHINE}) on ${MACHINE_REAL}${NORMAL}\n"
630
631 build_spy_send_profile &
632 build_spy compiling
633
634 if [ -f $BASEDIR/log_${MACHINE}/02_base/stage2-LFS ]; then
635 prepareenv
636 echo "Using installed toolchain" >> $LOGFILE
637 beautify message DONE "Stage toolchain already built or extracted"
638 else
639 if [ -z "$PACKAGE" ]; then
640 echo "Full toolchain compilation"
641 prepareenv
642
643 check_toolchain
644
645 beautify build_stage "Building toolchain"
646 toolchain_build
647 else
648 echo "Restore from $PACKAGE"
649 cd $BASEDIR && tar jxf $BASEDIR/cache/toolchains/$PACKAGE
650 prepareenv
651 fi
652 fi
653
654 beautify build_stage "Building base"
655 base_build
656
657 beautify build_stage "Building $SNAME"
658 ipfire_build
659
660 beautify build_stage "Building miscellaneous"
661 misc_build
662
663 beautify build_stage "Building installer"
664 installer_build
665
666 beautify build_stage "Building packages"
667 packages_build
668
669 echo ""
670 echo "... and all this hard work for this:"
671 ls -sh $BASEDIR/${SNAME}-${VERSION}.${MACHINE}.iso
672
673 local BLD_TIME_END=`date +%s`
674 build_spy set duration $[ $BLD_TIME_END - $BLD_TIME_START ]
675 build_spy idle
676 rm -f $RUNNING
677 }
678
679 gettoolchain() {
680 check_user
681 if [ ! -f $BASEDIR/cache/toolchains/$TOOLCHAINNAME.tar.bz2 ]; then
682 URL_TOOLCHAIN=$(grep URL_TOOLCHAIN lfs/Config | awk '{ print $3 }')
683 DIR_TOOLCHAIN="$BASEDIR/cache/toolchains"
684
685 echo "Loading toolchain for $MACHINE"
686 scp -2C ${IPFIRE_USER}@${URL_TOOLCHAIN}/$TOOLCHAINNAME.tar.bz2 \
687 ${DIR_TOOLCHAIN}
688 else
689 echo -n "Toolchain \"$TOOLCHAINNAME\" is already existing"
690 beautify message SKIP
691 fi
692 }
693
694 puttoolchain() {
695 check_user
696 if [ -f $BASEDIR/cache/toolchains/$TOOLCHAINNAME.tar.bz2 ]; then
697 URL_TOOLCHAIN=$(grep URL_TOOLCHAIN lfs/Config | awk '{ print $3 }')
698 DIR_TOOLCHAIN="$BASEDIR/cache/toolchains"
699
700 echo "Pushing toolchain for $MACHINE"
701 scp -2C ${DIR_TOOLCHAIN}/$TOOLCHAINNAME.tar.bz2 \
702 ${IPFIRE_USER}@${URL_TOOLCHAIN}
703 else
704 echo -n "Toolchain \"$TOOLCHAINNAME\" is not existing. "
705 echo -n "Run \"./make.sh build\", first"
706 beautify message SKIP
707 fi
708 }
709
710 getsource() {
711 if [ ! -d $BASEDIR/cache ]; then
712 mkdir -p $BASEDIR/cache/{tarballs,patches}
713 fi
714 mkdir -p $BASEDIR/log_${MACHINE}
715 echo -e "${BOLD}Preload all source files${NORMAL}"
716 cd $BASEDIR/lfs
717 for i in *; do
718 if [ -f "$i" -a "$i" != "Config" ]; then
719 make -s -f $i \
720 LFS_BASEDIR=$BASEDIR \
721 MESSAGE="$i\t" \
722 SSP=$SSP \
723 PIE=$PIE \
724 PAX=$PAX download 2>> $LOGFILE
725 [ $? -ne 0 ] && beautify message FAIL
726 fi
727 done
728 cd $BASEDIR
729 }
730
731 putsource() {
732 check_user
733 URL_SOURCE=$(grep URL_SOURCE lfs/Config | awk '{ print $3 }')
734 REMOTE_FILES=$(echo "ls -1" | sftp -C ${IPFIRE_USER}@${URL_SOURCE})
735
736 cd $BASEDIR/cache/tarballs/
737 for file in $(ls -1); do
738 grep -q "$file" <<<$REMOTE_FILES && continue
739 NEW_FILES="$NEW_FILES $file"
740 done
741 [ -n "$NEW_FILES" ] && scp -2C $NEW_FILES ${IPFIRE_USER}@${URL_SOURCE}
742 cd $BASEDIR
743 }
744
745 puttarget() {
746 check_user
747 URL_TARGET=$(grep URL_TARGET lfs/Config | awk '{ print $3 }')
748 DIR="${BASEDIR}/${HOSTNAME}/$(date '+%Y%m%d-%k')/"
749
750 rm -rf ${DIR} 2>/dev/null
751 mkdir -p ${DIR}
752
753 [ -e "${BASEDIR}/packages" ] && cp -al ${BASEDIR}/packages ${DIR}
754 cp -l ${BASEDIR}/${SNAME}-${VERSION}.${MACHINE}.iso ${DIR}
755
756 cd $BASEDIR && \
757 scp -2C -r ${HOSTNAME} ${IPFIRE_USER}@${URL_TARGET} || :
758
759 rm -rf ${DIR} 2>/dev/null
760 }