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