]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
make.sh: Add helper function to run a make command
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 Jul 2024 10:06:53 +0000 (10:06 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Jul 2024 15:39:44 +0000 (15:39 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
make.sh

diff --git a/make.sh b/make.sh
index 4a55868b257232bfa8dbef20718090255e458a3f..c04d86fc4f1e156654c165ff0d859b8ce4b78097 100755 (executable)
--- a/make.sh
+++ b/make.sh
@@ -748,38 +748,91 @@ lfsmake1() {
        print_status DONE
 }
 
-lfsmake2() {
-       lfsmakecommoncheck $*
+run_command() {
+       local pkg
+       local action
+
+       local chroot="false"
+
+       while [ $# -gt 0 ]; do
+               case "${1}" in
+                       --chroot)
+                               chroot="true"
+                               ;;
+
+                       -*)
+                               echo "Unknown argument: ${1}" >&2
+                               return 2
+                               ;;
+
+                       *)
+                               # Set pkg
+                               if [ -z "${pkg}" ]; then
+                                       pkg="${1}"
+
+                               # Set action
+                               elif [ -z "${action}" ]; then
+                                       action="${1}"
+
+                               # Fail on everything else
+                               else
+                                       echo "Unknown argument: ${1}" >&2
+                                       return 2
+                               fi
+                               ;;
+               esac
+               shift
+       done
+
+       # Run the common check
+       lfsmakecommoncheck "${pkg}"
        [ $? == 1 ] && return 0
 
-       enterchroot \
-               bash -x -c "cd /usr/src/lfs && \
-                       make -f $* \
-                       LFS_BASEDIR=/usr/src install" \
-               >> ${LOGFILE} 2>&1 &
+       local command=(
+               # Run a shell
+               "bash"
 
-       if ! wait_until_finished $!; then
+               # Enable tracing
+               "-x"
+
+               # Run the following command
+               "-c" "cd /usr/src/lfs && make -f ${pkg} LFS_BASEDIR=/usr/src ${action}"
+       )
+
+       # Run this in chroot?
+       case "${chroot}" in
+               true)
+                       command=( "enterchroot" "${command[@]}" )
+                       ;;
+       esac
+
+       # Run the command and pipe all output to the logfile
+       if ! "${command[@]}" >> "${LOGFILE}" 2>&1; then
                print_status FAIL
-               exiterror "Building $*"
+               return 1
        fi
 
+       # All done
        print_status DONE
+       return 0
 }
 
-ipfiredist() {
-       lfsmakecommoncheck $*
-       [ $? == 1 ] && return 0
-
-       enterchroot \
-               bash -x -c "cd /usr/src/lfs && make -f $* LFS_BASEDIR=/usr/src dist" \
-               >> ${LOGFILE} 2>&1 &
+lfsmake2() {
+       local pkg="${1}"
 
-       if ! wait_until_finished $!; then
-               print_status FAIL
-               exiterror "Packaging $*"
+       # Run install on the package
+       if ! run_command --chroot "${pkg}" install; then
+               exiterror "Building ${pkg}"
        fi
+}
 
-       print_status DONE
+ipfiredist() {
+       local pkg="${1}"
+
+       # Run dist on the package
+       if ! run_command --chroot "${pkg}" dist; then
+               exiterror "Packging ${pkg}"
+       fi
 }
 
 wait_until_finished() {