#!/bin/bash #y = builtin #m = module proc pause { echo -n "Press enter to continue..." read zzz } proc log_ver { touch $(BUILD_LOG) shell { if test -f /etc/DISTRO_SPECS { source /etc/DISTRO_SPECS echo "$DISTRO_NAME $DISTRO_VERSION [$[uname -m]]" } gcc --version | head -1 git --version | head -1 mksquashfs -version | head -1 echo } | tee -a $(BUILD_LOG) } #====================================================================== proc config_is_set { test ! $1 -o ! $2 && return local opt=$1 file=$2 if grep -q -E "^$(opt)=y|^$(opt)=m" $file { return 0 } else { return 1 } } # $1 = type # $2 = config_opt # $3 = config_file proc config_set { test ! $1 -o ! $2 -o ! $3 && return 1 local type=$1 opt=$2 file=$3 t match $type { with builtin setglobal t = ''y'' with custom setglobal t = ''c'' #for special purposes (further processing) with * setglobal t = ''m'' #module = default } sed -i -e "s|# $opt .*|$(opt)=$(t)|" \ -e "s|^$opt=.*|$(opt)=$(t)|" $file } proc config_unset { test ! $1 -o ! $2 && return local opt=$1 file=$2 sed -i -e "s|^$(opt)=y|# $opt is not set|" \ -e "s|^$(opt)=m|# $opt is not set|" $file } proc config_toggle { test ! $1 -o ! $2 && return local opt=$1 file=$2 if config_is_set $opt $file { config_unset $opt $file } else { config_set module $opt $file } } proc config_delete { test ! $1 -o ! $2 && return local opt=$1 file=$2 sed -i -e "/^$(opt)=y/d" -e "/ $(opt) /d" $file } # $1 = config file proc config_get_builtin { grep '=y' $1 | cut -f1 -d '=' ; } proc config_get_module { grep '=m' $1 | cut -f1 -d '=' ; } proc config_get_set { grep -E '=m|=y' $1 | cut -f1 -d '=' ; } proc config_get_unset { grep 'not set' $1 | cut -f2 -d ' ' ; } # $1 = config_file # $2 = file with fixed config options proc fix_config { test ! $1 -o ! $2 && return local file=$1 fixed_opts=$2 shell { cat $fixed_opts | sed -e 's| is not set||' -e '/^$/d' -e '/##/d' | \ while read line { match $line { with *'=m' setglobal C_OPT = $(line%=*) ; echo "s%.*$(C_OPT).*%$(C_OPT)=m%" with *'=y' setglobal C_OPT = $(line%=*) ; echo "s%.*$(C_OPT).*%$(C_OPT)=y%" with * setglobal C_OPT = $(line:2) ; echo "s%.*$(C_OPT).*%# $(C_OPT) is not set%" } } } > /tmp/ksed.file cp $1 "$1".orig sed -i -f /tmp/ksed.file $1 } ############## ## EXAMPLES ## ############## # $1: kernel config file proc set_pae { #http://askubuntu.com/questions/395771/in-32-bit-ubuntu-12-04-how-can-i-find-out-if-pae-has-been-enabled config_set builtin CONFIG_X86_PAE $1 config_set builtin CONFIG_HIGHMEM64G $1 config_unset CONFIG_HIGHMEM4G $1 } # $1: kernel config file proc unset_pae { config_delete CONFIG_X86_PAE $1 config_unset CONFIG_HIGHMEM64G $1 config_set builtin CONFIG_HIGHMEM4G $1 } # $1: kernel config file proc set_i486 { config_set builtin CONFIG_M486 $1 for i in [CONFIG_M386 CONFIG_M686 CONFIG_M586 CONFIG_M586TSC CONFIG_M586MMX CONFIG_MPENTIUMII CONFIG_MPENTIUMIII CONFIG_MPENTIUMM CONFIG_MPENTIUM4 CONFIG_MK6 CONFIG_MK7 CONFIG_MK8 CONFIG_MCRUSOE CONFIG_MEFFICEON CONFIG_MWINCHIPC6 CONFIG_MWINCHIP3D CONFIG_MELAN CONFIG_MGEODEGX1 CONFIG_MGEODE_LX CONFIG_MCYRIXIII CONFIG_MVIAC3_2 CONFIG_MVIAC7 CONFIG_MCORE2 CONFIG_MATOM] { config_unset $i $1 } } # $1: kernel config file proc set_i686 { config_set builtin CONFIG_M686 $1 for i in [CONFIG_M386 CONFIG_M486 CONFIG_M586 CONFIG_M586TSC CONFIG_M586MMX CONFIG_MPENTIUMII CONFIG_MPENTIUMIII CONFIG_MPENTIUMM CONFIG_MPENTIUM4 CONFIG_MK6 CONFIG_MK7 CONFIG_MK8 CONFIG_MCRUSOE CONFIG_MEFFICEON CONFIG_MWINCHIPC6 CONFIG_MWINCHIP3D CONFIG_MELAN CONFIG_MGEODEGX1 CONFIG_MGEODE_LX CONFIG_MCYRIXIII CONFIG_MVIAC3_2 CONFIG_MVIAC7 CONFIG_MCORE2 CONFIG_MATOM] { config_unset $i $1 } } # $HOST_ARCH and $x86_* are set in build.conf and/or build.sh # edits .config in current dir # part of build.sh ... proc i386_specific_stuff { if test $HOST_ARCH = "x86" { if test $x86_disable_pae = "yes" { if grep 'CONFIG_X86_PAE=y' .config { #CONFIG_HIGHMEM64G=y log_msg "Disabling PAE..." setglobal MAKEOLDCONFIG = '1' unset_pae .config } } if test $x86_enable_pae = "yes" { if ! grep 'CONFIG_X86_PAE=y' .config { log_msg "Enabling PAE..." setglobal MAKEOLDCONFIG = '1' set_pae .config } } if test $x86_set_i486 = "yes" { if grep -q 'CONFIG_OUTPUT_FORMAT="elf32-i386"' .config { if ! grep -q 'CONFIG_M486=y' .config { log_msg "Forcing i486..." setglobal MAKEOLDCONFIG = '1' set_i486 .config } } } if test $x86_set_i686 = "yes" { if grep -q 'CONFIG_OUTPUT_FORMAT="elf32-i386"' .config { if ! grep -q 'CONFIG_M686=y' .config { log_msg "Forcing i686..." setglobal MAKEOLDCONFIG = '1' set_i686 .config } } } test $MAKEOLDCONFIG != "" && make silentoldconfig } } #$@ ### END ###