scripts/gen_in_frags.sh
author "Yann E. MORIN" <yann.morin.1998@free.fr>
Thu Jan 10 00:27:13 2013 +0100 (2013-01-10)
changeset 3159 fb71cad4b085
permissions -rwxr-xr-x
arch/arm: OABI is no more, switch to only EABI

Well, leave the prompt as an OBSOLETE thing, scheduled to
be removed soon.

As an indication OABI lives its last days, gcc-4.8 will no
longer recognise non-EABI targets.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
yann@2537
     1
#!/bin/sh
yann@2537
     2
set -e
yann@2537
     3
yann@2537
     4
# This scripts generates either a choice or a menuconfig
yann@2537
     5
# with the specified entries.
yann@2537
     6
#
yann@2537
     7
# Usage:
yann@2537
     8
#   generate a choice:
yann@2537
     9
#       gen_in_frags.sh choice <out-file> <label> <config-prefix> <base-dir> <conditionals> entry [entry...]
yann@2537
    10
#
yann@2537
    11
#   generate a menuconfig:
yann@2537
    12
#       gen_in_frags.sh menu <out-file> <label> <config-prefix> <base-dir> entry [entry...]
yann@2537
    13
#
yann@2537
    14
# where:
yann@2537
    15
#   out-file
yann@2537
    16
#       put the generated choice/menuconfig into that file
yann@2537
    17
#       for choices, it acts as the base bname of the file, the secondary
yann@2537
    18
#       parts (the .in.2) are put in out-file.2
yann@2537
    19
#
yann@2537
    20
#   label
yann@2537
    21
#       name for the entries family
yann@2537
    22
#       eg. Architecture, Kernel...
yann@2537
    23
#
yann@2537
    24
#   config-prefix
yann@2537
    25
#       prefix for the choice entries
yann@2537
    26
#       eg. ARCH, KERNEL...
yann@2537
    27
#
yann@2537
    28
#   base-dir
yann@2537
    29
#       base directory containing config files
yann@2537
    30
#       eg. config/arch, config/kernel...
yann@2537
    31
#
yann@2537
    32
#   conditionals (valid only for choice)
yann@2537
    33
#       generate backend conditionals if Y/y, don't if anything else
yann@2537
    34
#       if 'Y' (or 'y'), a dependency on the backen mode will be added
yann@2537
    35
#       to each entry
yann@2537
    36
#
yann@2537
    37
#   entry [entry...]
yann@2537
    38
#       a list of entry/ies toadd to the choice/menuconfig
yann@2537
    39
#       eg.:
yann@2537
    40
#           arm mips sh x86...
yann@2537
    41
#           linux cygwin mingw32 solaris...
yann@2537
    42
#           ...
yann@2537
    43
#
yann@2537
    44
#------------------------------------------------------------------------------
yann@2537
    45
yann@2537
    46
# Generate a choice
yann@2537
    47
# See above for usage
yann@2537
    48
gen_choice() {
yann@2537
    49
    local out_file="${1}"
yann@2537
    50
    local label="${2}"
yann@2537
    51
    local cfg_prefix="${3}"
yann@2537
    52
    local base_dir="${4}"
yann@2537
    53
    local cond="${5}"
yann@2537
    54
    shift 5
yann@2537
    55
    local file entry _entry
yann@2537
    56
yann@2537
    57
    # Generate the part-1
yann@2537
    58
    exec >"${out_file}"
yann@2537
    59
    printf '# %s menu\n' "${label}"
yann@2537
    60
    printf '# Generated file, do not edit!!!\n'
yann@2537
    61
    printf '\n'
yann@2537
    62
    printf 'choice GEN_CHOICE_%s\n' "${cfg_prefix}"
yann@2537
    63
    printf '    bool\n'
yann@2537
    64
    printf '    prompt "%s"\n' "${label}"
yann@2537
    65
    printf '\n'
yann@2537
    66
    for entry in "${@}"; do
yann@2537
    67
        file="${base_dir}/${entry}.in"
yann@2537
    68
        _entry=$(printf '%s\n' "${entry}" |"${sed}" -r -s -e 's/[-.+]/_/g;')
yann@2537
    69
        printf 'config %s_%s\n' "${cfg_prefix}" "${_entry}"
yann@2537
    70
        printf '    bool\n'
yann@2537
    71
        printf '    prompt "%s"\n' "${entry}"
yann@2537
    72
        if [ "${cond}" = "Y" -o "${cond}" = "y" ]; then
yann@2537
    73
            printf '    depends on %s_%s_AVAILABLE\n' "${cfg_prefix}" "${_entry}"
yann@2537
    74
        fi
yann@2537
    75
        "${sed}" -r -e '/^## depends on /!d; s/^## /    /;' ${file} 2>/dev/null
yann@2537
    76
        "${sed}" -r -e '/^## select /!d; s/^## /    /;' ${file} 2>/dev/null
yann@2537
    77
        if "${grep}" -E '^## help' ${file} >/dev/null 2>&1; then
yann@2537
    78
            printf '    help\n'
yann@2537
    79
            "${sed}" -r -e '/^## help ?/!d; s/^## help ?/      /;' ${file} 2>/dev/null
yann@2537
    80
        fi
yann@2537
    81
        printf '\n'
yann@2537
    82
    done
yann@2537
    83
    printf 'endchoice\n'
yann@2537
    84
yann@2537
    85
    for entry in "${@}"; do
yann@2537
    86
        file="${base_dir}/${entry}.in"
yann@2537
    87
        _entry=$(printf '%s\n' "${entry}" |"${sed}" -r -s -e 's/[-.+]/_/g;')
yann@2537
    88
        printf '\n'
yann@2537
    89
        if [ "${cond}" = "Y" -o "${cond}" = "y" ]; then
yann@2537
    90
            printf 'config %s_%s_AVAILABLE\n' "${cfg_prefix}" "${_entry}"
yann@2537
    91
            printf '    bool\n'
yann@2537
    92
            printf '    default y if'
yann@2537
    93
            printf ' BACKEND_%s = "%s"' "${cfg_prefix}" "${entry}"
yann@2537
    94
            printf ' || BACKEND_%s = ""' "${cfg_prefix}"
yann@2537
    95
            printf ' || ! BACKEND\n'
yann@2537
    96
        fi
yann@2537
    97
        printf 'if %s_%s\n' "${cfg_prefix}" "${_entry}"
yann@2537
    98
        printf 'config %s\n' "${cfg_prefix}"
yann@2537
    99
        printf '    default "%s" if %s_%s\n' "${entry}" "${cfg_prefix}" "${_entry}"
yann@2537
   100
        printf 'source "%s"\n' "${file}"
yann@2537
   101
        printf 'endif\n'
yann@2537
   102
    done
yann@2537
   103
yann@2537
   104
    # Generate the part-2
yann@2537
   105
    exec >"${out_file}.2"
yann@2537
   106
    printf '# %s second part options\n' "${label}"
yann@2537
   107
    printf '# Generated file, do not edit!!!\n'
yann@2537
   108
    for entry in "${@}"; do
yann@2537
   109
        file="${base_dir}/${entry}.in"
yann@2537
   110
        _entry=$(printf '%s\n' "${entry}" |"${sed}" -r -s -e 's/[-.+]/_/g;')
yann@2537
   111
        if [ -f "${file}.2" ]; then
yann@2537
   112
            printf '\n'
yann@2537
   113
            printf 'if %s_%s\n' "${cfg_prefix}" "${_entry}"
yann@2537
   114
            printf 'comment "%s other options"\n' "${entry}"
yann@2537
   115
            printf 'source "%s.2"\n' "${file}"
yann@2537
   116
            printf 'endif\n'
yann@2537
   117
        fi
yann@2537
   118
    done
yann@2537
   119
}
yann@2537
   120
yann@2537
   121
# Generate a menuconfig
yann@2537
   122
# See above for usage
yann@2537
   123
gen_menu() {
yann@2537
   124
    local out_file="${1}"
yann@2537
   125
    local label="${2}"
yann@2537
   126
    local cfg_prefix="${3}"
yann@2537
   127
    local base_dir="${4}"
yann@2537
   128
    shift 4
yann@2537
   129
    local file entry _entry
yann@2537
   130
yann@2537
   131
    # GEnerate the menuconfig
yann@2537
   132
    exec >"${out_file}"
yann@2537
   133
    printf '# %s menu\n' "${label}"
yann@2537
   134
    printf '# Generated file, do not edit!!!\n'
yann@2537
   135
    printf '\n'
yann@2537
   136
    for entry in "${@}"; do
yann@2537
   137
        file="${base_dir}/${entry}.in"
yann@2537
   138
        _entry=$(printf '%s\n' "${entry}" |"${sed}" -r -s -e 's/[-.+]/_/g;')
yann@2537
   139
        printf 'menuconfig %s_%s\n' "${cfg_prefix}" "${_entry}"
yann@2537
   140
        printf '    bool\n'
yann@2537
   141
        printf '    prompt "%s"\n' "${entry}"
yann@2537
   142
        "${sed}" -r -e '/^## depends on /!d; s/^## /    /;' ${file} 2>/dev/null
yann@2537
   143
        "${sed}" -r -e '/^## select /!d; s/^## /    /;' ${file} 2>/dev/null
yann@2537
   144
        if "${grep}" -E '^## help' ${file} >/dev/null 2>&1; then
yann@2537
   145
            printf '    help\n'
yann@2537
   146
            "${sed}" -r -e '/^## help ?/!d; s/^## help ?/      /;' ${file} 2>/dev/null
yann@2537
   147
        fi
yann@2537
   148
        printf '\n'
yann@2537
   149
        printf 'if %s_%s\n' "${cfg_prefix}" "${_entry}"
yann@2537
   150
        printf 'source "%s"\n' "${file}"
yann@2537
   151
        printf 'endif\n'
yann@2537
   152
        printf '\n'
yann@2537
   153
    done
yann@2537
   154
}
yann@2537
   155
yann@2537
   156
type="${1}"
yann@2537
   157
shift
yann@2537
   158
"gen_${type}" "${@}"