Skip to content

Commit

Permalink
kbuild: add is_config_enabled function
Browse files Browse the repository at this point in the history
Signed-off-by: Yujie Liu <[email protected]>
Signed-off-by: Philip Li <[email protected]>
  • Loading branch information
Yujie-Liu authored and rli9 committed Nov 29, 2023
1 parent a5e034b commit c6319ac
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
37 changes: 37 additions & 0 deletions kbuild/kbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,40 @@ get_config_value()
cut -f2- -d= |
sed 's/\"//g'
}

# is_config_enabled CONFIG_BOOT_LINK_OFFSET
# - 202003/h8300-randconfig-a001-20200327:CONFIG_BOOT_LINK_OFFSET= # false
# - 202003/sh-randconfig-a001-20200313:CONFIG_BOOT_LINK_OFFSET=0x00800000 # true
#
# is_config_enabled CONFIG_BOOT_LINK_OFFSET=
# - 202003/h8300-randconfig-a001-20200327:CONFIG_BOOT_LINK_OFFSET= # true
# - 202003/sh-randconfig-a001-20200313:CONFIG_BOOT_LINK_OFFSET=0x00800000 # true
is_config_enabled()
{
local config="$1"
local config_file

[[ $config ]] || return

if [[ $2 ]]; then
config_file="$2"
elif [[ -s .config ]]; then
config_file=.config
elif [[ $KBUILD_OUTPUT ]] && [[ -s $KBUILD_OUTPUT/.config ]]; then
config_file=$KBUILD_OUTPUT/.config
elif [[ $BUILD_PATH ]] && [[ -s $BUILD_PATH/.config ]]; then
config_file=$BUILD_PATH/.config
elif [[ $BUILD_DIR ]] && [[ -s $BUILD_DIR/.config ]]; then
config_file=$BUILD_DIR/.config
else
return 2 # ENOENT
fi

# $ echo "CONFIG_CPU_BIG_ENDIAN=y" | grep "^CONFIG_CPU_BIG_ENDIAN=[^n]"; echo $?
# CONFIG_CPU_BIG_ENDIAN=y
# 0
# $ echo "CONFIG_CPU_BIG_ENDIAN=n" | grep "^CONFIG_CPU_BIG_ENDIAN=[^n]"; echo $?
# 1
[[ $config =~ '=' ]] || config+='=[^n]'
grep -q "^$config" "$config_file"
}
16 changes: 8 additions & 8 deletions kbuild/make.cross
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ setup_compiler_for_parisc()
{
local gcc_arch=hppa-linux
update_path_env_for_parisc $gcc_arch || return
if grep -s -q 'CONFIG_64BIT=y' $BUILD_DIR/.config; then
if is_config_enabled 'CONFIG_64BIT'; then
# 64bit build needs both hppa-linux and hppa64-linux
# > Assembler messages:
# > ../arch/parisc/kernel/vdso32/sigtramp.S:39: Error: unknown pseudo-op: `.proc'
Expand All @@ -279,7 +279,7 @@ setup_crosstool_gcc()
# start to support big endian arc toolchain form gcc-9.3.0
# for earlier gcc version, will failed to find arceb-elf for
# big endian arceb-elf tool chain
if grep -q 'CONFIG_CPU_BIG_ENDIAN=y' $BUILD_DIR/.config; then
if is_config_enabled 'CONFIG_CPU_BIG_ENDIAN'; then
gcc_arch=arceb-elf
else
gcc_arch=arc-elf
Expand All @@ -299,8 +299,8 @@ setup_crosstool_gcc()
;;
powerpc)
gcc_arch=powerpc-linux
grep -q 'CONFIG_PPC64=y' $BUILD_DIR/.config && {
if grep -q 'CONFIG_CPU_LITTLE_ENDIAN=y' $BUILD_DIR/.config; then
is_config_enabled 'CONFIG_PPC64' && {
if is_config_enabled 'CONFIG_CPU_LITTLE_ENDIAN'; then
gcc_arch=powerpc64le-linux
else
gcc_arch=powerpc64-linux
Expand All @@ -320,7 +320,7 @@ setup_crosstool_gcc()
gcc_arch=or1k-linux
;;
riscv)
if grep -q 'CONFIG_32BIT=y' $BUILD_DIR/.config; then
if is_config_enabled 'CONFIG_32BIT=y'; then
gcc_arch=riscv32-linux
else
gcc_arch=riscv64-linux
Expand Down Expand Up @@ -415,8 +415,8 @@ setup_crosstool_clang()
opt_llvm_ias="LLVM_IAS=1"
elif [[ $ARCH = "powerpc" ]]; then
local cross_compile='powerpc-linux-gnu-'
grep -q 'CONFIG_PPC64=y' $BUILD_DIR/.config && {
if grep -q 'CONFIG_CPU_LITTLE_ENDIAN=y' $BUILD_DIR/.config; then
is_config_enabled 'CONFIG_PPC64' && {
if is_config_enabled 'CONFIG_CPU_LITTLE_ENDIAN'; then
cross_compile='powerpc64le-linux-gnu-'
else
cross_compile='powerpc64-linux-gnu-'
Expand All @@ -425,7 +425,7 @@ setup_crosstool_clang()
opt_cross="$opt_cross CROSS_COMPILE=$cross_compile"
[[ $kernel_version_major -eq 5 && $kernel_version_minor -gt 14 && $kernel_version_minor -lt 18 ]] && opt_llvm_ias="LLVM_IAS=0"
elif [[ $ARCH = "riscv" ]]; then
if grep -q 'CONFIG_32BIT=y' $BUILD_DIR/.config; then
if is_config_enabled 'CONFIG_32BIT'; then
opt_cross="$opt_cross $(COMPILER=gcc && setup_crosstool_gcc && echo $opt_cross)"
else
opt_cross="$opt_cross CROSS_COMPILE=riscv64-linux-gnu-"
Expand Down

0 comments on commit c6319ac

Please sign in to comment.