kconfig/kconfig.mk
changeset 940 f0f9ba3f98f2
parent 926 fe3e5a3331b6
child 942 86f3e28fa3cc
     1.1 --- a/kconfig/kconfig.mk	Tue Oct 14 16:50:33 2008 +0000
     1.2 +++ b/kconfig/kconfig.mk	Wed Oct 15 21:29:56 2008 +0000
     1.3 @@ -56,13 +56,13 @@
     1.4  
     1.5  # Where to access to the source config files from
     1.6  config:
     1.7 -	@echo "  LN    config"
     1.8 -	@ln -s $(CT_LIB_DIR)/config config
     1.9 +	@$(ECHO) "  LN    config"
    1.10 +	$(SILENT)ln -s $(CT_LIB_DIR)/config config
    1.11  
    1.12  # Where to store the generated config files into
    1.13  config.gen:
    1.14 -	@echo "  MKDIR config.gen"
    1.15 -	@mkdir -p config.gen
    1.16 +	@$(ECHO) "  MKDIR config.gen"
    1.17 +	$(SILENT)mkdir -p config.gen
    1.18  
    1.19  #-----------------------------------------------------------
    1.20  # Build list of per-component-type items to easily build generated files
    1.21 @@ -89,8 +89,8 @@
    1.22  # Example to build the kernels generated config file:
    1.23  # $(call build_gen_choice_in,config.gen/kernel.in,Target OS,KERNEL,config/kernel,$(KERNELS))
    1.24  define build_gen_choice_in
    1.25 -	@echo '  IN    $(1)'
    1.26 -	@(echo "# $(2) menu";                                               \
    1.27 +	@$(ECHO) '  IN    $(1)'
    1.28 +	$(SILENT)(echo "# $(2) menu";                                       \
    1.29  	  echo "# Generated file, do not edit!!!";                          \
    1.30  	  echo "";                                                          \
    1.31  	  echo "choice";                                                    \
    1.32 @@ -136,8 +136,8 @@
    1.33  # Example to build the tools generated config file:
    1.34  # $(call build_gen_menu_in,config.gen/tools.in,Tools,TOOL,config/tools,$(TOOLS))
    1.35  define build_gen_menu_in
    1.36 -	@echo '  IN    $(1)'
    1.37 -	@(echo "# $(2) facilities menu";                                    \
    1.38 +	@$(ECHO) '  IN    $(1)'
    1.39 +	$(SILENT)(echo "# $(2) facilities menu";                            \
    1.40  	  echo "# Generated file, do not edit!!!";                          \
    1.41  	  echo "";                                                          \
    1.42  	  for entry in $(5); do                                             \
    1.43 @@ -184,14 +184,14 @@
    1.44  #-----------------------------------------------------------
    1.45  # The configurators rules
    1.46  
    1.47 -menuconfig: $(CONFIG_FILES) $(obj)/mconf
    1.48 -	@$(obj)/mconf $(KCONFIG_TOP)
    1.49 +menuconfig: $(obj)/mconf $(CONFIG_FILES)
    1.50 +	$(SILENT)$< $(KCONFIG_TOP)
    1.51  
    1.52 -oldconfig: $(CONFIG_FILES) $(obj)/conf
    1.53 -	@$(obj)/conf -s $(KCONFIG_TOP)
    1.54 +oldconfig: .config $(obj)/conf $(CONFIG_FILES)
    1.55 +	$(SILENT)$< -s $(KCONFIG_TOP)
    1.56  
    1.57 -defoldconfig: $(CONFIG_FILES) $(obj)/conf
    1.58 -	@yes "" |$(obj)/conf -s $(KCONFIG_TOP)
    1.59 +defoldconfig: .config $(obj)/conf $(CONFIG_FILES)
    1.60 +	$(SILENT)yes "" |$< -s $(KCONFIG_TOP)
    1.61  
    1.62  #-----------------------------------------------------------
    1.63  # Help text used by make help
    1.64 @@ -199,50 +199,84 @@
    1.65  help-config::
    1.66  	@echo  '  menuconfig         - Update current config using a menu based program'
    1.67  	@echo  '  oldconfig          - Update current config using a provided .config as base'
    1.68 -	@echo  '                       build log piped into stdin'
    1.69 +	@echo  '  defoldconfig       - As oldconfig, above, but using defaults for new options'
    1.70  
    1.71  #-----------------------------------------------------------
    1.72 -# Not-so-cheesy build, needs rework...
    1.73 +# Hmmm! Cheesy build!
    1.74 +# Or: where I can unveil my make-fu... :-]
    1.75  
    1.76 -SHIPPED := $(CT_LIB_DIR)/kconfig/zconf.tab.c $(CT_LIB_DIR)/kconfig/lex.zconf.c $(CT_LIB_DIR)/kconfig/zconf.hash.c
    1.77 +# Oh! Files not here are there, in fact! :-)
    1.78 +vpath %.c $(CT_LIB_DIR)
    1.79 +vpath %.h $(CT_LIB_DIR)
    1.80  
    1.81 -$(obj)/conf $(obj)/mconf: $(obj)
    1.82 +# What is the compiler?
    1.83 +HOST_CC ?= gcc -funsigned-char
    1.84  
    1.85 -$(obj):
    1.86 -	@mkdir -p $(obj)
    1.87 +# Compiler and linker flags to use ncurses
    1.88 +CFLAGS += $(shell $(CT_LIB_DIR)/kconfig/lxdialog/check-lxdialog.sh -ccflags)
    1.89 +LDFLAGS += $(shell $(CT_LIB_DIR)/kconfig/lxdialog/check-lxdialog.sh -ldflags $(HOST_CC))
    1.90  
    1.91 -HEADERS = $(CT_LIB_DIR)/kconfig/expr.h      \
    1.92 -          $(CT_LIB_DIR)/kconfig/lkc.h       \
    1.93 -          $(CT_LIB_DIR)/kconfig/lkc_proto.h
    1.94 +# Common source files, and lxdialog source files
    1.95 +SRC = kconfig/zconf.tab.c
    1.96 +LXSRC = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/kconfig/lxdialog/*.c))
    1.97  
    1.98 -FILES = $(CT_LIB_DIR)/kconfig/confdata.c    \
    1.99 -        $(CT_LIB_DIR)/kconfig/expr.c        \
   1.100 -        $(CT_LIB_DIR)/kconfig/menu.c        \
   1.101 -        $(CT_LIB_DIR)/kconfig/symbol.c      \
   1.102 -        $(CT_LIB_DIR)/kconfig/util.c
   1.103 +# What's needed to build 'conf'
   1.104 +conf_SRC  = $(SRC) kconfig/conf.c
   1.105 +conf_OBJ  = $(patsubst %.c,%.o,$(conf_SRC))
   1.106  
   1.107 -$(obj)/mconf: $(SHIPPED) $(CT_LIB_DIR)/kconfig/mconf.c  \
   1.108 -              $(HEADERS) $(FILES)                       \
   1.109 -              $(CT_LIB_DIR)/kconfig/kconfig.mk
   1.110 -	@echo '  LD    $@'
   1.111 -	@$(HOST_CC) $(CFLAGS) -o $@ $(CT_LIB_DIR)/kconfig/{mconf.c,zconf.tab.c,lxdialog/*.c} \
   1.112 -	     $(shell $(CT_LIB_DIR)/kconfig/lxdialog/check-lxdialog.sh -ccflags)              \
   1.113 -	     $(shell $(CT_LIB_DIR)/kconfig/lxdialog/check-lxdialog.sh -ldflags $(HOST_CC))
   1.114 +# What's needed to build 'mconf'
   1.115 +mconf_SRC = $(SRC) $(LXSRC) kconfig/mconf.c
   1.116 +mconf_OBJ = $(patsubst %.c,%.o,$(mconf_SRC))
   1.117  
   1.118 -$(obj)/conf: $(SHIPPED) $(CT_LIB_DIR)/kconfig/conf.c    \
   1.119 -             $(HEADERS) $(FILES)                        \
   1.120 -             $(CT_LIB_DIR)/kconfig/kconfig.mk
   1.121 -	@echo '  LD    $@'
   1.122 -	@$(HOST_CC) $(CFLAGS) -o $@ $(CT_LIB_DIR)/kconfig/{conf.c,zconf.tab.c}
   1.123 +# Cheesy auto-dependencies
   1.124 +DEPS = $(patsubst %.c,%.d,$(sort $(conf_SRC) $(mconf_SRC)))
   1.125 +
   1.126 +# This is not very nice, as they will get rebuild even if (dist)cleaning... :-(
   1.127 +# Should look into the Linux kernel Kbuild to see how they do that...
   1.128 +# To really make me look into this, keep the annoying "DEP xxx" messages.
   1.129 +# Also see the comment for the "%.o: %c" rule below
   1.130 +%.d: %.c $(CT_LIB_DIR)/kconfig/kconfig.mk
   1.131 +	$(SILENT)if [ ! -d $(obj)/lxdialog ]; then  \
   1.132 +	   $(ECHO) "  MKDIR $(obj)";           \
   1.133 +	   mkdir -p $(obj)/lxdialog;        \
   1.134 +	 fi
   1.135 +	@$(ECHO) "  DEP   $@"
   1.136 +	$(SILENT)$(HOST_CC) $(CFLAGS) -MM $< |sed -r -e 's|([^:]+.o)( *:+)|$(<:.c=.o) $@\2|;' >$@
   1.137 +-include $(DEPS)
   1.138 +
   1.139 +# Each .o must depend on the corresponding .c (obvious, isn't it?),
   1.140 +# but *can not* depend on kconfig/, because kconfig can be touched
   1.141 +# during the build (who's touching it, btw?) so each .o would be
   1.142 +# re-built when they sould not be.
   1.143 +# So manually check for presence of $(obj) (ie. kconfig), and only mkdir
   1.144 +# if needed. After all, that's not so bad...
   1.145 +# mkdir $(obj)/lxdialog, because we need it, and incidentally, that
   1.146 +# also creates $(obj).
   1.147 +# Also rebuild the object files is the makefile is changed
   1.148 +%.o: %.c $(CT_LIB_DIR)/kconfig/kconfig.mk
   1.149 +	$(SILENT)if [ ! -d $(obj)/lxdialog ]; then  \
   1.150 +	   $(ECHO) "  MKDIR $(obj)";           \
   1.151 +	   mkdir -p $(obj)/lxdialog;        \
   1.152 +	 fi
   1.153 +	@$(ECHO) "  CC    $@"
   1.154 +	$(SILENT)$(HOST_CC) $(CFLAGS) -o $@ -c $<
   1.155 +
   1.156 +$(obj)/mconf: $(mconf_OBJ)
   1.157 +	@$(ECHO) '  LD    $@'
   1.158 +	$(SILENT)$(HOST_CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
   1.159 +
   1.160 +$(obj)/conf: $(conf_OBJ)
   1.161 +	@$(ECHO) '  LD    $@'
   1.162 +	$(SILENT)$(HOST_CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
   1.163  
   1.164  #-----------------------------------------------------------
   1.165  # Cleaning up the mess...
   1.166  
   1.167  clean::
   1.168 -	@echo "  CLEAN kconfig"
   1.169 -	@rm -f kconfig/{,m}conf
   1.170 -	@rmdir --ignore-fail-on-non-empty kconfig 2>/dev/null || true
   1.171 -	@echo "  CLEAN config"
   1.172 -	@rm -f config 2>/dev/null || true
   1.173 -	@echo "  CLEAN config.gen"
   1.174 -	@rm -rf config.gen
   1.175 +	@$(ECHO) "  CLEAN kconfig"
   1.176 +	$(SILENT)rm -f kconfig/{,m}conf $(conf_OBJ) $(mconf_OBJ) $(DEPS)
   1.177 +	$(SILENT)rmdir --ignore-fail-on-non-empty kconfig{/lxdialog,} 2>/dev/null || true
   1.178 +	@$(ECHO) "  CLEAN config"
   1.179 +	$(SILENT)rm -f config 2>/dev/null || true
   1.180 +	@$(ECHO) "  CLEAN config.gen"
   1.181 +	$(SILENT)rm -rf config.gen