mirror of
https://github.com/crosstool-ng/crosstool-ng.git
synced 2025-01-29 15:44:03 +00:00
config: move multi-line shell commands from Makefile to script
Maintaining thos multi-line shell commands in a Makefile rule is a real PITA. Move the two affected rules (build_gen_choice_in and build_gen_menu_in to a shell script. Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
This commit is contained in:
parent
ff2e756f59
commit
f1c0186b2f
135
config/config.mk
135
config/config.mk
@ -31,10 +31,13 @@ GEN_CONFIG_FILES = config.gen/arch.in \
|
||||
config.gen/libc.in \
|
||||
config.gen/debug.in
|
||||
# ... and how to access them:
|
||||
# Generated files depends on config.mk (this file) because it has the
|
||||
# functions needed to build the genrated files, and thus they might
|
||||
# need re-generation if config.mk changes
|
||||
$(GEN_CONFIG_FILES): config.gen \
|
||||
# Generated files depends on the gen_in_frags script because it has the
|
||||
# functions needed to build the genrated files, and thus they might need
|
||||
# re-generation if it changes.
|
||||
# They also depends on config.mk (this file) because it has the dependency
|
||||
# rules, and thus they might need re-generation if the deps change.
|
||||
$(GEN_CONFIG_FILES): config.gen \
|
||||
$(CT_LIB_DIR)/scripts/gen_in_frags.sh \
|
||||
$(CT_LIB_DIR)/config/config.mk
|
||||
|
||||
# Helper entry for the configurators
|
||||
@ -60,134 +63,30 @@ CCS = $(patsubst config/cc/%.in,%,$(CC_CONFIG_FILES))
|
||||
LIBCS = $(patsubst config/libc/%.in,%,$(LIBC_CONFIG_FILES))
|
||||
DEBUGS = $(patsubst config/debug/%.in,%,$(DEBUG_CONFIG_FILES))
|
||||
|
||||
#-----------------------------------------------------------
|
||||
# Helper functions to ease building generated config files
|
||||
|
||||
# The function 'build_gen_choice_in' builds a choice-menu of a list of
|
||||
# components in the given list, also adding source-ing of associazted
|
||||
# config files:
|
||||
# $1 : destination file
|
||||
# $2 : name for the entries family (eg. Architecture, kernel...)
|
||||
# $3 : prefix for the choice entries (eg. ARCH, KERNEL...)
|
||||
# $4 : base directory containing config files
|
||||
# $5 : generate backend conditionals if Y, don't if anything else
|
||||
# $6 : list of config entries (eg. for architectures: "alpha arm ia64"...,
|
||||
# and for kernels: "bare-metal linux"...)
|
||||
# Example to build the kernels generated config file:
|
||||
# $(call build_gen_choice_in,config.gen/kernel.in,Target OS,KERNEL,config/kernel,$(KERNELS))
|
||||
define build_gen_choice_in
|
||||
@$(ECHO) ' IN $(1)'
|
||||
$(SILENT)(echo "# $(2) menu"; \
|
||||
echo "# Generated file, do not edit!!!"; \
|
||||
echo ""; \
|
||||
echo "choice GEN_CHOICE_$(3)"; \
|
||||
echo " bool"; \
|
||||
echo " prompt \"$(2)\""; \
|
||||
echo ""; \
|
||||
for entry in $(6); do \
|
||||
file="$(4)/$${entry}.in"; \
|
||||
_entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;'); \
|
||||
echo "config $(3)_$${_entry}"; \
|
||||
echo " bool"; \
|
||||
echo " prompt \"$${entry}\""; \
|
||||
if [ "$(5)" = "Y" ]; then \
|
||||
echo " depends on $(3)_$${_entry}_AVAILABLE"; \
|
||||
fi; \
|
||||
$(sed) -r -e '/^## depends on /!d; s/^## / /;' $${file} 2>/dev/null; \
|
||||
$(sed) -r -e '/^## select /!d; s/^## / /;' $${file} 2>/dev/null; \
|
||||
if grep -E '^## help' $${file} >/dev/null 2>&1; then \
|
||||
echo " help"; \
|
||||
$(sed) -r -e '/^## help ?/!d; s/^## help ?/ /;' $${file} 2>/dev/null;\
|
||||
fi; \
|
||||
echo ""; \
|
||||
done; \
|
||||
echo "endchoice"; \
|
||||
for entry in $(6); do \
|
||||
file="$(4)/$${entry}.in"; \
|
||||
_entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;'); \
|
||||
echo ""; \
|
||||
if [ "$(5)" = "Y" ]; then \
|
||||
echo "config $(3)_$${_entry}_AVAILABLE"; \
|
||||
echo " bool"; \
|
||||
echo " default y if BACKEND_$(3) = \"$${entry}\" || BACKEND_$(3) = \"\" || ! BACKEND"; \
|
||||
fi; \
|
||||
echo "if $(3)_$${_entry}"; \
|
||||
echo "config $(3)"; \
|
||||
echo " default \"$${entry}\" if $(3)_$${_entry}"; \
|
||||
echo "source \"$${file}\""; \
|
||||
echo "endif"; \
|
||||
done; \
|
||||
) >$(1)
|
||||
$(SILENT)(echo "# $(2) second part options"; \
|
||||
echo "# Generated file, do not edit!!!"; \
|
||||
for entry in $(6); do \
|
||||
file="$(4)/$${entry}.in"; \
|
||||
_entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;'); \
|
||||
if [ -f "$${file}.2" ]; then \
|
||||
echo ""; \
|
||||
echo "if $(3)_$${_entry}"; \
|
||||
echo "comment \"$${entry} other options\""; \
|
||||
echo "source \"$${file}.2\""; \
|
||||
echo "endif"; \
|
||||
fi; \
|
||||
done; \
|
||||
) >$(1).2
|
||||
endef
|
||||
|
||||
# The function 'build_gen_menu_in' builds a menuconfig for each component in
|
||||
# the given list, source-ing the associated files conditionnaly:
|
||||
# $1 : destination file
|
||||
# $2 : name of entries family (eg. Tools, Debug...)
|
||||
# $3 : prefix for the menu entries (eg. DEBUG)
|
||||
# $4 : base directory containing config files
|
||||
# $5 : list of config entries (eg. for debug: "dmalloc duma gdb"...)
|
||||
# Example to build the generated debug config file:
|
||||
# $(call build_gen_menu_in,config.gen/debug.in,Debug,DEBUG,config/debug,$(DEBUGS))
|
||||
define build_gen_menu_in
|
||||
@$(ECHO) ' IN $(1)'
|
||||
$(SILENT)(echo "# $(2) facilities menu"; \
|
||||
echo "# Generated file, do not edit!!!"; \
|
||||
echo ""; \
|
||||
for entry in $(5); do \
|
||||
file="$(4)/$${entry}.in"; \
|
||||
_entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;'); \
|
||||
echo "menuconfig $(3)_$${_entry}"; \
|
||||
echo " bool"; \
|
||||
echo " prompt \"$${entry}\""; \
|
||||
$(sed) -r -e '/^## depends on /!d; s/^## / /;' $${file} 2>/dev/null; \
|
||||
$(sed) -r -e '/^## select /!d; s/^## / /;' $${file} 2>/dev/null; \
|
||||
if grep -E '^## help' $${file} >/dev/null 2>&1; then \
|
||||
echo " help"; \
|
||||
$(sed) -r -e '/^## help ?/!d; s/^## help ?/ /;' $${file} 2>/dev/null;\
|
||||
fi; \
|
||||
echo ""; \
|
||||
echo "if $(3)_$${_entry}"; \
|
||||
echo "source \"$${file}\""; \
|
||||
echo "endif"; \
|
||||
echo ""; \
|
||||
done; \
|
||||
) >$(1)
|
||||
endef
|
||||
|
||||
#-----------------------------------------------------------
|
||||
# The rules for the generated config files
|
||||
|
||||
# WARNING! If a .in file disapears between two runs, that will NOT be detected!
|
||||
|
||||
config.gen/arch.in: $(ARCH_CONFIG_FILES) $(ARCH_CONFIG_FILES_2)
|
||||
$(call build_gen_choice_in,$@,Target Architecture,ARCH,config/arch,Y,$(ARCHS))
|
||||
@$(ECHO) ' IN $(@)'
|
||||
$(SILENT)$(CT_LIB_DIR)/scripts/gen_in_frags.sh choice "$@" "Target Architecture" "ARCH" "config/arch" "Y" $(ARCHS)
|
||||
|
||||
config.gen/kernel.in: $(KERNEL_CONFIG_FILES) $(KERNEL_CONFIG_FILES_2)
|
||||
$(call build_gen_choice_in,$@,Target OS,KERNEL,config/kernel,Y,$(KERNELS))
|
||||
@$(ECHO) ' IN $(@)'
|
||||
$(SILENT)$(CT_LIB_DIR)/scripts/gen_in_frags.sh choice "$@" "Target OS" "KERNEL" "config/kernel" "Y" $(KERNELS)
|
||||
|
||||
config.gen/cc.in: $(CC_CONFIG_FILES) $(CC_CONFIG_FILES_2)
|
||||
$(call build_gen_choice_in,$@,C compiler,CC,config/cc,,$(CCS))
|
||||
@$(ECHO) ' IN $(@)'
|
||||
$(SILENT)$(CT_LIB_DIR)/scripts/gen_in_frags.sh choice "$@" "C compiler" "CC" "config/cc" "N" $(CCS)
|
||||
|
||||
config.gen/libc.in: $(LIBC_CONFIG_FILES) $(LIBC_CONFIG_FILES_2)
|
||||
$(call build_gen_choice_in,$@,C library,LIBC,config/libc,Y,$(LIBCS))
|
||||
@$(ECHO) ' IN $(@)'
|
||||
$(SILENT)$(CT_LIB_DIR)/scripts/gen_in_frags.sh choice "$@" "C library" "LIBC" "config/libc" "Y" $(LIBCS)
|
||||
|
||||
config.gen/debug.in: $(DEBUG_CONFIG_FILES)
|
||||
$(call build_gen_menu_in,$@,Debug,DEBUG,config/debug,$(DEBUGS))
|
||||
@$(ECHO) ' IN $(@)'
|
||||
$(SILENT)$(CT_LIB_DIR)/scripts/gen_in_frags.sh menu "$@" "Debug facilities" "DEBUG" "config/debug" $(DEBUGS)
|
||||
|
||||
#-----------------------------------------------------------
|
||||
# Cleaning up the mess...
|
||||
|
158
scripts/gen_in_frags.sh
Executable file
158
scripts/gen_in_frags.sh
Executable file
@ -0,0 +1,158 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# This scripts generates either a choice or a menuconfig
|
||||
# with the specified entries.
|
||||
#
|
||||
# Usage:
|
||||
# generate a choice:
|
||||
# gen_in_frags.sh choice <out-file> <label> <config-prefix> <base-dir> <conditionals> entry [entry...]
|
||||
#
|
||||
# generate a menuconfig:
|
||||
# gen_in_frags.sh menu <out-file> <label> <config-prefix> <base-dir> entry [entry...]
|
||||
#
|
||||
# where:
|
||||
# out-file
|
||||
# put the generated choice/menuconfig into that file
|
||||
# for choices, it acts as the base bname of the file, the secondary
|
||||
# parts (the .in.2) are put in out-file.2
|
||||
#
|
||||
# label
|
||||
# name for the entries family
|
||||
# eg. Architecture, Kernel...
|
||||
#
|
||||
# config-prefix
|
||||
# prefix for the choice entries
|
||||
# eg. ARCH, KERNEL...
|
||||
#
|
||||
# base-dir
|
||||
# base directory containing config files
|
||||
# eg. config/arch, config/kernel...
|
||||
#
|
||||
# conditionals (valid only for choice)
|
||||
# generate backend conditionals if Y/y, don't if anything else
|
||||
# if 'Y' (or 'y'), a dependency on the backen mode will be added
|
||||
# to each entry
|
||||
#
|
||||
# entry [entry...]
|
||||
# a list of entry/ies toadd to the choice/menuconfig
|
||||
# eg.:
|
||||
# arm mips sh x86...
|
||||
# linux cygwin mingw32 solaris...
|
||||
# ...
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
# Generate a choice
|
||||
# See above for usage
|
||||
gen_choice() {
|
||||
local out_file="${1}"
|
||||
local label="${2}"
|
||||
local cfg_prefix="${3}"
|
||||
local base_dir="${4}"
|
||||
local cond="${5}"
|
||||
shift 5
|
||||
local file entry _entry
|
||||
|
||||
# Generate the part-1
|
||||
exec >"${out_file}"
|
||||
printf '# %s menu\n' "${label}"
|
||||
printf '# Generated file, do not edit!!!\n'
|
||||
printf '\n'
|
||||
printf 'choice GEN_CHOICE_%s\n' "${cfg_prefix}"
|
||||
printf ' bool\n'
|
||||
printf ' prompt "%s"\n' "${label}"
|
||||
printf '\n'
|
||||
for entry in "${@}"; do
|
||||
file="${base_dir}/${entry}.in"
|
||||
_entry=$(printf '%s\n' "${entry}" |"${sed}" -r -s -e 's/[-.+]/_/g;')
|
||||
printf 'config %s_%s\n' "${cfg_prefix}" "${_entry}"
|
||||
printf ' bool\n'
|
||||
printf ' prompt "%s"\n' "${entry}"
|
||||
if [ "${cond}" = "Y" -o "${cond}" = "y" ]; then
|
||||
printf ' depends on %s_%s_AVAILABLE\n' "${cfg_prefix}" "${_entry}"
|
||||
fi
|
||||
"${sed}" -r -e '/^## depends on /!d; s/^## / /;' ${file} 2>/dev/null
|
||||
"${sed}" -r -e '/^## select /!d; s/^## / /;' ${file} 2>/dev/null
|
||||
if "${grep}" -E '^## help' ${file} >/dev/null 2>&1; then
|
||||
printf ' help\n'
|
||||
"${sed}" -r -e '/^## help ?/!d; s/^## help ?/ /;' ${file} 2>/dev/null
|
||||
fi
|
||||
printf '\n'
|
||||
done
|
||||
printf 'endchoice\n'
|
||||
|
||||
for entry in "${@}"; do
|
||||
file="${base_dir}/${entry}.in"
|
||||
_entry=$(printf '%s\n' "${entry}" |"${sed}" -r -s -e 's/[-.+]/_/g;')
|
||||
printf '\n'
|
||||
if [ "${cond}" = "Y" -o "${cond}" = "y" ]; then
|
||||
printf 'config %s_%s_AVAILABLE\n' "${cfg_prefix}" "${_entry}"
|
||||
printf ' bool\n'
|
||||
printf ' default y if'
|
||||
printf ' BACKEND_%s = "%s"' "${cfg_prefix}" "${entry}"
|
||||
printf ' || BACKEND_%s = ""' "${cfg_prefix}"
|
||||
printf ' || ! BACKEND\n'
|
||||
fi
|
||||
printf 'if %s_%s\n' "${cfg_prefix}" "${_entry}"
|
||||
printf 'config %s\n' "${cfg_prefix}"
|
||||
printf ' default "%s" if %s_%s\n' "${entry}" "${cfg_prefix}" "${_entry}"
|
||||
printf 'source "%s"\n' "${file}"
|
||||
printf 'endif\n'
|
||||
done
|
||||
|
||||
# Generate the part-2
|
||||
exec >"${out_file}.2"
|
||||
printf '# %s second part options\n' "${label}"
|
||||
printf '# Generated file, do not edit!!!\n'
|
||||
for entry in "${@}"; do
|
||||
file="${base_dir}/${entry}.in"
|
||||
_entry=$(printf '%s\n' "${entry}" |"${sed}" -r -s -e 's/[-.+]/_/g;')
|
||||
if [ -f "${file}.2" ]; then
|
||||
printf '\n'
|
||||
printf 'if %s_%s\n' "${cfg_prefix}" "${_entry}"
|
||||
printf 'comment "%s other options"\n' "${entry}"
|
||||
printf 'source "%s.2"\n' "${file}"
|
||||
printf 'endif\n'
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Generate a menuconfig
|
||||
# See above for usage
|
||||
gen_menu() {
|
||||
local out_file="${1}"
|
||||
local label="${2}"
|
||||
local cfg_prefix="${3}"
|
||||
local base_dir="${4}"
|
||||
shift 4
|
||||
local file entry _entry
|
||||
|
||||
# GEnerate the menuconfig
|
||||
exec >"${out_file}"
|
||||
printf '# %s menu\n' "${label}"
|
||||
printf '# Generated file, do not edit!!!\n'
|
||||
printf '\n'
|
||||
for entry in "${@}"; do
|
||||
file="${base_dir}/${entry}.in"
|
||||
_entry=$(printf '%s\n' "${entry}" |"${sed}" -r -s -e 's/[-.+]/_/g;')
|
||||
printf 'menuconfig %s_%s\n' "${cfg_prefix}" "${_entry}"
|
||||
printf ' bool\n'
|
||||
printf ' prompt "%s"\n' "${entry}"
|
||||
"${sed}" -r -e '/^## depends on /!d; s/^## / /;' ${file} 2>/dev/null
|
||||
"${sed}" -r -e '/^## select /!d; s/^## / /;' ${file} 2>/dev/null
|
||||
if "${grep}" -E '^## help' ${file} >/dev/null 2>&1; then
|
||||
printf ' help\n'
|
||||
"${sed}" -r -e '/^## help ?/!d; s/^## help ?/ /;' ${file} 2>/dev/null
|
||||
fi
|
||||
printf '\n'
|
||||
printf 'if %s_%s\n' "${cfg_prefix}" "${_entry}"
|
||||
printf 'source "%s"\n' "${file}"
|
||||
printf 'endif\n'
|
||||
printf '\n'
|
||||
done
|
||||
}
|
||||
|
||||
type="${1}"
|
||||
shift
|
||||
"gen_${type}" "${@}"
|
Loading…
x
Reference in New Issue
Block a user