]> git.ipfire.org Git - ipfire-3.x.git/blame - tools/make-include
Fixed passwordsave in installer.
[ipfire-3.x.git] / tools / make-include
CommitLineData
ca8da28e
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
acef7362 5# Copyright (C) 2008 Michael Tremer & Christian Schmidt #
ca8da28e
MT
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
10f9531b
MT
27CONFIG_ROOT=/etc/$SNAME # Configuration rootdir
28NICE=10 # Nice level
29TARGET=i686 # Default target
867471db 30KVER=`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`
7a1bd584 31MACHINE_REAL=`uname -m`
0627b392 32GIT_TAG=$(git tag | tail -1)
ca8da28e 33
7de88c9f
MT
34# Security options
35SSP=1
718561ec 36PIE=1
7de88c9f
MT
37PAX=1
38
485f0a3b 39# Embedded build
283eab18 40EMB=0
485f0a3b 41
4b9c6965
MT
42# Building options
43BUILD_EXTRAS=1
44BUILD_DEBUG=0
45
0627b392 46# Parallelism flag
71136ced 47PARALLELISMFLAGS=-j$(( $(grep processor < /proc/cpuinfo | wc -l) * 2 + 1 ))
3888140c
MT
48DISTCC_HOSTS=localhost
49
ca8da28e
MT
50PWD=`pwd`
51BASENAME=`basename $0`
52
53# Debian specific settings
54if [ ! -e /etc/debian_version ]; then
55 FULLPATH=`which $0`
56else
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
63fi
64
65BASEDIR=`echo $FULLPATH | sed "s/\/$BASENAME//g"`
66export BASEDIR
ca8da28e 67
503775f9
MT
68HOSTNAME=${HOSTNAME-$(hostname -f || hostname)}
69
98be0467
MT
70. $BASEDIR/tools/make-beautify # Load this very early
71
ca8da28e
MT
72###############################################################################
73#
74# Read the local configuration to override the environment variables
75#
76###############################################################################
77
46bbc95f
MT
78if ! [ -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
ca8da28e
MT
81fi
82
46bbc95f 83. $BASEDIR/.config
ca8da28e
MT
84
85###############################################################################
86#
87# Variables that are not modifyable by .config
88#
89###############################################################################
90
7a1bd584
MT
91if [ 'i686' = $MACHINE_REAL \
92 -o 'i586' = $MACHINE_REAL \
93 -o 'i486' = $MACHINE_REAL \
7a1bd584 94 -o 'x86_64' = $MACHINE_REAL ]; then
acef7362 95 IFS_HOST="$(echo $MACHTYPE | sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")"
7a1bd584
MT
96else
97 beautify message FAIL
98 echo "Can't determine your architecture - $MACHINE_REAL"
99 exit 1
100fi
101
102if [ 'i686' = $TARGET -o 'i586' = $TARGET \
acef7362 103 -o 'i486' = $TARGET ]; then
7a1bd584
MT
104 MACHINE=${TARGET}
105 MACHINE_REAL=${MACHINE_REAL}
ca8da28e 106 LINKER=/lib/ld-linux.so.2
acef7362
MT
107 IFS_TARGET="${MACHINE}-pc-linux-gnu"
108 CFLAGS="-march=${MACHINE} -O2 -pipe -fomit-frame-pointer"
109 CXXFLAGS="${CFLAGS}"
7a1bd584
MT
110elif [ 'via-c7' = $TARGET ]; then
111 MACHINE=i686
112 MACHINE_REAL=${MACHINE_REAL}
113 LINKER=/lib/ld-linux.so.2
acef7362 114 IFS_TARGET="${MACHINE}-pc-linux-gnu"
2f51f075 115 CFLAGS="-march=${MACHINE} -mmmx -msse -msse2 -msse3 -O2 -pipe"
acef7362 116 CXXFLAGS="${CFLAGS}"
7a1bd584 117elif [ 'via-c3' = $TARGET ]; then
ca8da28e 118 MACHINE=i586
7a1bd584 119 MACHINE_REAL=${MACHINE_REAL}
ca8da28e 120 LINKER=/lib/ld-linux.so.2
acef7362
MT
121 IFS_TARGET="${MACHINE}-pc-linux-gnu"
122 CFLAGS="-march=c3 -m3dnow -O2 -pipe -fomit-frame-pointer"
123 CXXFLAGS="${CFLAGS}"
9816acd6
MT
124elif [ '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}"
ca8da28e
MT
131else
132 beautify message FAIL
9816acd6 133 echo "Not a valid target arch (i686|i586|i486|via-c7|via-c3|geodelx) - $TARGET"
7a1bd584 134 exit 1
ca8da28e
MT
135fi
136
be472d5a
MT
137mkdir $BASEDIR/log_${MACHINE}/ 2>/dev/null
138
ca8da28e
MT
139# Set up what used to be /tools
140TOOLS_DIR=/tools_${MACHINE}
141
142# Set up /installer
ccdb935e 143INSTALLER_DIR=/pomona
ca8da28e 144
31c59de6
MT
145# A place to build the iso
146CDROM_DIR=/cdrom
147
148# A place to keep the images
149IMAGES_DIR=/images
150
ca8da28e 151# include machine in TOOLCHAINNAME
acef7362 152TOOLCHAINNAME=$SNAME-$TOOLCHAINVERSION-toolchain-t${TARGET}-m${MACHINE}
ca8da28e 153
98be0467 154# Files that indicates that we are running or failed
da1befdd 155RUNNING=$BASEDIR/.running
98be0467 156FAILED=$BASEDIR/.failed
ca8da28e
MT
157
158################################################################################
159# #
160# Necessary shell functions #
161# #
162################################################################################
163
0cba4dde 164. $BASEDIR/tools/make-buildspy
38e7c3ac
MT
165. $BASEDIR/tools/make-check
166. $BASEDIR/tools/make-batch
167. $BASEDIR/tools/make-compilers
168. $BASEDIR/tools/make-git
0cba4dde 169
ca8da28e 170evaluate() {
da1befdd
MT
171 RETVAL=$?
172 if [ "$RETVAL" -eq "0" ]; then
ca8da28e
MT
173 beautify message DONE
174 else
ca8da28e 175 beautify message FAIL
ca8da28e 176 fi
da1befdd 177 (exit $RETVAL)
ca8da28e
MT
178}
179
ca8da28e 180stdumount() {
4ce0b818 181 sleep 0.3 # Wait one second for finish of processes
ca8da28e
MT
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
187exiterror() {
188 stdumount
98be0467 189 dialogerror $*
c90c0df9 190 build_spy error &
98be0467
MT
191 touch $FAILED
192 rm -f $RUNNING 2>/dev/null
ca8da28e
MT
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################################################################################
199entershell() {
6e0756c3 200 PATH=${TOOLS_DIR}/usr/bin:/bin:/usr/bin:/sbin:/usr/sbin:${TOOLS_DIR}/bin:/usr/${MACHINE_REAL}-linux/bin
ca8da28e
MT
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 \
acef7362 211 PS1="${BOLD}[chroot-${TARGET}(${MACHINE})]${NORMAL} \u:\w\$ " \
ca8da28e
MT
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 \
3d84c75d 222 PARALLELISMFLAGS=$PARALLELISMFLAGS \
ca8da28e
MT
223 LINKER=$LINKER \
224 TOOLS_DIR=$TOOLS_DIR \
225 INSTALLER_DIR=$INSTALLER_DIR \
226 MACHINE="$MACHINE" \
227 MACHINE_REAL="$MACHINE_REAL" \
acef7362
MT
228 CFLAGS="$CFLAGS" \
229 CXXFLAGS="$CXXFLAGS" \
230 IFS_HOST="$IFS_HOST" \
231 IFS_TARGET="$IFS_TARGET" \
ca8da28e
MT
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 #
a57b7dd3
MT
250# :1 skip (nothing to do) #
251# or fail if no script file found #
ca8da28e
MT
252################################################################################
253lfsmakecommoncheck()
254{
255 # Script present?
256 if [ ! -f $BASEDIR/lfs/$1 ]; then
a57b7dd3 257 exiterror "No such file or directory: $BASEDIR/lfs/$1"
ca8da28e
MT
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
4b9c6965
MT
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
ca8da28e
MT
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
98be0467
MT
294 build_spy set package $1 &
295
ca8da28e
MT
296 return 0 # pass all!
297} # End of lfsmakecommoncheck()
298
299################################################################################
300# This is the function that builds every package in stage "toolchain" #
301################################################################################
302toolchain_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" \
acef7362
MT
316 MACHINE_REAL="$MACHINE_REAL" \
317 IFS_HOST="$IFS_HOST" \
318 IFS_TARGET="$IFS_TARGET" \
ca8da28e
MT
319 LFS_BASEDIR=$BASEDIR \
320 LFS=$LFS \
6d18f164
MT
321 INSTALLER_DIR=$INSTALLER_DIR \
322 PARALLELISMFLAGS=$PARALLELISMFLAGS \
ca8da28e
MT
323 KVER=$KVER \
324 STAGE=$STAGE \
325 STAGE_ORDER=$STAGE_ORDER \
7de88c9f
MT
326 SSP=$SSP \
327 PIE=$PIE \
328 PAX=$PAX \
ca8da28e
MT
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################################################################################
10f9531b 345# This is the function that builds every package in stage "base" and "ipfire" #
ca8da28e
MT
346################################################################################
347ipfire_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 \
3d84c75d 377 PARALLELISMFLAGS=$PARALLELISMFLAGS \
ca8da28e
MT
378 LINKER=$LINKER \
379 TOOLS_DIR=$TOOLS_DIR \
380 INSTALLER_DIR=$INSTALLER_DIR \
31c59de6
MT
381 CDROM_DIR=$CDROM_DIR \
382 IMAGES_DIR=$IMAGES_DIR \
ca8da28e
MT
383 MACHINE="$MACHINE" \
384 MACHINE_REAL="$MACHINE_REAL" \
08be8cf6
MT
385 CFLAGS="$CFLAGS" \
386 CXXFLAGS="$CXXFLAGS" \
acef7362
MT
387 IFS_HOST="$IFS_HOST" \
388 IFS_TARGET="$IFS_TARGET" \
8b78946b 389 IFS_ARCH="$TARGET" \
ca8da28e
MT
390 KVER=$KVER \
391 STAGE=$STAGE \
392 STAGE_ORDER=$STAGE_ORDER \
7de88c9f
MT
393 SSP=$SSP \
394 PIE=$PIE \
395 PAX=$PAX \
283eab18 396 EMB=$EMB \
ca8da28e
MT
397 LOGFILE=`echo $LOGFILE | sed "s,$BASEDIR,/usr/src,g"` \
398 bash -x -c "cd /usr/src/lfs && \
399 $EXTRA_MAKE make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
400
401 local COMPILE_SUCCESS=$?
402 local PKG_TIME_END=`date +%s`
403
404 if [ $COMPILE_SUCCESS -ne 0 ]; then
405 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ] $1 $PKG_VER $STAGE_ORDER $STAGE
406 exiterror "Building $*";
407 else
408 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ] $1 $PKG_VER $STAGE_ORDER $STAGE
409 fi
410
411 return 0
412} # End of ipfire_make()
413
ca8da28e
MT
414################################################################################
415# This prepares the build environment #
416################################################################################
417prepareenv() {
acef7362 418 LOGFILE=$BASEDIR/log_${MACHINE}/_build.00-preparation.log
ca8da28e
MT
419 export LOGFILE
420 mkdir -p $BASEDIR/log_${MACHINE}/01_toolchain 2>/dev/null
acef7362 421 mkdir -p $BASEDIR/log_${MACHINE}/02_base 2>/dev/null
4ce0b818 422 mkdir -p $BASEDIR/log_${MACHINE}/03_${SNAME} 2>/dev/null
acef7362 423 mkdir -p $BASEDIR/log_${MACHINE}/04_misc 2>/dev/null
a57b7dd3
MT
424 mkdir -p $BASEDIR/log_${MACHINE}/05_installer 2>/dev/null
425 mkdir -p $BASEDIR/log_${MACHINE}/06_packages 2>/dev/null
ca8da28e
MT
426
427 #############################################################################
428 # Are we running the right shell? #
429 #############################################################################
430
431 if [ ! "$BASH" ]; then
432 exiterror "BASH environment variable is not set. You're probably running the wrong shell."
433 fi
434
435 if [ -z "${BASH_VERSION}" ]; then
436 exiterror "Not running BASH shell."
437 fi
438
439 #############################################################################
440 # Trap on emergency exit #
441 #############################################################################
442 trap "exiterror 'Build process interrupted'" SIGINT SIGTERM SIGKILL SIGSTOP SIGQUIT
443
444
445 #############################################################################
446 # Resetting our nice level #
447 #############################################################################
e3d88b86 448 echo -ne "Resetting our nice level to $NICE"
ca8da28e
MT
449 renice $NICE $$ > /dev/null
450 if [ `nice` != "$NICE" ]; then
451 beautify message FAIL
452 exiterror "Failed to set correct nice level"
453 else
454 beautify message DONE
455 fi
456
457 # Set SCHED_BATCH
7de88c9f 458 if [ -x /usr/bin/schedtool ]; then
7de88c9f 459 /usr/bin/schedtool -B $$
c90c0df9
MT
460 if [ $? -ne 0 ]; then
461 echo -ne "Setting kernel schedular to SCHED_BATCH"
7de88c9f
MT
462 beautify message FAIL
463 fi
464 fi
ca8da28e
MT
465
466 ##############################################################################
467 # Checking if running as root user #
468 ##############################################################################
ca8da28e 469 if [ `id -u` != 0 ]; then
c90c0df9 470 echo -ne "Checking if we're running as root user"
ca8da28e
MT
471 beautify message FAIL
472 exiterror "Not building as root"
ca8da28e
MT
473 fi
474
475
476 ##############################################################################
477 # Checking for necessary temporary space #
478 ##############################################################################
ca8da28e
MT
479 BASE_DEV=`df -P -k $BASEDIR | tail -n 1 | awk '{ print $1 }'`
480 BASE_ASPACE=`df -P -k $BASEDIR | tail -n 1 | awk '{ print $4 }'`
481 if (( 2048000 > $BASE_ASPACE )); then
482 BASE_USPACE=`du -skx $BASEDIR | awk '{print $1}'`
483 if (( 2048000 - $BASE_USPACE > $BASE_ASPACE )); then
c90c0df9 484 echo -ne "Checking for necessary space on disk $BASE_DEV"
ca8da28e
MT
485 beautify message FAIL
486 exiterror "Not enough temporary space available, need at least 2GB on $BASE_DEV"
487 fi
ca8da28e
MT
488 fi
489
7de88c9f
MT
490 ##############################################################################
491 # Setting security features #
492 ##############################################################################
493
494 echo -ne "Stack smashing protector (SSP)"
495 if [ $SSP -eq 1 ]; then
496 beautify message ON
497 else
498 beautify message OFF
499 fi
500
501 echo -ne "Position independent executeables (PIE)"
502 if [ $PIE -eq 1 ]; then
503 beautify message ON
504 else
505 beautify message OFF
506 fi
507
508 echo -ne "GRSecurity (PAX)"
509 if [ $PAX -eq 1 ]; then
510 beautify message ON
511 else
512 beautify message OFF
513 fi
514
515 export SSP PIE PAX
ca8da28e 516
485f0a3b
MT
517 ##############################################################################
518 # Embedded build #
519 ##############################################################################
520
521 echo -ne "Embedded build"
283eab18 522 if [ $EMB -eq 1 ]; then
485f0a3b
MT
523 beautify message ON
524 check_loop || exiterror "Can't build flash images on this machine."
525 else
526 beautify message OFF
527 fi
528
283eab18 529 export EMB
485f0a3b 530
c90c0df9
MT
531 ##############################################################################
532 # Checking CPU features #
533 ##############################################################################
534
535 CHECK_CPU=""
536 if [ 'via-c7' = $TARGET ]; then
5717f807 537 CHECK_CPU="sse sse2 pni"
c90c0df9
MT
538 elif [ 'via-c3' = $TARGET ]; then
539 CHECK_CPU="3dnow"
540 fi
541
542 for flag in $CHECK_CPU; do
543 check_cpu $flag || \
544 exiterror "Your system doesn't support needed cpu feature \"$flag\" to build target $TARGET."
545 done
546
ca8da28e
MT
547 ##############################################################################
548 # Building Linux From Scratch system configuration #
549 ##############################################################################
550
551 # Set umask
552 umask 022
553
554 # Set LFS Directory
4ce0b818 555 LFS=$BASEDIR/build_${MACHINE}/${SNAME}
ca8da28e
MT
556
557 # Check /tools symlink
558 if [ -h $TOOLS_DIR ]; then
559 rm -f $TOOLS_DIR
560 fi
7de88c9f 561 if [ ! -a $TOOLS_DIR ]; then
ca8da28e
MT
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
ccdb935e 575 mkdir -p $BASEDIR/build_${MACHINE}/{$TOOLS_DIR,cdrom,$INSTALLER_DIR,$IMAGES_DIR} 2>/dev/null
ca8da28e 576 mkdir -p $BASEDIR/{cache,ccache,distcc} 2>/dev/null
1146889e
MT
577 mkdir -p $BASEDIR/cache/{toolchains,patches,tarballs} 2>/dev/null
578 mkdir -p $LFS/{$TOOLS_DIR,usr/src} 2>/dev/null
3de07634
MT
579 mkdir -p $LFS/{dev,etc,proc,sys} 2>/dev/null
580 mkdir -p $LFS/dev/pts 2>/dev/null
581 mkdir -p $LFS/usr/src/{cache,config,doc,lfs,log_${MACHINE},src,ccache,distcc} 2>/dev/null
582 mkdir -p $LFS/{$INSTALLER_DIR,cdrom,images} 2>/dev/null
ca8da28e
MT
583
584 mknod -m 600 $BASEDIR/build/dev/console c 5 1 2>/dev/null
585 mknod -m 666 $BASEDIR/build/dev/null c 1 3 2>/dev/null
586
587 # Make all sources and proc available under lfs build
10f9531b
MT
588 mount --bind /dev $LFS/dev
589 mount --bind /proc $LFS/proc
3de07634 590 mount --bind /sys $LFS/sys
10f9531b
MT
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
10f9531b 600 mount --bind $BASEDIR/build_${MACHINE}/$CDROM_DIR $LFS/$CDROM_DIR
ccdb935e
MT
601 mount --bind $BASEDIR/build_${MACHINE}/$INSTALLER_DIR $LFS/$INSTALLER_DIR
602 mount --bind $BASEDIR/build_${MACHINE}/$IMAGES_DIR $LFS/$IMAGES_DIR
ca8da28e 603
ca8da28e
MT
604 # Run LFS static binary creation scripts one by one
605 export CCACHE_DIR=$BASEDIR/ccache
606 export CCACHE_HASHDIR=1
3888140c 607 if [ ! -z "$DISTCC_HOSTS" ]; then
ca8da28e
MT
608 export CCACHE_PREFIX="distcc"
609 export DISTCC_DIR=$BASEDIR/distcc
610 fi
611
3888140c 612 [ -z "$DISTCC_HOSTS" ] || echo "$DISTCC_HOSTS" > $DISTCC_DIR/hosts
ca8da28e
MT
613
614 # Remove pre-install list of installed files in case user erase some files before rebuild
615 rm -f $LFS/usr/src/lsalr 2>/dev/null
616}
617
cfccf561
MT
618build() {
619 clear
620 #a prebuilt toolchain package is only used if found in cache
621 if [ ! -d $BASEDIR/cache ]; then
c90c0df9 622 exiterror "Use make.sh source get first!"
ca8da28e 623 fi
cfccf561
MT
624 cd $BASEDIR/cache/toolchains
625 PACKAGE=`ls -v -r $TOOLCHAINNAME.tar.bz2 2> /dev/null | head -n 1`
626 #only restore on a clean disk
ca8da28e 627
fb86d09d 628 local BLD_TIME_START=`date +%s`
98be0467 629 touch $RUNNING; rm -f $FAILED 2>/dev/null
fb86d09d 630
acef7362 631 echo -ne "Building for ${BOLD}${TARGET} (${MACHINE}) on ${MACHINE_REAL}${NORMAL}\n"
fb86d09d 632
0cba4dde 633 build_spy_send_profile &
c90c0df9 634 build_spy compiling &
fb86d09d 635
cfccf561
MT
636 if [ -f $BASEDIR/log_${MACHINE}/02_base/stage2-LFS ]; then
637 prepareenv
638 echo "Using installed toolchain" >> $LOGFILE
639 beautify message DONE "Stage toolchain already built or extracted"
640 else
641 if [ -z "$PACKAGE" ]; then
acef7362 642 echo "Full toolchain compilation"
cfccf561 643 prepareenv
38e7c3ac 644
cfccf561
MT
645 check_toolchain
646
647 beautify build_stage "Building toolchain"
648 toolchain_build
649 else
acef7362 650 echo "Restore from $PACKAGE"
d4155cdb
MT
651 cd $BASEDIR && tar jxf $BASEDIR/cache/toolchains/$PACKAGE
652 prepareenv
cfccf561
MT
653 fi
654 fi
655
656 beautify build_stage "Building base"
657 base_build
ca8da28e 658
cfccf561
MT
659 beautify build_stage "Building $SNAME"
660 ipfire_build
ca8da28e 661
cfccf561
MT
662 beautify build_stage "Building miscellaneous"
663 misc_build
ca8da28e 664
ccdb935e 665if [ "${EMB}" -eq "0" ]; then
cfccf561
MT
666 beautify build_stage "Building installer"
667 installer_build
ccdb935e 668fi
ca8da28e 669
cfccf561
MT
670 beautify build_stage "Building packages"
671 packages_build
672
673 echo ""
674 echo "... and all this hard work for this:"
4ce0b818 675 ls -sh $BASEDIR/${SNAME}-${VERSION}.${MACHINE}.iso
fb86d09d
MT
676
677 local BLD_TIME_END=`date +%s`
678 build_spy set duration $[ $BLD_TIME_END - $BLD_TIME_START ]
679 build_spy idle
da1befdd 680 rm -f $RUNNING
ca8da28e 681}
3349c6c9
MT
682
683gettoolchain() {
da1befdd 684 check_user
3349c6c9
MT
685 if [ ! -f $BASEDIR/cache/toolchains/$TOOLCHAINNAME.tar.bz2 ]; then
686 URL_TOOLCHAIN=$(grep URL_TOOLCHAIN lfs/Config | awk '{ print $3 }')
687 DIR_TOOLCHAIN="$BASEDIR/cache/toolchains"
688
689 echo "Loading toolchain for $MACHINE"
da1befdd
MT
690 scp -2C ${IPFIRE_USER}@${URL_TOOLCHAIN}/$TOOLCHAINNAME.tar.bz2 \
691 ${DIR_TOOLCHAIN}
3349c6c9
MT
692 else
693 echo -n "Toolchain \"$TOOLCHAINNAME\" is already existing"
694 beautify message SKIP
695 fi
696}
da1befdd
MT
697
698puttoolchain() {
699 check_user
700 if [ -f $BASEDIR/cache/toolchains/$TOOLCHAINNAME.tar.bz2 ]; then
701 URL_TOOLCHAIN=$(grep URL_TOOLCHAIN lfs/Config | awk '{ print $3 }')
702 DIR_TOOLCHAIN="$BASEDIR/cache/toolchains"
703
704 echo "Pushing toolchain for $MACHINE"
705 scp -2C ${DIR_TOOLCHAIN}/$TOOLCHAINNAME.tar.bz2 \
706 ${IPFIRE_USER}@${URL_TOOLCHAIN}
707 else
708 echo -n "Toolchain \"$TOOLCHAINNAME\" is not existing. "
709 echo -n "Run \"./make.sh build\", first"
710 beautify message SKIP
711 fi
712}
713
714getsource() {
715 if [ ! -d $BASEDIR/cache ]; then
716 mkdir -p $BASEDIR/cache/{tarballs,patches}
717 fi
718 mkdir -p $BASEDIR/log_${MACHINE}
719 echo -e "${BOLD}Preload all source files${NORMAL}"
720 cd $BASEDIR/lfs
721 for i in *; do
722 if [ -f "$i" -a "$i" != "Config" ]; then
723 make -s -f $i \
724 LFS_BASEDIR=$BASEDIR \
725 MESSAGE="$i\t" \
726 SSP=$SSP \
727 PIE=$PIE \
728 PAX=$PAX download 2>> $LOGFILE
729 [ $? -ne 0 ] && beautify message FAIL
730 fi
731 done
732 cd $BASEDIR
733}
734
735putsource() {
736 check_user
737 URL_SOURCE=$(grep URL_SOURCE lfs/Config | awk '{ print $3 }')
738 REMOTE_FILES=$(echo "ls -1" | sftp -C ${IPFIRE_USER}@${URL_SOURCE})
739
740 cd $BASEDIR/cache/tarballs/
741 for file in $(ls -1); do
742 grep -q "$file" <<<$REMOTE_FILES && continue
743 NEW_FILES="$NEW_FILES $file"
744 done
745 [ -n "$NEW_FILES" ] && scp -2C $NEW_FILES ${IPFIRE_USER}@${URL_SOURCE}
746 cd $BASEDIR
747}
e70deaa8
MT
748
749puttarget() {
750 check_user
751 URL_TARGET=$(grep URL_TARGET lfs/Config | awk '{ print $3 }')
c4f3946f 752 DIR="${BASEDIR}/${HOSTNAME}/$(date '+%Y%m%d-%0k')/"
e70deaa8 753
47778a57
MT
754 # If there is no iso, we do nothing.
755 [ -e "${BASEDIR}/${SNAME}-${VERSION}.${MACHINE}.iso" ] || return 0
756
757 rm -rf ${BASEDIR}/${HOSTNAME} 2>/dev/null
e70deaa8
MT
758 mkdir -p ${DIR}
759
760 [ -e "${BASEDIR}/packages" ] && cp -al ${BASEDIR}/packages ${DIR}
3554fded 761 [ -e "${BATCHLOG}" ] && \
93cb874d 762 python ${BASEDIR}/tools/alog2html < ${BATCHLOG} > ${DIR}/build_log.html
3554fded 763 git_export; cp -l ${BASEDIR}/${SNAME}-${VERSION}.source.tar.gz ${DIR}
896427c7 764 git_diff >/dev/null && cp -l ${DIFF_NAME} ${DIR}
e70deaa8
MT
765 cp -l ${BASEDIR}/${SNAME}-${VERSION}.${MACHINE}.iso ${DIR}
766
767 cd $BASEDIR && \
47778a57 768 scp -2C -r ${HOSTNAME} ${IPFIRE_USER}@${URL_TARGET} || :
e70deaa8 769
47778a57 770 rm -rf ${BASEDIR}/${HOSTNAME} 2>/dev/null
e70deaa8 771}