kconfig/kconfig.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed May 18 23:00:46 2011 +0200 (2011-05-18)
changeset 2467 200836977ce6
parent 2448 a103abae1560
child 2564 5d4e91c0343e
permissions -rw-r--r--
config: rename variables that are arrays

Make it explicit that a variable is an array bu the name of the variable.
It will be used later when .config gets munged to allow both multiple
arguments and arguments with spaces at the same time to be passed from the
configuration down to the build scripts.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
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@945
     8
# The place where the kconfig stuff lies
yann@926
     9
obj = kconfig
yann@926
    10
yann@926
    11
#-----------------------------------------------------------
yann@926
    12
# The configurators rules
yann@182
    13
yann@2454
    14
configurators = menuconfig nconfig oldconfig
yann@946
    15
PHONY += $(configurators)
yann@945
    16
yann@946
    17
$(configurators): config_files
yann@946
    18
yann@946
    19
menuconfig: $(obj)/mconf
yann@959
    20
	@$(ECHO) "  CONF  $(KCONFIG_TOP)"
yann@940
    21
	$(SILENT)$< $(KCONFIG_TOP)
yann@1
    22
yann@2454
    23
nconfig: $(obj)/nconf
yann@2454
    24
	@$(ECHO) "  CONF  $(KCONFIG_TOP)"
yann@2454
    25
	$(SILENT)$< $(KCONFIG_TOP)
yann@2454
    26
yann@946
    27
oldconfig: $(obj)/conf .config
yann@945
    28
	@$(ECHO) "  CONF  $(KCONFIG_TOP)"
yann@2448
    29
	$(SILENT)$< --silent$@ $(KCONFIG_TOP)
yann@1
    30
yann@1803
    31
# Always be silent, the stdout an be >.config
yann@1803
    32
extractconfig:
yann@1803
    33
	@awk 'BEGIN { dump=0; }                                                 \
yann@1803
    34
	      dump==1 && $$0~/^\[.....\][[:space:]]+(# |)CT_/ {                 \
yann@1803
    35
	          $$1="";                                                       \
yann@1803
    36
	          gsub("^[[:space:]]","");                                      \
yann@1803
    37
	          print;                                                        \
yann@1803
    38
	      }                                                                 \
yann@1803
    39
	      $$0~/Dumping user-supplied crosstool-NG configuration: done in/ { \
yann@1803
    40
	          dump=0;                                                       \
yann@1803
    41
	      }                                                                 \
yann@1803
    42
	      $$0~/Dumping user-supplied crosstool-NG configuration$$/ {        \
yann@1803
    43
	          dump=1;                                                       \
yann@1803
    44
	      }'
yann@1803
    45
yann@926
    46
#-----------------------------------------------------------
yann@1
    47
# Help text used by make help
yann@926
    48
yann@176
    49
help-config::
yann@333
    50
	@echo  '  menuconfig         - Update current config using a menu based program'
yann@333
    51
	@echo  '  oldconfig          - Update current config using a provided .config as base'
yann@1803
    52
	@echo  '  extractconfig      - Extract to stdout the configuration items from a'
yann@1803
    53
	@echo  '                       build.log file piped to stdin'
yann@1
    54
yann@926
    55
#-----------------------------------------------------------
yann@940
    56
# Hmmm! Cheesy build!
yann@940
    57
# Or: where I can unveil my make-fu... :-]
yann@1
    58
yann@940
    59
# Oh! Files not here are there, in fact! :-)
yann@940
    60
vpath %.c $(CT_LIB_DIR)
yann@940
    61
vpath %.h $(CT_LIB_DIR)
yann@1
    62
yann@940
    63
# What is the compiler?
yann@940
    64
HOST_CC ?= gcc -funsigned-char
yann@959
    65
HOST_LD ?= gcc
yann@959
    66
yann@959
    67
# Helpers
yann@2448
    68
check_gettext = $(CT_LIB_DIR)/kconfig/check.sh
yann@959
    69
check_lxdialog = $(CT_LIB_DIR)/kconfig/lxdialog/check-lxdialog.sh
yann@959
    70
yann@959
    71
# Build flags
yann@2448
    72
CFLAGS = -DCONFIG_=\"CT_\" -DPACKAGE=\"crosstool-NG\"
yann@959
    73
LDFLAGS =
yann@182
    74
yann@943
    75
# Compiler flags to use gettext
yann@959
    76
INTL_CFLAGS = $(shell $(SHELL) $(check_gettext) $(HOST_CC) $(EXTRA_CFLAGS))
yann@943
    77
yann@940
    78
# Compiler and linker flags to use ncurses
yann@959
    79
NCURSES_CFLAGS = $(shell $(SHELL) $(check_lxdialog) -ccflags)
yann@2125
    80
NCURSES_LDFLAGS = $(shell $(SHELL) $(check_lxdialog) -ldflags $(HOST_CC))
yann@2125
    81
yann@2125
    82
# Check that we have the required ncurses stuff installed for lxdialog (menuconfig)
yann@2125
    83
dochecklxdialog:
yann@2125
    84
	$(SILENT)$(SHELL) $(check_lxdialog) -check $(HOST_CC) $(NCURSES_CFLAGS) $(NCURSES_LDFLAGS)
yann@182
    85
yann@959
    86
# Common source files
yann@959
    87
COMMON_SRC = kconfig/zconf.tab.c
yann@959
    88
COMMON_OBJ = $(patsubst %.c,%.o,$(COMMON_SRC))
yann@959
    89
COMMON_DEP = $(patsubst %.o,%.dep,$(COMMON_OBJ))
yann@959
    90
$(COMMON_OBJ) $(COMMON_DEP): CFLAGS += $(INTL_CFLAGS)
yann@959
    91
yann@959
    92
# lxdialog source files
yann@959
    93
LX_SRC = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/kconfig/lxdialog/*.c))
yann@959
    94
LX_OBJ = $(patsubst %.c,%.o,$(LX_SRC))
yann@959
    95
LX_DEP = $(patsubst %.o,%.dep,$(LX_OBJ))
yann@959
    96
$(LX_OBJ) $(LX_DEP): CFLAGS += $(NCURSES_CFLAGS) $(INTL_CFLAGS)
yann@816
    97
yann@940
    98
# What's needed to build 'conf'
yann@959
    99
conf_SRC = kconfig/conf.c
yann@959
   100
conf_OBJ = $(patsubst %.c,%.o,$(conf_SRC))
yann@959
   101
conf_DEP = $(patsubst %.o,%.dep,$(conf_OBJ))
yann@959
   102
$(conf_OBJ) $(conf_DEP): CFLAGS += $(INTL_CFLAGS)
yann@816
   103
yann@940
   104
# What's needed to build 'mconf'
yann@959
   105
mconf_SRC = kconfig/mconf.c
yann@940
   106
mconf_OBJ = $(patsubst %.c,%.o,$(mconf_SRC))
yann@959
   107
mconf_DEP = $(patsubst %.c,%.dep,$(mconf_SRC))
yann@959
   108
$(mconf_OBJ) $(mconf_DEP): CFLAGS += $(NCURSES_CFLAGS) $(INTL_CFLAGS)
yann@959
   109
$(obj)/mconf: LDFLAGS += $(NCURSES_LDFLAGS)
yann@2454
   110
yann@2454
   111
# What's needed to build 'nconf'
yann@2454
   112
nconf_SRC = kconfig/nconf.c kconfig/nconf.gui.c
yann@2454
   113
nconf_OBJ = $(patsubst %.c,%.o,$(nconf_SRC))
yann@2454
   114
nconf_DEP = $(patsubst %.c,%.dep,$(nconf_SRC))
yann@2454
   115
$(nconf_OBJ) $(nconf_DEP): CFLAGS += $(INTL_CFLAGS)
yann@2454
   116
$(obj)/nconf: LDFLAGS += -lmenu -lpanel -lncurses
yann@2454
   117
yann@2454
   118
# Under Cygwin, we need to auto-import some libs (which ones, exactly?)
yann@2454
   119
# for mconf and nconf to lin properly.
yann@1087
   120
ifeq ($(shell uname -o 2>/dev/null || echo unknown),Cygwin)
yann@1087
   121
$(obj)/mconf: LDFLAGS += -Wl,--enable-auto-import
yann@2454
   122
$(obj)/nconf: LDFLAGS += -Wl,--enable-auto-import
yann@1087
   123
endif
yann@959
   124
yann@959
   125
# These are generated files:
yann@2454
   126
ALL_OBJS = $(sort $(COMMON_OBJ) $(LX_OBJ) $(conf_OBJ) $(mconf_OBJ) $(nconf_OBJ))
yann@2454
   127
ALL_DEPS = $(sort $(COMMON_DEP) $(LX_DEP) $(conf_DEP) $(mconf_DEP) $(nconf_DEP))
yann@1
   128
yann@940
   129
# Cheesy auto-dependencies
yann@946
   130
# Only parse the following if a configurator was called, to avoid building
yann@946
   131
# dependencies when not needed (eg. list-steps, list-samples...)
yann@946
   132
# We must be carefull what we enclose, because we need some of the variable
yann@946
   133
# definitions for clean (and distclean) at least.
yann@946
   134
# Just protecting the "-include $(DEPS)" line should be sufficient.
yann@2125
   135
# And in case we want menuconfig, we have to check that lxdialog
yann@2125
   136
# can find a curses lib.
yann@946
   137
yann@946
   138
ifneq ($(strip $(MAKECMDGOALS)),)
yann@946
   139
ifneq ($(strip $(filter $(configurators),$(MAKECMDGOALS))),)
yann@946
   140
yann@959
   141
DEPS = $(COMMON_DEP)
yann@959
   142
ifneq ($(strip $(filter oldconfig,$(MAKECMDGOALS))),)
yann@959
   143
DEPS += $(conf_DEP)
yann@959
   144
endif
yann@959
   145
ifneq ($(strip $(filter menuconfig,$(MAKECMDGOALS))),)
yann@959
   146
DEPS += $(mconf_DEP) $(LX_DEP)
yann@2125
   147
$(COMMON_OBJ) $(COMMON_DEP): |dochecklxdialog
yann@2125
   148
$(LX_OBJ) $(LX_DEP): |dochecklxdialog
yann@2125
   149
$(mconf_OBJ) $(mconf_DEP): |dochecklxdialog
yann@959
   150
endif
yann@2454
   151
ifneq ($(strip $(filter nconfig,$(MAKECMDGOALS))),)
yann@2454
   152
DEPS += $(nconf_DEP)
yann@2454
   153
endif
yann@959
   154
yann@945
   155
-include $(DEPS)
yann@940
   156
yann@946
   157
endif # MAKECMDGOALS contains a configurator rule
yann@946
   158
endif # MAKECMDGOALS != ""
yann@946
   159
yann@959
   160
# Each .o or .dep *can not* directly depend on kconfig/, because kconfig can
yann@959
   161
# be touched during the build (who's touching it, btw?) so each .o or .dep
yann@959
   162
# would be re-built when it sould not be.
yann@959
   163
# So manually check for presence of $(obj) (ie. kconfig), and only mkdir
yann@959
   164
# if needed. After all, that's not so bad...
yann@959
   165
# mkdir $(obj)/lxdialog, because we need it, and incidentally, that
yann@959
   166
# also creates $(obj).
yann@959
   167
define check_kconfig_dir
yann@940
   168
	$(SILENT)if [ ! -d $(obj)/lxdialog ]; then  \
yann@940
   169
	   $(ECHO) "  MKDIR $(obj)";           \
yann@940
   170
	   mkdir -p $(obj)/lxdialog;        \
yann@940
   171
	 fi
yann@959
   172
endef
yann@959
   173
yann@959
   174
# Build the dependency for C files
yann@959
   175
%.dep: %.c $(CT_LIB_DIR)/kconfig/kconfig.mk
yann@959
   176
	$(check_kconfig_dir)
yann@940
   177
	@$(ECHO) "  DEP   $@"
yann@1155
   178
	$(SILENT)$(HOST_CC) $(CFLAGS) $(EXTRA_CFLAGS) -MM $< |$(sed) -r -e 's|([^:]+.o)( *:+)|$(<:.c=.o) $@\2|;' >$@
yann@940
   179
yann@959
   180
# Build C files
yann@940
   181
%.o: %.c $(CT_LIB_DIR)/kconfig/kconfig.mk
yann@959
   182
	$(check_kconfig_dir)
yann@940
   183
	@$(ECHO) "  CC    $@"
yann@943
   184
	$(SILENT)$(HOST_CC) $(CFLAGS) $(EXTRA_CFLAGS) -o $@ -c $<
yann@940
   185
yann@959
   186
# Actual link
yann@959
   187
$(obj)/mconf: $(COMMON_OBJ) $(LX_OBJ) $(mconf_OBJ)
yann@940
   188
	@$(ECHO) '  LD    $@'
yann@1087
   189
	$(SILENT)$(HOST_LD) -o $@ $^ $(LDFLAGS) $(EXTRA_LDFLAGS)
yann@940
   190
yann@2454
   191
$(obj)/nconf: $(COMMON_OBJ) $(nconf_OBJ)
yann@2454
   192
	@$(ECHO) '  LD    $@'
yann@2454
   193
	$(SILENT)$(HOST_LD) -o $@ $^ $(LDFLAGS) $(EXTRA_LDFLAGS)
yann@2454
   194
yann@959
   195
$(obj)/conf: $(COMMON_OBJ) $(conf_OBJ)
yann@940
   196
	@$(ECHO) '  LD    $@'
yann@1087
   197
	$(SILENT)$(HOST_LD) -o $@ $^ $(LDFLAGS) $(EXTRA_LDFLAGS)
yann@1
   198
yann@926
   199
#-----------------------------------------------------------
yann@926
   200
# Cleaning up the mess...
yann@926
   201
yann@1
   202
clean::
yann@940
   203
	@$(ECHO) "  CLEAN kconfig"
yann@2454
   204
	$(SILENT)rm -f kconfig/{,m,n}conf{,.exe} $(ALL_OBJS) $(ALL_DEPS)
yann@940
   205
	$(SILENT)rmdir --ignore-fail-on-non-empty kconfig{/lxdialog,} 2>/dev/null || true