config/config.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed May 18 23:00:46 2011 +0200 (2011-05-18)
changeset 2467 200836977ce6
parent 2445 7000b634ba04
child 2484 d1a8c2ae7946
permissions -rw-r--r--
config: rename variables that are arrays

Make it explicit that a variable is an array bu the name of the variable.
It will be used later when .config gets munged to allow both multiple
arguments and arguments with spaces at the same time to be passed from the
configuration down to the build scripts.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
     1 # ===========================================================================
     2 # crosstool-NG genererated config files
     3 # These targets are used from top-level makefile
     4 
     5 #-----------------------------------------------------------
     6 # List all config files, wether sourced or generated
     7 
     8 # The top-level config file to be used be configurators
     9 KCONFIG_TOP = config/config.in
    10 
    11 # Build the list of all source config files
    12 STATIC_CONFIG_FILES = $(patsubst $(CT_LIB_DIR)/%,%,$(shell find $(CT_LIB_DIR)/config -type f \( -name '*.in' -o -name '*.in.2' \) 2>/dev/null))
    13 # ... and how to access them:
    14 $(STATIC_CONFIG_FILES): config
    15 
    16 # Build a list of per-component-type source config files
    17 ARCH_CONFIG_FILES     = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/arch/*.in))
    18 ARCH_CONFIG_FILES_2   = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/arch/*.in.2))
    19 KERNEL_CONFIG_FILES   = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/kernel/*.in))
    20 KERNEL_CONFIG_FILES_2 = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/kernel/*.in.2))
    21 CC_CONFIG_FILES       = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/cc/*.in))
    22 CC_CONFIG_FILES_2     = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/cc/*.in.2))
    23 LIBC_CONFIG_FILES     = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/libc/*.in))
    24 LIBC_CONFIG_FILES_2   = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/libc/*.in.2))
    25 DEBUG_CONFIG_FILES    = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/debug/*.in))
    26 
    27 # Build the list of generated config files
    28 GEN_CONFIG_FILES = config.gen/arch.in     \
    29                    config.gen/kernel.in   \
    30                    config.gen/cc.in       \
    31                    config.gen/libc.in     \
    32                    config.gen/debug.in
    33 # ... and how to access them:
    34 # Generated files depends on config.mk (this file) because it has the
    35 # functions needed to build the genrated files, and thus they might
    36 # need re-generation if config.mk changes
    37 $(GEN_CONFIG_FILES): config.gen                         \
    38                      $(CT_LIB_DIR)/config/config.mk
    39 
    40 # Helper entry for the configurators
    41 PHONY += config_files
    42 config_files: $(STATIC_CONFIG_FILES) $(GEN_CONFIG_FILES)
    43 
    44 # Where to access to the source config files from
    45 config:
    46 	@$(ECHO) "  LN    config"
    47 	$(SILENT)ln -s $(CT_LIB_DIR)/config config
    48 
    49 # Where to store the generated config files into
    50 config.gen:
    51 	@$(ECHO) "  MKDIR config.gen"
    52 	$(SILENT)mkdir -p config.gen
    53 
    54 #-----------------------------------------------------------
    55 # Build list of per-component-type items to easily build generated files
    56 
    57 ARCHS   = $(patsubst config/arch/%.in,%,$(ARCH_CONFIG_FILES))
    58 KERNELS = $(patsubst config/kernel/%.in,%,$(KERNEL_CONFIG_FILES))
    59 CCS     = $(patsubst config/cc/%.in,%,$(CC_CONFIG_FILES))
    60 LIBCS   = $(patsubst config/libc/%.in,%,$(LIBC_CONFIG_FILES))
    61 DEBUGS  = $(patsubst config/debug/%.in,%,$(DEBUG_CONFIG_FILES))
    62 
    63 #-----------------------------------------------------------
    64 # Helper functions to ease building generated config files
    65 
    66 # The function 'build_gen_choice_in' builds a choice-menu of a list of
    67 # components in the given list, also adding source-ing of associazted
    68 # config files:
    69 # $1 : destination file
    70 # $2 : name for the entries family (eg. Architecture, kernel...)
    71 # $3 : prefix for the choice entries (eg. ARCH, KERNEL...)
    72 # $4 : base directory containing config files
    73 # $5 : generate backend conditionals if Y, don't if anything else
    74 # $6 : list of config entries (eg. for architectures: "alpha arm ia64"...,
    75 #      and for kernels: "bare-metal linux"...)
    76 # Example to build the kernels generated config file:
    77 # $(call build_gen_choice_in,config.gen/kernel.in,Target OS,KERNEL,config/kernel,$(KERNELS))
    78 define build_gen_choice_in
    79 	@$(ECHO) '  IN    $(1)'
    80 	$(SILENT)(echo "# $(2) menu";                                           \
    81 	  echo "# Generated file, do not edit!!!";                              \
    82 	  echo "";                                                              \
    83 	  echo "choice GEN_CHOICE_$(3)";                                        \
    84 	  echo "    bool";                                                      \
    85 	  echo "    prompt \"$(2)\"";                                           \
    86 	  echo "";                                                              \
    87 	  for entry in $(6); do                                                 \
    88 	    file="$(4)/$${entry}.in";                                           \
    89 	    _entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;');        \
    90 	    echo "config $(3)_$${_entry}";                                      \
    91 	    echo "    bool";                                                    \
    92 	    echo "    prompt \"$${entry}\"";                                    \
    93 	    if [ "$(5)" = "Y" ]; then                                           \
    94 	      echo "    depends on $(3)_$${_entry}_AVAILABLE";                  \
    95 	    fi;                                                                 \
    96 	    sed -r -e '/^## depends on /!d; s/^## /    /;' $${file} 2>/dev/null;\
    97 	    sed -r -e '/^## select /!d; s/^## /    /;' $${file} 2>/dev/null;    \
    98 	    if grep -E '^## help' $${file} >/dev/null 2>&1; then                        \
    99 	      echo "    help";                                                          \
   100 	      sed -r -e '/^## help ?/!d; s/^## help ?/      /;' $${file} 2>/dev/null;   \
   101 	    fi;                                                                         \
   102 	    echo "";                                                            \
   103 	  done;                                                                 \
   104 	  echo "endchoice";                                                     \
   105 	  for entry in $(6); do                                                 \
   106 	    file="$(4)/$${entry}.in";                                           \
   107 	    _entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;');        \
   108 	    echo "";                                                            \
   109 	    if [ "$(5)" = "Y" ]; then                                                                           \
   110 	      echo "config $(3)_$${_entry}_AVAILABLE";                                                          \
   111 	      echo "    bool";                                                                                  \
   112 	      echo "    default n if ! ( BACKEND_$(3) = \"$${entry}\" || BACKEND_$(3) = \"\" || ! BACKEND )";   \
   113 	      echo "    default y if BACKEND_$(3) = \"$${entry}\" || BACKEND_$(3) = \"\" || ! BACKEND";         \
   114 	    fi;                                                                                                 \
   115 	    echo "if $(3)_$${_entry}";                                          \
   116 	    echo "config $(3)";                                                 \
   117 	    echo "    default \"$${entry}\" if $(3)_$${_entry}";                \
   118 	    echo "source \"$${file}\"";                                         \
   119 	    echo "endif";                                                       \
   120 	  done;                                                                 \
   121 	 ) >$(1)
   122 	$(SILENT)(echo "# $(2) second part options";                            \
   123 	  echo "# Generated file, do not edit!!!";                              \
   124 	  for entry in $(6); do                                                 \
   125 	    file="$(4)/$${entry}.in";                                           \
   126 	    _entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;');        \
   127 	    if [ -f "$${file}.2" ]; then                                        \
   128 	      echo "";                                                          \
   129 	      echo "if $(3)_$${_entry}";                                        \
   130 	      echo "comment \"$${entry} other options\"";                       \
   131 	      echo "source \"$${file}.2\"";                                     \
   132 	      echo "endif";                                                     \
   133 	    fi;                                                                 \
   134 	  done;                                                                 \
   135 	 ) >$(1).2
   136 endef
   137 
   138 # The function 'build_gen_menu_in' builds a menuconfig for each component in
   139 # the given list, source-ing the associated files conditionnaly:
   140 # $1 : destination file
   141 # $2 : name of entries family (eg. Tools, Debug...)
   142 # $3 : prefix for the menu entries (eg. DEBUG)
   143 # $4 : base directory containing config files
   144 # $5 : list of config entries (eg. for debug: "dmalloc duma gdb"...)
   145 # Example to build the generated debug config file:
   146 # $(call build_gen_menu_in,config.gen/debug.in,Debug,DEBUG,config/debug,$(DEBUGS))
   147 define build_gen_menu_in
   148 	@$(ECHO) '  IN    $(1)'
   149 	$(SILENT)(echo "# $(2) facilities menu";                                \
   150 	  echo "# Generated file, do not edit!!!";                              \
   151 	  echo "";                                                              \
   152 	  for entry in $(5); do                                                 \
   153 	    file="$(4)/$${entry}.in";                                           \
   154 	    _entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;');        \
   155 	    echo "menuconfig $(3)_$${_entry}";                                  \
   156 	    echo "    bool";                                                    \
   157 	    echo "    prompt \"$${entry}\"";                                    \
   158 	    sed -r -e '/^## depends on /!d; s/^## /    /;' $${file} 2>/dev/null;\
   159 	    sed -r -e '/^## select /!d; s/^## /    /;' $${file} 2>/dev/null;    \
   160 	    if grep -E '^## help' $${file} >/dev/null 2>&1; then                        \
   161 	      echo "    help";                                                          \
   162 	      sed -r -e '/^## help ?/!d; s/^## help ?/      /;' $${file} 2>/dev/null;   \
   163 	    fi;                                                                         \
   164 	    echo "";                                                            \
   165 	    echo "if $(3)_$${_entry}";                                          \
   166 	    echo "source \"$${file}\"";                                         \
   167 	    echo "endif";                                                       \
   168 	    echo "";                                                            \
   169 	  done;                                                                 \
   170 	 ) >$(1)
   171 endef
   172 
   173 #-----------------------------------------------------------
   174 # The rules for the generated config files
   175 
   176 # WARNING! If a .in file disapears between two runs, that will NOT be detected!
   177 
   178 config.gen/arch.in: $(ARCH_CONFIG_FILES) $(ARCH_CONFIG_FILES_2)
   179 	$(call build_gen_choice_in,$@,Target Architecture,ARCH,config/arch,Y,$(ARCHS))
   180 
   181 config.gen/kernel.in: $(KERNEL_CONFIG_FILES) $(KERNEL_CONFIG_FILES_2)
   182 	$(call build_gen_choice_in,$@,Target OS,KERNEL,config/kernel,Y,$(KERNELS))
   183 
   184 config.gen/cc.in: $(CC_CONFIG_FILES) $(CC_CONFIG_FILES_2)
   185 	$(call build_gen_choice_in,$@,C compiler,CC,config/cc,,$(CCS))
   186 
   187 config.gen/libc.in: $(LIBC_CONFIG_FILES) $(LIBC_CONFIG_FILES_2)
   188 	$(call build_gen_choice_in,$@,C library,LIBC,config/libc,Y,$(LIBCS))
   189 
   190 config.gen/debug.in: $(DEBUG_CONFIG_FILES)
   191 	$(call build_gen_menu_in,$@,Debug,DEBUG,config/debug,$(DEBUGS))
   192 
   193 #-----------------------------------------------------------
   194 # Cleaning up the mess...
   195 
   196 clean::
   197 	@$(ECHO) "  CLEAN config"
   198 	$(SILENT)rm -f config 2>/dev/null || true
   199 	@$(ECHO) "  CLEAN config.gen"
   200 	$(SILENT)rm -rf config.gen