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