kconfig/kconfig.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Oct 19 09:34:32 2008 +0000 (2008-10-19)
changeset 946 253df9d80065
parent 945 d0e5f04d2e06
child 959 955712a44ff0
permissions -rw-r--r--
Avoid (re)building the kconfig dependencies when we don't need them (clean, build, list-steps...).

/trunk/kconfig/kconfig.mk | 24 20 4 0 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
     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 #-----------------------------------------------------------
     9 # Some static /configuration/
    10 
    11 # The place where the kconfig stuff lies
    12 obj = kconfig
    13 
    14 #-----------------------------------------------------------
    15 # The configurators rules
    16 
    17 configurators = menuconfig oldconfig defoldconfig
    18 PHONY += $(configurators)
    19 
    20 $(configurators): config_files
    21 
    22 menuconfig: $(obj)/mconf
    23 	@$(ECHO) "  MCONF $(KCONFIG_TOP)"
    24 	$(SILENT)$< $(KCONFIG_TOP)
    25 
    26 oldconfig: $(obj)/conf .config
    27 	@$(ECHO) "  CONF  $(KCONFIG_TOP)"
    28 	$(SILENT)$< -s $(KCONFIG_TOP)
    29 
    30 defoldconfig: $(obj)/conf .config
    31 	@$(ECHO) "  CONF  $(KCONFIG_TOP)"
    32 	$(SILENT)yes "" |$< -s $(KCONFIG_TOP)
    33 
    34 #-----------------------------------------------------------
    35 # Help text used by make help
    36 
    37 help-config::
    38 	@echo  '  menuconfig         - Update current config using a menu based program'
    39 	@echo  '  oldconfig          - Update current config using a provided .config as base'
    40 	@echo  '  defoldconfig       - As oldconfig, above, but using defaults for new options'
    41 
    42 #-----------------------------------------------------------
    43 # Hmmm! Cheesy build!
    44 # Or: where I can unveil my make-fu... :-]
    45 
    46 # Oh! Files not here are there, in fact! :-)
    47 vpath %.c $(CT_LIB_DIR)
    48 vpath %.h $(CT_LIB_DIR)
    49 
    50 # What is the compiler?
    51 HOST_CC ?= gcc -funsigned-char
    52 
    53 # Compiler flags to use gettext
    54 EXTRA_CFLAGS += $(shell $(SHELL) $(CT_LIB_DIR)/kconfig/check-gettext.sh $(HOST_CC) $(CFLAGS))
    55 
    56 # Compiler and linker flags to use ncurses
    57 EXTRA_CFLAGS += $(shell $(SHELL) $(CT_LIB_DIR)/kconfig/lxdialog/check-lxdialog.sh -ccflags)
    58 EXTRA_LDFLAGS += $(shell $(SHELL) $(CT_LIB_DIR)/kconfig/lxdialog/check-lxdialog.sh -ldflags $(HOST_CC))
    59 
    60 # Common source files, and lxdialog source files
    61 SRC = kconfig/zconf.tab.c
    62 LXSRC = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/kconfig/lxdialog/*.c))
    63 
    64 # What's needed to build 'conf'
    65 conf_SRC  = $(SRC) kconfig/conf.c
    66 conf_OBJ  = $(patsubst %.c,%.o,$(conf_SRC))
    67 
    68 # What's needed to build 'mconf'
    69 mconf_SRC = $(SRC) $(LXSRC) kconfig/mconf.c
    70 mconf_OBJ = $(patsubst %.c,%.o,$(mconf_SRC))
    71 
    72 # Cheesy auto-dependencies
    73 DEPS = $(patsubst %.c,%.dep,$(sort $(conf_SRC) $(mconf_SRC)))
    74 
    75 # Only parse the following if a configurator was called, to avoid building
    76 # dependencies when not needed (eg. list-steps, list-samples...)
    77 # We must be carefull what we enclose, because we need some of the variable
    78 # definitions for clean (and distclean) at least.
    79 # Just protecting the "-include $(DEPS)" line should be sufficient.
    80 
    81 ifneq ($(strip $(MAKECMDGOALS)),)
    82 ifneq ($(strip $(filter $(configurators),$(MAKECMDGOALS))),)
    83 
    84 -include $(DEPS)
    85 
    86 endif # MAKECMDGOALS contains a configurator rule
    87 endif # MAKECMDGOALS != ""
    88 
    89 # This is not very nice, as they will get rebuild even if (dist)cleaning... :-(
    90 # Should look into the Linux kernel Kbuild to see how they do that...
    91 # To really make me look into this, keep the annoying "DEP xxx" messages.
    92 # Also see the comment for the "%.o: %c" rule below
    93 %.dep: %.c $(CT_LIB_DIR)/kconfig/kconfig.mk $(CT_NG)
    94 	$(SILENT)if [ ! -d $(obj)/lxdialog ]; then  \
    95 	   $(ECHO) "  MKDIR $(obj)";           \
    96 	   mkdir -p $(obj)/lxdialog;        \
    97 	 fi
    98 	@$(ECHO) "  DEP   $@"
    99 	$(SILENT)$(HOST_CC) $(CFLAGS) $(EXTRA_CFLAGS) -MM $< |sed -r -e 's|([^:]+.o)( *:+)|$(<:.c=.o) $@\2|;' >$@
   100 
   101 # Each .o must depend on the corresponding .c (obvious, isn't it?),
   102 # but *can not* depend on kconfig/, because kconfig can be touched
   103 # during the build (who's touching it, btw?) so each .o would be
   104 # re-built when they sould not be.
   105 # So manually check for presence of $(obj) (ie. kconfig), and only mkdir
   106 # if needed. After all, that's not so bad...
   107 # mkdir $(obj)/lxdialog, because we need it, and incidentally, that
   108 # also creates $(obj).
   109 # Also rebuild the object files is the makefile is changed
   110 %.o: %.c $(CT_LIB_DIR)/kconfig/kconfig.mk
   111 	$(SILENT)if [ ! -d $(obj)/lxdialog ]; then  \
   112 	   $(ECHO) "  MKDIR $(obj)";           \
   113 	   mkdir -p $(obj)/lxdialog;        \
   114 	 fi
   115 	@$(ECHO) "  CC    $@"
   116 	$(SILENT)$(HOST_CC) $(CFLAGS) $(EXTRA_CFLAGS) -o $@ -c $<
   117 
   118 $(obj)/mconf: $(mconf_OBJ)
   119 	@$(ECHO) '  LD    $@'
   120 	$(SILENT)$(HOST_CC) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^
   121 
   122 $(obj)/conf: $(conf_OBJ)
   123 	@$(ECHO) '  LD    $@'
   124 	$(SILENT)$(HOST_CC) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^
   125 
   126 #-----------------------------------------------------------
   127 # Cleaning up the mess...
   128 
   129 clean::
   130 	@$(ECHO) "  CLEAN kconfig"
   131 	$(SILENT)rm -f kconfig/{,m}conf $(conf_OBJ) $(mconf_OBJ) $(DEPS)
   132 	$(SILENT)rmdir --ignore-fail-on-non-empty kconfig{/lxdialog,} 2>/dev/null || true