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