config/config.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed Mar 17 00:21:57 2010 +0100 (2010-03-17)
changeset 1854 02b74bd4373f
parent 1269 17e37102a037
child 1868 89f16f038b92
permissions -rw-r--r--
tools: move sstrip to the binary utilities menu

sstrip is now alone in its 'tools' menu, and we will probably never gain
any other 'tool'. Besides, sstrip is just strip, but a little bit more
agressive, so it deserves going to the 'binary utilities' menu.
     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 : list of config entries (eg. for architectures: "alpha arm ia64"...,
    70 #      and for kernels: "bare-metal linux"...)
    71 # Example to build the kernels generated config file:
    72 # $(call build_gen_choice_in,config.gen/kernel.in,Target OS,KERNEL,config/kernel,$(KERNELS))
    73 define build_gen_choice_in
    74 	@$(ECHO) '  IN    $(1)'
    75 	$(SILENT)(echo "# $(2) menu";                                           \
    76 	  echo "# Generated file, do not edit!!!";                              \
    77 	  echo "";                                                              \
    78 	  echo "choice";                                                        \
    79 	  echo "    bool";                                                      \
    80 	  echo "    prompt \"$(2)\"";                                           \
    81 	  echo "";                                                              \
    82 	  for entry in $(5); do                                                 \
    83 	    file="$(4)/$${entry}.in";                                           \
    84 	    _entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;');        \
    85 	    echo "config $(3)_$${_entry}";                                      \
    86 	    echo "    bool";                                                    \
    87 	    echo "    prompt \"$${entry}\"";                                    \
    88 	    dep_val=$$($(grep) -E '^# depends on ' $${file} 2>/dev/null);       \
    89 	    if [ -n "$${dep_val}" ]; then                                       \
    90 	      echo "    $${dep_val#\# }";                                       \
    91 	    fi;                                                                 \
    92 	    echo "";                                                            \
    93 	  done;                                                                 \
    94 	  echo "endchoice";                                                     \
    95 	  for entry in $(5); do                                                 \
    96 	    file="$(4)/$${entry}.in";                                           \
    97 	    _entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;');        \
    98 	    echo "";                                                            \
    99 	    echo "if $(3)_$${_entry}";                                          \
   100 	    echo "config $(3)";                                                 \
   101 	    echo "    default \"$${entry}\" if $(3)_$${_entry}";                \
   102 	    echo "source $${file}";                                             \
   103 	    echo "endif";                                                       \
   104 	  done;                                                                 \
   105 	  echo "";                                                              \
   106 	  for file in $(wildcard $(4)/*.in-common); do                          \
   107 	    echo "source $${file}";                                             \
   108 	  done;                                                                 \
   109 	 ) >$(1)
   110 endef
   111 
   112 # The function 'build_gen_menu_in' builds a menuconfig for each component in
   113 # the given list, source-ing the associated files conditionnaly:
   114 # $1 : destination file
   115 # $2 : name of entries family (eg. Tools, Debug...)
   116 # $3 : prefix for the menu entries (eg. DEBUG)
   117 # $4 : base directory containing config files
   118 # $5 : list of config entries (eg. for debug: "dmalloc duma gdb"...)
   119 # Example to build the generated debug config file:
   120 # $(call build_gen_menu_in,config.gen/debug.in,Debug,DEBUG,config/debug,$(DEBUGS))
   121 define build_gen_menu_in
   122 	@$(ECHO) '  IN    $(1)'
   123 	$(SILENT)(echo "# $(2) facilities menu";                                \
   124 	  echo "# Generated file, do not edit!!!";                              \
   125 	  echo "";                                                              \
   126 	  for entry in $(5); do                                                 \
   127 	    file="$(4)/$${entry}.in";                                           \
   128 	    _entry=$$(echo "$${entry}" |$(sed) -r -s -e 's/[-.+]/_/g;');        \
   129 	    echo "menuconfig $(3)_$${_entry}";                                  \
   130 	    echo "    bool";                                                    \
   131 	    echo "    prompt \"$${entry}\"";                                    \
   132 	    dep_val=$$($(grep) -E '^# depends on ' $${file} 2>/dev/null);       \
   133 	    if [ -n "$${dep_val}" ]; then                                       \
   134 	      echo "    $${dep_val#\# }";                                       \
   135 	    fi;                                                                 \
   136 	    echo "if $(3)_$${_entry}";                                          \
   137 	    echo "source $${file}";                                             \
   138 	    echo "endif";                                                       \
   139 	    echo "";                                                            \
   140 	  done;                                                                 \
   141 	 ) >$(1)
   142 endef
   143 
   144 #-----------------------------------------------------------
   145 # The rules for the generated config files
   146 
   147 config.gen/arch.in: $(ARCH_CONFIG_FILES)
   148 	$(call build_gen_choice_in,$@,Target Architecture,ARCH,config/arch,$(ARCHS))
   149 
   150 config.gen/kernel.in: $(KERNEL_CONFIG_FILES)
   151 	$(call build_gen_choice_in,$@,Target OS,KERNEL,config/kernel,$(KERNELS))
   152 
   153 config.gen/cc.in: $(CC_CONFIG_FILES)
   154 	$(call build_gen_choice_in,$@,C compiler,CC,config/cc,$(CCS))
   155 
   156 config.gen/libc.in: $(LIBC_CONFIG_FILES)
   157 	$(call build_gen_choice_in,$@,C library,LIBC,config/libc,$(LIBCS))
   158 
   159 config.gen/debug.in: $(DEBUG_CONFIG_FILES)
   160 	$(call build_gen_menu_in,$@,Debug,DEBUG,config/debug,$(DEBUGS))
   161 
   162 #-----------------------------------------------------------
   163 # Cleaning up the mess...
   164 
   165 clean::
   166 	@$(ECHO) "  CLEAN config"
   167 	$(SILENT)rm -f config 2>/dev/null || true
   168 	@$(ECHO) "  CLEAN config.gen"
   169 	$(SILENT)rm -rf config.gen