1 # ===========================================================================
2 # crosstool-NG configuration targets
3 # These targets are used from top-level makefile
5 # Derive the project version from, well, the project version:
6 export PROJECTVERSION=$(CT_VERSION)
8 #-----------------------------------------------------------
9 # Some static /configuration/
11 KCONFIG_TOP = config/config.in
13 PHONY += clean help oldconfig menuconfig defoldconfig
15 # Darwin (MacOS-X) does not have proper libintl support
16 ifeq ($(shell uname -s),Darwin)
20 ifneq ($(KBUILD_NO_NLS),)
21 CFLAGS += -DKBUILD_NO_NLS
24 #-----------------------------------------------------------
25 # List all config files, source and generated
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
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))
40 # Build the list of generated config files
41 GEN_CONFIG_FILES = config.gen/arch.in \
42 config.gen/kernel.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
54 # KCONFIG_TOP should already be in STATIC_CONFIG_FILES, anyway...
55 CONFIG_FILES = $(sort $(KCONFIG_TOP) $(STATIC_CONFIG_FILES) $(GEN_CONFIG_FILES))
57 # Where to access to the source config files from
60 $(SILENT)ln -s $(CT_LIB_DIR)/config config
62 # Where to store the generated config files into
64 @$(ECHO) " MKDIR config.gen"
65 $(SILENT)mkdir -p config.gen
67 #-----------------------------------------------------------
68 # Build list of per-component-type items to easily build generated files
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))
77 #-----------------------------------------------------------
78 # Helper functions to ease building generated config files
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
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
93 $(SILENT)(echo "# $(2) menu"; \
94 echo "# Generated file, do not edit!!!"; \
98 echo " prompt \"$(2)\""; \
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}"; \
105 printf " prompt \"$${entry}"; \
106 if grep -E '^# +EXPERIMENTAL$$' $${file} >/dev/null 2>&1; then \
107 echo " (EXPERIMENTAL)\""; \
108 echo " depends on EXPERIMENTAL"; \
115 for entry in $(5); do \
116 file="$(4)/$${entry}.in"; \
117 _entry=$$(echo "$${entry}" |sed -r -s -e 's/[-.+]/_/g;'); \
119 echo "if $(3)_$${_entry}"; \
120 echo "config $(3)"; \
121 echo " default \"$${entry}\" if $(3)_$${_entry}"; \
122 echo "source $${file}"; \
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
140 $(SILENT)(echo "# $(2) facilities menu"; \
141 echo "# Generated file, do not edit!!!"; \
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}"; \
148 printf " prompt \"$${entry}"; \
149 if grep -E '^# +EXPERIMENTAL$$' $${file} >/dev/null 2>&1; then \
150 echo " (EXPERIMENTAL)\""; \
151 echo " depends on EXPERIMENTAL"; \
155 echo "if $(3)_$${_entry}"; \
156 echo "source $${file}"; \
163 #-----------------------------------------------------------
164 # The rules for the generated config files
166 config.gen/arch.in: $(ARCH_CONFIG_FILES)
167 $(call build_gen_choice_in,$@,Target Architecture,ARCH,config/arch,$(ARCHS))
169 config.gen/kernel.in: $(KERNEL_CONFIG_FILES)
170 $(call build_gen_choice_in,$@,Target OS,KERNEL,config/kernel,$(KERNELS))
172 config.gen/cc.in: $(CC_CONFIG_FILES)
173 $(call build_gen_choice_in,$@,C compiler,CC,config/cc,$(CCS))
175 config.gen/libc.in: $(LIBC_CONFIG_FILES)
176 $(call build_gen_choice_in,$@,C library,LIBC,config/libc,$(LIBCS))
178 config.gen/tools.in: $(TOOL_CONFIG_FILES)
179 $(call build_gen_menu_in,$@,Tools,TOOL,config/tools,$(TOOLS))
181 config.gen/debug.in: $(DEBUG_CONFIG_FILES)
182 $(call build_gen_menu_in,$@,Debug,DEBUG,config/debug,$(DEBUGS))
184 #-----------------------------------------------------------
185 # The configurators rules
187 menuconfig: $(obj)/mconf $(CONFIG_FILES)
188 $(SILENT)$< $(KCONFIG_TOP)
190 oldconfig: .config $(obj)/conf $(CONFIG_FILES)
191 $(SILENT)$< -s $(KCONFIG_TOP)
193 defoldconfig: .config $(obj)/conf $(CONFIG_FILES)
194 $(SILENT)yes "" |$< -s $(KCONFIG_TOP)
196 #-----------------------------------------------------------
197 # Help text used by make help
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 ' defoldconfig - As oldconfig, above, but using defaults for new options'
204 #-----------------------------------------------------------
205 # Hmmm! Cheesy build!
206 # Or: where I can unveil my make-fu... :-]
208 # Oh! Files not here are there, in fact! :-)
209 vpath %.c $(CT_LIB_DIR)
210 vpath %.h $(CT_LIB_DIR)
212 # What is the compiler?
213 HOST_CC ?= gcc -funsigned-char
215 # Compiler and linker flags to use ncurses
216 CFLAGS += $(shell $(CT_LIB_DIR)/kconfig/lxdialog/check-lxdialog.sh -ccflags)
217 LDFLAGS += $(shell $(CT_LIB_DIR)/kconfig/lxdialog/check-lxdialog.sh -ldflags $(HOST_CC))
219 # Common source files, and lxdialog source files
220 SRC = kconfig/zconf.tab.c
221 LXSRC = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/kconfig/lxdialog/*.c))
223 # What's needed to build 'conf'
224 conf_SRC = $(SRC) kconfig/conf.c
225 conf_OBJ = $(patsubst %.c,%.o,$(conf_SRC))
227 # What's needed to build 'mconf'
228 mconf_SRC = $(SRC) $(LXSRC) kconfig/mconf.c
229 mconf_OBJ = $(patsubst %.c,%.o,$(mconf_SRC))
231 # Cheesy auto-dependencies
232 DEPS = $(patsubst %.c,%.d,$(sort $(conf_SRC) $(mconf_SRC)))
234 # This is not very nice, as they will get rebuild even if (dist)cleaning... :-(
235 # Should look into the Linux kernel Kbuild to see how they do that...
236 # To really make me look into this, keep the annoying "DEP xxx" messages.
237 # Also see the comment for the "%.o: %c" rule below
238 %.d: %.c $(CT_LIB_DIR)/kconfig/kconfig.mk
239 $(SILENT)if [ ! -d $(obj)/lxdialog ]; then \
240 $(ECHO) " MKDIR $(obj)"; \
241 mkdir -p $(obj)/lxdialog; \
244 $(SILENT)$(HOST_CC) $(CFLAGS) -MM $< |sed -r -e 's|([^:]+.o)( *:+)|$(<:.c=.o) $@\2|;' >$@
247 # Each .o must depend on the corresponding .c (obvious, isn't it?),
248 # but *can not* depend on kconfig/, because kconfig can be touched
249 # during the build (who's touching it, btw?) so each .o would be
250 # re-built when they sould not be.
251 # So manually check for presence of $(obj) (ie. kconfig), and only mkdir
252 # if needed. After all, that's not so bad...
253 # mkdir $(obj)/lxdialog, because we need it, and incidentally, that
254 # also creates $(obj).
255 # Also rebuild the object files is the makefile is changed
256 %.o: %.c $(CT_LIB_DIR)/kconfig/kconfig.mk
257 $(SILENT)if [ ! -d $(obj)/lxdialog ]; then \
258 $(ECHO) " MKDIR $(obj)"; \
259 mkdir -p $(obj)/lxdialog; \
262 $(SILENT)$(HOST_CC) $(CFLAGS) -o $@ -c $<
264 $(obj)/mconf: $(mconf_OBJ)
266 $(SILENT)$(HOST_CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
268 $(obj)/conf: $(conf_OBJ)
270 $(SILENT)$(HOST_CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
272 #-----------------------------------------------------------
273 # Cleaning up the mess...
276 @$(ECHO) " CLEAN kconfig"
277 $(SILENT)rm -f kconfig/{,m}conf $(conf_OBJ) $(mconf_OBJ) $(DEPS)
278 $(SILENT)rmdir --ignore-fail-on-non-empty kconfig{/lxdialog,} 2>/dev/null || true
279 @$(ECHO) " CLEAN config"
280 $(SILENT)rm -f config 2>/dev/null || true
281 @$(ECHO) " CLEAN config.gen"
282 $(SILENT)rm -rf config.gen