kconfig/kconfig.mk
changeset 959 955712a44ff0
parent 946 253df9d80065
child 1087 5be36a4b304d
     1.1 --- a/kconfig/kconfig.mk	Sun Oct 19 09:34:32 2008 +0000
     1.2 +++ b/kconfig/kconfig.mk	Wed Oct 22 16:56:23 2008 +0000
     1.3 @@ -5,39 +5,31 @@
     1.4  # Derive the project version from, well, the project version:
     1.5  export PROJECTVERSION=$(CT_VERSION)
     1.6  
     1.7 -#-----------------------------------------------------------
     1.8 -# Some static /configuration/
     1.9 -
    1.10  # The place where the kconfig stuff lies
    1.11  obj = kconfig
    1.12  
    1.13  #-----------------------------------------------------------
    1.14  # The configurators rules
    1.15  
    1.16 -configurators = menuconfig oldconfig defoldconfig
    1.17 +configurators = menuconfig oldconfig
    1.18  PHONY += $(configurators)
    1.19  
    1.20  $(configurators): config_files
    1.21  
    1.22  menuconfig: $(obj)/mconf
    1.23 -	@$(ECHO) "  MCONF $(KCONFIG_TOP)"
    1.24 +	@$(ECHO) "  CONF  $(KCONFIG_TOP)"
    1.25  	$(SILENT)$< $(KCONFIG_TOP)
    1.26  
    1.27  oldconfig: $(obj)/conf .config
    1.28  	@$(ECHO) "  CONF  $(KCONFIG_TOP)"
    1.29  	$(SILENT)$< -s $(KCONFIG_TOP)
    1.30  
    1.31 -defoldconfig: $(obj)/conf .config
    1.32 -	@$(ECHO) "  CONF  $(KCONFIG_TOP)"
    1.33 -	$(SILENT)yes "" |$< -s $(KCONFIG_TOP)
    1.34 -
    1.35  #-----------------------------------------------------------
    1.36  # Help text used by make help
    1.37  
    1.38  help-config::
    1.39  	@echo  '  menuconfig         - Update current config using a menu based program'
    1.40  	@echo  '  oldconfig          - Update current config using a provided .config as base'
    1.41 -	@echo  '  defoldconfig       - As oldconfig, above, but using defaults for new options'
    1.42  
    1.43  #-----------------------------------------------------------
    1.44  # Hmmm! Cheesy build!
    1.45 @@ -49,29 +41,53 @@
    1.46  
    1.47  # What is the compiler?
    1.48  HOST_CC ?= gcc -funsigned-char
    1.49 +HOST_LD ?= gcc
    1.50 +
    1.51 +# Helpers
    1.52 +check_gettext = $(CT_LIB_DIR)/kconfig/check-gettext.sh
    1.53 +check_lxdialog = $(CT_LIB_DIR)/kconfig/lxdialog/check-lxdialog.sh
    1.54 +
    1.55 +# Build flags
    1.56 +CFLAGS = 
    1.57 +LDFLAGS =
    1.58  
    1.59  # Compiler flags to use gettext
    1.60 -EXTRA_CFLAGS += $(shell $(SHELL) $(CT_LIB_DIR)/kconfig/check-gettext.sh $(HOST_CC) $(CFLAGS))
    1.61 +INTL_CFLAGS = $(shell $(SHELL) $(check_gettext) $(HOST_CC) $(EXTRA_CFLAGS))
    1.62  
    1.63  # Compiler and linker flags to use ncurses
    1.64 -EXTRA_CFLAGS += $(shell $(SHELL) $(CT_LIB_DIR)/kconfig/lxdialog/check-lxdialog.sh -ccflags)
    1.65 -EXTRA_LDFLAGS += $(shell $(SHELL) $(CT_LIB_DIR)/kconfig/lxdialog/check-lxdialog.sh -ldflags $(HOST_CC))
    1.66 +NCURSES_CFLAGS = $(shell $(SHELL) $(check_lxdialog) -ccflags)
    1.67 +NCURSES_LDFLAGS = $(shell $(SHELL) $(check_lxdialog) -ldflags $(HOST_CC) $(LX_FLAGS) $(EXTRA_CFLAGS))
    1.68  
    1.69 -# Common source files, and lxdialog source files
    1.70 -SRC = kconfig/zconf.tab.c
    1.71 -LXSRC = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/kconfig/lxdialog/*.c))
    1.72 +# Common source files
    1.73 +COMMON_SRC = kconfig/zconf.tab.c
    1.74 +COMMON_OBJ = $(patsubst %.c,%.o,$(COMMON_SRC))
    1.75 +COMMON_DEP = $(patsubst %.o,%.dep,$(COMMON_OBJ))
    1.76 +$(COMMON_OBJ) $(COMMON_DEP): CFLAGS += $(INTL_CFLAGS)
    1.77 +
    1.78 +# lxdialog source files
    1.79 +LX_SRC = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/kconfig/lxdialog/*.c))
    1.80 +LX_OBJ = $(patsubst %.c,%.o,$(LX_SRC))
    1.81 +LX_DEP = $(patsubst %.o,%.dep,$(LX_OBJ))
    1.82 +$(LX_OBJ) $(LX_DEP): CFLAGS += $(NCURSES_CFLAGS) $(INTL_CFLAGS)
    1.83  
    1.84  # What's needed to build 'conf'
    1.85 -conf_SRC  = $(SRC) kconfig/conf.c
    1.86 -conf_OBJ  = $(patsubst %.c,%.o,$(conf_SRC))
    1.87 +conf_SRC = kconfig/conf.c
    1.88 +conf_OBJ = $(patsubst %.c,%.o,$(conf_SRC))
    1.89 +conf_DEP = $(patsubst %.o,%.dep,$(conf_OBJ))
    1.90 +$(conf_OBJ) $(conf_DEP): CFLAGS += $(INTL_CFLAGS)
    1.91  
    1.92  # What's needed to build 'mconf'
    1.93 -mconf_SRC = $(SRC) $(LXSRC) kconfig/mconf.c
    1.94 +mconf_SRC = kconfig/mconf.c
    1.95  mconf_OBJ = $(patsubst %.c,%.o,$(mconf_SRC))
    1.96 +mconf_DEP = $(patsubst %.c,%.dep,$(mconf_SRC))
    1.97 +$(mconf_OBJ) $(mconf_DEP): CFLAGS += $(NCURSES_CFLAGS) $(INTL_CFLAGS)
    1.98 +$(obj)/mconf: LDFLAGS += $(NCURSES_LDFLAGS)
    1.99 +
   1.100 +# These are generated files:
   1.101 +ALL_OBJS = $(sort $(COMMON_OBJ) $(LX_OBJ) $(conf_OBJ) $(mconf_OBJ))
   1.102 +ALL_DEPS = $(sort $(COMMON_DEP) $(LX_DEP) $(conf_DEP) $(mconf_DEP))
   1.103  
   1.104  # Cheesy auto-dependencies
   1.105 -DEPS = $(patsubst %.c,%.dep,$(sort $(conf_SRC) $(mconf_SRC)))
   1.106 -
   1.107  # Only parse the following if a configurator was called, to avoid building
   1.108  # dependencies when not needed (eg. list-steps, list-samples...)
   1.109  # We must be carefull what we enclose, because we need some of the variable
   1.110 @@ -81,52 +97,58 @@
   1.111  ifneq ($(strip $(MAKECMDGOALS)),)
   1.112  ifneq ($(strip $(filter $(configurators),$(MAKECMDGOALS))),)
   1.113  
   1.114 +DEPS = $(COMMON_DEP)
   1.115 +ifneq ($(strip $(filter oldconfig,$(MAKECMDGOALS))),)
   1.116 +DEPS += $(conf_DEP)
   1.117 +endif
   1.118 +ifneq ($(strip $(filter menuconfig,$(MAKECMDGOALS))),)
   1.119 +DEPS += $(mconf_DEP) $(LX_DEP)
   1.120 +endif
   1.121 +
   1.122  -include $(DEPS)
   1.123  
   1.124  endif # MAKECMDGOALS contains a configurator rule
   1.125  endif # MAKECMDGOALS != ""
   1.126  
   1.127 -# This is not very nice, as they will get rebuild even if (dist)cleaning... :-(
   1.128 -# Should look into the Linux kernel Kbuild to see how they do that...
   1.129 -# To really make me look into this, keep the annoying "DEP xxx" messages.
   1.130 -# Also see the comment for the "%.o: %c" rule below
   1.131 -%.dep: %.c $(CT_LIB_DIR)/kconfig/kconfig.mk $(CT_NG)
   1.132 +# Each .o or .dep *can not* directly depend on kconfig/, because kconfig can
   1.133 +# be touched during the build (who's touching it, btw?) so each .o or .dep
   1.134 +# would be re-built when it sould not be.
   1.135 +# So manually check for presence of $(obj) (ie. kconfig), and only mkdir
   1.136 +# if needed. After all, that's not so bad...
   1.137 +# mkdir $(obj)/lxdialog, because we need it, and incidentally, that
   1.138 +# also creates $(obj).
   1.139 +define check_kconfig_dir
   1.140  	$(SILENT)if [ ! -d $(obj)/lxdialog ]; then  \
   1.141  	   $(ECHO) "  MKDIR $(obj)";           \
   1.142  	   mkdir -p $(obj)/lxdialog;        \
   1.143  	 fi
   1.144 +endef
   1.145 +
   1.146 +# Build the dependency for C files
   1.147 +%.dep: %.c $(CT_LIB_DIR)/kconfig/kconfig.mk
   1.148 +	$(check_kconfig_dir)
   1.149  	@$(ECHO) "  DEP   $@"
   1.150  	$(SILENT)$(HOST_CC) $(CFLAGS) $(EXTRA_CFLAGS) -MM $< |sed -r -e 's|([^:]+.o)( *:+)|$(<:.c=.o) $@\2|;' >$@
   1.151  
   1.152 -# Each .o must depend on the corresponding .c (obvious, isn't it?),
   1.153 -# but *can not* depend on kconfig/, because kconfig can be touched
   1.154 -# during the build (who's touching it, btw?) so each .o would be
   1.155 -# re-built when they sould not be.
   1.156 -# So manually check for presence of $(obj) (ie. kconfig), and only mkdir
   1.157 -# if needed. After all, that's not so bad...
   1.158 -# mkdir $(obj)/lxdialog, because we need it, and incidentally, that
   1.159 -# also creates $(obj).
   1.160 -# Also rebuild the object files is the makefile is changed
   1.161 +# Build C files
   1.162  %.o: %.c $(CT_LIB_DIR)/kconfig/kconfig.mk
   1.163 -	$(SILENT)if [ ! -d $(obj)/lxdialog ]; then  \
   1.164 -	   $(ECHO) "  MKDIR $(obj)";           \
   1.165 -	   mkdir -p $(obj)/lxdialog;        \
   1.166 -	 fi
   1.167 +	$(check_kconfig_dir)
   1.168  	@$(ECHO) "  CC    $@"
   1.169  	$(SILENT)$(HOST_CC) $(CFLAGS) $(EXTRA_CFLAGS) -o $@ -c $<
   1.170  
   1.171 -$(obj)/mconf: $(mconf_OBJ)
   1.172 +# Actual link
   1.173 +$(obj)/mconf: $(COMMON_OBJ) $(LX_OBJ) $(mconf_OBJ)
   1.174  	@$(ECHO) '  LD    $@'
   1.175 -	$(SILENT)$(HOST_CC) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^
   1.176 +	$(SILENT)$(HOST_LD) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^
   1.177  
   1.178 -$(obj)/conf: $(conf_OBJ)
   1.179 +$(obj)/conf: $(COMMON_OBJ) $(conf_OBJ)
   1.180  	@$(ECHO) '  LD    $@'
   1.181 -	$(SILENT)$(HOST_CC) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^
   1.182 +	$(SILENT)$(HOST_LD) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^
   1.183  
   1.184  #-----------------------------------------------------------
   1.185  # Cleaning up the mess...
   1.186  
   1.187  clean::
   1.188  	@$(ECHO) "  CLEAN kconfig"
   1.189 -	$(SILENT)rm -f kconfig/{,m}conf $(conf_OBJ) $(mconf_OBJ) $(DEPS)
   1.190 +	$(SILENT)rm -f kconfig/{,m}conf $(ALL_OBJS) $(ALL_DEPS)
   1.191  	$(SILENT)rmdir --ignore-fail-on-non-empty kconfig{/lxdialog,} 2>/dev/null || true