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