kconfig/kconfig.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Oct 14 16:50:33 2008 +0000 (2008-10-14)
changeset 926 fe3e5a3331b6
parent 925 ac50e4f1360a
child 940 f0f9ba3f98f2
permissions -rw-r--r--
Rework the kconfig stuff
- better handle config file generation dependencies
- get rid of CT_TOP_DIR where useless
- rearrange code to be cleaner, and add adequate '#----' comments to split the different parts
- a few eye-candy here and there

/trunk/kconfig/kconfig.mk | 158 99 59 0 +++++++++++++++++++++++++++++++++--------------------
1 file changed, 99 insertions(+), 59 deletions(-)
     1 # ===========================================================================
     2 # crosstool-NG configuration targets
     3 # These targets are used from top-level makefile
     4 
     5 # Derive the project version from, well, the project version:
     6 export PROJECTVERSION=$(CT_VERSION)
     7 
     8 #-----------------------------------------------------------
     9 # Some static /configuration/
    10 
    11 KCONFIG_TOP = config/config.in
    12 obj = kconfig
    13 PHONY += clean help oldconfig menuconfig defoldconfig
    14 
    15 # Darwin (MacOS-X) does not have proper libintl support
    16 ifeq ($(shell uname -s),Darwin)
    17 KBUILD_NO_NLS:=1
    18 endif
    19 
    20 ifneq ($(KBUILD_NO_NLS),)
    21 CFLAGS += -DKBUILD_NO_NLS
    22 endif
    23 
    24 #-----------------------------------------------------------
    25 # List all config files, source and generated
    26 
    27 # Build the list of all source config files
    28 STATIC_CONFIG_FILES = $(patsubst $(CT_LIB_DIR)/%,%,$(shell find $(CT_LIB_DIR)/config -type f -name '*.in' 2>/dev/null))
    29 # ... and how to access them:
    30 $(STATIC_CONFIG_FILES): config
    31 
    32 # Build a list of per-component-type source config files
    33 ARCH_CONFIG_FILES   = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/arch/*.in))
    34 KERNEL_CONFIG_FILES = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/kernel/*.in))
    35 CC_CONFIG_FILES     = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/cc/*.in))
    36 LIBC_CONFIG_FILES   = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/libc/*.in))
    37 DEBUG_CONFIG_FILES  = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/debug/*.in))
    38 TOOL_CONFIG_FILES   = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/tools/*.in))
    39 
    40 # Build the list of generated config files
    41 GEN_CONFIG_FILES = config.gen/arch.in     \
    42                    config.gen/kernel.in   \
    43                    config.gen/cc.in       \
    44                    config.gen/libc.in     \
    45                    config.gen/tools.in    \
    46                    config.gen/debug.in
    47 # ... and how to access them:
    48 # Generated files depends on kconfig.mk (this file) because it has the
    49 # functions needed to build the genrated files, and thus they might
    50 # need re-generation if kconfig.mk changes
    51 $(GEN_CONFIG_FILES): config.gen                         \
    52                      $(CT_LIB_DIR)/kconfig/kconfig.mk
    53 
    54 # KCONFIG_TOP should already be in STATIC_CONFIG_FILES, anyway...
    55 CONFIG_FILES = $(sort $(KCONFIG_TOP) $(STATIC_CONFIG_FILES) $(GEN_CONFIG_FILES))
    56 
    57 # Where to access to the source config files from
    58 config:
    59 	@echo "  LN    config"
    60 	@ln -s $(CT_LIB_DIR)/config config
    61 
    62 # Where to store the generated config files into
    63 config.gen:
    64 	@echo "  MKDIR config.gen"
    65 	@mkdir -p config.gen
    66 
    67 #-----------------------------------------------------------
    68 # Build list of per-component-type items to easily build generated files
    69 
    70 ARCHS   = $(patsubst config/arch/%.in,%,$(ARCH_CONFIG_FILES))
    71 KERNELS = $(patsubst config/kernel/%.in,%,$(KERNEL_CONFIG_FILES))
    72 CCS     = $(patsubst config/cc/%.in,%,$(CC_CONFIG_FILES))
    73 LIBCS   = $(patsubst config/libc/%.in,%,$(LIBC_CONFIG_FILES))
    74 DEBUGS  = $(patsubst config/debug/%.in,%,$(DEBUG_CONFIG_FILES))
    75 TOOLS   = $(patsubst config/tools/%.in,%,$(TOOL_CONFIG_FILES))
    76 
    77 #-----------------------------------------------------------
    78 # Helper functions to ease building generated config files
    79 
    80 # The function 'build_gen_choice_in' builds a choice-menu of a list of
    81 # components in the given list, also adding source-ing of associazted
    82 # config files:
    83 # $1 : destination file
    84 # $2 : name for the entries family (eg. Architecture, kernel...)
    85 # $3 : prefix for the choice entries (eg. ARCH, KERNEL...)
    86 # $4 : base directory containing config files
    87 # $5 : list of config entries (eg. for architectures: "alpha arm ia64"...,
    88 #      and for kernels: "bare-metal linux"...)
    89 # Example to build the kernels generated config file:
    90 # $(call build_gen_choice_in,config.gen/kernel.in,Target OS,KERNEL,config/kernel,$(KERNELS))
    91 define build_gen_choice_in
    92 	@echo '  IN    $(1)'
    93 	@(echo "# $(2) menu";                                               \
    94 	  echo "# Generated file, do not edit!!!";                          \
    95 	  echo "";                                                          \
    96 	  echo "choice";                                                    \
    97 	  echo "    bool";                                                  \
    98 	  echo "    prompt \"$(2)\"";                                       \
    99 	  echo "";                                                          \
   100 	  for entry in $(5); do                                             \
   101 	    file="$(4)/$${entry}.in";                                       \
   102 	    _entry=$$(echo "$${entry}" |sed -r -s -e 's/[-.+]/_/g;');       \
   103 	    echo "config $(3)_$${_entry}";                                  \
   104 	    echo "    bool";                                                \
   105 	    printf "    prompt \"$${entry}";                                \
   106 	    if grep -E '^# +EXPERIMENTAL$$' $${file} >/dev/null 2>&1; then  \
   107 	      echo " (EXPERIMENTAL)\"";                                     \
   108 	      echo "    depends on EXPERIMENTAL";                           \
   109 	    else                                                            \
   110 	      echo "\"";                                                    \
   111 	    fi;                                                             \
   112 	  done;                                                             \
   113 	  echo "";                                                          \
   114 	  echo "endchoice";                                                 \
   115 	  for entry in $(5); do                                             \
   116 	    file="$(4)/$${entry}.in";                                       \
   117 	    _entry=$$(echo "$${entry}" |sed -r -s -e 's/[-.+]/_/g;');       \
   118 	    echo "";                                                        \
   119 	    echo "if $(3)_$${_entry}";                                      \
   120 	    echo "config $(3)";                                             \
   121 	    echo "    default \"$${entry}\" if $(3)_$${_entry}";            \
   122 	    echo "source $${file}";                                         \
   123 	    echo "endif";                                                   \
   124 	  done;                                                             \
   125 	 ) >$(1)
   126 endef
   127 
   128 # The function 'build_gen_menu_in' builds a menuconfig for each component in
   129 # the given list, source-ing the associated files conditionnaly:
   130 # $1 : destination file
   131 # $2 : name of entries family (eg. Tools, Debug...)
   132 # $3 : prefix for the menu entries (eg. TOOL, DEBUG)
   133 # $4 : base directory containing config files
   134 # $5 : list of config entries (eg. for tools: "libelf sstrip"..., and for
   135 #      debug: "dmalloc duma gdb"...)
   136 # Example to build the tools generated config file:
   137 # $(call build_gen_menu_in,config.gen/tools.in,Tools,TOOL,config/tools,$(TOOLS))
   138 define build_gen_menu_in
   139 	@echo '  IN    $(1)'
   140 	@(echo "# $(2) facilities menu";                                    \
   141 	  echo "# Generated file, do not edit!!!";                          \
   142 	  echo "";                                                          \
   143 	  for entry in $(5); do                                             \
   144 	    file="$(4)/$${entry}.in";                                       \
   145 	    _entry=$$(echo "$${entry}" |sed -r -s -e 's/[-.+]/_/g;');       \
   146 	    echo "menuconfig $(3)_$${_entry}";                              \
   147 	    echo "    bool";                                                \
   148 	    printf "    prompt \"$${entry}";                                \
   149 	    if grep -E '^# +EXPERIMENTAL$$' $${file} >/dev/null 2>&1; then  \
   150 	      echo " (EXPERIMENTAL)\"";                                     \
   151 	      echo "    depends on EXPERIMENTAL";                           \
   152 	    else                                                            \
   153 	      echo "\"";                                                    \
   154 	    fi;                                                             \
   155 	    echo "if $(3)_$${_entry}";                                      \
   156 	    echo "source $${file}";                                         \
   157 	    echo "endif";                                                   \
   158 	    echo "";                                                        \
   159 	  done;                                                             \
   160 	 ) >$(1)
   161 endef
   162 
   163 #-----------------------------------------------------------
   164 # The rules for the generated config files
   165 
   166 config.gen/arch.in: $(ARCH_CONFIG_FILES)
   167 	$(call build_gen_choice_in,$@,Target Architecture,ARCH,config/arch,$(ARCHS))
   168 
   169 config.gen/kernel.in: $(KERNEL_CONFIG_FILES)
   170 	$(call build_gen_choice_in,$@,Target OS,KERNEL,config/kernel,$(KERNELS))
   171 
   172 config.gen/cc.in: $(CC_CONFIG_FILES)
   173 	$(call build_gen_choice_in,$@,C compiler,CC,config/cc,$(CCS))
   174 
   175 config.gen/libc.in: $(LIBC_CONFIG_FILES)
   176 	$(call build_gen_choice_in,$@,C library,LIBC,config/libc,$(LIBCS))
   177 
   178 config.gen/tools.in: $(TOOL_CONFIG_FILES)
   179 	$(call build_gen_menu_in,$@,Tools,TOOL,config/tools,$(TOOLS))
   180 
   181 config.gen/debug.in: $(DEBUG_CONFIG_FILES)
   182 	$(call build_gen_menu_in,$@,Debug,DEBUG,config/debug,$(DEBUGS))
   183 
   184 #-----------------------------------------------------------
   185 # The configurators rules
   186 
   187 menuconfig: $(CONFIG_FILES) $(obj)/mconf
   188 	@$(obj)/mconf $(KCONFIG_TOP)
   189 
   190 oldconfig: $(CONFIG_FILES) $(obj)/conf
   191 	@$(obj)/conf -s $(KCONFIG_TOP)
   192 
   193 defoldconfig: $(CONFIG_FILES) $(obj)/conf
   194 	@yes "" |$(obj)/conf -s $(KCONFIG_TOP)
   195 
   196 #-----------------------------------------------------------
   197 # Help text used by make help
   198 
   199 help-config::
   200 	@echo  '  menuconfig         - Update current config using a menu based program'
   201 	@echo  '  oldconfig          - Update current config using a provided .config as base'
   202 	@echo  '                       build log piped into stdin'
   203 
   204 #-----------------------------------------------------------
   205 # Not-so-cheesy build, needs rework...
   206 
   207 SHIPPED := $(CT_LIB_DIR)/kconfig/zconf.tab.c $(CT_LIB_DIR)/kconfig/lex.zconf.c $(CT_LIB_DIR)/kconfig/zconf.hash.c
   208 
   209 $(obj)/conf $(obj)/mconf: $(obj)
   210 
   211 $(obj):
   212 	@mkdir -p $(obj)
   213 
   214 HEADERS = $(CT_LIB_DIR)/kconfig/expr.h      \
   215           $(CT_LIB_DIR)/kconfig/lkc.h       \
   216           $(CT_LIB_DIR)/kconfig/lkc_proto.h
   217 
   218 FILES = $(CT_LIB_DIR)/kconfig/confdata.c    \
   219         $(CT_LIB_DIR)/kconfig/expr.c        \
   220         $(CT_LIB_DIR)/kconfig/menu.c        \
   221         $(CT_LIB_DIR)/kconfig/symbol.c      \
   222         $(CT_LIB_DIR)/kconfig/util.c
   223 
   224 $(obj)/mconf: $(SHIPPED) $(CT_LIB_DIR)/kconfig/mconf.c  \
   225               $(HEADERS) $(FILES)                       \
   226               $(CT_LIB_DIR)/kconfig/kconfig.mk
   227 	@echo '  LD    $@'
   228 	@$(HOST_CC) $(CFLAGS) -o $@ $(CT_LIB_DIR)/kconfig/{mconf.c,zconf.tab.c,lxdialog/*.c} \
   229 	     $(shell $(CT_LIB_DIR)/kconfig/lxdialog/check-lxdialog.sh -ccflags)              \
   230 	     $(shell $(CT_LIB_DIR)/kconfig/lxdialog/check-lxdialog.sh -ldflags $(HOST_CC))
   231 
   232 $(obj)/conf: $(SHIPPED) $(CT_LIB_DIR)/kconfig/conf.c    \
   233              $(HEADERS) $(FILES)                        \
   234              $(CT_LIB_DIR)/kconfig/kconfig.mk
   235 	@echo '  LD    $@'
   236 	@$(HOST_CC) $(CFLAGS) -o $@ $(CT_LIB_DIR)/kconfig/{conf.c,zconf.tab.c}
   237 
   238 #-----------------------------------------------------------
   239 # Cleaning up the mess...
   240 
   241 clean::
   242 	@echo "  CLEAN kconfig"
   243 	@rm -f kconfig/{,m}conf
   244 	@rmdir --ignore-fail-on-non-empty kconfig 2>/dev/null || true
   245 	@echo "  CLEAN config"
   246 	@rm -f config 2>/dev/null || true
   247 	@echo "  CLEAN config.gen"
   248 	@rm -rf config.gen