config/config.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Oct 18 18:37:28 2008 +0000 (2008-10-18)
changeset 945 d0e5f04d2e06
parent 943 kconfig/kconfig.mk@1cca90ce0481
child 1001 c8ac48ba1411
permissions -rw-r--r--
Extract the config files related stuff from the kconfig stuff
- create config/config.mk, with all the config.gen/ rules
- the only common points between config files and configurators:
- the top-level config file to include, stored in KCONFIG_TOP
- the config_file rules, which makes config files available to configurators
- dependency-files are renamed from %.d to %.dep (.d is reserved for directories)
- a few eye-candy here and there

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