]> git.ipfire.org Git - ipfire-3.x.git/blob - tools/make-include
Made a function that checks if the host cpu has all functionalities we need.
[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 IFS_ARCH="$TARGET" \
400 KVER=$KVER \
401 STAGE=$STAGE \
402 STAGE_ORDER=$STAGE_ORDER \
403 SSP=$SSP \
404 PIE=$PIE \
405 PAX=$PAX \
406 EMB=$EMB \
407 LOGFILE=`echo $LOGFILE | sed "s,$BASEDIR,/usr/src,g"` \
408 bash -x -c "cd /usr/src/lfs && \
409 $EXTRA_MAKE make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
410
411 local COMPILE_SUCCESS=$?
412 local PKG_TIME_END=`date +%s`
413
414 if [ $COMPILE_SUCCESS -ne 0 ]; then
415 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ] $1 $PKG_VER $STAGE_ORDER $STAGE
416 exiterror "Building $*";
417 else
418 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ] $1 $PKG_VER $STAGE_ORDER $STAGE
419 fi
420
421 return 0
422 } # End of ipfire_make()
423
424 ################################################################################
425 # This prepares the build environment #
426 ################################################################################
427 prepareenv() {
428 LOGFILE=$BASEDIR/log_${MACHINE}/_build.00-preparation.log
429 export LOGFILE
430 mkdir -p $BASEDIR/log_${MACHINE}/01_toolchain 2>/dev/null
431 mkdir -p $BASEDIR/log_${MACHINE}/02_base 2>/dev/null
432 mkdir -p $BASEDIR/log_${MACHINE}/03_${SNAME} 2>/dev/null
433 mkdir -p $BASEDIR/log_${MACHINE}/04_misc 2>/dev/null
434 mkdir -p $BASEDIR/log_${MACHINE}/05_installer 2>/dev/null
435 mkdir -p $BASEDIR/log_${MACHINE}/06_packages 2>/dev/null
436
437 #############################################################################
438 # Are we running the right shell? #
439 #############################################################################
440
441 if [ ! "$BASH" ]; then
442 exiterror "BASH environment variable is not set. You're probably running the wrong shell."
443 fi
444
445 if [ -z "${BASH_VERSION}" ]; then
446 exiterror "Not running BASH shell."
447 fi
448
449 #############################################################################
450 # Trap on emergency exit #
451 #############################################################################
452 trap "exiterror 'Build process interrupted'" SIGINT SIGTERM SIGKILL SIGSTOP SIGQUIT
453
454
455 #############################################################################
456 # Resetting our nice level #
457 #############################################################################
458 echo -ne "Resetting our nice level to $NICE"
459 renice $NICE $$ > /dev/null
460 if [ `nice` != "$NICE" ]; then
461 beautify message FAIL
462 exiterror "Failed to set correct nice level"
463 else
464 beautify message DONE
465 fi
466
467 # Set SCHED_BATCH
468 if [ -x /usr/bin/schedtool ]; then
469 /usr/bin/schedtool -B $$
470 if [ $? -ne 0 ]; then
471 echo -ne "Setting kernel schedular to SCHED_BATCH"
472 beautify message FAIL
473 fi
474 fi
475
476 ##############################################################################
477 # Checking if running as root user #
478 ##############################################################################
479 if [ `id -u` != 0 ]; then
480 echo -ne "Checking if we're running as root user"
481 beautify message FAIL
482 exiterror "Not building as root"
483 fi
484
485
486 ##############################################################################
487 # Checking for necessary temporary space #
488 ##############################################################################
489 BASE_DEV=`df -P -k $BASEDIR | tail -n 1 | awk '{ print $1 }'`
490 BASE_ASPACE=`df -P -k $BASEDIR | tail -n 1 | awk '{ print $4 }'`
491 if (( 2048000 > $BASE_ASPACE )); then
492 BASE_USPACE=`du -skx $BASEDIR | awk '{print $1}'`
493 if (( 2048000 - $BASE_USPACE > $BASE_ASPACE )); then
494 echo -ne "Checking for necessary space on disk $BASE_DEV"
495 beautify message FAIL
496 exiterror "Not enough temporary space available, need at least 2GB on $BASE_DEV"
497 fi
498 fi
499
500 ##############################################################################
501 # Setting security features #
502 ##############################################################################
503
504 echo -ne "Stack smashing protector (SSP)"
505 if [ $SSP -eq 1 ]; then
506 beautify message ON
507 else
508 beautify message OFF
509 fi
510
511 echo -ne "Position independent executeables (PIE)"
512 if [ $PIE -eq 1 ]; then
513 beautify message ON
514 else
515 beautify message OFF
516 fi
517
518 echo -ne "GRSecurity (PAX)"
519 if [ $PAX -eq 1 ]; then
520 beautify message ON
521 else
522 beautify message OFF
523 fi
524
525 export SSP PIE PAX
526
527 ##############################################################################
528 # Embedded build #
529 ##############################################################################
530
531 echo -ne "Embedded build"
532 if [ $EMB -eq 1 ]; then
533 beautify message ON
534 check_loop || exiterror "Can't build flash images on this machine."
535 else
536 beautify message OFF
537 fi
538
539 export EMB
540
541 ##############################################################################
542 # Checking CPU features #
543 ##############################################################################
544
545 CHECK_CPU=""
546 if [ 'via-c7' = $TARGET ]; then
547 CHECK_CPU="sse sse2 pne"
548 elif [ 'via-c3' = $TARGET ]; then
549 CHECK_CPU="3dnow"
550 fi
551
552 for flag in $CHECK_CPU; do
553 check_cpu $flag || \
554 exiterror "Your system doesn't support needed cpu feature \"$flag\" to build target $TARGET."
555 done
556
557 ##############################################################################
558 # Building Linux From Scratch system configuration #
559 ##############################################################################
560
561 # Set umask
562 umask 022
563
564 # Set LFS Directory
565 LFS=$BASEDIR/build_${MACHINE}/${SNAME}
566
567 # Check /tools symlink
568 if [ -h $TOOLS_DIR ]; then
569 rm -f $TOOLS_DIR
570 fi
571 if [ ! -a $TOOLS_DIR ]; then
572 ln -s $BASEDIR/build_${MACHINE}/$TOOLS_DIR /
573 fi
574 if [ ! -h $TOOLS_DIR ]; then
575 exiterror "Could not create $TOOLS_DIR symbolic link."
576 fi
577
578 # Setup environment
579 set +h
580 LC_ALL=POSIX
581 export LFS LC_ALL
582 unset CC CXX CPP LD_LIBRARY_PATH LD_PRELOAD
583
584 # Make some extra directories
585 mkdir -p $BASEDIR/build_${MACHINE}/{$TOOLS_DIR,cdrom} 2>/dev/null
586 mkdir -p $BASEDIR/{cache,ccache,distcc} 2>/dev/null
587 mkdir -p $BASEDIR/cache/{toolchains,patches,tarballs} 2>/dev/null
588 mkdir -p $LFS/{$TOOLS_DIR,usr/src} 2>/dev/null
589 mkdir -p $LFS/dev/pts
590 mkdir -p $LFS/proc
591 mkdir -p $LFS/usr/src/{cache,config,doc,lfs,log_${MACHINE},src,ccache,distcc}
592 mkdir -p $LFS/{$INSTALLER_DIR,cdrom,images}
593 mkdir -p $LFS/etc
594
595 mknod -m 600 $BASEDIR/build/dev/console c 5 1 2>/dev/null
596 mknod -m 666 $BASEDIR/build/dev/null c 1 3 2>/dev/null
597
598 # Make all sources and proc available under lfs build
599 mount --bind /dev $LFS/dev
600 mount --bind /proc $LFS/proc
601 mount --bind $BASEDIR/cache $LFS/usr/src/cache
602 mount --bind $BASEDIR/ccache $LFS/usr/src/ccache
603 mount --bind $BASEDIR/distcc $LFS/usr/src/distcc
604 mount --bind $BASEDIR/config $LFS/usr/src/config
605 mount --bind $BASEDIR/doc $LFS/usr/src/doc
606 mount --bind $BASEDIR/lfs $LFS/usr/src/lfs
607 mount --bind $BASEDIR/log_${MACHINE} $LFS/usr/src/log_${MACHINE}
608 mount --bind $BASEDIR/src $LFS/usr/src/src
609 mount --bind $BASEDIR/build_${MACHINE}/$TOOLS_DIR $LFS/$TOOLS_DIR
610 mount --bind $BASEDIR/build_${MACHINE}/$CDROM_DIR $LFS/$CDROM_DIR
611
612 # Run LFS static binary creation scripts one by one
613 export CCACHE_DIR=$BASEDIR/ccache
614 export CCACHE_HASHDIR=1
615 if [ ! -z "$DISTCC_HOSTS" ]; then
616 export CCACHE_PREFIX="distcc"
617 export DISTCC_DIR=$BASEDIR/distcc
618 fi
619
620 [ -z "$DISTCC_HOSTS" ] || echo "$DISTCC_HOSTS" > $DISTCC_DIR/hosts
621
622 # Remove pre-install list of installed files in case user erase some files before rebuild
623 rm -f $LFS/usr/src/lsalr 2>/dev/null
624 }
625
626 build() {
627 clear
628 #a prebuilt toolchain package is only used if found in cache
629 if [ ! -d $BASEDIR/cache ]; then
630 exiterror "Use make.sh source get first!"
631 fi
632 cd $BASEDIR/cache/toolchains
633 PACKAGE=`ls -v -r $TOOLCHAINNAME.tar.bz2 2> /dev/null | head -n 1`
634 #only restore on a clean disk
635
636 local BLD_TIME_START=`date +%s`
637 touch $RUNNING; rm -f $FAILED 2>/dev/null
638
639 echo -ne "Building for ${BOLD}${TARGET} (${MACHINE}) on ${MACHINE_REAL}${NORMAL}\n"
640
641 build_spy_send_profile &
642 build_spy compiling &
643
644 if [ -f $BASEDIR/log_${MACHINE}/02_base/stage2-LFS ]; then
645 prepareenv
646 echo "Using installed toolchain" >> $LOGFILE
647 beautify message DONE "Stage toolchain already built or extracted"
648 else
649 if [ -z "$PACKAGE" ]; then
650 echo "Full toolchain compilation"
651 prepareenv
652
653 check_toolchain
654
655 beautify build_stage "Building toolchain"
656 toolchain_build
657 else
658 echo "Restore from $PACKAGE"
659 cd $BASEDIR && tar jxf $BASEDIR/cache/toolchains/$PACKAGE
660 prepareenv
661 fi
662 fi
663
664 beautify build_stage "Building base"
665 base_build
666
667 beautify build_stage "Building $SNAME"
668 ipfire_build
669
670 beautify build_stage "Building miscellaneous"
671 misc_build
672
673 beautify build_stage "Building installer"
674 installer_build
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 set duration $[ $BLD_TIME_END - $BLD_TIME_START ]
685 build_spy 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 cp -l ${BASEDIR}/${SNAME}-${VERSION}.${MACHINE}.iso ${DIR}
768
769 cd $BASEDIR && \
770 scp -2C -r ${HOSTNAME} ${IPFIRE_USER}@${URL_TARGET} || :
771
772 rm -rf ${BASEDIR}/${HOSTNAME} 2>/dev/null
773 }