scripts/gen_in_frags.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed May 04 00:04:23 2011 +0200 (2011-05-04)
changeset 2608 aa09a36c3d36
permissions -rwxr-xr-x
scripts/functions: test for decompressors before use

./configure does check for the presence of gz and bzip2, so we can
safely use them in the build scripts.

On the other hand, more recent formats (eg. XZ) are not yet widely
available, and we do not want, and can't, force the user to install
them as a pre-requisite.

So, build up a list of allowed tarball formats based on the available
decompressors. For no, this is a static list, but the upcoming XZ
support will conditionnaly add to this list.

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