]> git.ipfire.org Git - ipfire-3.x.git/blobdiff - kernel/scripts/configure
kernel: configure: Pass arch as an extra argument
[ipfire-3.x.git] / kernel / scripts / configure
index e60bc83966738ec0798b0a7a72f292beaea6a286..b2c1fa3718a8bdfc785ad53135d4039996290c3c 100755 (executable)
@@ -7,8 +7,78 @@
 BASEDIR=$(dirname ${0})
 SCRIPTS_DIR=${BASEDIR}
 
-CONFIGS="x86_64:default i686:legacy i686:default"
-CONFIGS="${CONFIGS} armv7hl:omap armv5tel:versatile armv5tel:kirkwood"
+# x86_64
+CONFIGS="x86_64:default"
+
+# aarch64
+CONFIGS="${CONFIGS} aarch64:default"
+
+# armv7hl
+CONFIGS="${CONFIGS} armv7hl:default"
+
+PLATFORMS="x86 arm"
+declare -A SUBPLATFORMS
+SUBPLATFORMS=(
+       [arm]="arm64 arm32"
+)
+
+search_kernel_dir() {
+       local dir
+       for dir in /builddir/source/linux-*; do
+               if [ -d "${dir}" ]; then
+                       echo "${dir}"
+                       break
+               fi
+       done
+}
+
+function get_platform() {
+       local arch="${1}"
+
+       case "${arch}" in
+               aarch64|arm*)
+                       echo "arm"
+                       ;;
+               x86_64|i?86)
+                       echo "x86"
+                       ;;
+               *)
+                       return 1
+                       ;;
+       esac
+}
+
+function get_subplatform() {
+       local arch="${1}"
+
+       case "${arch}" in
+               aarch64)
+                       echo "arm64"
+                       ;;
+               arm*)
+                       echo "arm32"
+                       ;;
+               *)
+                       return 1
+                       ;;
+       esac
+}
+
+function get_kernel_arch() {
+       local arch="${1}"
+
+       case "${arch}" in
+               aarch64)
+                       echo "arm64"
+                       ;;
+               arm*)
+                       echo "arm"
+                       ;;
+               x86_64)
+                       echo "x86"
+                       ;;
+       esac
+}
 
 function merge_config() {
        local arch=${1}
@@ -24,7 +94,7 @@ function merge_config() {
                fi
        done
 
-       local config_mode="oldnoconfig"
+       local config_mode="olddefconfig"
        local extra_configs
        while [ $# -gt 0 ]; do
                case "${1}" in
@@ -47,25 +117,17 @@ function merge_config() {
        case "${arch}:${flavour}" in
                # x86
                x86_64:default)
-                       configs="${configs} config-x86-generic config-x86_64-default"
-                       ;;
-               i686:default)
-                       configs="${configs} config-x86-generic config-i686-default"
+                       configs="${configs} config-x86-generic"
                        ;;
-               i686:legacy)
-                       configs="${configs} config-x86-generic config-i686-default"
-                       configs="${configs} config-i686-legacy"
+
+               # ARM64
+               aarch64:default)
+                       configs="${configs} config-arm-generic config-arm64-generic"
                        ;;
 
                # ARM
-               armv5tel:versatile)
-                       configs="${configs} config-arm-generic"
-                       ;;
-               armv5tel:kirkwood)
-                       configs="${configs} config-arm-generic config-armv5tel-kirkwood"
-                       ;;
-               armv7hl:omap)
-                       configs="${configs} config-arm-generic config-armv7hl-omap"
+               armv7hl:default)
+                       configs="${configs} config-arm-generic config-arm32-generic"
                        ;;
                *)
                        echo >&2 "ERROR: Invalid parameters given: $@"
@@ -73,17 +135,6 @@ function merge_config() {
                        ;;
        esac
 
-       # Determine the kernel arch.
-       local kernel_arch=
-       case "${arch}" in
-               arm*)
-                       kernel_arch="arm"
-                       ;;
-               i?86|x86*)
-                       kernel_arch="x86"
-                       ;;
-       esac
-
        # Merge the configuration files from its elementary configuration
        # files.
        local tmp_out=$(mktemp)
@@ -93,11 +144,12 @@ function merge_config() {
        for config in ${configs}; do
                cat ${tmp_out} > ${tmp_in}
                perl ${SCRIPTS_DIR}/merge.pl \
-                       ${config} ${tmp_in} > ${tmp_out}
+                       ${tmp_in} ${config} > ${tmp_out}
        done
 
        if [ "${config_mode}" != "none" ]; then
-               echo "Running 'make oldnoconfig' for ${arch} (${flavour})..."
+               echo "Running 'make olddefconfig' for ${arch} (${flavour})..."
+               local kernel_arch="$(get_kernel_arch "${arch}")"
                (
                        cd ${KERNEL_DIR}
                        cat ${tmp_out} > .config
@@ -111,9 +163,17 @@ function merge_config() {
 }
 
 # This function runs an interactive "make oldconfig".
-function make_oldconfig() {
-       local arch="x86_64"
-       local kernel_arch="x86"
+function make_config() {
+       local action="${1}"
+       local arch="${2}"
+
+       # Default to x86_64 when no arch is given
+       if [ -z "${arch}" ]; then
+               arch="x86_64"
+       fi
+
+       # Detect kernel arch
+       local kernel_arch="$(get_kernel_arch "${arch}")"
        local flavour="default"
 
        local config_in=$(mktemp)
@@ -123,27 +183,14 @@ function make_oldconfig() {
        merge_config ${arch} ${flavour} ${config_in} --mode=none
 
        (
-               cd ${KERNEL_DIR}
+               pushd ${KERNEL_DIR}
                cat ${config_in} > .config
 
                echo "You may now edit the configuration..."
-
-               local option
-               select option in oldconfig menuconfig oldnoconfig startover quit; do
-                       case "${option}" in
-                               oldconfig|menuconfig|oldnoconfig)
-                                       make ARCH=${kernel_arch} ${option}
-                                       ;;
-                               startover)
-                                       cat ${config_in} > .config
-                                       ;;
-                               quit)
-                                       break
-                                       ;;
-                       esac
-               done
+               make ARCH=${kernel_arch} "${action}"
 
                cat .config > ${config_out}
+               popd
        )
 
        ${SCRIPTS_DIR}/configdiff.py ${config_in} ${config_out} > ${diff_out}
@@ -156,16 +203,18 @@ function make_oldconfig() {
 
 # config-generic
 #  Intersection of all files.
-# config-x86-generic
-#  Diff of (intersection of (i686-{default,legacy} and x86_64-default)
-#  against config-generic).
 # config-x86-x86_64
 #  Diff against merge of (config-generic and config-x86-generic).
 
 function diff_configs() {
        local extra_configs="$@"
 
-       declare -A arch_configs
+       local filename
+       local platform
+       local subplatform
+
+       declare -A platform_configs
+       declare -A subplatform_configs
 
        tmpdir=$(mktemp -d)
 
@@ -177,35 +226,28 @@ function diff_configs() {
 
                merge_config ${arch} ${flavour} ${filename} ${extra_configs}
 
-               # Do not include i686 legacy.
-               case "${config}" in
-                       i686:legacy)
-                               continue
-                               ;;
-                       armv5tel:versatile)
-                               ;;
-                       arm*)
-                               continue
-                               ;;
-               esac
+               platform="$(get_platform "${arch}")"
+               subplatform="$(get_subplatform "${arch}")"
 
-               case "${arch}" in
-                       x86*|i?86)
-                               arch_configs[x86]="${arch_configs[x86]} ${filename}"
-                               ;;
-                       arm*)
-                               arch_configs[arm]="${arch_configs[arm]} ${filename}"
-                               ;;
-                       *)
-                               echo >&2 "ERROR: Invalid architecture: ${arch}"
-                               ;;
-               esac
+               if [ -n "${subplatform}" ]; then
+                       subplatform_configs[${subplatform}]="${subplatform_configs[${subplatform}]} ${filename}"
+               else
+                       platform_configs[${platform}]="${platform_configs[${platform}]} ${filename}"
+               fi
        done
 
-       common_configs=""
-       for arch in x86 arm; do
-               filename="${tmpdir}/config-${arch}-common"
-               ${SCRIPTS_DIR}/configcommon.py ${arch_configs[${arch}]} \
+       local common_configs
+       for platform in ${PLATFORMS}; do
+               for subplatform in ${SUBPLATFORMS[${platform}]}; do
+                       filename="${tmpdir}/config-${subplatform}-common"
+                       ${SCRIPTS_DIR}/configcommon.py ${subplatform_configs[${subplatform}]} \
+                               > ${filename}
+
+                       platform_configs[${platform}]="${platform_configs[${platform}]} ${filename}"
+               done
+
+               filename="${tmpdir}/config-${platform}-common"
+               ${SCRIPTS_DIR}/configcommon.py ${platform_configs[${platform}]} \
                        > ${filename}
 
                common_configs="${common_configs} ${filename}"
@@ -213,38 +255,35 @@ function diff_configs() {
 
        ${SCRIPTS_DIR}/configcommon.py ${common_configs} > ${tmpdir}/config-generic
 
-       ${SCRIPTS_DIR}/configdiff.py ${tmpdir}/config-generic ${tmpdir}/config-arm-common \
-               > ${tmpdir}/config-arm-generic
+       for platform in ${PLATFORMS}; do
+               for subplatform in ${SUBPLATFORMS[${platform}]}; do
+                       ${SCRIPTS_DIR}/configdiff.py \
+                               ${tmpdir}/config-${platform}-common \
+                               ${tmpdir}/config-${subplatform}-common \
+                               > ${tmpdir}/config-${subplatform}-generic
+               done
 
-       ${SCRIPTS_DIR}/configdiff.py ${tmpdir}/config-generic ${tmpdir}/config-x86-common \
-               > ${tmpdir}/config-x86-generic
+               ${SCRIPTS_DIR}/configdiff.py \
+                       ${tmpdir}/config-generic \
+                       ${tmpdir}/config-${platform}-common \
+                       > ${tmpdir}/config-${platform}-generic
+       done
 
        for config in ${CONFIGS}; do
                arch=${config%:*}
                flavour=${config#*:}
 
-               case "${config}" in
-                       arm*:*)
-                               suparch="arm"
-                               ;;
-                       i?86:*|x86*:*)
-                               suparch="x86"
-                               ;;
-               esac
                filename=${tmpdir}/config-${arch}-${flavour}
 
                case "${config}" in
-                       i686:legacy)
-                               # Legacy depends directly on the default configuration.
-                               ${SCRIPTS_DIR}/configdiff.py ${tmpdir}/config-i686-default \
-                                       ${filename} > ${filename}.tmp
-                               ;;
-                       armv5tel:versatile)
+                       aarch64:default|armv7hl:default|x86_64:default)
+                               # Virtual configuration
                                rm -f ${filename}
                                continue
                                ;;
                        *)
-                               ${SCRIPTS_DIR}/configdiff.py ${tmpdir}/config-${suparch}-common \
+                               platform="$(get_subplatform "${arch}" || get_platform "${arch}")"
+                               ${SCRIPTS_DIR}/configdiff.py ${tmpdir}/config-${platform}-common \
                                        ${filename} > ${filename}.tmp
                                ;;
                esac
@@ -262,25 +301,21 @@ function diff_configs() {
        rm -rf ${tmpdir}
 }
 
-KERNEL_DIR=
+KERNEL_DIR="$(search_kernel_dir)"
 
 # Parse commandline.
 while [ $# -gt 0 ]; do
        arg=${1}; shift
        case "${arg}" in
-               --kernel-dir=*)
-                       KERNEL_DIR=${arg#--kernel-dir=}
-                       ;;
                help|"")
                        echo "${0} - available commands:"
                        echo "    * merge <arch> <flavour> <output filename>"
-                       echo "    * update ..."
+                       echo "    * menuconfig"
                        echo "    * oldconfig"
-                       echo ""
-                       echo "    You must always set --kernel-dir=..."
+                       echo "    * olddefconfig"
                        exit 0
                        ;;
-               merge|oldconfig|update)
+               listnewconfig|menuconfig|merge|oldconfig|olddefconfig)
                        action=${arg}
                        break
                        ;;
@@ -288,7 +323,7 @@ while [ $# -gt 0 ]; do
 done
 
 if [ -z "${KERNEL_DIR}" ]; then
-       echo >&2 "--kernel-dir=... was not set!"
+       echo >&2 "KERNEL_DIR was not set!"
        exit 2
 fi
 
@@ -302,12 +337,8 @@ case "${action}" in
                merge_config $@
                exit $?
                ;;
-       oldconfig)
-               make_oldconfig
-               exit $?
-               ;;
-       update)
-               diff_configs $@
+       listnewconfig|menuconfig|oldconfig|olddefconfig)
+               make_config "${action}" "$@"
                exit $?
                ;;
 esac