forked from ipfire/ipfire-2.x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.sh
executable file
·1863 lines (1647 loc) · 43.9 KB
/
make.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
############################################################################
# #
# This file is part of the IPFire Firewall. #
# #
# IPFire is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# IPFire is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with IPFire; if not, write to the Free Software #
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
# #
# Copyright (C) 2007-2017 IPFire Team <info@ipfire.org>. #
# #
############################################################################
#
NAME="IPFire" # Software name
SNAME="ipfire" # Short name
VERSION="2.19" # Version number
CORE="117" # Core Level (Filename)
PAKFIRE_CORE="117" # Core Level (PAKFIRE)
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD` # Git Branch
SLOGAN="www.ipfire.org" # Software slogan
CONFIG_ROOT=/var/ipfire # Configuration rootdir
NICE=10 # Nice level
MAX_RETRIES=1 # prefetch/check loop
BUILD_IMAGES=1 # Flash and Xen Downloader
KVER=`grep --max-count=1 VER lfs/linux | awk '{ print $3 }'`
GIT_TAG=$(git tag | tail -1) # Git Tag
GIT_LASTCOMMIT=$(git log | head -n1 | cut -d" " -f2 |head -c8) # Last commit
TOOLCHAINVER=20171121
###############################################################################
#
# Beautifying variables & presentation & input output interface
#
###############################################################################
# Remember if the shell is interactive or not
if [ -t 0 ] && [ -t 1 ]; then
INTERACTIVE=true
else
INTERACTIVE=false
fi
# Sets or adjusts pretty formatting variables
resize_terminal() {
## Screen Dimentions
# Find current screen size
COLUMNS=$(tput cols)
# When using remote connections, such as a serial port, stty size returns 0
if ! ${INTERACTIVE} || [ "${COLUMNS}" = "0" ]; then
COLUMNS=80
fi
# Measurements for positioning result messages
OPTIONS_WIDTH=20
TIME_WIDTH=12
STATUS_WIDTH=8
NAME_WIDTH=$(( COLUMNS - OPTIONS_WIDTH - TIME_WIDTH - STATUS_WIDTH ))
LINE_WIDTH=$(( COLUMNS - STATUS_WIDTH ))
TIME_COL=$(( NAME_WIDTH + OPTIONS_WIDTH ))
STATUS_COL=$(( TIME_COL + TIME_WIDTH ))
}
# Initially setup terminal
resize_terminal
# Call resize_terminal when terminal is being resized
trap "resize_terminal" WINCH
# Define color for messages
BOLD="\\033[1;39m"
DONE="\\033[1;32m"
SKIP="\\033[1;34m"
WARN="\\033[1;35m"
FAIL="\\033[1;31m"
NORMAL="\\033[0;39m"
# New architecture variables
HOST_ARCH="$(uname -m)"
PWD=$(pwd)
BASENAME=$(basename $0)
# Debian specific settings
if [ ! -e /etc/debian_version ]; then
FULLPATH=`which $0`
else
if [ -x /usr/bin/realpath ]; then
FULLPATH=`/usr/bin/realpath $0`
else
echo "ERROR: Need to do apt-get install realpath"
exit 1
fi
fi
# This is the directory where make.sh is in
export BASEDIR=$(echo $FULLPATH | sed "s/\/$BASENAME//g")
LOGFILE=$BASEDIR/log/_build.preparation.log
export LOGFILE
DIR_CHK=$BASEDIR/cache/check
mkdir $BASEDIR/log/ 2>/dev/null
system_processors() {
getconf _NPROCESSORS_ONLN 2>/dev/null || echo "1"
}
system_memory() {
local key val unit
while read -r key val unit; do
case "${key}" in
MemTotal:*)
# Convert to MB
echo "$(( ${val} / 1024 ))"
break
;;
esac
done < /proc/meminfo
}
configure_build() {
local build_arch="${1}"
if [ "${build_arch}" = "default" ]; then
build_arch="$(configure_build_guess)"
fi
case "${build_arch}" in
x86_64)
BUILDTARGET="${build_arch}-unknown-linux-gnu"
CROSSTARGET="${build_arch}-cross-linux-gnu"
BUILD_PLATFORM="x86"
CFLAGS_ARCH="-m64 -mtune=generic"
;;
i586)
BUILDTARGET="${build_arch}-pc-linux-gnu"
CROSSTARGET="${build_arch}-cross-linux-gnu"
BUILD_PLATFORM="x86"
CFLAGS_ARCH="-march=i586 -mtune=generic -fomit-frame-pointer"
;;
aarch64)
BUILDTARGET="${build_arch}-unknown-linux-gnu"
CROSSTARGET="${build_arch}-cross-linux-gnu"
BUILD_PLATFORM="arm"
CFLAGS_ARCH=""
;;
armv7hl)
BUILDTARGET="${build_arch}-unknown-linux-gnueabi"
CROSSTARGET="${build_arch}-cross-linux-gnueabi"
BUILD_PLATFORM="arm"
CFLAGS_ARCH="-march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard"
;;
armv5tel)
BUILDTARGET="${build_arch}-unknown-linux-gnueabi"
CROSSTARGET="${build_arch}-cross-linux-gnueabi"
BUILD_PLATFORM="arm"
CFLAGS_ARCH="-march=armv5te -mfloat-abi=soft -fomit-frame-pointer"
;;
*)
exiterror "Cannot build for architure ${build_arch}"
;;
esac
# Check if the QEMU helper is available if needed.
if qemu_is_required "${build_arch}"; then
local qemu_build_helper="$(qemu_find_build_helper_name "${build_arch}")"
if [ -n "${qemu_build_helper}" ]; then
QEMU_TARGET_HELPER="${qemu_build_helper}"
else
exiterror "Could not find a binfmt_misc helper entry for ${build_arch}"
fi
fi
BUILD_ARCH="${build_arch}"
TOOLS_DIR="/tools_${BUILD_ARCH}"
# Enables hardening
HARDENING_CFLAGS="-Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4"
CFLAGS="-O2 -pipe -Wall -fexceptions -fPIC ${CFLAGS_ARCH}"
CXXFLAGS="${CFLAGS}"
# Determine parallelism
if [ -z "${MAKETUNING}" ]; then
# We assume that each process consumes about
# 192MB of memory. Therefore we find out how
# many processes fit into memory.
local mem_max=$(( ${HOST_MEM} / 192 ))
local processors="$(system_processors)"
local cpu_max=$(( ${processors} * 2 ))
local parallelism
if [ ${mem_max} -lt ${cpu_max} ]; then
parallelism=${mem_max}
else
parallelism=${cpu_max}
fi
# limit to -j23 because perl will not build
# more
if [ ${parallelism} -gt 23 ]; then
parallelism=23
fi
MAKETUNING="-j${parallelism}"
fi
}
configure_build_guess() {
case "${HOST_ARCH}" in
x86_64|i686|i586)
echo "i586"
;;
aarch64)
echo "aarch64"
;;
armv7*|armv6*|armv5*)
echo "armv5tel"
;;
*)
exiterror "Cannot guess build architecture"
;;
esac
}
stdumount() {
umount $BASEDIR/build/sys 2>/dev/null;
umount $BASEDIR/build/dev/shm 2>/dev/null;
umount $BASEDIR/build/dev/pts 2>/dev/null;
umount $BASEDIR/build/dev 2>/dev/null;
umount $BASEDIR/build/proc 2>/dev/null;
umount $BASEDIR/build/install/mnt 2>/dev/null;
umount $BASEDIR/build/usr/src/cache 2>/dev/null;
umount $BASEDIR/build/usr/src/ccache 2>/dev/null;
umount $BASEDIR/build/usr/src/config 2>/dev/null;
umount $BASEDIR/build/usr/src/doc 2>/dev/null;
umount $BASEDIR/build/usr/src/html 2>/dev/null;
umount $BASEDIR/build/usr/src/langs 2>/dev/null;
umount $BASEDIR/build/usr/src/lfs 2>/dev/null;
umount $BASEDIR/build/usr/src/log 2>/dev/null;
umount $BASEDIR/build/usr/src/src 2>/dev/null;
}
now() {
date -u "+%s"
}
format_runtime() {
local seconds=${1}
if [ ${seconds} -ge 3600 ]; then
printf "%d:%02d:%02d\n" \
"$(( seconds / 3600 ))" \
"$(( seconds % 3600 / 60 ))" \
"$(( seconds % 3600 % 60 ))"
elif [ ${seconds} -ge 60 ]; then
printf "%d:%02d\n" \
"$(( seconds / 60 ))" \
"$(( seconds % 60 ))"
else
printf "%d\n" "${seconds}"
fi
}
print_line() {
local line="$@"
printf "%-${LINE_WIDTH}s" "${line}"
}
_print_line() {
local status="${1}"
shift
if ${INTERACTIVE}; then
printf "${!status}"
fi
print_line "$@"
if ${INTERACTIVE}; then
printf "${NORMAL}"
fi
}
print_headline() {
_print_line BOLD "$@"
}
print_error() {
_print_line FAIL "$@"
}
print_package() {
local name="${1}"
shift
local version="$(grep -E "^VER |^VER=|^VER " $BASEDIR/lfs/${name} | awk '{ print $3 }')"
local options="$@"
local string="${name}"
if [ -n "${version}" ] && [ "${version}" != "ipfire" ]; then
string="${string} (${version})"
fi
printf "%-$(( ${NAME_WIDTH} - 1 ))s " "${string}"
printf "%$(( ${OPTIONS_WIDTH} - 1 ))s " "${options}"
}
print_runtime() {
local runtime=$(format_runtime $@)
if ${INTERACTIVE}; then
printf "\\033[${TIME_COL}G[ ${BOLD}%$(( ${TIME_WIDTH} - 4 ))s${NORMAL} ]" "${runtime}"
else
printf "[ %$(( ${TIME_WIDTH} - 4 ))s ]" "${runtime}"
fi
}
print_status() {
local status="${1}"
local color="${!status}"
if ${INTERACTIVE}; then
printf "\\033[${STATUS_COL}G[${color-${BOLD}} %-$(( ${STATUS_WIDTH} - 4 ))s ${NORMAL}]\n" "${status}"
else
printf "[ %-$(( ${STATUS_WIDTH} - 4 ))s ]\n" "${status}"
fi
}
print_build_stage() {
print_headline "$@"
# end line
printf "\n"
}
print_build_summary() {
local runtime=$(format_runtime $@)
print_line "*** Build finished in ${runtime}"
print_status DONE
}
exiterror() {
stdumount
for i in `seq 0 7`; do
if ( losetup /dev/loop${i} 2>/dev/null | grep -q "/install/images" ); then
losetup -d /dev/loop${i} 2>/dev/null
fi;
done
# Dump logfile
if [ -n "${LOGFILE}" ] && [ -e "${LOGFILE}" ]; then
echo # empty line
local line
while read -r line; do
echo " ${line}"
done <<< "$(tail -n30 ${LOGFILE})"
fi
echo # empty line
local line
for line in "ERROR: $@" " Check ${LOGFILE} for errors if applicable"; do
print_error "${line}"
print_status FAIL
done
exit 1
}
prepareenv() {
# Are we running the right shell?
if [ -z "${BASH}" ]; then
exiterror "BASH environment variable is not set. You're probably running the wrong shell."
fi
if [ -z "${BASH_VERSION}" ]; then
exiterror "Not running BASH shell."
fi
# Trap on emergency exit
trap "exiterror 'Build process interrupted'" SIGINT SIGTERM SIGKILL SIGSTOP SIGQUIT
# Resetting our nice level
if ! renice ${NICE} $$ >/dev/null; then
exiterror "Failed to set nice level to ${NICE}"
fi
# Checking if running as root user
if [ $(id -u) -ne 0 ]; then
exiterror "Not building as root"
fi
# Checking for necessary temporary space
print_line "Checking for necessary space on disk $BASE_DEV"
BASE_DEV=`df -P -k $BASEDIR | tail -n 1 | awk '{ print $1 }'`
BASE_ASPACE=`df -P -k $BASEDIR | tail -n 1 | awk '{ print $4 }'`
if (( 2048000 > $BASE_ASPACE )); then
BASE_USPACE=`du -skx $BASEDIR | awk '{print $1}'`
if (( 2048000 - $BASE_USPACE > $BASE_ASPACE )); then
print_status FAIL
exiterror "Not enough temporary space available, need at least 2GB on $BASE_DEV"
fi
else
print_status DONE
fi
# Set umask
umask 022
# Set LFS Directory
LFS=$BASEDIR/build
# Setup environment
set +h
LC_ALL=POSIX
export LFS LC_ALL CFLAGS CXXFLAGS MAKETUNING
unset CC CXX CPP LD_LIBRARY_PATH LD_PRELOAD
# Make some extra directories
mkdir -p "${BASEDIR}/build${TOOLS_DIR}" 2>/dev/null
mkdir -p $BASEDIR/build/{etc,usr/src} 2>/dev/null
mkdir -p $BASEDIR/build/{dev/{shm,pts},proc,sys}
mkdir -p $BASEDIR/{cache,ccache} 2>/dev/null
mkdir -p $BASEDIR/build/usr/src/{cache,config,doc,html,langs,lfs,log,src,ccache}
mknod -m 600 $BASEDIR/build/dev/console c 5 1 2>/dev/null
mknod -m 666 $BASEDIR/build/dev/null c 1 3 2>/dev/null
# Make all sources and proc available under lfs build
mount --bind /dev $BASEDIR/build/dev
mount --bind /dev/pts $BASEDIR/build/dev/pts
mount --bind /dev/shm $BASEDIR/build/dev/shm
mount --bind /proc $BASEDIR/build/proc
mount --bind /sys $BASEDIR/build/sys
mount --bind $BASEDIR/cache $BASEDIR/build/usr/src/cache
mount --bind $BASEDIR/ccache $BASEDIR/build/usr/src/ccache
mount --bind $BASEDIR/config $BASEDIR/build/usr/src/config
mount --bind $BASEDIR/doc $BASEDIR/build/usr/src/doc
mount --bind $BASEDIR/html $BASEDIR/build/usr/src/html
mount --bind $BASEDIR/langs $BASEDIR/build/usr/src/langs
mount --bind $BASEDIR/lfs $BASEDIR/build/usr/src/lfs
mount --bind $BASEDIR/log $BASEDIR/build/usr/src/log
mount --bind $BASEDIR/src $BASEDIR/build/usr/src/src
# Run LFS static binary creation scripts one by one
export CCACHE_DIR=$BASEDIR/ccache
export CCACHE_COMPRESS=1
export CCACHE_COMPILERCHECK="string:toolchain-${TOOLCHAINVER} ${BUILD_ARCH}"
# Remove pre-install list of installed files in case user erase some files before rebuild
rm -f $BASEDIR/build/usr/src/lsalr 2>/dev/null
# Prepare string for /etc/system-release.
SYSTEM_RELEASE="${NAME} ${VERSION} (${BUILD_ARCH})"
if [ "$(git status -s | wc -l)" == "0" ]; then
GIT_STATUS=""
else
GIT_STATUS="-dirty"
fi
case "$GIT_BRANCH" in
core*|beta?|rc?)
SYSTEM_RELEASE="${SYSTEM_RELEASE} - $GIT_BRANCH$GIT_STATUS"
;;
*)
SYSTEM_RELEASE="${SYSTEM_RELEASE} - Development Build: $GIT_BRANCH/$GIT_LASTCOMMIT$GIT_STATUS"
;;
esac
}
enterchroot() {
# Install QEMU helper, if needed
qemu_install_helper
local PATH="${TOOLS_DIR}/ccache/bin:/bin:/usr/bin:/sbin:/usr/sbin:${TOOLS_DIR}/bin"
PATH="${PATH}" chroot ${LFS} env -i \
HOME="/root" \
TERM="${TERM}" \
PS1="${PS1}" \
PATH="${PATH}" \
SYSTEM_RELEASE="${SYSTEM_RELEASE}" \
PAKFIRE_CORE="${PAKFIRE_CORE}" \
NAME="${NAME}" \
SNAME="${SNAME}" \
VERSION="${VERSION}" \
CORE="${CORE}" \
SLOGAN="${SLOGAN}" \
TOOLS_DIR="${TOOLS_DIR}" \
CONFIG_ROOT="${CONFIG_ROOT}" \
CFLAGS="${CFLAGS} ${HARDENING_CFLAGS}" \
CXXFLAGS="${CXXFLAGS} ${HARDENING_CFLAGS}" \
BUILDTARGET="${BUILDTARGET}" \
CROSSTARGET="${CROSSTARGET}" \
BUILD_ARCH="${BUILD_ARCH}" \
BUILD_PLATFORM="${BUILD_PLATFORM}" \
CCACHE_DIR=/usr/src/ccache \
CCACHE_COMPRESS="${CCACHE_COMPRESS}" \
CCACHE_COMPILERCHECK="${CCACHE_COMPILERCHECK}" \
KVER="${KVER}" \
$(fake_environ) \
$(qemu_environ) \
"$@"
}
entershell() {
if [ ! -e $BASEDIR/build/usr/src/lfs/ ]; then
exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/"
fi
echo "Entering to a shell inside LFS chroot, go out with exit"
local PS1="ipfire build chroot ($(uname -m)) \u:\w\$ "
if enterchroot bash -i; then
stdumount
else
print_status FAIL
exiterror "chroot error"
fi
}
lfsmakecommoncheck() {
# Script present?
if [ ! -f $BASEDIR/lfs/$1 ]; then
exiterror "No such file or directory: $BASEDIR/$1"
fi
# Print package name and version
print_package $@
# Check if this package is supported by our architecture.
# If no SUP_ARCH is found, we assume the package can be built for all.
if grep "^SUP_ARCH" ${BASEDIR}/lfs/${1} >/dev/null; then
# Check if package supports ${BUILD_ARCH} or all architectures.
if ! grep -E "^SUP_ARCH.*${BUILD_ARCH}|^SUP_ARCH.*all" ${BASEDIR}/lfs/${1} >/dev/null; then
print_runtime 0
print_status SKIP
return 1
fi
fi
# Script slipped?
local i
for i in $SKIP_PACKAGE_LIST
do
if [ "$i" == "$1" ]; then
print_status SKIP
return 1;
fi
done
echo -ne "`date -u '+%b %e %T'`: Building $* " >> $LOGFILE
cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR BUILD_ARCH="${BUILD_ARCH}" \
MESSAGE="$1\t " download >> $LOGFILE 2>&1
if [ $? -ne 0 ]; then
exiterror "Download error in $1"
fi
cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR BUILD_ARCH="${BUILD_ARCH}" \
MESSAGE="$1\t md5sum" md5 >> $LOGFILE 2>&1
if [ $? -ne 0 ]; then
exiterror "md5sum error in $1, check file in cache or signature"
fi
return 0 # pass all!
}
lfsmake1() {
lfsmakecommoncheck $*
[ $? == 1 ] && return 0
cd $BASEDIR/lfs && env -i \
PATH="${TOOLS_DIR}/ccache/bin:${TOOLS_DIR}/bin:$PATH" \
CCACHE_DIR="${CCACHE_DIR}" \
CCACHE_COMPRESS="${CCACHE_COMPRESS}" \
CCACHE_COMPILERCHECK="${CCACHE_COMPILERCHECK}" \
CFLAGS="${CFLAGS}" \
CXXFLAGS="${CXXFLAGS}" \
MAKETUNING="${MAKETUNING}" \
make -f $* \
TOOLCHAIN=1 \
TOOLS_DIR="${TOOLS_DIR}" \
CROSSTARGET="${CROSSTARGET}" \
BUILDTARGET="${BUILDTARGET}" \
BUILD_ARCH="${BUILD_ARCH}" \
BUILD_PLATFORM="${BUILD_PLATFORM}" \
LFS_BASEDIR="${BASEDIR}" \
ROOT="${LFS}" \
KVER="${KVER}" \
install >> $LOGFILE 2>&1 &
if ! wait_until_finished $!; then
print_status FAIL
exiterror "Building $*"
fi
print_status DONE
}
lfsmake2() {
lfsmakecommoncheck $*
[ $? == 1 ] && return 0
local PS1='\u:\w$ '
enterchroot \
${EXTRA_PATH}bash -x -c "cd /usr/src/lfs && \
MAKETUNING=${MAKETUNING} \
make -f $* \
LFS_BASEDIR=/usr/src install" \
>> ${LOGFILE} 2>&1 &
if ! wait_until_finished $!; then
print_status FAIL
exiterror "Building $*"
fi
print_status DONE
}
ipfiredist() {
lfsmakecommoncheck $*
[ $? == 1 ] && return 0
local PS1='\u:\w$ '
enterchroot \
bash -x -c "cd /usr/src/lfs && make -f $* LFS_BASEDIR=/usr/src dist" \
>> ${LOGFILE} 2>&1 &
if ! wait_until_finished $!; then
print_status FAIL
exiterror "Packaging $*"
fi
print_status DONE
}
wait_until_finished() {
local pid=${1}
local start_time=$(now)
# Show progress
if ${INTERACTIVE}; then
# Wait a little just in case the process
# has finished very quickly.
sleep 0.1
local runtime
while kill -0 ${pid} 2>/dev/null; do
print_runtime $(( $(now) - ${start_time} ))
# Wait a little
sleep 1
done
fi
# Returns the exit code of the child process
wait ${pid}
local ret=$?
if ! ${INTERACTIVE}; then
print_runtime $(( $(now) - ${start_time} ))
fi
return ${ret}
}
fake_environ() {
[ -e "${BASEDIR}/build${TOOLS_DIR}/lib/libpakfire_preload.so" ] || return
local env="LD_PRELOAD=${TOOLS_DIR}/lib/libpakfire_preload.so"
# Fake kernel version, because some of the packages do not compile
# with kernel 3.0 and later.
env="${env} UTS_RELEASE=${KVER}"
# Fake machine version.
env="${env} UTS_MACHINE=${BUILD_ARCH}"
echo "${env}"
}
qemu_environ() {
local env
# Don't add anything if qemu is not used.
if ! qemu_is_required; then
return
fi
# Set default qemu options
case "${BUILD_ARCH}" in
arm*)
QEMU_CPU="${QEMU_CPU:-cortex-a9}"
env="${env} QEMU_CPU=${QEMU_CPU}"
;;
esac
# Enable QEMU strace
#env="${env} QEMU_STRACE=1"
echo "${env}"
}
qemu_is_required() {
local build_arch="${1}"
if [ -z "${build_arch}" ]; then
build_arch="${BUILD_ARCH}"
fi
case "${HOST_ARCH},${build_arch}" in
x86_64,arm*|i?86,arm*|i?86,x86_64)
return 0
;;
*)
return 1
;;
esac
}
qemu_install_helper() {
# Do nothing, if qemu is not required
if ! qemu_is_required; then
return 0
fi
if [ ! -e /proc/sys/fs/binfmt_misc/status ]; then
exiterror "binfmt_misc not mounted. QEMU_TARGET_HELPER not useable."
fi
if [ ! $(cat /proc/sys/fs/binfmt_misc/status) = 'enabled' ]; then
exiterror "binfmt_misc not enabled. QEMU_TARGET_HELPER not useable."
fi
if [ -z "${QEMU_TARGET_HELPER}" ]; then
exiterror "QEMU_TARGET_HELPER not set"
fi
# Check if the helper is already installed.
if [ -x "${LFS}${QEMU_TARGET_HELPER}" ]; then
return 0
fi
# Try to find a suitable binary that we can install
# to the build environment.
local file
for file in "${QEMU_TARGET_HELPER}" "${QEMU_TARGET_HELPER}-static"; do
# file must exist and be executable.
[ -x "${file}" ] || continue
# Must be static.
file_is_static "${file}" || continue
local dirname="${LFS}$(dirname "${file}")"
mkdir -p "${dirname}"
install -m 755 "${file}" "${LFS}${QEMU_TARGET_HELPER}"
return 0
done
exiterror "Could not find a statically-linked QEMU emulator: ${QEMU_TARGET_HELPER}"
}
qemu_find_build_helper_name() {
local build_arch="${1}"
local magic
case "${build_arch}" in
arm*)
magic="7f454c4601010100000000000000000002002800"
;;
x86_64)
magic="7f454c4602010100000000000000000002003e00"
;;
esac
[ -z "${magic}" ] && return 1
local file
for file in /proc/sys/fs/binfmt_misc/*; do
# skip write only register entry
[ $(basename "${file}") = "register" ] && continue
# Search for the file with the correct magic value.
grep -qE "^magic ${magic}$" "${file}" || continue
local interpreter="$(grep "^interpreter" "${file}" | awk '{ print $2 }')"
[ -n "${interpreter}" ] || continue
[ "${interpreter:0:1}" = "/" ] || continue
[ -x "${interpreter}" ] || continue
echo "${interpreter}"
return 0
done
return 1
}
file_is_static() {
local file="${1}"
file ${file} 2>/dev/null | grep -q "statically linked"
}
update_language_list() {
local path="${1}"
local lang
for lang in ${path}/*.po; do
lang="$(basename "${lang}")"
echo "${lang%*.po}"
done | sort -u > "${path}/LINGUAS"
}
# Load configuration file
if [ -f .config ]; then
. .config
fi
# TARGET_ARCH is BUILD_ARCH now
if [ -n "${TARGET_ARCH}" ]; then
BUILD_ARCH="${TARGET_ARCH}"
unset TARGET_ARCH
fi
# Get the amount of memory in this build system
HOST_MEM=$(system_memory)
if [ -n "${BUILD_ARCH}" ]; then
configure_build "${BUILD_ARCH}"
else
configure_build "default"
fi
buildtoolchain() {
local error=false
case "${BUILD_ARCH}:${HOST_ARCH}" in
# x86_64
x86_64:x86_64)
# This is working.
;;
# x86
i586:i586|i586:i686|i586:x86_64)
# These are working.
;;
i586:*)
error=true
;;
# ARM
arvm7hl:armv7hl|armv7hl:armv7l)
# These are working.
;;
armv5tel:armv5tel|armv5tel:armv5tejl|armv5tel:armv6l|armv5tel:armv7l|armv5tel:aarch64)
# These are working.
;;
armv5tel:*)
error=true
;;
esac
${error} && \
exiterror "Cannot build ${BUILD_ARCH} toolchain on $(uname -m). Please use the download if any."
local gcc=$(type -p gcc)
if [ -z "${gcc}" ]; then
exiterror "Could not find GCC. You will need a working build enviroment in order to build the toolchain."
fi
# Check ${TOOLS_DIR} symlink
if [ -h "${TOOLS_DIR}" ]; then
rm -f "${TOOLS_DIR}"
fi
if [ ! -e "${TOOLS_DIR}" ]; then
ln -s "${BASEDIR}/build${TOOLS_DIR}" "${TOOLS_DIR}"
fi
if [ ! -h "${TOOLS_DIR}" ]; then
exiterror "Could not create ${TOOLS_DIR} symbolic link"
fi
LOGFILE="$BASEDIR/log/_build.toolchain.log"
export LOGFILE
lfsmake1 stage1
lfsmake1 ccache PASS=1
lfsmake1 binutils PASS=1
lfsmake1 gcc PASS=1
lfsmake1 linux KCFG="-headers"
lfsmake1 glibc
lfsmake1 gcc PASS=L
lfsmake1 binutils PASS=2
lfsmake1 gcc PASS=2
lfsmake1 ccache PASS=2
lfsmake1 tcl
lfsmake1 expect
lfsmake1 dejagnu
lfsmake1 pkg-config
lfsmake1 ncurses
lfsmake1 bash
lfsmake1 bzip2
lfsmake1 automake
lfsmake1 coreutils
lfsmake1 diffutils
lfsmake1 findutils
lfsmake1 gawk
lfsmake1 gettext
lfsmake1 grep
lfsmake1 gzip
lfsmake1 m4
lfsmake1 make
lfsmake1 patch
lfsmake1 perl
lfsmake1 sed
lfsmake1 tar
lfsmake1 texinfo
lfsmake1 xz
lfsmake1 fake-environ
lfsmake1 strip
lfsmake1 cleanup-toolchain
}
buildbase() {
LOGFILE="$BASEDIR/log/_build.base.log"
export LOGFILE
lfsmake2 stage2
lfsmake2 linux KCFG="-headers"
lfsmake2 man-pages
lfsmake2 glibc
lfsmake2 tzdata
lfsmake2 cleanup-toolchain
lfsmake2 zlib
lfsmake2 binutils
lfsmake2 gmp
lfsmake2 gmp-compat
lfsmake2 mpfr
lfsmake2 libmpc
lfsmake2 file
lfsmake2 gcc
lfsmake2 sed
lfsmake2 autoconf
lfsmake2 automake
lfsmake2 berkeley
lfsmake2 coreutils
lfsmake2 iana-etc
lfsmake2 m4
lfsmake2 bison
lfsmake2 ncurses-compat
lfsmake2 ncurses
lfsmake2 procps
lfsmake2 libtool
lfsmake2 perl
lfsmake2 readline
lfsmake2 readline-compat
lfsmake2 bzip2
lfsmake2 pcre
lfsmake2 pcre-compat
lfsmake2 bash
lfsmake2 diffutils
lfsmake2 e2fsprogs
lfsmake2 ed
lfsmake2 findutils
lfsmake2 flex