]> git.ipfire.org Git - ipfire-2.x.git/blame_incremental - make.sh
vulnerabilities.cgi add indirect target selection
[ipfire-2.x.git] / make.sh
... / ...
CommitLineData
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007-2025 IPFire Team <info@ipfire.org> #
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
22NAME="IPFire" # Software name
23SNAME="ipfire" # Short name
24# If you update the version don't forget to update backupiso and add it to core update
25VERSION="2.29" # Version number
26CORE="196" # Core Level (Filename)
27SLOGAN="www.ipfire.org" # Software slogan
28CONFIG_ROOT=/var/ipfire # Configuration rootdir
29
30# Information from Git
31GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD)" # Git Branch
32GIT_TAG="$(git tag | tail -1)" # Git Tag
33GIT_LASTCOMMIT="$(git rev-parse --verify HEAD)" # Last commit
34
35TOOLCHAINVER="20250430"
36
37KVER_SUFFIX="-${SNAME}"
38
39# Kernel Version
40KVER="$(grep --max-count=1 VER lfs/linux | awk '{ print $3 }')"
41KVER="${KVER/-rc/.0-rc}${KVER_SUFFIX}"
42
43###############################################################################
44#
45# Beautifying variables & presentation & input output interface
46#
47###############################################################################
48
49# All supported architectures
50ARCHES=(
51 aarch64
52 riscv64
53 x86_64
54)
55
56HOST_ARCH="${HOSTTYPE}"
57HOST_KERNEL="$(uname -r)"
58LC_ALL=POSIX
59PS1='\u:\w$ '
60
61HAS_TIME_NAMESPACE="true"
62
63# Disable time namespaces for older kernels
64case "${HOST_KERNEL}" in
65 4.*|5.[12345].*)
66 HAS_TIME_NAMESPACE="false"
67 ;;
68esac
69
70# Are we reading from/writing to a terminal?
71is_terminal() {
72 [ -t 0 ] && [ -t 1 ] && [ -t 2 ]
73}
74
75# Define color for messages
76if is_terminal; then
77 BOLD="$(tput bold)"
78 RED="$(tput setaf 1)"
79 GREEN="$(tput setaf 2)"
80 YELLOW="$(tput setaf 3)"
81 CYAN="$(tput setaf 6)"
82 NORMAL="$(tput sgr0)"
83fi
84
85# Sets or adjusts pretty formatting variables
86resize_terminal() {
87 # Find current screen size
88 COLUMNS="$(tput cols)"
89
90 # When using remote connections, such as a serial port, stty size returns 0
91 if ! is_terminal || [ "${COLUMNS}" = "0" ]; then
92 COLUMNS=80
93 fi
94
95 # Wipe any previous content before updating the counters
96 if [ -n "${TIME_COL}" ]; then
97 tput hpa "${TIME_COL}"
98 tput el
99 fi
100
101 # The status column is always 8 characters wide
102 STATUS_WIDTH=8
103
104 # The time column is always 12 characters wide
105 TIME_WIDTH=12
106
107 # Where do the columns start?
108 (( STATUS_COL = COLUMNS - STATUS_WIDTH ))
109 (( TIME_COL = STATUS_COL - TIME_WIDTH ))
110}
111
112# Initially setup terminal
113resize_terminal
114
115# Call resize_terminal when terminal is being resized
116trap "resize_terminal" WINCH
117
118# Writes a line to the log file
119log() {
120 local line="$@"
121
122 # Fetch the current timestamp
123 local t="$(date -u "+%b %e %T")"
124
125 # Append the line to file
126 if [ -w "${LOGFILE}" ]; then
127 echo "${t}: ${line}" >> "${LOGFILE}"
128 fi
129
130 return 0
131}
132
133find_base() {
134 local path
135
136 # Figure out the absolute script path using readlink
137 path="$(readlink -f "${0}" 2>&1)"
138
139 # If that failed, try realpath
140 if [ -z "${path}" ]; then
141 path="$(realpath "${0}" 2>&1)"
142 fi
143
144 # If that failed, I am out of ideas
145 if [ -z "${path}" ]; then
146 echo "${0}: Could not determine BASEDIR" >&2
147 return 1
148 fi
149
150 # Return the dirname
151 dirname "${path}"
152}
153
154system_processors() {
155 getconf _NPROCESSORS_ONLN 2>/dev/null || echo "1"
156}
157
158system_memory() {
159 local key val unit
160
161 while read -r key val unit; do
162 case "${key}" in
163 MemTotal:*)
164 # Convert to MB
165 echo "$(( ${val} / 1024 ))"
166 break
167 ;;
168 esac
169 done < /proc/meminfo
170}
171
172format_runtime() {
173 local seconds=${1}
174
175 if [ ${seconds} -ge 3600 ]; then
176 printf "%d:%02d:%02d\n" \
177 "$(( seconds / 3600 ))" \
178 "$(( seconds % 3600 / 60 ))" \
179 "$(( seconds % 3600 % 60 ))"
180 elif [ ${seconds} -ge 60 ]; then
181 printf "%d:%02d\n" \
182 "$(( seconds / 60 ))" \
183 "$(( seconds % 60 ))"
184 else
185 printf "%d\n" "${seconds}"
186 fi
187}
188
189print_line() {
190 # Print the string all the way to the status column
191 printf "%-${STATUS_COL}s" "$*"
192}
193
194print_headline() {
195 printf "${BOLD}%s${NORMAL}\n" "$*"
196}
197
198print_package() {
199 local name="${1}"
200 shift
201
202 local version="$(grep -E "^VER |^VER=|^VER " $BASEDIR/lfs/${name} | awk '{ print $3 }')"
203 local options="$@"
204
205 local string="${name}"
206 if [ -n "${version}" ] && [ "${version}" != "ipfire" ]; then
207 string="${string} (${version})"
208 fi
209
210 # Add the options
211 if [ -n "${options}" ]; then
212 string="${string} ${options[@]}"
213 fi
214
215 # Print the string
216 print_line "${string}"
217}
218
219print_runtime() {
220 local runtime=$(format_runtime $@)
221
222 # Move back the cursor to rewrite the runtime
223 if is_terminal; then
224 tput hpa "${TIME_COL}"
225 fi
226
227 printf "[ ${BOLD}%$(( TIME_WIDTH - 4 ))s${NORMAL} ]" "${runtime}"
228}
229
230print_status() {
231 local status="${1}"
232 local color
233
234 case "${status}" in
235 DONE)
236 color="${BOLD}${GREEN}"
237 ;;
238 FAIL)
239 color="${BOLD}${RED}"
240 ;;
241 SKIP)
242 color="${BOLD}${CYAN}"
243 ;;
244 WARN)
245 color="${BOLD}${YELLOW}"
246 ;;
247 *)
248 color="${BOLD}"
249 ;;
250 esac
251
252 # Move to the start of the column
253 if is_terminal; then
254 tput hpa "${STATUS_COL}"
255 fi
256
257 printf "[ ${color}%$(( STATUS_WIDTH - 4 ))s${NORMAL} ]\n" "${status}"
258}
259
260print_build_summary() {
261 local runtime="${1}"
262
263 print_line "*** Build Finished"
264 print_runtime "${runtime}"
265 print_status DONE
266}
267
268# Launches a timer process as a co-process
269launch_timer() {
270 # Do nothing if the timer is already running
271 if [ -n "${TIMER_PID}" ]; then
272 return 0
273 fi
274
275 # Don't launch the timer when we are not on a terminal
276 if ! is_terminal; then
277 return 0
278 fi
279
280 # Launch the co-process
281 coproc TIMER { "${0}" "__timer" "$$"; }
282
283 # Register the signal handlers
284 trap "__timer_event" SIGUSR1
285 trap "terminate_timer" EXIT
286}
287
288# Terminates a previously launched timer
289terminate_timer() {
290 if [ -n "${TIMER_PID}" ]; then
291 kill -TERM "${TIMER_PID}"
292 fi
293}
294
295# The timer main loop
296__timer() {
297 local pid="${1}"
298
299 # Send SIGUSR1 to the main process once a second
300 # If the parent process has gone away, we will terminate.
301 while sleep 1; do
302 if ! kill -USR1 "${pid}" &>/dev/null; then
303 break
304 fi
305 done
306
307 return 0
308}
309
310# Called when the timer triggers
311# This function does nothing, but is needed interrupt the wait call
312__timer_event() {
313 return 0
314}
315
316exiterror() {
317 # Dump logfile
318 if [ -n "${LOGFILE}" ] && [ -e "${LOGFILE}" ]; then
319 echo # empty line
320
321 local line
322 while read -r line; do
323 echo " ${line}"
324 done <<< "$(tail -n30 ${LOGFILE})"
325 fi
326
327 echo # empty line
328
329 local line
330 for line in "ERROR: $@" " Check ${LOGFILE} for errors if applicable"; do
331 print_line "${line}"
332 print_status FAIL
333 done
334
335 exit 1
336}
337
338prepareenv() {
339 local network="false"
340
341 # Are we running the right shell?
342 if [ -z "${BASH}" ]; then
343 exiterror "BASH environment variable is not set. You're probably running the wrong shell."
344 fi
345
346 if [ -z "${BASH_VERSION}" ]; then
347 exiterror "Not running BASH shell."
348 fi
349
350 # Trap on emergency exit
351 trap "exiterror 'Build process interrupted'" SIGINT SIGTERM SIGQUIT
352
353 # Checking if running as root user
354 if [ "${UID}" -ne 0 ]; then
355 exiterror "root privileges required for building"
356 fi
357
358 local required_space
359
360 # Parse arguments
361 while [ $# -gt 0 ]; do
362 case "${1}" in
363 --required-space=*)
364 required_space="${1#--required-space=}"
365 ;;
366
367 --network)
368 network="true"
369 ;;
370
371 *)
372 exiterror "Unknown argument: ${1}"
373 ;;
374 esac
375 shift
376 done
377
378 # Do we need to check the required space?
379 if [ -n "${required_space}" ]; then
380 local free_space free_blocks block_size
381 local consumed_space path
382
383 # Fetch free blocks
384 read -r free_blocks block_size <<< "$(stat --file-system --format="%a %S" "${BASEDIR}")"
385
386 # Calculate free space
387 (( free_space = free_blocks * block_size / 1024 / 1024 ))
388
389 # If we don't have the total space free, we need to check how much we have consumed already...
390 if [ "${free_space}" -lt "${required_space}" ]; then
391 # Add any consumed space
392 while read -r consumed_space path; do
393 (( free_space += consumed_space / 1024 / 1024 ))
394 done <<< "$(du --summarize --bytes "${BUILD_DIR}" "${IMAGES_DIR}" "${LOG_DIR}" 2>/dev/null)"
395 fi
396
397 # Check that we have the required space
398 if [ "${free_space}" -lt "${required_space}" ]; then
399 exiterror "Not enough temporary space available, need at least ${required_space}MiB, but only have ${free_space}MiB"
400 fi
401 fi
402
403 # Set umask
404 umask 022
405
406 # Make some extra directories
407 mkdir -p "${CCACHE_DIR}"
408 mkdir -p "${IMAGES_DIR}"
409 mkdir -p "${PACKAGES_DIR}"
410 mkdir -p "${BUILD_DIR}/${TOOLS_DIR}"
411 mkdir -p "${BUILD_DIR}/cache"
412 mkdir -p "${BUILD_DIR}/dev"
413 mkdir -p "${BUILD_DIR}/etc"
414 mkdir -p "${BUILD_DIR}/proc"
415 mkdir -p "${BUILD_DIR}/root"
416 mkdir -p "${BUILD_DIR}/sys"
417 mkdir -p "${BUILD_DIR}/tmp"
418 mkdir -p "${BUILD_DIR}/usr/src"
419 mkdir -p "${BUILD_DIR}/usr/src/cache"
420 mkdir -p "${BUILD_DIR}/usr/src/ccache"
421 mkdir -p "${BUILD_DIR}/usr/src/config"
422 mkdir -p "${BUILD_DIR}/usr/src/doc"
423 mkdir -p "${BUILD_DIR}/usr/src/html"
424 mkdir -p "${BUILD_DIR}/usr/src/images"
425 mkdir -p "${BUILD_DIR}/usr/src/langs"
426 mkdir -p "${BUILD_DIR}/usr/src/lfs"
427 mkdir -p "${BUILD_DIR}/usr/src/log"
428 mkdir -p "${BUILD_DIR}/usr/src/src"
429
430 # Make BUILD_DIR a mountpoint
431 mount -o bind "${BUILD_DIR}" "${BUILD_DIR}"
432
433 # Create a new, minimal /dev
434 mount build_dev "${BUILD_DIR}/dev" \
435 -t devtmpfs -o "nosuid,noexec,mode=0755,size=4m,nr_inodes=64k"
436
437 # Mount a new /dev/pts
438 mount build_dev_pts "${BUILD_DIR}/dev/pts" \
439 -t devpts -o "nosuid,noexec,newinstance,ptmxmode=0666,mode=620"
440
441 # Mount a new /dev/shm
442 mount build_dev_shm "${BUILD_DIR}/dev/shm" \
443 -t tmpfs -o "nosuid,nodev,strictatime,mode=1777,size=1024m"
444
445 # Mount a new /tmp
446 mount build_tmp "${BUILD_DIR}/tmp" \
447 -t tmpfs -o "nosuid,nodev,strictatime,size=4G,nr_inodes=1M,mode=1777"
448
449 # Create an empty /proc directory and make it a mountpoint
450 mkdir -p "${BUILD_DIR}/proc"
451 mount --bind "${BUILD_DIR}/proc" "${BUILD_DIR}/proc"
452
453 # Make all sources and proc available under lfs build
454 mount --bind /sys "${BUILD_DIR}/sys"
455 mount --bind -o ro "${BASEDIR}/cache" "${BUILD_DIR}/usr/src/cache"
456 mount --bind -o ro "${BASEDIR}/config" "${BUILD_DIR}/usr/src/config"
457 mount --bind -o ro "${BASEDIR}/doc" "${BUILD_DIR}/usr/src/doc"
458 mount --bind -o ro "${BASEDIR}/html" "${BUILD_DIR}/usr/src/html"
459 mount --bind -o ro "${BASEDIR}/langs" "${BUILD_DIR}/usr/src/langs"
460 mount --bind -o ro "${BASEDIR}/lfs" "${BUILD_DIR}/usr/src/lfs"
461 mount --bind -o ro "${BASEDIR}/src" "${BUILD_DIR}/usr/src/src"
462
463 # Mount the log directory
464 mount --bind "${LOG_DIR}" "${BUILD_DIR}/usr/src/log"
465
466 # Mount the ccache
467 mount --bind "${CCACHE_DIR}" "${BUILD_DIR}/usr/src/ccache"
468
469 # Mount the images directory
470 mount --bind "${IMAGES_DIR}" "${BUILD_DIR}/usr/src/images"
471
472 # Bind-mount files requires for networking if requested
473 if [ "${network}" = "true" ]; then
474 local file
475
476 for file in /etc/resolv.conf /etc/hosts; do
477 # Skip if the source files does not exist
478 if [ ! -e "${file}" ]; then
479 continue
480 fi
481
482 # Create the destination if it does not exist
483 if [ ! -e "${BUILD_DIR}/${file}" ]; then
484 touch "${BUILD_DIR}/${file}"
485 fi
486
487 # Mount the file read-only
488 mount --bind -o ro "${file}" "${BUILD_DIR}/${file}"
489 done
490 fi
491
492 # Configure the ccache
493 export CCACHE_TEMPDIR="/tmp"
494 export CCACHE_COMPILERCHECK="string:toolchain-${TOOLCHAINVER} ${BUILD_ARCH}"
495
496 # Install the QEMU helper
497 qemu_install_helper
498
499 # Remove pre-install list of installed files in case user erase some files before rebuild
500 rm -f "${BUILD_DIR}/usr/src/lsalr"
501
502 # Prepare string for /etc/system-release.
503 local system_release="${NAME} ${VERSION} (${BUILD_ARCH})"
504
505 case "${GIT_BRANCH}" in
506 core*|beta?|rc?)
507 system_release="${system_release} - ${GIT_BRANCH}"
508 ;;
509 *)
510 system_release="${system_release} - core${CORE} Development Build: ${GIT_BRANCH}/${GIT_LASTCOMMIT:0:8}"
511 ;;
512 esac
513
514 # Append -dirty tag for local changes
515 if [ "$(git status -s | wc -l)" != "0" ]; then
516 system_release="${system_release}-dirty"
517 fi
518
519 # Export variable
520 SYSTEM_RELEASE="${system_release}"
521
522 # Decide on PAKFIRE_TREE
523 case "${GIT_BRANCH}" in
524 core*)
525 PAKFIRE_TREE="stable"
526 ;;
527 master)
528 PAKFIRE_TREE="testing"
529 ;;
530 *)
531 PAKFIRE_TREE="unstable"
532 ;;
533 esac
534
535 # Setup ccache cache size
536 execute --chroot ccache --max-size="${CCACHE_CACHE_SIZE}"
537}
538
539entershell() {
540 echo "Entering to a shell inside the build environment, go out with exit"
541
542 local PS1="ipfire build chroot (${BUILD_ARCH}) \u:\w\$ "
543
544 # Run an interactive shell
545 execute --chroot --interactive --network bash -i
546}
547
548lfsmakecommoncheck() {
549 # Script present?
550 if [ ! -f $BASEDIR/lfs/$1 ]; then
551 exiterror "No such file or directory: $BASEDIR/$1"
552 fi
553
554 # Print package name and version
555 print_package $@
556
557 # Check if this package is supported by our architecture.
558 # If no SUP_ARCH is found, we assume the package can be built for all.
559 if grep "^SUP_ARCH" ${BASEDIR}/lfs/${1} >/dev/null; then
560 # Check if package supports ${BUILD_ARCH} or all architectures.
561 if ! grep -E "^SUP_ARCH.*${BUILD_ARCH}|^SUP_ARCH.*all" ${BASEDIR}/lfs/${1} >/dev/null; then
562 print_runtime 0
563 print_status SKIP
564 return 1
565 fi
566 fi
567
568 echo -ne "`date -u '+%b %e %T'`: Building $* " >> $LOGFILE
569
570 return 0 # pass all!
571}
572
573execute() {
574 local chroot="false"
575 local command=()
576 local interactive="false"
577 local timer
578 local network="false"
579
580 # Collect environment variables
581 local -A environ=(
582 [PATH]="${TOOLS_DIR}/ccache/bin:${TOOLS_DIR}/sbin:${TOOLS_DIR}/bin:${PATH}"
583 [HOME]="${HOME}"
584 [PS1]="${PS1}"
585 [TERM]="vt100"
586
587 # Distro Information
588 [NAME]="${NAME}"
589 [SNAME]="${SNAME}"
590 [VERSION]="${VERSION}"
591 [CORE]="${CORE}"
592 [SLOGAN]="${SLOGAN}"
593 [SYSTEM_RELEASE]="${SYSTEM_RELEASE}"
594 [PAKFIRE_TREE]="${PAKFIRE_TREE}"
595 [CONFIG_ROOT]="${CONFIG_ROOT}"
596
597 # Kernel Version
598 [KVER]="${KVER}"
599 [KVER_SUFFIX]="${KVER_SUFFIX}"
600
601 # Compiler flags
602 [CFLAGS]="${CFLAGS[@]}"
603 [CXXFLAGS]="${CFLAGS[@]}"
604 [RUSTFLAGS]="${RUSTFLAGS[@]}"
605
606 # ccache
607 [CCACHE_DIR]="${CCACHE_DIR}"
608 [CCACHE_TEMPDIR]="${CCACHE_TEMPDIR}"
609 [CCACHE_COMPILERCHECK]="${CCACHE_COMPILERCHECK}"
610
611 # System Properties
612 [SYSTEM_PROCESSORS]="${SYSTEM_PROCESSORS}"
613 [SYSTEM_MEMORY]="${SYSTEM_MEMORY}"
614
615 # Parallelism
616 [DEFAULT_PARALLELISM]="${DEFAULT_PARALLELISM}"
617
618 # Compression Options
619 [XZ_OPT]="${XZ_OPT[*]}"
620 [ZSTD_OPT]="${ZSTD_OPT[*]}"
621
622 # Build Architecture
623 [BUILD_ARCH]="${BUILD_ARCH}"
624 [BUILD_PLATFORM]="${BUILD_PLATFORM}"
625
626 # Targets
627 [CROSSTARGET]="${CROSSTARGET}"
628 [BUILDTARGET]="${BUILDTARGET}"
629
630 # Paths
631 [LFS_BASEDIR]="${BASEDIR}"
632 [BUILD_DIR]="${BUILD_DIR}"
633 [IMAGES_DIR]="${IMAGES_DIR}"
634 [LOG_DIR]="${LOG_DIR}"
635 [PACKAGES_DIR]="${PACKAGES_DIR}"
636 [TOOLS_DIR]="${TOOLS_DIR}"
637 )
638
639 local unshare=()
640
641 # Configure a new namespace
642 if [ -n "${IN_NAMESPACE}" ]; then
643 unshare+=(
644 # Create a new cgroup namespace
645 "--cgroup"
646
647 # Create a new mount namespace
648 "--mount"
649 "--propagation=slave"
650
651 # Create a new PID namespace and fork
652 "--pid"
653 "--fork"
654
655 # Create a new UTS namespace
656 "--uts"
657
658 # Mount /proc so that the build environment does not see
659 # any foreign processes.
660 "--mount-proc=${BUILD_DIR}/proc"
661
662 # If unshare is asked to terminate, terminate all child processes
663 "--kill-child"
664 )
665
666 # Optionally set up a new time namespace
667 if [ "${HAS_TIME_NAMESPACE}" = "true" ]; then
668 unshare+=( "--time" )
669 fi
670 fi
671
672 while [ $# -gt 0 ]; do
673 case "${1}" in
674 --chroot)
675 chroot="true"
676
677 # Update some variables
678 environ+=(
679 [PATH]="${TOOLS_DIR}/ccache/bin:/bin:/usr/bin:/sbin:/usr/sbin:${TOOLS_DIR}/sbin:${TOOLS_DIR}/bin"
680 [HOME]="/root"
681
682 # Paths
683 [LFS_BASEDIR]="/usr/src"
684 [BUILD_DIR]="/"
685 [IMAGES_DIR]="/usr/src/images"
686 [LOG_DIR]="/usr/src/log"
687 [PACKAGES_DIR]="/usr/src/images/packages"
688
689 # Compiler Cache
690 [CCACHE_DIR]="/usr/src/ccache"
691
692 # Go Cache
693 [GOCACHE]="/usr/src/ccache/go"
694 )
695
696 # Fake environment
697 if [ -e "${BUILD_DIR}${TOOLS_DIR}/lib/libpakfire_preload.so" ]; then
698 environ+=(
699 [LD_PRELOAD]="${TOOLS_DIR}/lib/libpakfire_preload.so"
700
701 # Fake kernel version, because some of the packages do not
702 # compile with kernel 3.0 and later
703 [UTS_RELEASE]="${KVER}"
704
705 # Fake machine
706 [UTS_MACHINE]="${BUILD_ARCH}"
707 )
708 fi
709 ;;
710
711 --interactive)
712 interactive="true"
713
714 # Use the actual value of $TERM
715 environ+=(
716 [TERM]="${TERM}"
717 )
718 ;;
719
720 --network)
721 network="true"
722
723 # Export the proxy configuration
724 environ+=(
725 [https_proxy]="${https_proxy}"
726 [http_proxy]="${http_proxy}"
727 )
728 ;;
729
730 --timer=*)
731 timer="${1#--timer=}"
732 ;;
733
734 -*)
735 echo "Unknown argument: ${1}" >&2
736 return 2
737 ;;
738
739 # Parse any custom environment variables
740 *=*)
741 environ["${1%=*}"]="${1#*=}"
742 ;;
743
744 # The rest is the command
745 *)
746 command+=( "$@" )
747 break
748 ;;
749 esac
750 shift
751 done
752
753 # Prepend any custom changes to PATH
754 if [ -n "${CUSTOM_PATH}" ]; then
755 environ[PATH]="${CUSTOM_PATH}:${environ[PATH]}"
756 fi
757
758 # Setup QEMU
759 if qemu_is_required; then
760 environ+=(
761 [QEMU_TARGET_HELPER]="${QEMU_TARGET_HELPER}"
762
763 # Enable QEMU strace
764 #[QEMU_STRACE]="1"
765 )
766
767 case "${BUILD_ARCH}" in
768 arm*)
769 environ+=(
770 [QEMU_CPU]="${QEMU_CPU:-cortex-a9}"
771 )
772 ;;
773
774 riscv64)
775 environ+=(
776 [QEMU_CPU]="${QEMU_CPU:-sifive-u54}"
777
778 # Bug fix for QEMU locking up
779 [G_SLICE]="always-malloc"
780 )
781 ;;
782 esac
783 fi
784
785 # Network
786 if [ "${network}" = "false" ]; then
787 unshare+=( "--net" )
788 fi
789
790 local execute=()
791 local env
792
793 # Create new namespaces
794 if [ "${#unshare[@]}" -gt 0 ]; then
795 execute+=(
796 "unshare" "${unshare[@]}"
797 )
798 fi
799
800 # Call a setup script in the new namespaces to perform
801 # further set up, but before we change root.
802 execute+=( "${BASEDIR}/tools/execute.sh" )
803
804 # Run in chroot?
805 if [ "${chroot}" = "true" ]; then
806 execute+=( "chroot" "${BUILD_DIR}" )
807 fi
808
809 # Set PATH so that we can find the env binary
810 local PATH="${environ[PATH]}:${PATH}"
811
812 # Reset the environment
813 execute+=(
814 "env"
815
816 # Clear the previous environment
817 "--ignore-environment"
818
819 # Change to the home directory
820 --chdir="${environ[HOME]}"
821 )
822
823 # Export the environment
824 for env in ${!environ[@]}; do
825 execute+=( "${env}=${environ[${env}]}" )
826 done
827
828 # Append the command
829 execute+=( "${command[@]}" )
830
831 local pid
832
833 # Return code
834 local r=0
835
836 # Store the start time
837 local t="${SECONDS}"
838
839 # Run the command in the background and pipe all output to the logfile
840 case "${interactive}" in
841 true)
842 "${execute[@]}" || return $?
843 ;;
844
845 false)
846 # Launch the timer if needed
847 if [ -n "${timer}" ]; then
848 launch_timer
849 fi
850
851 # Dispatch the command to the background
852 {
853 "${execute[@]}" >> "${LOGFILE}" 2>&1 </dev/null
854 } &
855
856 # Store the PID
857 pid="$!"
858
859 # Wait for the process to complete
860 while :; do
861 wait "${pid}"
862
863 # Store the return code
864 r="$?"
865
866 case "${r}" in
867 # Code means that we have received SIGUSR1 from the timer
868 138)
869 # Call the timer callback
870 if [ -n "${timer}" ]; then
871 "${timer}"
872 fi
873
874 # Go back and wait
875 continue
876 ;;
877
878 # Ignore SIGWINCH
879 156)
880 continue
881 ;;
882 esac
883
884 break
885 done
886
887 # Call the timer callback at least once
888 if [ -n "${timer}" ]; then
889 "${timer}"
890 fi
891 esac
892
893 return "${r}"
894}
895
896# Calls the makefile of a package
897make_pkg() {
898 local args=()
899 local pkg
900
901 local basedir="${BASEDIR}"
902
903 while [ $# -gt 0 ]; do
904 local arg="${1}"
905 shift
906
907 case "${arg}" in
908 --*)
909 case "${arg}" in
910 --chroot)
911 basedir="/usr/src"
912 ;;
913 esac
914
915 args+=( "${arg}" )
916 ;;
917
918 *)
919 pkg="${arg}"
920 break
921 ;;
922 esac
923 done
924
925 # Execute the make command in the environment
926 execute "${args[@]}" make --directory="${basedir}/lfs" --file="${pkg}" "$@"
927}
928
929lfsmake1() {
930 local pkg="${1}"
931 shift
932
933 # Run the common check
934 lfsmakecommoncheck "${pkg}" "$@"
935 [ $? == 1 ] && return 0
936
937 # Download source outside of the toolchain
938 if ! make_pkg --network "${pkg}" download "$@"; then
939 exiterror "Downloading ${pkg}"
940 fi
941
942 if ! make_pkg --timer="update_runtime" "${pkg}" TOOLCHAIN=1 ROOT="${BUILD_DIR}" b2 install "$@"; then
943 print_status FAIL
944
945 exiterror "Building ${pkg}"
946 fi
947
948 print_status DONE
949}
950
951lfsmake2() {
952 local pkg="${1}"
953 shift
954
955 # Run the common check
956 lfsmakecommoncheck "${pkg}" "$@"
957 [ $? == 1 ] && return 0
958
959 # Download source outside of the toolchain
960 if ! make_pkg --network "${pkg}" download "$@"; then
961 exiterror "Downloading ${pkg}"
962 fi
963
964 # Run install on the package
965 if ! make_pkg --chroot --timer="update_runtime" "${pkg}" b2 install "$@"; then
966 print_status FAIL
967
968 exiterror "Building ${pkg}"
969 fi
970
971 print_status DONE
972}
973
974ipfiredist() {
975 local pkg="${1}"
976 shift
977
978 # Run the common check
979 lfsmakecommoncheck "${pkg}" "$@"
980 [ $? == 1 ] && return 0
981
982 # Run dist on the package
983 if ! make_pkg --chroot --timer="update_runtime" "${pkg}" dist "$@"; then
984 print_status FAIL
985
986 exiterror "Packaging ${pkg}"
987 fi
988
989 print_status DONE
990}
991
992update_runtime() {
993 print_runtime "$(( SECONDS - t ))"
994}
995
996qemu_is_required() {
997 local build_arch="${1}"
998
999 if [ -z "${build_arch}" ]; then
1000 build_arch="${BUILD_ARCH}"
1001 fi
1002
1003 case "${HOST_ARCH},${build_arch}" in
1004 x86_64,arm*|x86_64,aarch64|x86_64,riscv64|i?86,arm*|i?86,aarch64|i?86,x86_64)
1005 return 0
1006 ;;
1007 *)
1008 return 1
1009 ;;
1010 esac
1011}
1012
1013qemu_install_helper() {
1014 # Do nothing, if qemu is not required
1015 if ! qemu_is_required; then
1016 return 0
1017 fi
1018
1019 if [ ! -e /proc/sys/fs/binfmt_misc/status ]; then
1020 exiterror "binfmt_misc not mounted. QEMU_TARGET_HELPER not useable."
1021 fi
1022
1023 if [ ! $(cat /proc/sys/fs/binfmt_misc/status) = 'enabled' ]; then
1024 exiterror "binfmt_misc not enabled. QEMU_TARGET_HELPER not useable."
1025 fi
1026
1027 # Search for the helper binary
1028 local qemu_build_helper="$(qemu_find_build_helper_name "${BUILD_ARCH}")"
1029
1030 # Try to find a suitable binary that we can install
1031 # to the build environment.
1032 local file
1033 for file in "${qemu_build_helper}" "${qemu_build_helper}-static"; do
1034 # file must exist and be executable.
1035 [ -x "${file}" ] || continue
1036
1037 # Must be static.
1038 file_is_static "${file}" || continue
1039
1040 local dirname="${BUILD_DIR}$(dirname "${file}")"
1041 mkdir -p "${dirname}"
1042
1043 # Create the mountpoint
1044 touch "${BUILD_DIR}${file}"
1045
1046 # Mount the helper
1047 if ! mount --bind -o ro "${file}" "${BUILD_DIR}${file}"; then
1048 exiterror "Could not mount ${file}"
1049 fi
1050
1051 # Set
1052 QEMU_TARGET_HELPER="${file}"
1053
1054 return 0
1055 done
1056
1057 exiterror "Could not find a statically-linked QEMU emulator: ${qemu_build_helper}"
1058}
1059
1060qemu_find_build_helper_name() {
1061 local build_arch="${1}"
1062
1063 local magic
1064 case "${build_arch}" in
1065 aarch64)
1066 magic="7f454c460201010000000000000000000200b700"
1067 ;;
1068 arm*)
1069 magic="7f454c4601010100000000000000000002002800"
1070 ;;
1071 riscv64)
1072 magic="7f454c460201010000000000000000000200f300"
1073 ;;
1074 x86_64)
1075 magic="7f454c4602010100000000000000000002003e00"
1076 ;;
1077 esac
1078
1079 [ -z "${magic}" ] && return 1
1080
1081 local file
1082 for file in /proc/sys/fs/binfmt_misc/*; do
1083 # skip write only register entry
1084 [ $(basename "${file}") = "register" ] && continue
1085 # Search for the file with the correct magic value.
1086 grep -qE "^magic ${magic}$" "${file}" || continue
1087
1088 local interpreter="$(grep "^interpreter" "${file}" | awk '{ print $2 }')"
1089
1090 [ -n "${interpreter}" ] || continue
1091 [ "${interpreter:0:1}" = "/" ] || continue
1092 [ -x "${interpreter}" ] || continue
1093
1094 echo "${interpreter}"
1095 return 0
1096 done
1097
1098 return 1
1099}
1100
1101file_is_static() {
1102 local file="${1}"
1103
1104 file -L "${file}" 2>/dev/null | grep -q -e "statically linked" -e "static-pie linked"
1105}
1106
1107update_language_list() {
1108 local path="${1}"
1109
1110 local lang
1111 for lang in ${path}/*.po; do
1112 lang="$(basename "${lang}")"
1113 echo "${lang%*.po}"
1114 done | sort -u > "${path}/LINGUAS"
1115}
1116
1117contributors() {
1118 local commits name
1119
1120 git shortlog --summary --numbered | while read -r commits name; do
1121 echo "${name}"
1122 done | grep -vE -e "^(alpha197|morlix|root|ummeegge)$" -e "via Development$" -e "@" -e "#$"
1123}
1124
1125update_contributors() {
1126 echo -n "Updating list of contributors"
1127
1128 local contributors="$(contributors | paste -sd , - | sed -e "s/,/&\\\\n/g")"
1129
1130 # Edit contributors into credits.cgi
1131 local tmp="$(mktemp)"
1132
1133 awk "/<!-- CONTRIBUTORS -->/{ p=1; print; printf \"${contributors}\n\"}/<!-- END -->/{ p=0 } !p" \
1134 < "${BASEDIR}/html/cgi-bin/credits.cgi" > "${tmp}"
1135
1136 # Copy back modified content
1137 cat "${tmp}" > "${BASEDIR}/html/cgi-bin/credits.cgi"
1138 unlink "${tmp}"
1139
1140 print_status DONE
1141 return 0
1142}
1143
1144# Download sources
1145download_sources() {
1146 local file
1147 local pkg
1148
1149 local failed_packages=()
1150
1151 # Walk through all files in LFS
1152 for file in "${BASEDIR}/lfs/"*; do
1153 pkg="${file##*/}"
1154
1155 # Skip some packages
1156 case "${pkg}" in
1157 Config)
1158 continue
1159 ;;
1160 esac
1161
1162 # Run the common check
1163 lfsmakecommoncheck "${pkg}"
1164 [ $? == 1 ] && continue
1165
1166 # Download and check the package
1167 if ! make_pkg --network "${pkg}" download b2; then
1168 failed_packages+=( "${pkg}" )
1169 print_status FAIL
1170 continue
1171 fi
1172
1173 print_status DONE
1174 done
1175
1176 # Fail if we could not download/verify all packages
1177 if [ "${#failed_packages[@]}" -gt 0 ]; then
1178 exiterror "Failed to download or verify some packages: ${failed_packages[@]}"
1179 fi
1180}
1181
1182# Download the toolchain
1183download_toolchain() {
1184 local toolchain="${1}"
1185
1186 # Do nothing if the toolchain has already been downloaded
1187 if [ -e "${TOOLCHAIN_DIR}/${toolchain}" ]; then
1188 return 0
1189 fi
1190
1191 # Ensure the directory exists
1192 mkdir -p "${TOOLCHAIN_DIR}"
1193
1194 # Create a temporary directory
1195 local tmp="$(mktemp -d)"
1196
1197 # Make the name for the checksum file
1198 local checksums="${toolchain/.tar.zst/.b2}"
1199
1200 # Download the toolchain and checksum files
1201 if ! wget --quiet --directory-prefix="${tmp}" \
1202 "${TOOLCHAIN_URL}/${toolchain}" \
1203 "${TOOLCHAIN_URL}/${checksums}"; then
1204 # Cleanup
1205 rm -rf "${tmp}"
1206
1207 return 1
1208 fi
1209
1210 # Check integrity
1211 if ! cd "${tmp}" && b2sum --quiet --check "${checksums}"; then
1212 # Cleanup
1213 rm -rf "${tmp}"
1214
1215 return 1
1216 fi
1217
1218 # Everything is good, move the files to their destination
1219 if ! mv \
1220 "${tmp}/${toolchain}" \
1221 "${tmp}/${checksums}" \
1222 "${TOOLCHAIN_DIR}"; then
1223 # Cleanup
1224 rm -rf "${tmp}"
1225
1226 return 1
1227 fi
1228
1229 # Cleanup
1230 rm -rf "${tmp}"
1231
1232 return 0
1233}
1234
1235# Extracts the toolchain
1236extract_toolchain() {
1237 local toolchain="${1}"
1238
1239 local build_dir="${BUILD_DIR#${BASEDIR}/}"
1240 local log_dir="${LOG_DIR#${BASEDIR}/}"
1241
1242 local args=(
1243 # Extract
1244 "ax"
1245
1246 # The file to extract
1247 "-f" "${TOOLCHAIN_DIR}/${toolchain}"
1248
1249 # The destination
1250 "-C" "${BASEDIR}"
1251
1252 # Transform any older toolchains
1253 "--transform" "s@^build/@${build_dir}/@"
1254 "--transform" "s@^log/@${log_dir}/@"
1255 )
1256
1257 # Extract the toolchain
1258 tar "${args[@]}" || return $?
1259}
1260
1261# Compresses the toolchain
1262compress_toolchain() {
1263 local toolchain="${1}"
1264
1265 log "Creating toolchain image for ${BUILD_ARCH}"
1266
1267 # Create a temporary directory
1268 local tmp="$(mktemp -d)"
1269
1270 # Make the name for the checksum file
1271 local checksums="${toolchain/.tar.zst/.b2}"
1272
1273 local build_dir="${BUILD_DIR#${BASEDIR}/}"
1274 local log_dir="${LOG_DIR#${BASEDIR}/}"
1275
1276 local args=(
1277 "--create"
1278
1279 # Filter through zstd with custom options
1280 "-I" "zstd ${ZSTD_OPT[*]}"
1281
1282 # Write to the temporary directory
1283 "-f" "${tmp}/${toolchain}"
1284
1285 # Start in the base directory
1286 "-C" "${BASEDIR}"
1287
1288 # Exclude the build logs
1289 "--exclude" "${log_dir}/_build.*.log"
1290
1291 # Include /bin/sh
1292 "${build_dir}/bin/sh"
1293
1294 # Include the /tools_${BUILD_ARCH} directory
1295 "${build_dir}/${TOOLS_DIR}"
1296
1297 # Include the log directory
1298 "${log_dir}"
1299 )
1300
1301 # Create the archive
1302 if ! tar "${args[@]}"; then
1303 # Cleanup
1304 rm -rf "${tmp}"
1305
1306 return 1
1307 fi
1308
1309 # Change to the temporary directory
1310 pushd "${tmp}" &>/dev/null
1311
1312 # Create the checksums
1313 if ! b2sum "${toolchain}" > "${tmp}/${checksums}"; then
1314 popd &>/dev/null
1315
1316 # Cleanup
1317 rm -rf "${tmp}"
1318
1319 return 1
1320 fi
1321
1322 popd &>/dev/null
1323
1324 # Everything is good, move the files to their destination
1325 if ! mv \
1326 "${tmp}/${toolchain}" \
1327 "${tmp}/${checksums}" \
1328 "${TOOLCHAIN_DIR}"; then
1329 # Cleanup
1330 rm -rf "${tmp}"
1331
1332 return 1
1333 fi
1334
1335 return 0
1336}
1337
1338build_toolchain() {
1339 local gcc=$(type -p gcc)
1340 if [ -z "${gcc}" ]; then
1341 exiterror "Could not find GCC. You will need a working build enviroment in order to build the toolchain."
1342 fi
1343
1344 # Check ${TOOLS_DIR} symlink
1345 if [ -h "${TOOLS_DIR}" ]; then
1346 rm -f "${TOOLS_DIR}"
1347 fi
1348
1349 if [ ! -e "${TOOLS_DIR}" ]; then
1350 ln -s "${BUILD_DIR}${TOOLS_DIR}" "${TOOLS_DIR}"
1351 fi
1352
1353 if [ ! -h "${TOOLS_DIR}" ]; then
1354 exiterror "Could not create ${TOOLS_DIR} symbolic link"
1355 fi
1356
1357 local LOGFILE="${LOG_DIR}/_build.toolchain.log"
1358
1359 lfsmake1 stage1
1360 lfsmake1 binutils PASS=1
1361 lfsmake1 gcc PASS=1
1362 lfsmake1 linux HEADERS=1
1363 lfsmake1 glibc
1364 lfsmake1 libxcrypt
1365 lfsmake1 gcc PASS=L
1366 lfsmake1 zlib-ng
1367 lfsmake1 binutils PASS=2
1368 lfsmake1 gcc PASS=2
1369 lfsmake1 zstd
1370 lfsmake1 ccache
1371 lfsmake1 tcl
1372 lfsmake1 expect
1373 lfsmake1 dejagnu
1374 lfsmake1 pkg-config
1375 lfsmake1 ncurses
1376 lfsmake1 bash
1377 lfsmake1 bzip2
1378 lfsmake1 automake
1379 lfsmake1 coreutils
1380 lfsmake1 diffutils
1381 lfsmake1 findutils
1382 lfsmake1 gawk
1383 lfsmake1 gettext
1384 lfsmake1 grep
1385 lfsmake1 gzip
1386 lfsmake1 m4
1387 lfsmake1 make
1388 lfsmake1 patch
1389 lfsmake1 perl
1390 lfsmake1 python3
1391 lfsmake1 sed
1392 lfsmake1 tar
1393 lfsmake1 texinfo
1394 lfsmake1 xz
1395 lfsmake1 bison
1396 lfsmake1 flex
1397 lfsmake1 fake-environ
1398 CUSTOM_PATH="${PATH}" lfsmake1 strip
1399 lfsmake1 cleanup-toolchain
1400}
1401
1402build_system() {
1403 local LOGFILE="${LOG_DIR}/_build.${SNAME}.log"
1404
1405 lfsmake2 stage2
1406 lfsmake2 linux HEADERS=1
1407 lfsmake2 man-pages
1408 lfsmake2 glibc
1409 lfsmake2 tzdata
1410 lfsmake2 cleanup-toolchain
1411 lfsmake2 zlib-ng
1412 [ "${BUILD_ARCH}" = "riscv64" ] && lfsmake2 gcc PASS=A
1413 lfsmake2 zstd
1414 lfsmake2 autoconf
1415 lfsmake2 autoconf-archive
1416 lfsmake2 automake
1417 lfsmake2 help2man
1418 lfsmake2 libtool
1419 lfsmake2 binutils
1420 lfsmake2 gmp
1421 lfsmake2 mpfr
1422 lfsmake2 libmpc
1423 lfsmake2 pkg-config
1424 lfsmake2 libxcrypt
1425 lfsmake2 file
1426 lfsmake2 gcc
1427 lfsmake2 attr
1428 lfsmake2 acl
1429 lfsmake2 sed
1430 lfsmake2 berkeley
1431 lfsmake2 coreutils
1432 lfsmake2 iana-etc
1433 lfsmake2 m4
1434 lfsmake2 bison
1435 lfsmake2 ncurses
1436 lfsmake2 perl
1437 lfsmake2 readline
1438 lfsmake2 bzip2
1439 lfsmake2 xz
1440 lfsmake2 lzip
1441 lfsmake2 pcre
1442 lfsmake2 pcre2
1443 lfsmake2 gettext
1444 lfsmake2 bash
1445 lfsmake2 diffutils
1446 lfsmake2 ed
1447 lfsmake2 findutils
1448 lfsmake2 flex
1449 lfsmake2 gawk
1450 lfsmake2 go
1451 lfsmake2 grep
1452 lfsmake2 groff
1453 lfsmake2 gperf
1454 lfsmake2 gzip
1455 lfsmake2 hostname
1456 lfsmake2 whois
1457 lfsmake2 kbd
1458 lfsmake2 less
1459 lfsmake2 procps
1460 lfsmake2 make
1461 lfsmake2 libpipeline
1462 lfsmake2 man
1463 lfsmake2 net-tools
1464 lfsmake2 patch
1465 lfsmake2 psmisc
1466 lfsmake2 shadow
1467 lfsmake2 sysklogd
1468 lfsmake2 sysvinit
1469 lfsmake2 tar
1470 lfsmake2 texinfo
1471 lfsmake2 util-linux
1472 lfsmake2 vim
1473 lfsmake2 e2fsprogs
1474 lfsmake2 jq
1475 lfsmake2 configroot
1476 lfsmake2 initscripts
1477 lfsmake2 backup
1478 lfsmake2 rust
1479 lfsmake2 openssl
1480 lfsmake2 popt
1481 lfsmake2 libedit
1482 lfsmake2 expat
1483 lfsmake2 libffi
1484 lfsmake2 gdbm
1485 lfsmake2 sqlite
1486 lfsmake2 python3
1487 lfsmake2 python3-setuptools
1488 lfsmake2 ninja
1489 lfsmake2 meson
1490 lfsmake2 pam
1491 lfsmake2 libcap
1492 lfsmake2 libcap-ng
1493 lfsmake2 libpcap
1494 lfsmake2 ppp
1495 lfsmake2 pptp
1496 lfsmake2 unzip
1497 lfsmake2 which
1498 lfsmake2 bc
1499 lfsmake2 cpio
1500 lfsmake2 libaio
1501 lfsmake2 freetype
1502 lfsmake2 libmnl
1503 lfsmake2 libnfnetlink
1504 lfsmake2 libnetfilter_queue
1505 lfsmake2 libnetfilter_conntrack
1506 lfsmake2 libnetfilter_cthelper
1507 lfsmake2 libnetfilter_cttimeout
1508 lfsmake2 iptables
1509 lfsmake2 iproute2
1510 lfsmake2 screen
1511 lfsmake2 elfutils
1512 lfsmake2 libconfig
1513 lfsmake2 curl
1514 lfsmake2 libarchive
1515 lfsmake2 cmake
1516 lfsmake2 json-c
1517 lfsmake2 tcl
1518 lfsmake2 python3-MarkupSafe
1519 lfsmake2 python3-Jinja2
1520 lfsmake2 kmod
1521 lfsmake2 udev
1522 lfsmake2 libusb
1523 lfsmake2 mdadm
1524 lfsmake2 dracut
1525 lfsmake2 lvm2
1526 lfsmake2 multipath-tools
1527 lfsmake2 glib
1528 lfsmake2 libgudev
1529 lfsmake2 libgpg-error
1530 lfsmake2 libgcrypt
1531 lfsmake2 libassuan
1532 lfsmake2 nettle
1533 lfsmake2 libsodium
1534 lfsmake2 libevent2
1535 lfsmake2 apr
1536 lfsmake2 aprutil
1537 lfsmake2 unbound
1538 lfsmake2 gnutls
1539 lfsmake2 libuv
1540 lfsmake2 liburcu
1541 lfsmake2 bind
1542 lfsmake2 dhcp
1543 lfsmake2 dhcpcd
1544 lfsmake2 boost
1545 lfsmake2 linux-atm
1546 lfsmake2 libqmi
1547 lfsmake2 c-ares
1548 lfsmake2 rust-dissimilar
1549 lfsmake2 rust-cfg-if
1550 lfsmake2 rust-libc
1551 lfsmake2 rust-getrandom
1552 lfsmake2 rust-typenum
1553 lfsmake2 rust-version-check
1554 lfsmake2 rust-generic-array
1555 lfsmake2 rust-crypto-common
1556 lfsmake2 rust-cipher
1557 lfsmake2 rust-hex
1558 lfsmake2 rust-unicode-xid
1559 lfsmake2 rust-unicode-ident
1560 lfsmake2 rust-proc-macro2
1561 lfsmake2 rust-quote
1562 lfsmake2 rust-syn-1.0.109
1563 lfsmake2 rust-syn
1564 lfsmake2 rust-home
1565 lfsmake2 rust-lazy-static
1566 lfsmake2 rust-memchr
1567 lfsmake2 rust-aho-corasick
1568 lfsmake2 rust-regex-syntax
1569 lfsmake2 rust-regex
1570 lfsmake2 rust-ucd-trie
1571 lfsmake2 rust-pest
1572 lfsmake2 rust-semver-parser
1573 lfsmake2 rust-semver
1574 lfsmake2 rust-same-file
1575 lfsmake2 rust-walkdir
1576 lfsmake2 rust-dirs
1577 lfsmake2 rust-toolchain_find
1578 lfsmake2 rust-serde_derive
1579 lfsmake2 rust-serde
1580 lfsmake2 rust-itoa
1581 lfsmake2 rust-ryu
1582 lfsmake2 rust-serde_json
1583 lfsmake2 rust-synstructure
1584 lfsmake2 rust-block-buffer
1585 lfsmake2 rust-digest
1586 lfsmake2 rust-ppv-lite86
1587 lfsmake2 rust-rand_core
1588 lfsmake2 rust-rand_core-0.4.2
1589 lfsmake2 rust-rand_core-0.3.1
1590 lfsmake2 rust-rand_chacha
1591 lfsmake2 rust-rand_hc
1592 lfsmake2 rust-rand
1593 lfsmake2 rust-rdrand
1594 lfsmake2 rust-rand-0.4
1595 lfsmake2 rust-log
1596 lfsmake2 rust-num_cpus
1597 lfsmake2 rust-crossbeam-utils
1598 lfsmake2 rust-autocfg
1599 lfsmake2 rust-memoffset
1600 lfsmake2 rust-scopeguard
1601 lfsmake2 rust-crossbeam-epoch
1602 lfsmake2 rust-crossbeam-deque
1603 lfsmake2 rust-either
1604 lfsmake2 rust-crossbeam-channel
1605 lfsmake2 rust-rayon-core
1606 lfsmake2 rust-rayon
1607 lfsmake2 rust-remove_dir_all
1608 lfsmake2 rust-tempdir
1609 lfsmake2 rust-glob
1610 lfsmake2 rust-once_cell
1611 lfsmake2 rust-termcolor
1612 lfsmake2 rust-serde_spanned
1613 lfsmake2 rust-toml_datetime
1614 lfsmake2 rust-equivalent
1615 lfsmake2 rust-allocator-api2
1616 lfsmake2 rust-foldhash
1617 lfsmake2 rust-hashbrown
1618 lfsmake2 rust-indexmap
1619 lfsmake2 rust-winnow
1620 lfsmake2 rust-toml_edit
1621 lfsmake2 rust-toml
1622 lfsmake2 rust-target-triple
1623 lfsmake2 rust-trybuild
1624 lfsmake2 rust-unindent
1625 lfsmake2 rust-proc-macro-hack
1626 lfsmake2 rust-indoc-impl
1627 lfsmake2 rust-indoc-impl-0.3.6
1628 lfsmake2 rust-indoc
1629 lfsmake2 rust-indoc-0.3.6
1630 lfsmake2 rust-instant
1631 lfsmake2 rust-lock_api
1632 lfsmake2 rust-smallvec
1633 lfsmake2 rust-parking_lot_core
1634 lfsmake2 rust-parking_lot
1635 lfsmake2 rust-paste-impl
1636 lfsmake2 rust-paste
1637 lfsmake2 rust-paste-0.1.18
1638 lfsmake2 rust-ctor
1639 lfsmake2 rust-ghost
1640 lfsmake2 rust-inventory-impl
1641 lfsmake2 rust-inventory
1642 lfsmake2 rust-pyo3-build-config
1643 lfsmake2 rust-pyo3-macros-backend
1644 lfsmake2 rust-pyo3-macros
1645 lfsmake2 rust-pyo3
1646 lfsmake2 rust-num-traits
1647 lfsmake2 rust-num-integer
1648 lfsmake2 rust-num_threads
1649 lfsmake2 rust-time
1650 lfsmake2 rust-iana-time-zone
1651 lfsmake2 rust-chrono
1652 lfsmake2 rust-asn1_derive
1653 lfsmake2 rust-asn1
1654 lfsmake2 rust-proc-macro-error-attr
1655 lfsmake2 rust-proc-macro-error
1656 lfsmake2 rust-Inflector
1657 lfsmake2 rust-ouroboros_macro
1658 lfsmake2 rust-aliasable
1659 lfsmake2 rust-stable_deref_trait
1660 lfsmake2 rust-ouroboros
1661 lfsmake2 rust-base64
1662 lfsmake2 rust-pem
1663 lfsmake2 gdb
1664 lfsmake2 grub
1665 lfsmake2 mandoc
1666 lfsmake2 efivar
1667 lfsmake2 efibootmgr
1668 lfsmake2 libtasn1
1669 lfsmake2 p11-kit
1670 lfsmake2 ca-certificates
1671 lfsmake2 fireinfo
1672 lfsmake2 libnet
1673 lfsmake2 libnl-3
1674 lfsmake2 libidn2
1675 lfsmake2 nasm
1676 lfsmake2 libexif
1677 lfsmake2 libjpeg
1678 lfsmake2 libpng
1679 lfsmake2 gd
1680 lfsmake2 slang
1681 lfsmake2 newt
1682 lfsmake2 libsmooth
1683 lfsmake2 pciutils
1684 lfsmake2 usbutils
1685 lfsmake2 libxml2
1686 lfsmake2 libxslt
1687 lfsmake2 perl-BerkeleyDB
1688 lfsmake2 cyrus-sasl
1689 lfsmake2 openldap
1690 lfsmake2 apache2
1691 lfsmake2 web-user-interface
1692 lfsmake2 flag-icons
1693 lfsmake2 jquery
1694 lfsmake2 bootstrap
1695 lfsmake2 arping
1696 lfsmake2 beep
1697 lfsmake2 libssh
1698 lfsmake2 libinih
1699 lfsmake2 xorriso
1700 lfsmake2 dosfstools
1701 lfsmake2 exfatprogs
1702 lfsmake2 reiserfsprogs
1703 lfsmake2 xfsprogs
1704 lfsmake2 sysfsutils
1705 lfsmake2 fuse
1706 lfsmake2 ntfs-3g
1707 lfsmake2 ethtool
1708 lfsmake2 fcron
1709 lfsmake2 wireguard-tools
1710 lfsmake2 perl-ExtUtils-PkgConfig
1711 lfsmake2 perl-GD
1712 lfsmake2 perl-GD-Graph
1713 lfsmake2 perl-GD-TextUtil
1714 lfsmake2 perl-Device-SerialPort
1715 lfsmake2 perl-Device-Modem
1716 lfsmake2 perl-Parse-Yapp
1717 lfsmake2 perl-Data-UUID
1718 lfsmake2 perl-Try-Tiny
1719 lfsmake2 perl-HTTP-Message
1720 lfsmake2 perl-HTTP-Date
1721 lfsmake2 gnupg
1722 lfsmake2 hdparm
1723 lfsmake2 whatmask
1724 lfsmake2 libtirpc
1725 lfsmake2 conntrack-tools
1726 lfsmake2 iputils
1727 lfsmake2 l7-protocols
1728 lfsmake2 hwdata
1729 lfsmake2 logrotate
1730 lfsmake2 logwatch
1731 lfsmake2 misc-progs
1732 lfsmake2 nano
1733 lfsmake2 perl-URI
1734 lfsmake2 perl-CGI
1735 lfsmake2 perl-Switch
1736 lfsmake2 perl-HTML-Tagset
1737 lfsmake2 perl-HTML-Parser
1738 lfsmake2 perl-HTML-Template
1739 lfsmake2 perl-libwww
1740 lfsmake2 perl-LWP-Protocol-https
1741 lfsmake2 perl-Net-HTTP
1742 lfsmake2 perl-Net-DNS
1743 lfsmake2 perl-Net-IPv4Addr
1744 lfsmake2 perl-Net_SSLeay
1745 lfsmake2 perl-IO-Stringy
1746 lfsmake2 perl-IO-Socket-SSL
1747 lfsmake2 perl-Unix-Syslog
1748 lfsmake2 perl-Mail-Tools
1749 lfsmake2 perl-MIME-Tools
1750 lfsmake2 perl-Net-Server
1751 lfsmake2 perl-Canary-Stability
1752 lfsmake2 perl-Convert-TNEF
1753 lfsmake2 perl-Convert-UUlib
1754 lfsmake2 perl-Archive-Zip
1755 lfsmake2 perl-Text-Tabs+Wrap
1756 lfsmake2 perl-XML-Parser
1757 lfsmake2 perl-Crypt-PasswdMD5
1758 lfsmake2 perl-Net-Telnet
1759 lfsmake2 perl-Capture-Tiny
1760 lfsmake2 perl-Config-AutoConf
1761 lfsmake2 perl-File-LibMagic
1762 lfsmake2 perl-Object-Tiny
1763 lfsmake2 perl-Archive-Peek-Libarchive
1764 lfsmake2 python3-inotify
1765 lfsmake2 python3-docutils
1766 lfsmake2 python3-daemon
1767 lfsmake2 ntp
1768 lfsmake2 openssh
1769 lfsmake2 fontconfig
1770 lfsmake2 dejavu-fonts-ttf
1771 lfsmake2 ubuntu-font-family
1772 lfsmake2 freefont
1773 lfsmake2 pixman
1774 lfsmake2 cairo
1775 lfsmake2 harfbuzz
1776 lfsmake2 fribidi
1777 lfsmake2 pango
1778 lfsmake2 rrdtool
1779 lfsmake2 setup
1780 lfsmake2 jansson
1781 lfsmake2 yaml
1782 lfsmake2 libhtp
1783 lfsmake2 colm
1784 lfsmake2 ragel
1785 lfsmake2 vectorscan
1786 lfsmake2 suricata
1787 lfsmake2 ids-ruleset-sources
1788 lfsmake2 ipblocklist-sources
1789 lfsmake2 squid
1790 lfsmake2 squidguard
1791 lfsmake2 calamaris
1792 lfsmake2 tcpdump
1793 lfsmake2 traceroute
1794 lfsmake2 wireless
1795 lfsmake2 pakfire
1796 lfsmake2 lz4
1797 lfsmake2 lzo
1798 lfsmake2 openvpn
1799 lfsmake2 mpage
1800 lfsmake2 dbus
1801 lfsmake2 intltool
1802 lfsmake2 libdaemon
1803 lfsmake2 avahi
1804 lfsmake2 libtalloc
1805 lfsmake2 cifs-utils
1806 lfsmake2 krb5
1807 lfsmake2 rpcsvc-proto
1808 lfsmake2 lmdb
1809 lfsmake2 samba
1810 lfsmake2 iniparser
1811 lfsmake2 netatalk
1812 lfsmake2 sudo
1813 lfsmake2 mc
1814 lfsmake2 wget
1815 lfsmake2 bridge-utils
1816 lfsmake2 smartmontools
1817 lfsmake2 htop
1818 lfsmake2 chkconfig
1819 lfsmake2 postfix
1820 lfsmake2 fetchmail
1821 lfsmake2 clamav
1822 lfsmake2 perl-NetAddr-IP
1823 lfsmake2 dma
1824 lfsmake2 alsa
1825 lfsmake2 guardian
1826 lfsmake2 libid3tag
1827 lfsmake2 libmad
1828 lfsmake2 libogg
1829 lfsmake2 libvorbis
1830 lfsmake2 flac
1831 lfsmake2 lame
1832 lfsmake2 soxr
1833 lfsmake2 libshout
1834 lfsmake2 gnump3d
1835 lfsmake2 libxxhash
1836 lfsmake2 rsync
1837 lfsmake2 rpcbind
1838 lfsmake2 keyutils
1839 lfsmake2 nfs
1840 lfsmake2 ncat
1841 lfsmake2 nmap
1842 lfsmake2 etherwake
1843 lfsmake2 bwm-ng
1844 lfsmake2 sysstat
1845 lfsmake2 strongswan
1846 lfsmake2 rng-tools
1847 lfsmake2 lsof
1848 lfsmake2 lm_sensors
1849 lfsmake2 libstatgrab
1850 lfsmake2 liboping
1851 lfsmake2 netsnmpd
1852 lfsmake2 nut
1853 lfsmake2 collectd
1854 lfsmake2 git
1855 lfsmake2 linux-firmware
1856 lfsmake2 dvb-firmwares
1857 lfsmake2 zd1211-firmware
1858 lfsmake2 rpi-firmware
1859 lfsmake2 intel-microcode
1860 lfsmake2 pcengines-apu-firmware
1861 lfsmake2 elinks
1862 lfsmake2 igmpproxy
1863 lfsmake2 opus
1864 lfsmake2 python3-toml
1865 lfsmake2 python3-pyproject2setuppy
1866 lfsmake2 python3-pyparsing
1867 lfsmake2 spice-protocol
1868 lfsmake2 spice
1869 lfsmake2 sdl2
1870 lfsmake2 libusbredir
1871 lfsmake2 libseccomp
1872 lfsmake2 libslirp
1873 lfsmake2 dtc
1874 lfsmake2 python3-tomli
1875 lfsmake2 qemu
1876 lfsmake2 nagios_nrpe
1877 lfsmake2 nagios-plugins
1878 lfsmake2 observium-agent
1879 lfsmake2 ebtables
1880 lfsmake2 faad2
1881 lfsmake2 alac
1882 lfsmake2 ffmpeg
1883 lfsmake2 vdr
1884 lfsmake2 vdr_streamdev
1885 lfsmake2 vdr_epgsearch
1886 lfsmake2 vdr_dvbapi
1887 lfsmake2 vdr_eepg
1888 lfsmake2 w_scan
1889 lfsmake2 fmt
1890 lfsmake2 mpd
1891 lfsmake2 libmpdclient
1892 lfsmake2 mpc
1893 lfsmake2 perl-Net-CIDR-Lite
1894 lfsmake2 perl-Net-SMTP-SSL
1895 lfsmake2 perl-Authen-SASL
1896 lfsmake2 perl-MIME-Lite
1897 lfsmake2 perl-Email-Date-Format
1898 lfsmake2 vnstat
1899 lfsmake2 iw
1900 lfsmake2 wpa_supplicant
1901 lfsmake2 hostapd
1902 lfsmake2 syslinux
1903 lfsmake2 tftpd
1904 lfsmake2 cpufrequtils
1905 lfsmake2 apcupsd
1906 lfsmake2 fireperf
1907 lfsmake2 iperf
1908 lfsmake2 iperf3
1909 lfsmake2 7zip
1910 lfsmake2 lynis
1911 lfsmake2 sshfs
1912 lfsmake2 utfcpp
1913 lfsmake2 taglib
1914 lfsmake2 perl-gettext
1915 lfsmake2 perl-Sort-Naturally
1916 lfsmake2 vdradmin
1917 lfsmake2 perl-DBI
1918 lfsmake2 perl-DBD-SQLite
1919 lfsmake2 perl-File-ReadBackwards
1920 lfsmake2 openvmtools
1921 lfsmake2 joe
1922 lfsmake2 monit
1923 lfsmake2 watchdog
1924 lfsmake2 usb_modeswitch
1925 lfsmake2 usb_modeswitch_data
1926 lfsmake2 zerofree
1927 lfsmake2 minicom
1928 lfsmake2 ddrescue
1929 lfsmake2 parted
1930 lfsmake2 swig
1931 lfsmake2 python3-pyelftools
1932 lfsmake2 u-boot
1933 lfsmake2 wireless-regdb
1934 lfsmake2 ddns
1935 lfsmake2 python3-pycparser
1936 lfsmake2 python3-charset-normalizer
1937 lfsmake2 python3-certifi
1938 lfsmake2 python3-idna
1939 lfsmake2 python3-requests
1940 lfsmake2 python3-pep517
1941 lfsmake2 python3-build
1942 lfsmake2 python3-install
1943 lfsmake2 python3-urllib3
1944 lfsmake2 python3-flit
1945 lfsmake2 python3-packaging
1946 lfsmake2 python3-typing-extensions
1947 lfsmake2 python3-semantic-version
1948 lfsmake2 python3-setuptools-scm
1949 lfsmake2 python3-setuptools-rust
1950 lfsmake2 python3-six
1951 lfsmake2 python3-dateutil
1952 lfsmake2 python3-jmespath
1953 lfsmake2 python3-colorama
1954 lfsmake2 python3-yaml
1955 lfsmake2 python3-s3transfer
1956 lfsmake2 python3-rsa
1957 lfsmake2 python3-pyasn1
1958 lfsmake2 python3-botocore
1959 lfsmake2 python3-cffi
1960 lfsmake2 python3-cryptography
1961 lfsmake2 python3-circuitbreaker
1962 lfsmake2 python3-pytz
1963 lfsmake2 python3-click
1964 lfsmake2 python3-arrow
1965 lfsmake2 python3-terminaltables
1966 lfsmake2 python3-pkgconfig
1967 lfsmake2 python3-msgpack
1968 lfsmake2 python3-editables
1969 lfsmake2 python3-pathspec
1970 lfsmake2 python3-pluggy
1971 lfsmake2 python3-calver
1972 lfsmake2 python3-trove-classifiers
1973 lfsmake2 python3-hatchling
1974 lfsmake2 python3-hatch-vcs
1975 lfsmake2 python3-hatch-fancy-pypi-readme
1976 lfsmake2 python3-attrs
1977 lfsmake2 python3-sniffio
1978 lfsmake2 python3-sortedcontainers
1979 lfsmake2 python3-outcome
1980 lfsmake2 python3-async_generator
1981 lfsmake2 python3-flit_scm
1982 lfsmake2 python3-exceptiongroup
1983 lfsmake2 python3-trio
1984 lfsmake2 python3-pyfuse3
1985 lfsmake2 aws-cli
1986 lfsmake2 oci-python-sdk
1987 lfsmake2 oci-cli
1988 lfsmake2 transmission
1989 lfsmake2 mtr
1990 lfsmake2 minidlna
1991 lfsmake2 acpid
1992 lfsmake2 fping
1993 lfsmake2 telnet
1994 lfsmake2 xinetd
1995 lfsmake2 stress
1996 lfsmake2 sarg
1997 lfsmake2 nginx
1998 lfsmake2 sysbench
1999 lfsmake2 strace
2000 lfsmake2 ltrace
2001 lfsmake2 ipfire-netboot
2002 lfsmake2 keepalived
2003 lfsmake2 ipvsadm
2004 lfsmake2 perl-Carp-Clan
2005 lfsmake2 perl-Date-Calc
2006 lfsmake2 perl-Date-Manip
2007 lfsmake2 perl-File-Tail
2008 lfsmake2 perl-TimeDate
2009 lfsmake2 swatch
2010 lfsmake2 tor
2011 lfsmake2 wavemon
2012 lfsmake2 iptraf-ng
2013 lfsmake2 iotop
2014 lfsmake2 stunnel
2015 lfsmake2 bacula
2016 lfsmake2 perl-Font-TTF
2017 lfsmake2 perl-IO-String
2018 lfsmake2 perl-PDF-API2
2019 lfsmake2 proxy-accounting
2020 lfsmake2 tmux
2021 lfsmake2 perl-Text-CSV_XS
2022 lfsmake2 lua
2023 lfsmake2 haproxy
2024 lfsmake2 ipset
2025 lfsmake2 dnsdist
2026 lfsmake2 bird
2027 lfsmake2 libyang
2028 lfsmake2 abseil-cpp
2029 lfsmake2 protobuf
2030 lfsmake2 protobuf-c
2031 lfsmake2 frr
2032 lfsmake2 dmidecode
2033 lfsmake2 mcelog
2034 lfsmake2 libpciaccess
2035 lfsmake2 ovmf
2036 lfsmake2 libvirt
2037 lfsmake2 freeradius
2038 lfsmake2 perl-common-sense
2039 lfsmake2 perl-inotify2
2040 lfsmake2 perl-Net-IP
2041 lfsmake2 wio
2042 lfsmake2 iftop
2043 lfsmake2 mdns-repeater
2044 lfsmake2 i2c-tools
2045 lfsmake2 nss-myhostname
2046 lfsmake2 dehydrated
2047 lfsmake2 libplist
2048 lfsmake2 nqptp
2049 lfsmake2 shairport-sync
2050 lfsmake2 borgbackup
2051 lfsmake2 knot
2052 lfsmake2 spectre-meltdown-checker
2053 lfsmake2 zabbix_agentd
2054 lfsmake2 flashrom
2055 lfsmake2 firmware-update
2056 lfsmake2 ruby
2057 lfsmake2 asciidoctor
2058 lfsmake2 speexdsp
2059 lfsmake2 tshark
2060 lfsmake2 speedtest-cli
2061 lfsmake2 amazon-ssm-agent
2062 lfsmake2 libloc
2063 lfsmake2 ncdu
2064 lfsmake2 lshw
2065 lfsmake2 socat
2066 lfsmake2 libcdada
2067 lfsmake2 pmacct
2068 lfsmake2 squid-asnbl
2069 lfsmake2 qemu-ga
2070 lfsmake2 gptfdisk
2071 lfsmake2 oath-toolkit
2072 lfsmake2 qrencode
2073 lfsmake2 perl-File-Remove
2074 lfsmake2 perl-Module-Build
2075 lfsmake2 perl-Module-ScanDeps
2076 lfsmake2 perl-YAML-Tiny
2077 lfsmake2 perl-Module-Install
2078 lfsmake2 perl-Imager
2079 lfsmake2 perl-Imager-QRCode
2080 lfsmake2 perl-MIME-Base32
2081 lfsmake2 perl-URI-Encode
2082 lfsmake2 rsnapshot
2083 lfsmake2 mympd
2084 lfsmake2 wsdd
2085 lfsmake2 btrfs-progs
2086 lfsmake2 inotify-tools
2087 lfsmake2 grub-btrfs
2088 lfsmake2 fort-validator
2089
2090 lfsmake2 linux
2091 lfsmake2 rtl8812au
2092 lfsmake2 linux-initrd
2093
2094 lfsmake2 memtest
2095
2096 # Build the installer
2097 lfsmake2 installer
2098
2099 # Build images
2100 lfsmake2 cdrom
2101 lfsmake2 flash-images
2102 lfsmake2 core-updates
2103}
2104
2105build_packages() {
2106 local LOGFILE="${LOG_DIR}/_build.packages.log"
2107
2108 # Build packages
2109 print_headline "Building Packages"
2110
2111 local path
2112 local -A pkgs=()
2113 local pkg
2114
2115 # Collect all packages
2116 for path in \
2117 "${BASEDIR}/config/rootfiles/packages/"* \
2118 "${BASEDIR}/config/rootfiles/packages/${BUILD_ARCH}"/*; do
2119 # Skip directories
2120 if [ -d "${path}" ]; then
2121 continue
2122 fi
2123
2124 pkgs["${path##*/}"]="${path}"
2125 done
2126
2127 # Package them all
2128 for pkg in ${!pkgs[@]}; do
2129 ipfiredist "${pkg}"
2130 done
2131}
2132
2133# This function will re-execute a command in a new namespace
2134exec_in_namespace() {
2135 # Nothing to do if we are already in a new namespace
2136 if [ -n "${IN_NAMESPACE}" ]; then
2137 return 0
2138 fi
2139
2140 # Forward any configuration
2141 local args=(
2142 "--target=${BUILD_ARCH}"
2143 )
2144
2145 IN_NAMESPACE=1 \
2146 exec unshare \
2147 --mount \
2148 --propagation=private \
2149 "${0}" "${args[@]}" "$@"
2150}
2151
2152check_for_missing_rootfiles() {
2153 print_headline "Checking for missing rootfiles..."
2154
2155 local file
2156 for file in ${LOG_DIR}/*_missing_rootfile; do
2157 [ -e "${file}" ] || continue
2158
2159 file="${file##*/}"
2160 file="${file/_missing_rootfile/}";
2161
2162 print_line "${file} is missing a rootfile"
2163 print_status FAIL
2164 done
2165
2166 return 0
2167}
2168
2169check_rootfiles_for_arch() {
2170 local arch="${1}"
2171
2172 local args=(
2173 # Search path
2174 "${BASEDIR}/config/rootfiles"
2175
2176 # Exclude old core updates
2177 "--exclude-dir" "oldcore"
2178
2179 # Ignore the update scripts
2180 "--exclude" "update.sh"
2181 )
2182
2183 # A list of files that are not scanned
2184 # because they probably cause some false positives.
2185 local excluded_files=(
2186 abseil-cpp
2187 cmake
2188 gdb
2189 liburcu
2190 ovmf
2191 qemu
2192 rust-memchr
2193 rust-libc
2194 rust-ppv-lite86
2195 xfsprogs
2196 )
2197
2198 # Exclude any architecture-specific directories
2199 local a
2200 for a in ${ARCHES[@]}; do
2201 args+=( "--exclude-dir" "${a}" )
2202 done
2203
2204 # Exclude all excluded files
2205 local x
2206 for x in ${excluded_files[@]}; do
2207 args+=( "--exclude" "${x}" )
2208 done
2209
2210 # Search for all files that contain the architecture
2211 local files=(
2212 $(grep --files-with-matches -r "^.*${arch}" "${args[@]}")
2213 )
2214
2215 local file
2216 for file in ${files[@]}; do
2217 print_line "${file} contains ${arch}"
2218 print_status FAIL
2219 done
2220
2221 return "${#files[@]}"
2222}
2223
2224check_rootfiles_for_pattern() {
2225 local pattern="${1}"
2226 local message="${2}"
2227
2228 local args=(
2229 # Search path
2230 "${BASEDIR}/config/rootfiles"
2231
2232 # Exclude old core updates
2233 "--exclude-dir" "oldcore"
2234
2235 # Ignore the update scripts
2236 "--exclude" "update.sh"
2237 )
2238
2239 if grep -r "${pattern}" "${args[@]}"; then
2240 if [ -n "${message}" ]; then
2241 print_line "${message}"
2242 print_status FAIL
2243 else
2244 print_file "Files matching '${pattern}' have been found in the rootfiles"
2245 print_status FAIL
2246 fi
2247 return 1
2248 fi
2249
2250 return 0
2251}
2252
2253check_rootfiles() {
2254 local failed=0
2255
2256 print_headline "Checking for rootfile consistency..."
2257
2258 # Check for changes
2259 if ! check_rootfiles_for_pattern "^[\+\-]" \
2260 "Rootfiles have changed in them"; then
2261 failed=1
2262 fi
2263
2264 # Check for /etc/init.d
2265 if ! check_rootfiles_for_pattern "^etc/init\.d/" \
2266 "/etc/init.d/* has been found. Please replace by /etc/rc.d/init.d"; then
2267 failed=1
2268 fi
2269
2270 # Check for /var/run
2271 if ! check_rootfiles_for_pattern "^var/run/.*" \
2272 "You cannot ship files in /var/run as it is a ramdisk"; then
2273 failed=1
2274 fi
2275
2276 # Check architectures
2277 local arch
2278 for arch in ${ARCHES[@]}; do
2279 check_rootfiles_for_arch "${arch}" || failed=$?
2280 done
2281
2282 # Return the error
2283 return ${failed}
2284}
2285
2286check_changed_rootfiles() {
2287 local files=(
2288 $(grep --files-with-matches -r "^+" "${LOG_DIR}" --exclude="_*" | sort)
2289 )
2290
2291 # If we have no matches, there is nothing to do
2292 [ "${#files[@]}" -eq 0 ] && return 0
2293
2294 print_line "Packages have created new files"
2295 print_status WARN
2296
2297 local file
2298 for file in ${files[@]}; do
2299 print_line " ${file##*/}"
2300 print_status WARN
2301 done
2302
2303 return 0
2304}
2305
2306# Set BASEDIR
2307readonly BASEDIR="$(find_base)"
2308
2309# Get some information about the host system
2310SYSTEM_PROCESSORS="$(system_processors)"
2311SYSTEM_MEMORY="$(system_memory)"
2312
2313# Default settings
2314BUILD_ARCH="${HOST_ARCH}"
2315CCACHE_CACHE_SIZE="4G"
2316
2317# Load configuration file
2318if [ -f .config ]; then
2319 source .config
2320fi
2321
2322# Parse any command line options (not commands)
2323while [ $# -gt 0 ]; do
2324 case "${1}" in
2325 --target=*)
2326 BUILD_ARCH="${1#--target=}"
2327 ;;
2328
2329 -*)
2330 exiterror "Unknown configuration option: ${1}"
2331 ;;
2332
2333 # Found a command, so exit options parsing
2334 *)
2335 break
2336 ;;
2337 esac
2338 shift
2339done
2340
2341# Check the architecture
2342case "${BUILD_ARCH}" in
2343 aarch64|x86_64|riscv64)
2344 ;;
2345
2346 *)
2347 exiterror "Unsupported architecture: ${BUILD_ARCH}"
2348 ;;
2349esac
2350
2351# Set build platform
2352case "${BUILD_ARCH}" in
2353 aarch64)
2354 BUILD_PLATFORM="arm"
2355 ;;
2356
2357 riscv64)
2358 BUILD_PLATFORM="riscv"
2359 ;;
2360
2361 x86_64)
2362 BUILD_PLATFORM="x86"
2363 ;;
2364esac
2365
2366# Configure the C compiler
2367CFLAGS=(
2368 # Optimize the code
2369 "-O2"
2370
2371 # Do not compile in any debugging information
2372 "-g0"
2373
2374 # Do not write temporary files
2375 "-pipe"
2376
2377 # Enable all warnings
2378 "-Wall"
2379
2380 # Enable exceptions
2381 "-fexceptions"
2382
2383 # Compile place-independent code
2384 "-fPIC"
2385
2386 # Fortify Source
2387 "-Wp,-U_FORTIFY_SOURCE"
2388 "-Wp,-D_FORTIFY_SOURCE=3"
2389
2390 # Enable additional checks for C++ in glibc
2391 "-Wp,-D_GLIBCXX_ASSERTIONS"
2392
2393 # Enable stack smashing protection
2394 "-fstack-protector-strong"
2395
2396 # Enable stack clash protection
2397 "-fstack-clash-protection"
2398)
2399
2400# Architecture-dependent compiler flags
2401case "${BUILD_ARCH}" in
2402 aarch64)
2403 CFLAGS+=(
2404 "-mbranch-protection=standard"
2405 )
2406 ;;
2407
2408 x86_64)
2409 CFLAGS+=(
2410 "-m64" "-mtune=generic" "-fcf-protection=full"
2411 )
2412 ;;
2413esac
2414
2415# Configure the Rust compiler
2416RUSTFLAGS=(
2417 "-Copt-level=3"
2418 "-Clink-arg=-Wl,-z,relro,-z,now"
2419 "-Ccodegen-units=1"
2420 "--cap-lints=warn"
2421)
2422
2423# Configure the compiler tuple
2424CROSSTARGET="${BUILD_ARCH}-cross-linux-gnu"
2425BUILDTARGET="${BUILD_ARCH}-pc-linux-gnu"
2426
2427# Use this as default PARALLELISM
2428DEFAULT_PARALLELISM="${SYSTEM_PROCESSORS}"
2429
2430# Limit lauched ninja build jobs to computed parallel value
2431NINJAJOBS="${DEFAULT_PARALLELISM}"
2432
2433# Configure XZ
2434XZ_OPT=(
2435 "-T0" "-8"
2436)
2437
2438# Configure Zstandard
2439ZSTD_OPT=(
2440 "-T0" "-19" "--long"
2441)
2442
2443# Set directories
2444readonly CACHE_DIR="${BASEDIR}/cache"
2445readonly TOOLCHAIN_DIR="${CACHE_DIR}/toolchains"
2446readonly CCACHE_DIR="${BASEDIR}/ccache/${BUILD_ARCH}/${TOOLCHAINVER}"
2447readonly BUILD_DIR="${BASEDIR}/build_${BUILD_ARCH}"
2448readonly IMAGES_DIR="${BASEDIR}/images_${BUILD_ARCH}"
2449readonly LOG_DIR="${BASEDIR}/log_${BUILD_ARCH}"
2450readonly PACKAGES_DIR="${IMAGES_DIR}/packages"
2451readonly TOOLS_DIR="/tools_${BUILD_ARCH}"
2452
2453# Set URLs
2454readonly SOURCE_URL="https://source.ipfire.org/ipfire-2.x"
2455readonly TOOLCHAIN_URL="https://source.ipfire.org/toolchains"
2456
2457# Set the LOGFILE
2458LOGFILE="${LOG_DIR}/_build.preparation.log"
2459
2460# Ensure that some basic directories exist
2461mkdir -p "${CACHE_DIR}" "${LOG_DIR}"
2462
2463# Toolchain Archive
2464readonly TOOLCHAIN="${SNAME}-${VERSION}-toolchain-${TOOLCHAINVER}-${BUILD_ARCH}.tar.zst"
2465
2466# See what we're supposed to do
2467case "$1" in
2468build)
2469 START_TIME="${SECONDS}"
2470
2471 # Launch in a new namespace
2472 exec_in_namespace "$@"
2473
2474 # Prepare the environment
2475 prepareenv --required-space=8192
2476
2477 # Check if the toolchain is available
2478 if [ ! -e "${BUILD_DIR}${TOOLS_DIR}/.toolchain-successful" ]; then
2479 # If we have the toolchain available, we extract it into the build environment
2480 if [ -r "${TOOLCHAIN_DIR}/${TOOLCHAIN}" ]; then
2481 print_headline "Packaged toolchain compilation"
2482
2483 # Extract the toolchain
2484 if ! extract_toolchain "${TOOLCHAIN}"; then
2485 exiterror "Failed extracting the toolchain"
2486 fi
2487
2488 # Otherwise perform a full toolchain compilation
2489 else
2490 print_headline "Full toolchain compilation"
2491 build_toolchain
2492 fi
2493 fi
2494
2495 print_headline "Building ${NAME}"
2496 build_system
2497
2498 # Build all packages
2499 build_packages
2500
2501 # Check for missing rootfiles
2502 check_for_missing_rootfiles
2503
2504 # Check for rootfile consistency
2505 if ! check_rootfiles; then
2506 exiterror "Rootfiles are inconsistent"
2507 fi
2508
2509 check_changed_rootfiles
2510
2511 print_build_summary $(( SECONDS - START_TIME ))
2512 ;;
2513tail)
2514 tail -F \
2515 "${LOG_DIR}/_build.preparation.log" \
2516 "${LOG_DIR}/_build.toolchain.log" \
2517 "${LOG_DIR}/_build.${SNAME}.log" \
2518 "${LOG_DIR}/_build.packages.log" 2>/dev/null
2519 ;;
2520shell)
2521 # Launch in a new namespace
2522 exec_in_namespace "$@"
2523
2524 # enter a shell inside LFS chroot
2525 # may be used to changed kernel settings
2526 prepareenv --network
2527 entershell
2528 ;;
2529check)
2530 # Check for rootfile consistency
2531 if ! check_rootfiles; then
2532 exiterror "Rootfiles are inconsistent"
2533 fi
2534
2535 check_changed_rootfiles
2536 ;;
2537clean)
2538 print_line "Cleaning build directory..."
2539
2540 # Cleanup build files
2541 rm -rf \
2542 "${BUILD_DIR}" \
2543 "${IMAGES_DIR}" \
2544 "${LOG_DIR}"
2545
2546 # Remove the /tools symlink
2547 if [ -h "${TOOLS_DIR}" ]; then
2548 rm -f "${TOOLS_DIR}"
2549 fi
2550
2551 print_status DONE
2552 ;;
2553downloadsrc)
2554 # Tell the user what we are about to do
2555 print_headline "Pre-loading all source files"
2556
2557 # Download all sources
2558 download_sources
2559 ;;
2560toolchain)
2561 # Launch in a new namespace
2562 exec_in_namespace "$@"
2563
2564 # Prepare the environment
2565 prepareenv
2566
2567 print_headline "Toolchain compilation (${BUILD_ARCH})"
2568
2569 # Build the toolchain
2570 build_toolchain
2571
2572 # Ensure the toolchain directory exists
2573 mkdir -p "${TOOLCHAIN_DIR}"
2574
2575 # Compress the toolchain
2576 if ! compress_toolchain "${TOOLCHAIN}"; then
2577 exiterror "Could not compress toolchain"
2578 fi
2579 ;;
2580
2581gettoolchain)
2582 download_toolchain "${TOOLCHAIN}"
2583 ;;
2584uploadsrc)
2585 # Check if IPFIRE_USER is set
2586 if [ -z "${IPFIRE_USER}" ]; then
2587 exiterror "You have to setup IPFIRE_USER first. See .config for details."
2588 fi
2589
2590 # Sync with upstream
2591 rsync \
2592 --recursive \
2593 --update \
2594 --ignore-existing \
2595 --progress \
2596 --human-readable \
2597 --exclude="toolchains/" \
2598 "${CACHE_DIR}/" \
2599 "${IPFIRE_USER}@people.ipfire.org:/pub/sources/source-2.x"
2600
2601 exit 0
2602 ;;
2603lang)
2604 echo -ne "Checking the translations for missing or obsolete strings..."
2605 chmod 755 $BASEDIR/tools/{check_strings.pl,sort_strings.pl,check_langs.sh}
2606 $BASEDIR/tools/sort_strings.pl en
2607 $BASEDIR/tools/sort_strings.pl de
2608 $BASEDIR/tools/sort_strings.pl fr
2609 $BASEDIR/tools/sort_strings.pl es
2610 $BASEDIR/tools/sort_strings.pl pl
2611 $BASEDIR/tools/sort_strings.pl ru
2612 $BASEDIR/tools/sort_strings.pl nl
2613 $BASEDIR/tools/sort_strings.pl tr
2614 $BASEDIR/tools/sort_strings.pl it
2615 $BASEDIR/tools/check_strings.pl en > $BASEDIR/doc/language_issues.en
2616 $BASEDIR/tools/check_strings.pl de > $BASEDIR/doc/language_issues.de
2617 $BASEDIR/tools/check_strings.pl fr > $BASEDIR/doc/language_issues.fr
2618 $BASEDIR/tools/check_strings.pl es > $BASEDIR/doc/language_issues.es
2619 $BASEDIR/tools/check_strings.pl pl > $BASEDIR/doc/language_issues.pl
2620 $BASEDIR/tools/check_strings.pl ru > $BASEDIR/doc/language_issues.ru
2621 $BASEDIR/tools/check_strings.pl nl > $BASEDIR/doc/language_issues.nl
2622 $BASEDIR/tools/check_strings.pl tr > $BASEDIR/doc/language_issues.tr
2623 $BASEDIR/tools/check_strings.pl it > $BASEDIR/doc/language_issues.it
2624 $BASEDIR/tools/check_langs.sh > $BASEDIR/doc/language_missings
2625 print_status DONE
2626
2627 echo -ne "Updating language lists..."
2628 update_language_list ${BASEDIR}/src/installer/po
2629 update_language_list ${BASEDIR}/src/setup/po
2630 print_status DONE
2631 ;;
2632update-contributors)
2633 update_contributors
2634 ;;
2635find-dependencies)
2636 shift
2637 exec "${BASEDIR}/tools/find-dependencies" "${BUILD_DIR}" "$@"
2638 ;;
2639check-manualpages)
2640 echo "Checking the manual pages for broken links..."
2641
2642 chmod 755 $BASEDIR/tools/check_manualpages.pl
2643 if $BASEDIR/tools/check_manualpages.pl; then
2644 print_status DONE
2645 else
2646 print_status FAIL
2647 fi
2648 ;;
2649__timer)
2650 __timer "${2}" || exit $?
2651 ;;
2652*)
2653 echo "Usage: $0 [OPTIONS] {build|check-manualpages|clean|downloadsrc|find-dependencies|gettoolchain|lang|shell|tail|toolchain|update-contributors|uploadsrc}"
2654 cat doc/make.sh-usage
2655 ;;
2656esac