config/config.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Fri Aug 06 23:45:35 2010 +0200 (2010-08-06)
branch1.7
changeset 2066 51b3646bcb9f
parent 1877 b579a5cb53d1
child 1976 2d90ec981ba3
permissions -rw-r--r--
1.7: close branch
     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' 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 KERNEL_CONFIG_FILES = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/kernel/*.in))
    19 CC_CONFIG_FILES     = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/cc/*.in))
    20 LIBC_CONFIG_FILES   = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/libc/*.in))
    21 DEBUG_CONFIG_FILES  = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/debug/*.in))
    22 
    23 # Build the list of generated config files
    24 GEN_CONFIG_FILES = config.gen/arch.in     \
    25                    config.gen/kernel.in   \
    26                    config.gen/cc.in       \
    27                    config.gen/libc.in     \
    28                    config.gen/debug.in
    29 # ... and how to access them:
    30 # Generated files depends on config.mk (this file) because it has the
    31 # functions needed to build the genrated files, and thus they might
    32 # need re-generation if config.mk changes
    33 $(GEN_CONFIG_FILES): config.gen                         \
    34                      $(CT_LIB_DIR)/config/config.mk
    35 
    36 # Helper entry for the configurators
    37 PHONY += config_files
    38 config_files: $(STATIC_CONFIG_FILES) $(GEN_CONFIG_FILES)
    39 
    40 # Where to access to the source config files from
    41 config:
    42 	@$(ECHO) "  LN    config"
    43 	$(SILENT)ln -s $(CT_LIB_DIR)/config config
    44 
    45 # Where to store the generated config files into
    46 config.gen:
    47 	@$(ECHO) "  MKDIR config.gen"
    48 	$(SILENT)mkdir -p config.gen
    49 
    50 #-----------------------------------------------------------
    51 # Build list of per-component-type items to easily build generated files
    52 
    53 ARCHS   = $(patsubst config/arch/%.in,%,$(ARCH_CONFIG_FILES))
    54 KERNELS = $(patsubst config/kernel/%.in,%,$(KERNEL_CONFIG_FILES))
    55 CCS     = $(patsubst config/cc/%.in,%,$(CC_CONFIG_FILES))
    56 LIBCS   = $(patsubst config/libc/%.in,%,$(LIBC_CONFIG_FILES))
    57 DEBUGS  = $(patsubst config/debug/%.in,%,$(DEBUG_CONFIG_FILES))
    58 
    59 #-----------------------------------------------------------
    60 # Helper functions to ease building generated config files
    61 
    62 # The function 'build_gen_choice_in' builds a choice-menu of a list of
    63 # components in the given list, also adding source-ing of associazted
    64 # config files:
    65 # $1 : destination file
    66 # $2 : name for the entries family (eg. Architecture, kernel...)
    67 # $3 : prefix for the choice entries (eg. ARCH, KERNEL...)
    68 # $4 : base directory containing config files
    69 # $5 : generate backend conditionals if Y, don't if anything else
    70 # $6 : list of config entries (eg. for architectures: "alpha arm ia64"...,
    71 #      and for kernels: "bare-metal linux"...)
    72 # Example to build the kernels generated config file:
    73 # $(call build_gen_choice_in,config.gen/kernel.in,Target OS,KERNEL,config/kernel,$(KERNELS))
    74 define build_gen_choice_in
    75 	@$(ECHO) '  IN    $(1)'
    76 	$(SILENT)(echo "# $(2) menu";                                           \
    77 	  echo "# Generated file, do not edit!!!";                              \
    78 	  echo "";                                                              \
    79 	  echo "choice";                                                        \
    80 	  echo "    bool";                                                      \
    81 	  echo "    prompt \"$(2)\"";                                           \
    82 	  echo "";                                                              \
    83 	  for entry in $(6); do                                                 \
    84 	    file="$(4)/$${entry}.in";                                           \
    85 	    _entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;');        \
    86 	    echo "config $(3)_$${_entry}";                                      \
    87 	    echo "    bool";                                                    \
    88 	    echo "    prompt \"$${entry}\"";                                    \
    89 	    dep_val=$$($(grep) -E '^# depends on ' $${file} 2>/dev/null);       \
    90 	    if [ -n "$${dep_val}" ]; then                                       \
    91 	      echo "    $${dep_val#\# }";                                       \
    92 	    fi;                                                                 \
    93 	    if [ "$(5)" = "Y" ]; then                                           \
    94 	      echo "    depends on $(3)_$${_entry}_AVAILABLE";                  \
    95 	    fi;                                                                 \
    96 	    echo "";                                                            \
    97 	  done;                                                                 \
    98 	  echo "endchoice";                                                     \
    99 	  for entry in $(6); do                                                 \
   100 	    file="$(4)/$${entry}.in";                                           \
   101 	    _entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;');        \
   102 	    echo "";                                                            \
   103 	    if [ "$(5)" = "Y" ]; then                                                                           \
   104 	      echo "config $(3)_$${_entry}_AVAILABLE";                                                          \
   105 	      echo "    bool";                                                                                  \
   106 	      echo "    default n if ! ( BACKEND_$(3) = \"$${entry}\" || BACKEND_$(3) = \"\" || ! BACKEND )";   \
   107 	      echo "    default y if BACKEND_$(3) = \"$${entry}\" || BACKEND_$(3) = \"\" || ! BACKEND";         \
   108 	    fi;                                                                                                 \
   109 	    echo "if $(3)_$${_entry}";                                          \
   110 	    echo "config $(3)";                                                 \
   111 	    echo "    default \"$${entry}\" if $(3)_$${_entry}";                \
   112 	    echo "source \"$${file}\"";                                         \
   113 	    echo "endif";                                                       \
   114 	  done;                                                                 \
   115 	  echo "";                                                              \
   116 	  for file in $(wildcard $(4)/*.in-common); do                          \
   117 	    echo "source \"$${file}\"";                                         \
   118 	  done;                                                                 \
   119 	 ) >$(1)
   120 endef
   121 
   122 # The function 'build_gen_menu_in' builds a menuconfig for each component in
   123 # the given list, source-ing the associated files conditionnaly:
   124 # $1 : destination file
   125 # $2 : name of entries family (eg. Tools, Debug...)
   126 # $3 : prefix for the menu entries (eg. DEBUG)
   127 # $4 : base directory containing config files
   128 # $5 : list of config entries (eg. for debug: "dmalloc duma gdb"...)
   129 # Example to build the generated debug config file:
   130 # $(call build_gen_menu_in,config.gen/debug.in,Debug,DEBUG,config/debug,$(DEBUGS))
   131 define build_gen_menu_in
   132 	@$(ECHO) '  IN    $(1)'
   133 	$(SILENT)(echo "# $(2) facilities menu";                                \
   134 	  echo "# Generated file, do not edit!!!";                              \
   135 	  echo "";                                                              \
   136 	  for entry in $(5); do                                                 \
   137 	    file="$(4)/$${entry}.in";                                           \
   138 	    _entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;');        \
   139 	    echo "menuconfig $(3)_$${_entry}";                                  \
   140 	    echo "    bool";                                                    \
   141 	    echo "    prompt \"$${entry}\"";                                    \
   142 	    dep_val=$$($(grep) -E '^# depends on ' $${file} 2>/dev/null);       \
   143 	    if [ -n "$${dep_val}" ]; then                                       \
   144 	      echo "    $${dep_val#\# }";                                       \
   145 	    fi;                                                                 \
   146 	    echo "if $(3)_$${_entry}";                                          \
   147 	    echo "source \"$${file}\"";                                         \
   148 	    echo "endif";                                                       \
   149 	    echo "";                                                            \
   150 	  done;                                                                 \
   151 	 ) >$(1)
   152 endef
   153 
   154 #-----------------------------------------------------------
   155 # The rules for the generated config files
   156 
   157 config.gen/arch.in: $(ARCH_CONFIG_FILES)
   158 	$(call build_gen_choice_in,$@,Target Architecture,ARCH,config/arch,Y,$(ARCHS))
   159 
   160 config.gen/kernel.in: $(KERNEL_CONFIG_FILES)
   161 	$(call build_gen_choice_in,$@,Target OS,KERNEL,config/kernel,Y,$(KERNELS))
   162 
   163 config.gen/cc.in: $(CC_CONFIG_FILES)
   164 	$(call build_gen_choice_in,$@,C compiler,CC,config/cc,,$(CCS))
   165 
   166 config.gen/libc.in: $(LIBC_CONFIG_FILES)
   167 	$(call build_gen_choice_in,$@,C library,LIBC,config/libc,Y,$(LIBCS))
   168 
   169 config.gen/debug.in: $(DEBUG_CONFIG_FILES)
   170 	$(call build_gen_menu_in,$@,Debug,DEBUG,config/debug,$(DEBUGS))
   171 
   172 #-----------------------------------------------------------
   173 # Cleaning up the mess...
   174 
   175 clean::
   176 	@$(ECHO) "  CLEAN config"
   177 	$(SILENT)rm -f config 2>/dev/null || true
   178 	@$(ECHO) "  CLEAN config.gen"
   179 	$(SILENT)rm -rf config.gen