1.1 --- a/config/config.mk Sun Jul 03 23:01:09 2011 +0200
1.2 +++ b/config/config.mk Sun Jul 03 23:02:16 2011 +0200
1.3 @@ -31,10 +31,13 @@
1.4 config.gen/libc.in \
1.5 config.gen/debug.in
1.6 # ... and how to access them:
1.7 -# Generated files depends on config.mk (this file) because it has the
1.8 -# functions needed to build the genrated files, and thus they might
1.9 -# need re-generation if config.mk changes
1.10 -$(GEN_CONFIG_FILES): config.gen \
1.11 +# Generated files depends on the gen_in_frags script because it has the
1.12 +# functions needed to build the genrated files, and thus they might need
1.13 +# re-generation if it changes.
1.14 +# They also depends on config.mk (this file) because it has the dependency
1.15 +# rules, and thus they might need re-generation if the deps change.
1.16 +$(GEN_CONFIG_FILES): config.gen \
1.17 + $(CT_LIB_DIR)/scripts/gen_in_frags.sh \
1.18 $(CT_LIB_DIR)/config/config.mk
1.19
1.20 # Helper entry for the configurators
1.21 @@ -61,133 +64,29 @@
1.22 DEBUGS = $(patsubst config/debug/%.in,%,$(DEBUG_CONFIG_FILES))
1.23
1.24 #-----------------------------------------------------------
1.25 -# Helper functions to ease building generated config files
1.26 -
1.27 -# The function 'build_gen_choice_in' builds a choice-menu of a list of
1.28 -# components in the given list, also adding source-ing of associazted
1.29 -# config files:
1.30 -# $1 : destination file
1.31 -# $2 : name for the entries family (eg. Architecture, kernel...)
1.32 -# $3 : prefix for the choice entries (eg. ARCH, KERNEL...)
1.33 -# $4 : base directory containing config files
1.34 -# $5 : generate backend conditionals if Y, don't if anything else
1.35 -# $6 : list of config entries (eg. for architectures: "alpha arm ia64"...,
1.36 -# and for kernels: "bare-metal linux"...)
1.37 -# Example to build the kernels generated config file:
1.38 -# $(call build_gen_choice_in,config.gen/kernel.in,Target OS,KERNEL,config/kernel,$(KERNELS))
1.39 -define build_gen_choice_in
1.40 - @$(ECHO) ' IN $(1)'
1.41 - $(SILENT)(echo "# $(2) menu"; \
1.42 - echo "# Generated file, do not edit!!!"; \
1.43 - echo ""; \
1.44 - echo "choice GEN_CHOICE_$(3)"; \
1.45 - echo " bool"; \
1.46 - echo " prompt \"$(2)\""; \
1.47 - echo ""; \
1.48 - for entry in $(6); do \
1.49 - file="$(4)/$${entry}.in"; \
1.50 - _entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;'); \
1.51 - echo "config $(3)_$${_entry}"; \
1.52 - echo " bool"; \
1.53 - echo " prompt \"$${entry}\""; \
1.54 - if [ "$(5)" = "Y" ]; then \
1.55 - echo " depends on $(3)_$${_entry}_AVAILABLE"; \
1.56 - fi; \
1.57 - $(sed) -r -e '/^## depends on /!d; s/^## / /;' $${file} 2>/dev/null; \
1.58 - $(sed) -r -e '/^## select /!d; s/^## / /;' $${file} 2>/dev/null; \
1.59 - if grep -E '^## help' $${file} >/dev/null 2>&1; then \
1.60 - echo " help"; \
1.61 - $(sed) -r -e '/^## help ?/!d; s/^## help ?/ /;' $${file} 2>/dev/null;\
1.62 - fi; \
1.63 - echo ""; \
1.64 - done; \
1.65 - echo "endchoice"; \
1.66 - for entry in $(6); do \
1.67 - file="$(4)/$${entry}.in"; \
1.68 - _entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;'); \
1.69 - echo ""; \
1.70 - if [ "$(5)" = "Y" ]; then \
1.71 - echo "config $(3)_$${_entry}_AVAILABLE"; \
1.72 - echo " bool"; \
1.73 - echo " default y if BACKEND_$(3) = \"$${entry}\" || BACKEND_$(3) = \"\" || ! BACKEND"; \
1.74 - fi; \
1.75 - echo "if $(3)_$${_entry}"; \
1.76 - echo "config $(3)"; \
1.77 - echo " default \"$${entry}\" if $(3)_$${_entry}"; \
1.78 - echo "source \"$${file}\""; \
1.79 - echo "endif"; \
1.80 - done; \
1.81 - ) >$(1)
1.82 - $(SILENT)(echo "# $(2) second part options"; \
1.83 - echo "# Generated file, do not edit!!!"; \
1.84 - for entry in $(6); do \
1.85 - file="$(4)/$${entry}.in"; \
1.86 - _entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;'); \
1.87 - if [ -f "$${file}.2" ]; then \
1.88 - echo ""; \
1.89 - echo "if $(3)_$${_entry}"; \
1.90 - echo "comment \"$${entry} other options\""; \
1.91 - echo "source \"$${file}.2\""; \
1.92 - echo "endif"; \
1.93 - fi; \
1.94 - done; \
1.95 - ) >$(1).2
1.96 -endef
1.97 -
1.98 -# The function 'build_gen_menu_in' builds a menuconfig for each component in
1.99 -# the given list, source-ing the associated files conditionnaly:
1.100 -# $1 : destination file
1.101 -# $2 : name of entries family (eg. Tools, Debug...)
1.102 -# $3 : prefix for the menu entries (eg. DEBUG)
1.103 -# $4 : base directory containing config files
1.104 -# $5 : list of config entries (eg. for debug: "dmalloc duma gdb"...)
1.105 -# Example to build the generated debug config file:
1.106 -# $(call build_gen_menu_in,config.gen/debug.in,Debug,DEBUG,config/debug,$(DEBUGS))
1.107 -define build_gen_menu_in
1.108 - @$(ECHO) ' IN $(1)'
1.109 - $(SILENT)(echo "# $(2) facilities menu"; \
1.110 - echo "# Generated file, do not edit!!!"; \
1.111 - echo ""; \
1.112 - for entry in $(5); do \
1.113 - file="$(4)/$${entry}.in"; \
1.114 - _entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;'); \
1.115 - echo "menuconfig $(3)_$${_entry}"; \
1.116 - echo " bool"; \
1.117 - echo " prompt \"$${entry}\""; \
1.118 - $(sed) -r -e '/^## depends on /!d; s/^## / /;' $${file} 2>/dev/null; \
1.119 - $(sed) -r -e '/^## select /!d; s/^## / /;' $${file} 2>/dev/null; \
1.120 - if grep -E '^## help' $${file} >/dev/null 2>&1; then \
1.121 - echo " help"; \
1.122 - $(sed) -r -e '/^## help ?/!d; s/^## help ?/ /;' $${file} 2>/dev/null;\
1.123 - fi; \
1.124 - echo ""; \
1.125 - echo "if $(3)_$${_entry}"; \
1.126 - echo "source \"$${file}\""; \
1.127 - echo "endif"; \
1.128 - echo ""; \
1.129 - done; \
1.130 - ) >$(1)
1.131 -endef
1.132 -
1.133 -#-----------------------------------------------------------
1.134 # The rules for the generated config files
1.135
1.136 # WARNING! If a .in file disapears between two runs, that will NOT be detected!
1.137
1.138 config.gen/arch.in: $(ARCH_CONFIG_FILES) $(ARCH_CONFIG_FILES_2)
1.139 - $(call build_gen_choice_in,$@,Target Architecture,ARCH,config/arch,Y,$(ARCHS))
1.140 + @$(ECHO) ' IN $(@)'
1.141 + $(SILENT)$(CT_LIB_DIR)/scripts/gen_in_frags.sh choice "$@" "Target Architecture" "ARCH" "config/arch" "Y" $(ARCHS)
1.142
1.143 config.gen/kernel.in: $(KERNEL_CONFIG_FILES) $(KERNEL_CONFIG_FILES_2)
1.144 - $(call build_gen_choice_in,$@,Target OS,KERNEL,config/kernel,Y,$(KERNELS))
1.145 + @$(ECHO) ' IN $(@)'
1.146 + $(SILENT)$(CT_LIB_DIR)/scripts/gen_in_frags.sh choice "$@" "Target OS" "KERNEL" "config/kernel" "Y" $(KERNELS)
1.147
1.148 config.gen/cc.in: $(CC_CONFIG_FILES) $(CC_CONFIG_FILES_2)
1.149 - $(call build_gen_choice_in,$@,C compiler,CC,config/cc,,$(CCS))
1.150 + @$(ECHO) ' IN $(@)'
1.151 + $(SILENT)$(CT_LIB_DIR)/scripts/gen_in_frags.sh choice "$@" "C compiler" "CC" "config/cc" "N" $(CCS)
1.152
1.153 config.gen/libc.in: $(LIBC_CONFIG_FILES) $(LIBC_CONFIG_FILES_2)
1.154 - $(call build_gen_choice_in,$@,C library,LIBC,config/libc,Y,$(LIBCS))
1.155 + @$(ECHO) ' IN $(@)'
1.156 + $(SILENT)$(CT_LIB_DIR)/scripts/gen_in_frags.sh choice "$@" "C library" "LIBC" "config/libc" "Y" $(LIBCS)
1.157
1.158 config.gen/debug.in: $(DEBUG_CONFIG_FILES)
1.159 - $(call build_gen_menu_in,$@,Debug,DEBUG,config/debug,$(DEBUGS))
1.160 + @$(ECHO) ' IN $(@)'
1.161 + $(SILENT)$(CT_LIB_DIR)/scripts/gen_in_frags.sh menu "$@" "Debug facilities" "DEBUG" "config/debug" $(DEBUGS)
1.162
1.163 #-----------------------------------------------------------
1.164 # Cleaning up the mess...
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/scripts/gen_in_frags.sh Sun Jul 03 23:02:16 2011 +0200
2.3 @@ -0,0 +1,158 @@
2.4 +#!/bin/sh
2.5 +set -e
2.6 +
2.7 +# This scripts generates either a choice or a menuconfig
2.8 +# with the specified entries.
2.9 +#
2.10 +# Usage:
2.11 +# generate a choice:
2.12 +# gen_in_frags.sh choice <out-file> <label> <config-prefix> <base-dir> <conditionals> entry [entry...]
2.13 +#
2.14 +# generate a menuconfig:
2.15 +# gen_in_frags.sh menu <out-file> <label> <config-prefix> <base-dir> entry [entry...]
2.16 +#
2.17 +# where:
2.18 +# out-file
2.19 +# put the generated choice/menuconfig into that file
2.20 +# for choices, it acts as the base bname of the file, the secondary
2.21 +# parts (the .in.2) are put in out-file.2
2.22 +#
2.23 +# label
2.24 +# name for the entries family
2.25 +# eg. Architecture, Kernel...
2.26 +#
2.27 +# config-prefix
2.28 +# prefix for the choice entries
2.29 +# eg. ARCH, KERNEL...
2.30 +#
2.31 +# base-dir
2.32 +# base directory containing config files
2.33 +# eg. config/arch, config/kernel...
2.34 +#
2.35 +# conditionals (valid only for choice)
2.36 +# generate backend conditionals if Y/y, don't if anything else
2.37 +# if 'Y' (or 'y'), a dependency on the backen mode will be added
2.38 +# to each entry
2.39 +#
2.40 +# entry [entry...]
2.41 +# a list of entry/ies toadd to the choice/menuconfig
2.42 +# eg.:
2.43 +# arm mips sh x86...
2.44 +# linux cygwin mingw32 solaris...
2.45 +# ...
2.46 +#
2.47 +#------------------------------------------------------------------------------
2.48 +
2.49 +# Generate a choice
2.50 +# See above for usage
2.51 +gen_choice() {
2.52 + local out_file="${1}"
2.53 + local label="${2}"
2.54 + local cfg_prefix="${3}"
2.55 + local base_dir="${4}"
2.56 + local cond="${5}"
2.57 + shift 5
2.58 + local file entry _entry
2.59 +
2.60 + # Generate the part-1
2.61 + exec >"${out_file}"
2.62 + printf '# %s menu\n' "${label}"
2.63 + printf '# Generated file, do not edit!!!\n'
2.64 + printf '\n'
2.65 + printf 'choice GEN_CHOICE_%s\n' "${cfg_prefix}"
2.66 + printf ' bool\n'
2.67 + printf ' prompt "%s"\n' "${label}"
2.68 + printf '\n'
2.69 + for entry in "${@}"; do
2.70 + file="${base_dir}/${entry}.in"
2.71 + _entry=$(printf '%s\n' "${entry}" |"${sed}" -r -s -e 's/[-.+]/_/g;')
2.72 + printf 'config %s_%s\n' "${cfg_prefix}" "${_entry}"
2.73 + printf ' bool\n'
2.74 + printf ' prompt "%s"\n' "${entry}"
2.75 + if [ "${cond}" = "Y" -o "${cond}" = "y" ]; then
2.76 + printf ' depends on %s_%s_AVAILABLE\n' "${cfg_prefix}" "${_entry}"
2.77 + fi
2.78 + "${sed}" -r -e '/^## depends on /!d; s/^## / /;' ${file} 2>/dev/null
2.79 + "${sed}" -r -e '/^## select /!d; s/^## / /;' ${file} 2>/dev/null
2.80 + if "${grep}" -E '^## help' ${file} >/dev/null 2>&1; then
2.81 + printf ' help\n'
2.82 + "${sed}" -r -e '/^## help ?/!d; s/^## help ?/ /;' ${file} 2>/dev/null
2.83 + fi
2.84 + printf '\n'
2.85 + done
2.86 + printf 'endchoice\n'
2.87 +
2.88 + for entry in "${@}"; do
2.89 + file="${base_dir}/${entry}.in"
2.90 + _entry=$(printf '%s\n' "${entry}" |"${sed}" -r -s -e 's/[-.+]/_/g;')
2.91 + printf '\n'
2.92 + if [ "${cond}" = "Y" -o "${cond}" = "y" ]; then
2.93 + printf 'config %s_%s_AVAILABLE\n' "${cfg_prefix}" "${_entry}"
2.94 + printf ' bool\n'
2.95 + printf ' default y if'
2.96 + printf ' BACKEND_%s = "%s"' "${cfg_prefix}" "${entry}"
2.97 + printf ' || BACKEND_%s = ""' "${cfg_prefix}"
2.98 + printf ' || ! BACKEND\n'
2.99 + fi
2.100 + printf 'if %s_%s\n' "${cfg_prefix}" "${_entry}"
2.101 + printf 'config %s\n' "${cfg_prefix}"
2.102 + printf ' default "%s" if %s_%s\n' "${entry}" "${cfg_prefix}" "${_entry}"
2.103 + printf 'source "%s"\n' "${file}"
2.104 + printf 'endif\n'
2.105 + done
2.106 +
2.107 + # Generate the part-2
2.108 + exec >"${out_file}.2"
2.109 + printf '# %s second part options\n' "${label}"
2.110 + printf '# Generated file, do not edit!!!\n'
2.111 + for entry in "${@}"; do
2.112 + file="${base_dir}/${entry}.in"
2.113 + _entry=$(printf '%s\n' "${entry}" |"${sed}" -r -s -e 's/[-.+]/_/g;')
2.114 + if [ -f "${file}.2" ]; then
2.115 + printf '\n'
2.116 + printf 'if %s_%s\n' "${cfg_prefix}" "${_entry}"
2.117 + printf 'comment "%s other options"\n' "${entry}"
2.118 + printf 'source "%s.2"\n' "${file}"
2.119 + printf 'endif\n'
2.120 + fi
2.121 + done
2.122 +}
2.123 +
2.124 +# Generate a menuconfig
2.125 +# See above for usage
2.126 +gen_menu() {
2.127 + local out_file="${1}"
2.128 + local label="${2}"
2.129 + local cfg_prefix="${3}"
2.130 + local base_dir="${4}"
2.131 + shift 4
2.132 + local file entry _entry
2.133 +
2.134 + # GEnerate the menuconfig
2.135 + exec >"${out_file}"
2.136 + printf '# %s menu\n' "${label}"
2.137 + printf '# Generated file, do not edit!!!\n'
2.138 + printf '\n'
2.139 + for entry in "${@}"; do
2.140 + file="${base_dir}/${entry}.in"
2.141 + _entry=$(printf '%s\n' "${entry}" |"${sed}" -r -s -e 's/[-.+]/_/g;')
2.142 + printf 'menuconfig %s_%s\n' "${cfg_prefix}" "${_entry}"
2.143 + printf ' bool\n'
2.144 + printf ' prompt "%s"\n' "${entry}"
2.145 + "${sed}" -r -e '/^## depends on /!d; s/^## / /;' ${file} 2>/dev/null
2.146 + "${sed}" -r -e '/^## select /!d; s/^## / /;' ${file} 2>/dev/null
2.147 + if "${grep}" -E '^## help' ${file} >/dev/null 2>&1; then
2.148 + printf ' help\n'
2.149 + "${sed}" -r -e '/^## help ?/!d; s/^## help ?/ /;' ${file} 2>/dev/null
2.150 + fi
2.151 + printf '\n'
2.152 + printf 'if %s_%s\n' "${cfg_prefix}" "${_entry}"
2.153 + printf 'source "%s"\n' "${file}"
2.154 + printf 'endif\n'
2.155 + printf '\n'
2.156 + done
2.157 +}
2.158 +
2.159 +type="${1}"
2.160 +shift
2.161 +"gen_${type}" "${@}"