commit:     94d32a155ef3e5cd59f852a032e5887b74306d81
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Sun Jul 28 22:06:33 2019 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Mon Jul 29 20:00:27 2019 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=94d32a15

Add --kernel-append-localversion option

Now that we moved $ARCH value to kernel's LOCALVERSION setting,
you cannot easily change LOCALVERSION anymore without losing
$ARCH information.

This can be annoying when you just want to build a new revision
which should have its own kernel binary, initramfs and modules
directory because you would have to remember to include default
value.

The new option will allow you to just append to genkernel's
KERNEL_LOCALVERSION value. This way you can just call genkernel
with --kernel-append-localversion=-rN option to build and test
a new revision.

Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 doc/genkernel.8.txt  |  6 +++++
 gen_cmdline.sh       |  6 +++++
 gen_determineargs.sh | 63 ++++++++++++++++++++++++++++++++++------------------
 3 files changed, 53 insertions(+), 22 deletions(-)

diff --git a/doc/genkernel.8.txt b/doc/genkernel.8.txt
index 35762a2..1b36729 100644
--- a/doc/genkernel.8.txt
+++ b/doc/genkernel.8.txt
@@ -124,6 +124,12 @@ KERNEL CONFIGURATION
 *--*[*no-*]*virtio*::
     Adds, or skip adding VirtIO support to kernel configuration.
 
+*--kernel-append-localversion*=<...>::
+    Appends value to genkernel's *KERNEL_LOCALVERSION* option (see below).
+    The idea is to use this option to allow to easily build a new revision
+    with own kernel binary, initramfs and modules directory without losing
+    default *KERNEL_LOCALVERSION* value.
+
 *--kernel-localversion*=<...>::
 Set kernel option *LOCALVERSION*. Use special value *UNSET* to
 unset any already set *LOCALVERSION*. The following placeholders are

diff --git a/gen_cmdline.sh b/gen_cmdline.sh
index 6fbf309..dcf479b 100755
--- a/gen_cmdline.sh
+++ b/gen_cmdline.sh
@@ -71,6 +71,8 @@ longusage() {
   echo "       --no-static             Do not build a static (monolithic 
kernel)"
   echo "  Kernel settings"
   echo "       --kerneldir=<dir>       Location of the kernel sources"
+  echo "       --kernel-append-localversion=<...>"
+  echo "                               Appends value to genkernel's 
KERNEL_LOCALVERSION option"
   echo "       --kernel-config=<file|default>"
   echo "                               Kernel configuration file to use for 
compilation; Use"
   echo "                               'default' to explicitly start from 
scratch using"
@@ -648,6 +650,10 @@ parse_cmdline() {
                        CMD_KERNEL_DIR="${*#*=}"
                        print_info 3 "CMD_KERNEL_DIR: ${CMD_KERNEL_DIR}"
                        ;;
+               --kernel-append-localversion=*)
+                       CMD_KERNEL_APPEND_LOCALVERSION="${*#*=}"
+                       print_info 3 "CMD_KERNEL_APPEND_LOCALVERSION: 
${CMD_KERNEL_APPEND_LOCALVERSION}"
+                       ;;
                --kernel-config=*)
                        CMD_KERNEL_CONFIG="${*#*=}"
                        print_info 3 "CMD_KERNEL_CONFIG: ${CMD_KERNEL_CONFIG}"

diff --git a/gen_determineargs.sh b/gen_determineargs.sh
index df0934d..f4b3cf7 100755
--- a/gen_determineargs.sh
+++ b/gen_determineargs.sh
@@ -290,6 +290,7 @@ determine_real_args() {
        set_config_with_override STRING CROSS_COMPILE                         
CMD_CROSS_COMPILE
        set_config_with_override STRING BOOTDIR                               
CMD_BOOTDIR                               "/boot"
        set_config_with_override STRING KERNEL_OUTPUTDIR                      
CMD_KERNEL_OUTPUTDIR                      "${KERNEL_DIR}"
+       set_config_with_override STRING KERNEL_APPEND_LOCALVERSION            
CMD_KERNEL_APPEND_LOCALVERSION
        set_config_with_override STRING KERNEL_LOCALVERSION                   
CMD_KERNEL_LOCALVERSION                   "-%%ARCH%%"
        set_config_with_override STRING MODPROBEDIR                           
CMD_MODPROBEDIR                           "/etc/modprobe.d"
 
@@ -630,6 +631,46 @@ determine_real_args() {
                need_tar=yes
        fi
 
+       # We always need to populate KERNEL_LOCALVERSION to be able to warn
+       # if user changed value but didn't rebuild kernel
+       local valid_localversion_pattern='^[A-Za-z0-9_.-]{1,}$'
+
+       if [ -n "${KERNEL_LOCALVERSION}" ]
+       then
+               case "${KERNEL_LOCALVERSION}" in
+                       UNSET)
+                               ;;
+                       *)
+                               KERNEL_LOCALVERSION=$(arch_replace 
"${KERNEL_LOCALVERSION}")
+                               if [ -z "${KERNEL_LOCALVERSION}" ]
+                               then
+                                       # We somehow lost value...
+                                       gen_die "Internal error: Variable 
'KERNEL_LOCALVERSION' is empty!"
+                               fi
+
+                               if [[ ! "${KERNEL_LOCALVERSION}" =~ 
${valid_localversion_pattern} ]]
+                               then
+                                       gen_die "--kernel-localversion value 
'${KERNEL_LOCALVERSION}' does not match '${valid_localversion_pattern}' regex!"
+                               fi
+                               ;;
+               esac
+       fi
+
+       if [ -n "${KERNEL_APPEND_LOCALVERSION}" ]
+       then
+               if [[ ! "${KERNEL_APPEND_LOCALVERSION}" =~ 
${valid_localversion_pattern} ]]
+               then
+                       gen_die "--kernel-append-localversion value 
'${KERNEL_APPEND_LOCALVERSION}' does not match '${valid_localversion_pattern}' 
regex!"
+               fi
+
+               if [[ "${KERNEL_LOCALVERSION}" == "UNSET" ]]
+               then
+                       gen_die "Cannot append '${KERNEL_APPEND_LOCALVERSION}' 
to KERNEL_LOCALVERSION you want to unset!"
+               else
+                       KERNEL_LOCALVERSION+="${KERNEL_APPEND_LOCALVERSION}"
+               fi
+       fi
+
        if isTrue "${BUILD_KERNEL}"
        then
                if [ "${KERNEL_DIR}" != "${KERNEL_OUTPUTDIR}" -a ! -d 
"${KERNEL_OUTPUTDIR}" ]
@@ -637,28 +678,6 @@ determine_real_args() {
                        print_warning 3 "Set --kernel-outputdir 
'${KERNEL_OUTPUTDIR}' does not exist; Will try to create ..."
                        mkdir -p "${KERNEL_OUTPUTDIR}" || gen_die "Failed to 
create '${KERNEL_OUTPUTDIR}'!"
                fi
-
-               if [ -n "${KERNEL_LOCALVERSION}" ]
-               then
-                       case "${KERNEL_LOCALVERSION}" in
-                               UNSET)
-                                       ;;
-                               *)
-                                       KERNEL_LOCALVERSION=$(arch_replace 
"${KERNEL_LOCALVERSION}")
-                                       if [ -z "${KERNEL_LOCALVERSION}" ]
-                                       then
-                                               # We somehow lost value...
-                                               gen_die "Internal error: 
Variable 'KERNEL_LOCALVERSION' is empty!"
-                                       fi
-
-                                       local 
valid_localversion_pattern='^[A-Za-z0-9_.-]{1,}$'
-                                       if [[ ! "${KERNEL_LOCALVERSION}" =~ 
${valid_localversion_pattern} ]]
-                                       then
-                                               gen_die "--kernel-localversion 
value '${KERNEL_LOCALVERSION}' does not match '${valid_localversion_pattern}' 
regex!"
-                                       fi
-                                       ;;
-                       esac
-               fi
        fi
 
        if ! isTrue "${BUILD_RAMDISK}"

Reply via email to