kconfig/kconfig.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Jul 12 23:52:24 2011 +0200 (2011-07-12)
branch1.11
changeset 2558 b7317d2fe0e9
parent 1973 20f02d426e15
child 2448 a103abae1560
permissions -rw-r--r--
scripts, cc/gcc: do not fail on existing symlinks or build.log

If the user builds a toolchain over an existing one, so, without removing
CT_PREFIX_DIR, the build fails as the symlinks already exist, as does the
build.log.

This can also happen (for build.log) if the user first ran in download-
or extract-only.

Patch (with no SoB) originally from:
Phil Wilshire <phil.wilshire@overturenetworks.com>

Modified by me as it did not apply cleanly.

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