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 # The place where the kconfig stuff lies
11 #-----------------------------------------------------------
12 # The configurators rules
14 configurators = menuconfig nconfig oldconfig
15 PHONY += $(configurators)
17 $(configurators): config_files
19 menuconfig: $(obj)/mconf
20 @$(ECHO) " CONF $(KCONFIG_TOP)"
21 $(SILENT)$< $(KCONFIG_TOP)
24 @$(ECHO) " CONF $(KCONFIG_TOP)"
25 $(SILENT)$< $(KCONFIG_TOP)
27 oldconfig: $(obj)/conf .config
28 @$(ECHO) " CONF $(KCONFIG_TOP)"
29 $(SILENT)$< --silent$@ $(KCONFIG_TOP)
31 # Always be silent, the stdout an be >.config
33 @awk 'BEGIN { dump=0; } \
34 dump==1 && $$0~/^\[.....\][[:space:]]+(# |)CT_/ { \
36 gsub("^[[:space:]]",""); \
39 $$0~/Dumping user-supplied crosstool-NG configuration: done in/ { \
42 $$0~/Dumping user-supplied crosstool-NG configuration$$/ { \
46 #-----------------------------------------------------------
47 # Help text used by make help
50 @echo ' menuconfig - Update current config using a menu based program'
51 @echo ' oldconfig - Update current config using a provided .config as base'
52 @echo ' extractconfig - Extract to stdout the configuration items from a'
53 @echo ' build.log file piped to stdin'
55 #-----------------------------------------------------------
57 # Or: where I can unveil my make-fu... :-]
59 # Oh! Files not here are there, in fact! :-)
60 vpath %.c $(CT_LIB_DIR)
61 vpath %.h $(CT_LIB_DIR)
63 # What is the compiler?
64 HOST_CC ?= gcc -funsigned-char
68 check_gettext = $(CT_LIB_DIR)/kconfig/check.sh
69 check_lxdialog = $(CT_LIB_DIR)/kconfig/lxdialog/check-lxdialog.sh
72 CFLAGS = -DCONFIG_=\"CT_\" -DPACKAGE=\"crosstool-NG\"
75 # Compiler flags to use gettext
76 INTL_CFLAGS = $(shell $(SHELL) $(check_gettext) $(HOST_CC) $(EXTRA_CFLAGS))
78 # Compiler and linker flags to use ncurses
79 NCURSES_CFLAGS = $(shell $(SHELL) $(check_lxdialog) -ccflags)
80 NCURSES_LDFLAGS = $(shell $(SHELL) $(check_lxdialog) -ldflags $(HOST_CC))
82 # Check that we have the required ncurses stuff installed for lxdialog (menuconfig)
84 $(SILENT)$(SHELL) $(check_lxdialog) -check $(HOST_CC) $(NCURSES_CFLAGS) $(NCURSES_LDFLAGS)
87 COMMON_SRC = kconfig/zconf.tab.c
88 COMMON_OBJ = $(patsubst %.c,%.o,$(COMMON_SRC))
89 COMMON_DEP = $(patsubst %.o,%.dep,$(COMMON_OBJ))
90 $(COMMON_OBJ) $(COMMON_DEP): CFLAGS += $(INTL_CFLAGS)
92 # lxdialog source files
93 LX_SRC = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/kconfig/lxdialog/*.c))
94 LX_OBJ = $(patsubst %.c,%.o,$(LX_SRC))
95 LX_DEP = $(patsubst %.o,%.dep,$(LX_OBJ))
96 $(LX_OBJ) $(LX_DEP): CFLAGS += $(NCURSES_CFLAGS) $(INTL_CFLAGS)
98 # What's needed to build 'conf'
99 conf_SRC = kconfig/conf.c
100 conf_OBJ = $(patsubst %.c,%.o,$(conf_SRC))
101 conf_DEP = $(patsubst %.o,%.dep,$(conf_OBJ))
102 $(conf_OBJ) $(conf_DEP): CFLAGS += $(INTL_CFLAGS)
104 # What's needed to build 'mconf'
105 mconf_SRC = kconfig/mconf.c
106 mconf_OBJ = $(patsubst %.c,%.o,$(mconf_SRC))
107 mconf_DEP = $(patsubst %.c,%.dep,$(mconf_SRC))
108 $(mconf_OBJ) $(mconf_DEP): CFLAGS += $(NCURSES_CFLAGS) $(INTL_CFLAGS)
109 $(obj)/mconf: LDFLAGS += $(NCURSES_LDFLAGS)
111 # What's needed to build 'nconf'
112 nconf_SRC = kconfig/nconf.c kconfig/nconf.gui.c
113 nconf_OBJ = $(patsubst %.c,%.o,$(nconf_SRC))
114 nconf_DEP = $(patsubst %.c,%.dep,$(nconf_SRC))
115 $(nconf_OBJ) $(nconf_DEP): CFLAGS += $(INTL_CFLAGS)
116 $(obj)/nconf: LDFLAGS += -lmenu -lpanel -lncurses
118 # Under Cygwin, we need to auto-import some libs (which ones, exactly?)
119 # for mconf and nconf to lin properly.
120 ifeq ($(shell uname -o 2>/dev/null || echo unknown),Cygwin)
121 $(obj)/mconf: LDFLAGS += -Wl,--enable-auto-import
122 $(obj)/nconf: LDFLAGS += -Wl,--enable-auto-import
125 # These are generated files:
126 ALL_OBJS = $(sort $(COMMON_OBJ) $(LX_OBJ) $(conf_OBJ) $(mconf_OBJ) $(nconf_OBJ))
127 ALL_DEPS = $(sort $(COMMON_DEP) $(LX_DEP) $(conf_DEP) $(mconf_DEP) $(nconf_DEP))
129 # Cheesy auto-dependencies
130 # Only parse the following if a configurator was called, to avoid building
131 # dependencies when not needed (eg. list-steps, list-samples...)
132 # We must be careful what we enclose, because we need some of the variable
133 # definitions for clean (and distclean) at least.
134 # Just protecting the "-include $(DEPS)" line should be sufficient.
135 # And in case we want menuconfig, we have to check that lxdialog
136 # can find a curses lib.
138 ifneq ($(strip $(MAKECMDGOALS)),)
139 ifneq ($(strip $(filter $(configurators),$(MAKECMDGOALS))),)
142 ifneq ($(strip $(filter oldconfig,$(MAKECMDGOALS))),)
145 ifneq ($(strip $(filter menuconfig,$(MAKECMDGOALS))),)
146 DEPS += $(mconf_DEP) $(LX_DEP)
147 $(COMMON_OBJ) $(COMMON_DEP): |dochecklxdialog
148 $(LX_OBJ) $(LX_DEP): |dochecklxdialog
149 $(mconf_OBJ) $(mconf_DEP): |dochecklxdialog
151 ifneq ($(strip $(filter nconfig,$(MAKECMDGOALS))),)
157 endif # MAKECMDGOALS contains a configurator rule
158 endif # MAKECMDGOALS != ""
160 # Each .o or .dep *can not* directly depend on kconfig/, because kconfig can
161 # be touched during the build (who's touching it, btw?) so each .o or .dep
162 # would be re-built when it should not be.
163 # So manually check for presence of $(obj) (ie. kconfig), and only mkdir
164 # if needed. After all, that's not so bad...
165 # mkdir $(obj)/lxdialog, because we need it, and incidentally, that
166 # also creates $(obj).
167 define check_kconfig_dir
168 $(SILENT)if [ ! -d $(obj)/lxdialog ]; then \
169 $(ECHO) " MKDIR $(obj)"; \
170 mkdir -p $(obj)/lxdialog; \
174 # Build the dependency for C files
175 %.dep: %.c $(CT_LIB_DIR)/kconfig/kconfig.mk
178 $(SILENT)$(HOST_CC) $(CFLAGS) $(EXTRA_CFLAGS) -MM $< |$(sed) -r -e 's|([^:]+.o)( *:+)|$(<:.c=.o) $@\2|;' >$@
181 %.o: %.c $(CT_LIB_DIR)/kconfig/kconfig.mk
184 $(SILENT)$(HOST_CC) $(CFLAGS) $(EXTRA_CFLAGS) -o $@ -c $<
187 $(obj)/mconf: $(COMMON_OBJ) $(LX_OBJ) $(mconf_OBJ)
189 $(SILENT)$(HOST_LD) -o $@ $^ $(LDFLAGS) $(EXTRA_LDFLAGS)
191 $(obj)/nconf: $(COMMON_OBJ) $(nconf_OBJ)
193 $(SILENT)$(HOST_LD) -o $@ $^ $(LDFLAGS) $(EXTRA_LDFLAGS)
195 $(obj)/conf: $(COMMON_OBJ) $(conf_OBJ)
197 $(SILENT)$(HOST_LD) -o $@ $^ $(LDFLAGS) $(EXTRA_LDFLAGS)
199 #-----------------------------------------------------------
200 # Cleaning up the mess...
203 @$(ECHO) " CLEAN kconfig"
204 $(SILENT)rm -f kconfig/{,m,n}conf{,.exe} $(ALL_OBJS) $(ALL_DEPS)
205 $(SILENT)rmdir --ignore-fail-on-non-empty kconfig{/lxdialog,} 2>/dev/null || true