kconfig/kconfig.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Fri Aug 19 00:52:05 2011 +0200 (2011-08-19)
branch1.12
changeset 2633 22e779b0a4ed
parent 2454 c70da6c50bdb
child 2650 4d299836e994
permissions -rw-r--r--
scripts: simplify and fix the toolchain config script

The script that is installed, and which sole purpose is to dump
the .config that was used to build the toolchain, is pure insanity.

Let's make it much, much more simpler...

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
(transplanted from 814ea73df7e0fab3db1cbe7623932714359c732b)
     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 # The place where the kconfig stuff lies
     9 obj = kconfig
    10 
    11 #-----------------------------------------------------------
    12 # The configurators rules
    13 
    14 configurators = menuconfig nconfig oldconfig
    15 PHONY += $(configurators)
    16 
    17 $(configurators): config_files
    18 
    19 menuconfig: $(obj)/mconf
    20 	@$(ECHO) "  CONF  $(KCONFIG_TOP)"
    21 	$(SILENT)$< $(KCONFIG_TOP)
    22 
    23 nconfig: $(obj)/nconf
    24 	@$(ECHO) "  CONF  $(KCONFIG_TOP)"
    25 	$(SILENT)$< $(KCONFIG_TOP)
    26 
    27 oldconfig: $(obj)/conf .config
    28 	@$(ECHO) "  CONF  $(KCONFIG_TOP)"
    29 	$(SILENT)$< --silent$@ $(KCONFIG_TOP)
    30 
    31 # Always be silent, the stdout an be >.config
    32 extractconfig:
    33 	@awk 'BEGIN { dump=0; }                                                 \
    34 	      dump==1 && $$0~/^\[.....\][[:space:]]+(# |)CT_/ {                 \
    35 	          $$1="";                                                       \
    36 	          gsub("^[[:space:]]","");                                      \
    37 	          print;                                                        \
    38 	      }                                                                 \
    39 	      $$0~/Dumping user-supplied crosstool-NG configuration: done in/ { \
    40 	          dump=0;                                                       \
    41 	      }                                                                 \
    42 	      $$0~/Dumping user-supplied crosstool-NG configuration$$/ {        \
    43 	          dump=1;                                                       \
    44 	      }'
    45 
    46 #-----------------------------------------------------------
    47 # Help text used by make help
    48 
    49 help-config::
    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'
    54 
    55 #-----------------------------------------------------------
    56 # Hmmm! Cheesy build!
    57 # Or: where I can unveil my make-fu... :-]
    58 
    59 # Oh! Files not here are there, in fact! :-)
    60 vpath %.c $(CT_LIB_DIR)
    61 vpath %.h $(CT_LIB_DIR)
    62 
    63 # What is the compiler?
    64 HOST_CC ?= gcc -funsigned-char
    65 HOST_LD ?= gcc
    66 
    67 # Helpers
    68 check_gettext = $(CT_LIB_DIR)/kconfig/check.sh
    69 check_lxdialog = $(CT_LIB_DIR)/kconfig/lxdialog/check-lxdialog.sh
    70 
    71 # Build flags
    72 CFLAGS = -DCONFIG_=\"CT_\" -DPACKAGE=\"crosstool-NG\"
    73 LDFLAGS =
    74 
    75 # Compiler flags to use gettext
    76 INTL_CFLAGS = $(shell $(SHELL) $(check_gettext) $(HOST_CC) $(EXTRA_CFLAGS))
    77 
    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))
    81 
    82 # Check that we have the required ncurses stuff installed for lxdialog (menuconfig)
    83 dochecklxdialog:
    84 	$(SILENT)$(SHELL) $(check_lxdialog) -check $(HOST_CC) $(NCURSES_CFLAGS) $(NCURSES_LDFLAGS)
    85 
    86 # Common source files
    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)
    91 
    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)
    97 
    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)
   103 
   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)
   110 
   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
   117 
   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
   123 endif
   124 
   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))
   128 
   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.
   137 
   138 ifneq ($(strip $(MAKECMDGOALS)),)
   139 ifneq ($(strip $(filter $(configurators),$(MAKECMDGOALS))),)
   140 
   141 DEPS = $(COMMON_DEP)
   142 ifneq ($(strip $(filter oldconfig,$(MAKECMDGOALS))),)
   143 DEPS += $(conf_DEP)
   144 endif
   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
   150 endif
   151 ifneq ($(strip $(filter nconfig,$(MAKECMDGOALS))),)
   152 DEPS += $(nconf_DEP)
   153 endif
   154 
   155 -include $(DEPS)
   156 
   157 endif # MAKECMDGOALS contains a configurator rule
   158 endif # MAKECMDGOALS != ""
   159 
   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;        \
   171 	 fi
   172 endef
   173 
   174 # Build the dependency for C files
   175 %.dep: %.c $(CT_LIB_DIR)/kconfig/kconfig.mk
   176 	$(check_kconfig_dir)
   177 	@$(ECHO) "  DEP   $@"
   178 	$(SILENT)$(HOST_CC) $(CFLAGS) $(EXTRA_CFLAGS) -MM $< |$(sed) -r -e 's|([^:]+.o)( *:+)|$(<:.c=.o) $@\2|;' >$@
   179 
   180 # Build C files
   181 %.o: %.c $(CT_LIB_DIR)/kconfig/kconfig.mk
   182 	$(check_kconfig_dir)
   183 	@$(ECHO) "  CC    $@"
   184 	$(SILENT)$(HOST_CC) $(CFLAGS) $(EXTRA_CFLAGS) -o $@ -c $<
   185 
   186 # Actual link
   187 $(obj)/mconf: $(COMMON_OBJ) $(LX_OBJ) $(mconf_OBJ)
   188 	@$(ECHO) '  LD    $@'
   189 	$(SILENT)$(HOST_LD) -o $@ $^ $(LDFLAGS) $(EXTRA_LDFLAGS)
   190 
   191 $(obj)/nconf: $(COMMON_OBJ) $(nconf_OBJ)
   192 	@$(ECHO) '  LD    $@'
   193 	$(SILENT)$(HOST_LD) -o $@ $^ $(LDFLAGS) $(EXTRA_LDFLAGS)
   194 
   195 $(obj)/conf: $(COMMON_OBJ) $(conf_OBJ)
   196 	@$(ECHO) '  LD    $@'
   197 	$(SILENT)$(HOST_LD) -o $@ $^ $(LDFLAGS) $(EXTRA_LDFLAGS)
   198 
   199 #-----------------------------------------------------------
   200 # Cleaning up the mess...
   201 
   202 clean::
   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