• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14CONFIG_CROSS_COMPILE := arm-none-eabi-
15CONFIG_STRICT_CFLAGS ?= y
16CONFIG_SAVE_TARGET ?= n
17CONFIG_FORCE_WIN_SHELL ?= y
18
19ifneq ($(CONFIG_ARCH_BOARD),)
20T := $(CONFIG_ARCH_BOARD)
21export NUTTX_BUILD :=1
22export KERNEL := NUTTX
23export NUTTX_ROOT := $(TOPDIR)
24NUTTX_LIBS := $(patsubst %,$(NUTTX_ROOT)/staging/%,$(LINKLIBS))
25NUTTX_CFG_FILE := $(NUTTX_ROOT)/.config
26else
27export NUTTX_ROOT := $(srctree)/thirdparty/incubator-nuttx/nuttx
28NUTTX_LIBS := $(filter-out $(NUTTX_ROOT)/staging/libproxies.a ,$(wildcard $(NUTTX_ROOT)/staging/*.a))
29NUTTX_CFG_FILE := $(srctree)/config/$(T)/defconfig
30endif
31
32export CONFIG_STRICT_CFLAGS CONFIG_SAVE_TARGET CONFIG_FORCE_WIN_SHELL
33
34# filter-out modules
35ifeq ($(FORCE_TO_FILTER_MODULE),1)
36filter-out-module :=
37filter-out-file :=
38endif
39# ---------------------------------------------------------------------------
40# Platform and shell detection
41
42export WIN_PLAT := n
43ifeq ($(OS),Windows_NT)
44# Detect Cygwin
45ifneq ($(findstring /,$(PWD)),/)
46# also $(findstring /,$(HOME)) ?
47WIN_PLAT := y
48endif
49endif
50
51export WIN_SHELL := n
52ifeq ($(WIN_PLAT),y)
53ifeq ($(CONFIG_FORCE_WIN_SHELL),y)
54WIN_SHELL := y
55else
56# Detect Unix-style shell
57ifeq ($(shell echo $$0),$$0)
58WIN_SHELL := y
59endif
60endif
61endif
62
63BACKSLASH := \ # backslash
64BACKSLASH := $(strip $(BACKSLASH))
65
66TO_UNIX_PATH = $(subst $(BACKSLASH),/,$(1))
67TO_WIN_PATH = $(subst /,$(BACKSLASH),$(1))
68ESC_WIN_PATH = $(subst $(BACKSLASH),$(BACKSLASH)$(BACKSLASH),$(1))
69
70ifeq ($(WIN_PLAT),y)
71ifeq ($(WIN_SHELL),y)
72# make will choose sh.exe as SHELL if it finds sh.exe in the directories of PATH, regardless of
73# the setting in environment or parent (e.g., when git.exe is in the PATH)
74SHELL := cmd.exe
75SHELL_CMD = $(call TO_WIN_PATH,$(1))
76else
77SHELL_CMD = $(call ESC_WIN_PATH,$(call TO_WIN_PATH,$(1)))
78endif
79else
80SHELL_CMD = $(1)
81endif
82
83# The Unix-style path is recognized by compiler toolchain, GNU utilities and windows redirection
84# operators, but not by windows native commands (e.g., mkdir) and applications.
85
86# End of platform and shell detection
87# ---------------------------------------------------------------------------
88
89# Do not use make's built-in rules and variables
90# (this increases performance and avoids hard-to-debug behaviour);
91MAKEFLAGS += -rR
92
93# Avoid funny character set dependencies
94unexport LC_ALL
95LC_COLLATE=C
96LC_NUMERIC=C
97export LC_COLLATE LC_NUMERIC
98
99# Avoid interference with shell env settings
100unexport GREP_OPTIONS
101
102# Check if just to show the help content
103ifeq ($(MAKECMDGOALS),help)
104ifeq ($(T),)
105HELP_TARGET := 1
106endif
107endif
108
109ifneq ($(HELP_TARGET),1)
110# We are using a recursive build, so we need to do a little thinking
111# to get the ordering right.
112#
113# Most importantly: sub-Makefiles should only ever modify files in
114# their own directory. If in some directory we have a dependency on
115# a file in another dir (which doesn't happen often, but it's often
116# unavoidable when linking the built-in.o targets which finally
117# turn into elf file), we will call a sub make in that other dir, and
118# after that we are sure that everything which is in that other dir
119# is now up to date.
120#
121# The only cases where we need to modify files which have global
122# effects are thus separated out and done before the recursive
123# descending is started. They are now explicitly listed as the
124# prepare rule.
125
126# Beautify output
127# ---------------------------------------------------------------------------
128#
129# Normally, we echo the whole command before executing it. By making
130# that echo $($(quiet)$(cmd)), we now have the possibility to set
131# $(quiet) to choose other forms of output instead, e.g.
132#
133#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
134#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
135#
136# If $(quiet) is empty, the whole command will be printed.
137# If it is set to "quiet_", only the short version will be printed.
138# If it is set to "silent_", nothing will be printed at all, since
139# the variable $(silent_cmd_cc_o_c) doesn't exist.
140#
141# A simple variant is to prefix commands with $(Q) - that's useful
142# for commands that shall be hidden in non-verbose mode.
143#
144#	$(Q)ln $@ :<
145#
146# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
147# If KBUILD_VERBOSE equals 1 then the above command is displayed.
148#
149# To put more focus on warnings, be less verbose as default
150# Use 'make V=1' to see the full commands
151
152ifeq ("$(origin V)","command line")
153  KBUILD_VERBOSE = $(V)
154endif
155ifndef KBUILD_VERBOSE
156  KBUILD_VERBOSE = 0
157endif
158
159ifeq ($(KBUILD_VERBOSE),1)
160  quiet :=
161  Q :=
162else
163  quiet := quiet_
164  Q := @
165endif
166
167# If the user is running make -s (silent mode), suppress echoing of
168# commands
169
170ifneq ($(filter 4.%,$(MAKE_VERSION)),) # make-4
171ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
172  quiet=silent_
173endif
174else                                   # make-3.8x
175ifneq ($(filter s% -s%,$(MAKEFLAGS)),)
176  quiet=silent_
177endif
178endif
179
180export quiet Q KBUILD_VERBOSE
181
182TARGET_CFG_FILE = config/$(T)/target.mk
183TARGET_COMMON_FILE = config/common.mk
184
185# To locate output files in a separate directory two syntaxes are supported.
186# In both cases the working directory must be the root of the kernel src.
187# 1) O=
188# Use "make O=dir/to/store/output/files/"
189#
190# 2) Set KBUILD_OUTPUT
191# Set the environment variable KBUILD_OUTPUT to point to the directory
192# where the output files shall be placed.
193# export KBUILD_OUTPUT=dir/to/store/output/files/
194# make
195#
196# The O= assignment takes precedence over the KBUILD_OUTPUT environment
197# variable.
198
199# KBUILD_SRC is set on invocation of make in OBJ directory
200# KBUILD_SRC is not intended to be used by the regular user (for now)
201ifeq ($(KBUILD_SRC),)
202
203export KBUILD_ROOT := $(CURDIR)
204
205# OK, Make called in directory where kernel src resides
206# Do we want to locate output files in a separate directory?
207
208export KBUILD_OUTPUT := $(CURDIR)/out
209ifeq ("$(origin O)","command line")
210  KBUILD_OUTPUT := $(O)
211endif
212
213# Select target
214ifeq ($(CONFIG_SAVE_TARGET),y)
215ifeq ($(T),)
216-include $(KBUILD_OUTPUT)/.config
217T := $(strip $(T))
218endif
219endif
220ifeq ($(T),)
221$(error Please specify the target in the command line: T=<targetName>)
222endif
223ifeq ($(wildcard $(TARGET_CFG_FILE)),)
224$(error Invalid target: T=$(T))
225endif
226export T
227
228KBUILD_OUTPUT := $(KBUILD_OUTPUT)/$(T)
229
230# That's our default target when none is given on the command line
231PHONY := _all
232_all:
233
234# Cancel implicit rules on the config file
235$(KBUILD_OUTPUT)/.config: ;
236
237ifneq ($(KBUILD_OUTPUT),)
238# Invoke a second make in the output directory, passing relevant variables
239# check that the output directory actually exists
240saved-output := $(KBUILD_OUTPUT)
241ifeq ($(WIN_PLAT),y)
242KBUILD_OUTPUT := $(subst /,\,$(KBUILD_OUTPUT))
243KBUILD_OUTPUT := $(shell ( if not exist $(KBUILD_OUTPUT)\ mkdir $(KBUILD_OUTPUT) ) \
244                         && cd $(KBUILD_OUTPUT) && cd)
245KBUILD_OUTPUT := $(subst \,/,$(KBUILD_OUTPUT))
246else
247KBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
248                         && /bin/pwd)
249endif
250
251$(if $(KBUILD_OUTPUT),, \
252     $(error failed to create output directory "$(saved-output)"))
253
254ifeq ($(CONFIG_SAVE_TARGET),y)
255ifeq ($(WIN_PLAT),y)
256_dummy := $(shell echo T := $(T)> $(KBUILD_OUTPUT)/../.config)
257else
258_dummy := $(shell echo "T := $(T)" > $(KBUILD_OUTPUT)/../.config)
259endif
260endif
261
262PHONY += $(MAKECMDGOALS) sub-make
263
264$(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
265	@:
266
267include $(CURDIR)/scripts/submods_init.mk
268
269ifneq ($(filter allclean,$(MAKECMDGOALS)),)
270ALLCLEAN := 1
271export ALLCLEAN
272endif
273
274# Look for make include files relative to root of kernel src
275MAKEFLAGS += --include-dir=$(CURDIR)
276
277ifeq ($(WIN_PLAT),y)
278START_TIME := $(shell echo %time%)
279START_DATE_TIME := $(shell echo %date% %time%)
280else
281START_TIME := $(shell date +"%s.%N")
282START_DATE_TIME := $(shell date +"%Y-%m-%d %T.%N")
283endif
284
285sub-make: FORCE
286	@echo MAKE START: $(START_DATE_TIME)
287	$(Q)$(MAKE) -C $(KBUILD_OUTPUT) KBUILD_SRC=$(CURDIR) \
288		-f $(CURDIR)/Makefile $(filter-out _all sub-make,$(MAKECMDGOALS))
289ifeq ($(WIN_PLAT),y)
290	@echo MAKE END: %date% %time%
291ifneq ($(wildcard tools/timediff.bat),)
292	@tools/timediff.bat "%time%" "$(START_TIME)"
293endif
294else
295	@echo MAKE END: $$(date +"%Y-%m-%d %T.%N")
296	@printf "MAKE TIME: %.2f seconds\n" $$(echo "$$(date +%s.%N) - $(START_TIME)" | bc)
297endif
298
299# Leave processing to above invocation of make
300skip-makefile := 1
301endif # ifneq ($(KBUILD_OUTPUT),)
302endif # ifeq ($(KBUILD_SRC),)
303
304# We process the rest of the Makefile if this is the final invocation of make
305ifneq ($(skip-makefile),1)
306
307# Do not print "Entering directory ...",
308# but we want to display it when entering to the output directory
309# so that IDEs/editors are able to understand relative filenames.
310MAKEFLAGS += --no-print-directory
311
312# If building an external module we do not care about the all: rule
313# but instead _all depend on modules
314PHONY += all
315_all: all
316
317ifeq ($(KBUILD_SRC),)
318        # building in the source tree
319        srctree := .
320else
321        ifeq ($(KBUILD_SRC)/,$(dir $(CURDIR)))
322                # building in a subdirectory of the source tree
323                srctree := ..
324        else
325                ifeq ($(KBUILD_SRC)/,$(dir $(patsubst %/,%,$(dir $(CURDIR)))))
326                        srctree := ../..
327                else
328                        srctree := $(KBUILD_SRC)
329                endif
330        endif
331endif
332objtree		:= .
333src		:= $(srctree)
334obj		:= $(objtree)
335
336VPATH		:= $(srctree)
337
338export srctree objtree VPATH
339
340BES_LIB_DIR ?= lib/bes
341export BES_LIB_DIR
342
343# Git revision
344ifeq ($(WIN_PLAT),y)
345GIT_REVISION := $(shell (where git >nul 2>&1) && (git rev-parse --short HEAD 2>nul))
346else
347GIT_REVISION := $(shell (which git >/dev/null 2>&1) && (git rev-parse --short HEAD 2>/dev/null))
348endif
349
350ifneq ($(GIT_REVISION),)
351ifeq ($(WIN_PLAT),y)
352GIT_REVISION := $(GIT_REVISION)$(shell (git diff --quiet && git diff --cached --quiet) >nul 2>&1 || echo -dirty)
353else
354GIT_REVISION := $(GIT_REVISION)$(shell (git diff --quiet && git diff --cached --quiet) >/dev/null 2>&1 || echo -dirty)
355endif
356endif
357
358
359# Cross compiling and selecting different set of gcc/bin-utils
360# ---------------------------------------------------------------------------
361#
362# When performing cross compilation for other architectures ARCH shall be set
363# to the target architecture. (See arch/* for the possibilities).
364# ARCH can be set during invocation of make:
365# make ARCH=ia64
366# Another way is to have ARCH set in the environment.
367# The default ARCH is the host where make is executed.
368
369# CROSS_COMPILE specify the prefix used for all executables used
370# during compilation. Only gcc and related bin-utils executables
371# are prefixed with $(CROSS_COMPILE).
372# CROSS_COMPILE can be set on the command line
373# make CROSS_COMPILE=ia64-linux-
374# Alternatively CROSS_COMPILE can be set in the environment.
375# A third alternative is to store a setting in .config so that plain
376# "make" in the configured kernel build directory always uses that.
377# Default value for CROSS_COMPILE is not to prefix executables
378# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
379ARCH		?= arm
380CROSS_COMPILE	?= $(CONFIG_CROSS_COMPILE:"%"=%)
381
382# SHELL used by kbuild
383ifneq ($(WIN_PLAT),y)
384CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
385          else if [ -x /bin/bash ]; then echo /bin/bash; \
386          else echo sh; fi ; fi)
387endif
388
389# Make variables (CC, etc...)
390ifeq ($(TOOLCHAIN),armclang)
391CC		= armclang --target=arm-arm-none-eabi
392CPP		= $(CC) -E
393AS		= $(CC)
394C++		= $(CC)
395LD		= $(CC)
396AR		= armar
397NM		= fromelf
398STRIP	= fromelf
399OBJCOPY	= fromelf
400OBJDUMP	= fromelf
401else
402AS		= $(CROSS_COMPILE)as
403CC		= $(CROSS_COMPILE)gcc
404CPP		= $(CC) -E
405C++		= $(CROSS_COMPILE)g++
406LD		= $(CC)
407#LD		= $(CROSS_COMPILE)ld
408AR		= $(CROSS_COMPILE)ar
409NM		= $(CROSS_COMPILE)nm
410STRIP	= $(CROSS_COMPILE)strip
411OBJCOPY	= $(CROSS_COMPILE)objcopy
412OBJDUMP	= $(CROSS_COMPILE)objdump
413endif
414
415AWK		= awk
416PERL	= perl
417PYTHON	= python
418
419ifeq ($(WIN_PLAT),y)
420TO_RCF	= $(PERL) $(subst /,\,$(srctree)/tools/bin2ascii.pl)
421else
422TO_RCF	= $(srctree)/tools/bin2ascii.pl
423endif
424
425KBUILD_CPPFLAGS :=
426
427KBUILD_CFLAGS	:= -fno-common -fmessage-length=0 -Wall \
428		   -fno-exceptions -ffunction-sections \
429		   -fdata-sections -fomit-frame-pointer
430
431# By default char on ARM platform is unsigned char, but char on x86 platform
432# is signed char. To avoid porting issues, force char to be signed char
433# on ARM platform.
434KBUILD_CFLAGS	+= -fsigned-char
435
436ifneq ($(TOOLCHAIN),armclang)
437# 1) Avoid checking out-of-bound array accesses in a loop
438#    (and unrolling/peeling/exiting the loop based on the check)
439# 2) Avoid detecting paths dereferencing a NULL pointer
440#    (and turning the problematic statement into a trap)
441KBUILD_CFLAGS	+= -fno-aggressive-loop-optimizations \
442		   -fno-isolate-erroneous-paths-dereference
443endif
444
445# Treat floating-point constants as float instead of double
446ifeq ($(TOOLCHAIN),armclang)
447KBUILD_CFLAGS	+= -cl-single-precision-constant -fshort-enums
448else
449KBUILD_CFLAGS	+= -fsingle-precision-constant
450endif
451KBUILD_CFLAGS	+= -Wdouble-promotion -Wfloat-conversion
452
453# NOTE:
454# In armclang -g == -gdwarf-4, and fromelf cannot interleave source in disassembly file when -gdwarf-4 or -O1/2/3 is specified.
455KBUILD_CFLAGS	+= -g
456
457#C_ONLY_FLAGS	:= -std=gnu89
458C_ONLY_FLAGS	:= -std=gnu99
459
460C++_ONLY_FLAGS	:= -std=gnu++14 -fno-rtti
461
462KBUILD_AFLAGS   := -D__ASSEMBLY__
463
464export ARCH CROSS_COMPILE AS LD CC
465export CPP C++ AR NM STRIP OBJCOPY OBJDUMP
466export MAKE AWK PERL PYTHON
467
468export KBUILD_CPPFLAGS NOSTDINC_FLAGS OBJCOPYFLAGS LDFLAGS
469export KBUILD_CFLAGS
470export KBUILD_AFLAGS
471export KBUILD_ARFLAGS
472export C_ONLY_FLAGS C++_ONLY_FLAGS
473
474# Files to ignore in find ... statements
475
476export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o    \
477			  -name CVS -o -name .pc -o -name .hg -o -name .git \) \
478			  -prune -o
479export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
480			 --exclude CVS --exclude .pc --exclude .hg --exclude .git
481
482# ===========================================================================
483# Build targets only.
484
485# Objects we will link into $(IMAGE_FILE) / subdirs we need to visit
486init-y		:= init/
487core-y		:= main/
488
489LDS_FILE	:= best1000.lds
490
491# Link flags for all LD processes
492LINK_CFLAGS	:=
493export LINK_CFLAGS
494
495# Link flags for image only
496LIB_LDFLAGS		:=
497CFLAGS_IMAGE	:= -static
498ifeq ($(TOOLCHAIN),armclang)
499LDFLAGS_IMAGE	:= --no_locals
500else
501LDFLAGS_IMAGE	:= -X --no-wchar-size-warning
502endif
503
504include $(srctree)/scripts/include.mk
505
506# Include target definitions
507include $(srctree)/$(TARGET_CFG_FILE)
508include $(srctree)/$(TARGET_COMMON_FILE)
509
510$(srctree)/$(TARGET_CFG_FILE): ;
511$(srctree)/$(TARGET_COMMON_FILE): ;
512
513ifneq ($(filter-out %/,$(init-y) $(core-y)),)
514$(error The object files cannot be linked at top level: $(filter-out %/,$(init-y) $(core-y)))
515endif
516
517# filter-out modules
518ifeq ($(FORCE_TO_FILTER_MODULE),1)
519filter-module := $(patsubst %/,%,$(filter-out-module))
520export filter-module-pattern  := $(addsuffix %,$(filter-module))
521core-y := $(filter-out $(filter-module-pattern),$(core-y))
522filter-obj := $(patsubst %.c, %.o, $(filter-out-file))
523filter-obj += $(patsubst %.S, %.o, $(filter-out-file))
524filter-obj += $(patsubst %.cc, %.o, $(filter-out-file))
525filter-obj += $(patsubst %.cpp, %.o, $(filter-out-file))
526export filter-obj
527endif
528
529ifeq ($(TOOLCHAIN),armclang)
530# Weak symbols must be put in the last library -- stupid armlink!
531core-y += platform/cmsis/weak_sym_armclang/
532
533# Entry objects
534ifeq ($(entry-y),)
535entry-y		+= utils/boot_struct/boot_struct.o
536ifeq ($(ROM_BUILD),1)
537entry-y		+= tests/rom/startup_ARMCM.o
538ifneq ($(filter tests/rom/,$(core-y)),)
539entry-y		+= tests/rom/export_fn_rom.o
540endif
541else # !ROM_BUILD
542entry-y		+= platform/cmsis/retarget_armclang_asm.o
543ifeq ($(PROGRAMMER),1)
544entry-y		+= tests/programmer/sys_api_programmer.o
545else
546entry-y		+= platform/main/startup_main.o
547endif
548endif # !ROM_BUILD
549endif
550ifeq ($(filter %.o,$(entry-y)),)
551$(error Entry objects must be defined in entry-y in target.mk)
552endif
553BAD_ENTRY_OBJS := $(filter-out %.o,$(entry-y))
554ifneq ($(BAD_ENTRY_OBJS),)
555$(error Only objects can be defined in entry-y in target.mk: $(BAD_ENTRY_OBJS))
556endif
557IMAGE_ENTRY := $(entry-y)
558USE_ROM_ENTRY := 0
559ifneq ($(ROM_IN_FLASH),1)
560ifeq ($(ROM_BUILD),1)
561USE_ROM_ENTRY := 1
562endif
563endif
564ifeq ($(USE_ROM_ENTRY),1)
565CFLAGS_IMAGE	+= -e Reset_Handler
566else ifeq ($(PROGRAMMER),1)
567CFLAGS_IMAGE	+= -e programmer_start
568else
569CFLAGS_IMAGE	+= -e __main
570endif
571endif
572
573ifneq ($(NO_BUILDID),1)
574ifneq ($(TOOLCHAIN),armclang)
575LDFLAGS_IMAGE	+= --build-id
576endif
577endif
578ifeq ($(CROSS_REF),1)
579ifeq ($(TOOLCHAIN),armclang)
580LDFLAGS_IMAGE	+= --xref
581else
582LDFLAGS_IMAGE	+= --cref
583endif
584endif
585
586REAL_LDS_FILE := $(LDS_FILE)
587ifeq ($(TOOLCHAIN),armclang)
588SCATTER_LDS_SUFFIX := _scat
589ifeq ($(filter %$(SCATTER_LDS_SUFFIX),$(LDS_FILE)),)
590REAL_LDS_FILE := $(LDS_FILE)$(SCATTER_LDS_SUFFIX)
591endif
592endif
593
594# Generate REVISION_INFO (might be defined in target)
595ifeq ($(REVISION_INFO),)
596ifeq ($(CUST_TGT_INFO),)
597REVISION_INFO := $(GIT_REVISION):$(T)
598else
599REVISION_INFO := $(GIT_REVISION):$(CUST_TGT_INFO)
600endif
601endif
602
603REVISION_INFO := $(subst $(space),-,$(strip $(REVISION_INFO)))
604SOFTWARE_VERSION := $(subst $(space),-,$(strip $(SOFTWARE_VERSION)))
605
606$(info -------------------------------)
607$(info REVISION_INFO: $(REVISION_INFO))
608$(info -------------------------------)
609
610# Build host and user info
611ifeq ($(WIN_PLAT),y)
612export BUILD_HOSTNAME := $(COMPUTERNAME)
613export BUILD_USERNAME := $(USERNAME)
614else
615export BUILD_HOSTNAME := $(shell hostname -s)
616export BUILD_USERNAME := $(shell id -un)
617endif
618
619BUILD_HOSTNAME := $(subst $(space),-,$(strip $(BUILD_HOSTNAME)))
620BUILD_USERNAME := $(subst $(space),-,$(strip $(BUILD_USERNAME)))
621
622# Default kernel image to build when no specific target is given.
623# IMAGE_FILE may be overruled on the command line or
624# set in the environment
625IMAGE_FILE ?= $(notdir $(T)).elf
626
627ifneq ($(filter .map .bin .hex .lst,$(suffix $(IMAGE_FILE))),)
628$(error Invalid IMAGE_FILE (conflicted suffix): $(IMAGE_FILE))
629endif
630
631LST_SECTION_OPTS :=
632LST_SECTION_NAME :=
633ifneq ($(LST_ONLY_SECTION),)
634ifeq ($(TOOLCHAIN),armclang)
635LST_SECTION_OPTS += $(foreach m,$(subst $(comma),$(space),$(LST_ONLY_SECTION)),--only=$m )
636else
637LST_SECTION_OPTS += $(foreach m,$(subst $(comma),$(space),$(LST_ONLY_SECTION)),-j $m )
638endif
639LST_SECTION_NAME := _$(subst *,+,$(subst !,-,$(LST_ONLY_SECTION)))
640endif
641ifneq ($(LST_RM_SECTION),)
642ifeq ($(TOOLCHAIN),armclang)
643LST_SECTION_OPTS += $(foreach m,$(subst $(comma),$(space),$(LST_RM_SECTION)),--ignore_section=$m )
644else
645LST_SECTION_OPTS += $(foreach m,$(subst $(comma),$(space),$(LST_RM_SECTION)),-R $m )
646endif
647LST_SECTION_NAME := $(LST_SECTION_NAME)_no_$(subst *,+,$(subst !,-,$(LST_RM_SECTION)))
648endif
649
650IMAGE_MAP := $(addsuffix .map,$(basename $(IMAGE_FILE)))
651IMAGE_BIN := $(addsuffix .bin,$(basename $(IMAGE_FILE)))
652STR_BIN   := $(addsuffix .str,$(basename $(IMAGE_FILE)))
653IMAGE_HEX := $(addsuffix .hex,$(basename $(IMAGE_FILE)))
654IMAGE_RCF := $(addsuffix .rcf,$(basename $(IMAGE_FILE)))
655ifeq ($(LST_SECTION_OPTS),)
656IMAGE_LST := $(addsuffix .lst,$(basename $(IMAGE_FILE)))
657else
658IMAGE_LST := $(addsuffix $(LST_SECTION_NAME).lst,$(basename $(IMAGE_FILE)))
659endif
660append_lst_sec_name = $(addsuffix $(LST_SECTION_NAME)$(suffix $(1)),$(basename $(1)))
661
662IMAGE_LIB := lib$(addsuffix .a,$(basename $(IMAGE_FILE)))
663ifeq ($(LST_SECTION_OPTS),)
664IMAGE_LIB_LST := $(addsuffix .lst,$(basename $(IMAGE_LIB)))
665else
666IMAGE_LIB_LST := $(addsuffix $(LST_SECTION_NAME).lst,$(basename $(IMAGE_LIB)))
667endif
668
669IMAGE_CMSE_LIB := $(addsuffix _CMSE_Lib.o,$(basename $(IMAGE_FILE)))
670
671LDS_TARGET := _$(notdir $(REAL_LDS_FILE))
672
673IMAGE_VER  := build_info.o
674
675targets := $(LDS_TARGET) $(IMAGE_FILE) $(IMAGE_BIN) $(STR_BIN) $(IMAGE_RCF) $(IMAGE_LST) $(IMAGE_VER) $(IMAGE_LIB)
676cmd_files := $(wildcard $(foreach f,$(targets),$(call get_depfile_name,$(f))))
677
678ifneq ($(cmd_files),)
679include $(cmd_files)
680$(cmd_files): ;
681endif
682
683# The all: target is the default when no target is given on the
684# command line.
685# This allow a user to issue only 'make' to build a kernel including modules
686# Defaults to $(IMAGE_BIN)
687ifeq ($(TRACE_STR_SECTION),1)
688all: $(IMAGE_BIN) $(STR_BIN) ;
689else
690all: $(IMAGE_BIN) ;
691endif
692
693ifeq ($(TOOLCHAIN),armclang)
694      cmd_gen-IMAGE_BIN = $(OBJCOPY) --bincombined -o $@ $<
695else
696      cmd_gen-IMAGE_BIN = $(OBJCOPY) -R .trc_str -O binary $< $@
697endif
698quiet_cmd_gen-IMAGE_BIN = GENBIN  $@
699
700$(IMAGE_BIN): $(IMAGE_FILE)
701ifneq ($(filter 1,$(COMPILE_ONLY) $(NO_BIN)),)
702	@:
703else
704	+$(call if_changed,gen-IMAGE_BIN)
705endif
706
707ifeq ($(TOOLCHAIN),armclang)
708      cmd_gen-STR_BIN = $(OBJCOPY) --bincombined -o $@ $<
709else
710      cmd_gen-STR_BIN = $(OBJCOPY) -j .code_start_addr -j .rodata_str  -j .trc_str \
711          --change-section-lma .code_start_addr=0x00000000 \
712          --change-section-lma .rodata_str=0x00000010 \
713          --change-section-lma .trc_str=0x00030000 \
714          -O binary $< $@
715endif
716quiet_cmd_gen-STR_BIN = GENBIN  $@
717
718$(STR_BIN): $(IMAGE_FILE)
719ifneq ($(filter 1,$(COMPILE_ONLY) $(NO_BIN)),)
720	@:
721else
722	+$(call if_changed,gen-STR_BIN)
723endif
724
725ifneq ($(TOOLCHAIN),armclang)
726      cmd_gen-IMAGE_HEX = $(OBJCOPY) -O ihex $< $@
727quiet_cmd_gen-IMAGE_HEX = GENHEX  $@
728
729$(IMAGE_HEX): $(IMAGE_FILE)
730ifeq ($(COMPILE_ONLY),1)
731	@:
732else
733	+$(call if_changed,gen-IMAGE_HEX)
734endif
735endif
736
737PHONY += rcf
738rcf: $(IMAGE_RCF) ;
739
740ifeq ($(filter 1,$(ROM_BUILD) $(PROGRAMMER)),)
741ifeq ($(CHIP_SUBSYS),)
742IMAGE_IN_FLASH := 1
743endif
744endif
745ifneq ($(filter 1,$(ROM_IN_FLASH) $(PROGRAMMER_INFLASH) $(BTH_AS_MAIN_MCU)),)
746IMAGE_IN_FLASH := 1
747endif
748ifeq ($(IMAGE_IN_FLASH),1)
749ifeq ($(RAM_SIMU_FLASH),1)
750RCF_OPTIONS := 4 -flash
751else
752RCF_OPTIONS := 1 -flash
753endif
754endif
755
756      cmd_gen-IMAGE_RCF = $(TO_RCF) $< $@ $(RCF_OPTIONS)
757quiet_cmd_gen-IMAGE_RCF = GENRCF  $@
758
759$(IMAGE_RCF): $(IMAGE_BIN)
760	+$(call if_changed,gen-IMAGE_RCF)
761
762PHONY += lst lst_only
763lst lst_only: $(IMAGE_LST) ;
764
765PHONY += lib_lst lib_lst_only
766lib_lst lib_lst_only: $(IMAGE_LIB_LST) ;
767
768ifneq ($(filter lst_only lib_lst_only,$(MAKECMDGOALS)),)
769NO_COMPILE := 1
770endif
771
772ifeq ($(TOOLCHAIN),armclang)
773      cmd_gen-IMAGE_LST = $(OBJDUMP) $(LST_SECTION_OPTS) --datasymbols --text -c -d --output=$@ $<
774else
775ifeq ($(LST_SECTION_OPTS),)
776      cmd_gen-IMAGE_LST = $(OBJDUMP) -Sldx $< > $@
777else
778      cmd_gen-IMAGE_LST = $(OBJCOPY) $(LST_SECTION_OPTS) $< $(call append_lst_sec_name,$<) && $(OBJDUMP) -Sldx $(call append_lst_sec_name,$<) > $@
779endif
780endif
781quiet_cmd_gen-IMAGE_LST = GENLST  $@
782
783$(IMAGE_LST): $(IMAGE_FILE)
784	+$(call if_changed,gen-IMAGE_LST)
785
786$(IMAGE_LIB_LST): $(IMAGE_LIB)
787	+$(call if_changed,gen-IMAGE_LST)
788
789# Flags
790
791# arch Makefile may override CC so keep this after arch Makefile is included
792#ifeq ($(CONFIG_STRICT_CFLAGS),y)
793#NOSTDINC_FLAGS += -nostdinc
794#endif
795#NOSTDINC_FLAGS += -isystem "$(subst \,/,$(shell $(CC) -print-file-name=include))"
796
797ifeq ($(CONFIG_STRICT_CFLAGS),y)
798# warn about C99 declaration after statement
799#C_ONLY_FLAGS    += -Wdeclaration-after-statement
800
801# disallow errors like 'EXPORT_GPL(foo);' with missing header
802C_ONLY_FLAGS   += -Werror=implicit-int
803
804# require functions to have arguments in prototypes, not empty 'int foo()'
805#C_ONLY_FLAGS    += -Werror=strict-prototypes
806
807ifneq ($(NUTTX_BUILD),1)
808C_ONLY_FLAGS    += -Werror-implicit-function-declaration
809endif
810
811# Prohibit date/time macros, which would make the build non-deterministic
812#KBUILD_CFLAGS   += $(call cc-option,-Werror=date-time)
813
814ifneq ($(TOOLCHAIN),armclang)
815KBUILD_CFLAGS   += $(call cc-option,-Wlogical-op)
816KBUILD_CFLAGS   += $(call cc-option,-Wimplicit-fallthrough)
817endif
818
819#KBUILD_CFLAGS   += -Wno-address-of-packed-member
820
821KBUILD_CFLAGS	+= -Wno-trigraphs \
822		   -fno-strict-aliasing
823
824# Never change loops to C library calls like memcpy/memset
825# (otherwise it will be enabled by -O2 in GCC 10)
826ifneq ($(TOOLCHAIN),armclang)
827KBUILD_CFLAGS	+= -fno-tree-loop-distribute-patterns
828endif
829
830#KBUILD_CFLAGS	+= Wundef
831
832# use the deterministic mode of AR if available
833KBUILD_ARFLAGS := D
834
835include $(srctree)/scripts/extrawarn.mk
836endif # CONFIG_STRICT_CFLAGS
837
838ifeq ($(TOOLCHAIN),armclang)
839KBUILD_CFLAGS += -Wno-typedef-redefinition
840endif
841
842# Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments
843KBUILD_CPPFLAGS += $(KCPPFLAGS)
844KBUILD_AFLAGS += $(KAFLAGS)
845KBUILD_CFLAGS += $(KCFLAGS)
846
847IMAGE-dirs	:= $(patsubst %/,%,$(filter %/, $(init-y) $(core-y)))
848
849submodgoals =
850ifneq ($(SUBMODS),)
851include $(srctree)/scripts/submods.mk
852
853IMAGE-builddirs	:= $(call get_subdirs,$(IMAGE-dirs),$(SUBMODS))
854ifeq ($(COMPILE_ONLY),1)
855submodgoals = $(call get_submodgoals,$@,$(SUBMODS))
856endif
857else
858IMAGE-builddirs	:= $(IMAGE-dirs)
859endif
860
861IMAGE-alldirs	:= $(sort $(IMAGE-dirs) $(patsubst %/,%,$(filter %/, \
862			$(init-) $(core-) $(extra-))))
863
864init-y		:= $(patsubst %/, %/built-in$(built_in_suffix), $(init-y))
865core-y		:= $(patsubst %/, %/built-in$(built_in_suffix), $(core-y))
866
867IMAGE_INIT := $(init-y)
868IMAGE_MAIN := $(core-y)
869
870ifeq ($(ARM_CMNS),1)
871ifneq ($(NUTTX_BUILD),1)
872IMAGE_MAIN += ../$(ARM_CMSE_TARGET)/$(ARM_CMSE_TARGET)_CMSE_Lib.o
873endif
874endif
875
876ifeq ($(NO_COMPILE),1)
877IMAGE-deps :=
878else
879IMAGE-deps := $(LDS_TARGET) $(IMAGE_INIT) $(IMAGE_MAIN) $(IMAGE_VER)
880endif
881
882BUILD_INFO_FLAGS := \
883	-DREVISION_INFO=$(REVISION_INFO) \
884	-DFLASH_SIZE=$(FLASH_SIZE) \
885	-DOTA_UPGRADE_CRC_LOG_SIZE=$(OTA_UPGRADE_CRC_LOG_SIZE) \
886	-DNV_REC_DEV_VER=$(NV_REC_DEV_VER) \
887	-I$(srctree)/platform/hal
888
889BUILD_INFO_FLAGS += $(LDS_SECTION_FLAGS)
890BUILD_INFO_FLAGS += -DCHIP=$(CHIP)
891
892ifneq ($(HW_VERSION_STRING),)
893BUILD_INFO_FLAGS += -DHW_VERSION_STRING=$(HW_VERSION_STRING)
894endif
895
896ifneq ($(CHIP_SUBTYPE),)
897BUILD_INFO_FLAGS += -DCHIP_SUBTYPE=$(CHIP_SUBTYPE)
898endif
899ifneq ($(SOFTWARE_VERSION),)
900BUILD_INFO_FLAGS += -DSOFTWARE_VERSION=$(SOFTWARE_VERSION)
901endif
902ifneq ($(OTA_BOOT_SIZE),)
903BUILD_INFO_FLAGS += -DOTA_BOOT_OFFSET=$(OTA_BOOT_OFFSET) -DOTA_BOOT_SIZE=$(OTA_BOOT_SIZE)
904endif
905ifneq ($(OTA_CODE_OFFSET),)
906BUILD_INFO_FLAGS += -DOTA_CODE_OFFSET=$(OTA_CODE_OFFSET)
907endif
908ifneq ($(OTA_REMAP_OFFSET),)
909BUILD_INFO_FLAGS += -DOTA_REMAP_OFFSET=$(OTA_REMAP_OFFSET)
910endif
911ifeq ($(CRC32_OF_IMAGE),1)
912BUILD_INFO_FLAGS += -DCRC32_OF_IMAGE
913endif
914ifeq ($(TRACE_CRLF),1)
915BUILD_INFO_FLAGS += -DTRACE_CRLF
916endif
917
918BUILD_INFO_FLAGS += -DKERNEL=$(KERNEL)
919
920quiet_cmd_image_ver = CC      $(IMAGE_VER)
921      cmd_image_ver = $(CC) $(filter-out -Werror=date-time, \
922                             $(call flags,KBUILD_CPPFLAGS) \
923                             $(call flags,KBUILD_CFLAGS) \
924                             $(call flags,C_ONLY_FLAGS) \
925                             $(NOSTDINC_FLAGS)) \
926                             $(BUILD_INFO_FLAGS) \
927                             -MD -MP -MF $(depfile) -MT $@ \
928                             -c -o $@ $<
929
930IMAGE_VER_SRC := $(src)/utils/build_info/build_info.c
931
932$(IMAGE_VER): $(IMAGE_VER_SRC) $(filter-out $(IMAGE_VER),$(IMAGE-deps)) FORCE
933	$(call if_changed_dep,image_ver)
934
935# Linker scripts preprocessor (.lds.S -> .lds)
936# ---------------------------------------------------------------------------
937quiet_cmd_cpp_lds_S = LDS     $@
938      cmd_cpp_lds_S = $(CPP) $(call flags,KBUILD_CPPFLAGS) \
939                             $(call flags,CPPFLAGS_$(LDS_FILE)) \
940                             -MD -MP -MF $(depfile) -MT $@ \
941                             $(NOSTDINC_FLAGS) \
942                             -P -C -E -x c -o $@ $<
943
944LDS_SRC_STEM := $(src)/scripts/link/$(REAL_LDS_FILE)
945LDS_SRC := $(firstword $(wildcard $(LDS_SRC_STEM).S $(LDS_SRC_STEM).sx) $(LDS_SRC_STEM).S)
946
947$(LDS_TARGET): $(LDS_SRC) FORCE
948	$(call if_changed_dep,cpp_lds_S)
949
950PHONY += lds
951lds: $(LDS_TARGET) ;
952
953ifeq ($(NUTTX_BUILD),1)
954KBUILD_CPPFLAGS += -fno-builtin -DNUTTX_BUILD -D__NUTTX_SUPPORT__ -DFREE_WDATA_IN_HOOK
955NUTTX_INCLUDE :=  \
956	-I$(NUTTX_ROOT)/include/libcxx \
957	-I$(NUTTX_ROOT)/include\
958
959#NUTTX_INCLUDE += -include $(srctree)/platform/hal/hal_trace.h
960C++_ONLY_FLAGS += -DCONFIG_WCHAR_BUILTIN $(NUTTX_INCLUDE) -std=c++17 -D__NuttX__ -nostdinc++ -fpermissive
961C_ONLY_FLAGS += $(NUTTX_INCLUDE)
962CPPFLAGS_$(LDS_FILE) += -I$(NUTTX_ROOT)/include
963endif
964
965# Final link of $(IMAGE_FILE)
966# ---------------------------------------------------------------------------
967#
968# 1) Link the archives twice to solve circular references between two or
969#    more archives. Otherwise we should use --start-group and --end-group
970#    options. Normally, an archive is searched only once in the order that
971#    it is specified on the command line.
972# 2) Use --whole-archive option to solve weak symbol overriding issue.
973#    It tells LD to include every object file in the archive in the link,
974#    rather than searching the archive for the required object files.
975#    By default the strong symbols defined in the archive will not override
976#    any weak symbol, for LD only searches the archive if there is a undefined
977#    symbol (and a weak symbol is considered as a defined symbol).
978#
979ifeq ($(TOOLCHAIN),armclang)
980
981#LDFLAGS_IMAGE += --symbols --list_mapping_symbols
982ifeq ($(KBUILD_VERBOSE),1)
983LDFLAGS_IMAGE += --verbose
984endif
985ifeq ($(ARM_CMSE),1)
986LDFLAGS_IMAGE += --import-cmse-lib-out=$(IMAGE_CMSE_LIB)
987endif
988
989      cmd_link-IMAGE_FILE = $(LD) -o $@ \
990	      $(CFLAGS_IMAGE) \
991	      -Wl,$(subst $(space),$(comma),$(strip \
992	      $(LDFLAGS) $(LDFLAGS_IMAGE) \
993	      --scatter=$(LDS_TARGET) \
994	      --list=$(IMAGE_MAP) \
995	      --info=summarysizes --info=summarystack --info=totals --info=unused \
996	      --map --load_addr_map_info \
997	      --remove --no_autoat \
998	      --emit_debug_overlay_relocs --emit_debug_overlay_section \
999	      --diag_style=gnu --diag_suppress=L6314 --diag_suppress=L6329)) \
1000	      $(IMAGE_ENTRY) $(IMAGE_INIT) $(IMAGE_MAIN) $(IMAGE_VER) \
1001	      $(LIB_LDFLAGS) $(LIB_LDFLAGS)
1002
1003else # TOOLCHAIN != armclang
1004
1005ifeq ($(ARM_CMSE),1)
1006LDFLAGS_IMAGE += --cmse-implib --out-implib=$(IMAGE_CMSE_LIB)
1007endif
1008
1009      cmd_link-IMAGE_FILE = $(LD) -o $@ \
1010		  $(LD_USE_PATCH_SYMBOL) \
1011	      -T $(LDS_TARGET) \
1012	      $(CFLAGS_IMAGE) \
1013	      -Wl,$(subst $(space),$(comma),$(strip \
1014	      $(LDFLAGS) $(LDFLAGS_IMAGE) \
1015	      -Map=$(IMAGE_MAP) \
1016	      --gc-sections \
1017	      --whole-archive)) \
1018	      $(NUTTX_LIBS) $(IMAGE_INIT) $(IMAGE_MAIN) $(IMAGE_VER) \
1019	      -Wl,--no-whole-archive $(LIB_LDFLAGS) $(LIB_LDFLAGS)
1020
1021endif # TOOLCHAIN != armclang
1022quiet_cmd_link-IMAGE_FILE = LINK    $@
1023
1024# Include targets which we want to
1025# execute if the rest of the kernel build went well.
1026$(IMAGE_FILE): $(IMAGE-deps) $(NUTTX_LIBS) FORCE
1027ifneq ($(filter 1,$(COMPILE_ONLY) $(NO_COMPILE)),)
1028	@:
1029else
1030	+$(call if_changed,link-IMAGE_FILE)
1031endif
1032
1033PHONY += lib
1034lib: $(IMAGE_LIB) ;
1035
1036      cmd_gen_image_lib = $(call archive-cmd,$(IMAGE_INIT) $(IMAGE_MAIN) $(IMAGE_VER))
1037quiet_cmd_gen_image_lib = IMGLIB  $(@)
1038
1039$(IMAGE_LIB): $(IMAGE-deps) $(NUTTX_LIBS) FORCE
1040ifneq ($(filter 1,$(COMPILE_ONLY) $(NO_COMPILE)),)
1041	@:
1042else
1043	@$(call if_changed,gen_image_lib)
1044endif
1045
1046ifneq ($(IMAGE-deps),)
1047# The actual objects are generated when descending,
1048# make sure no implicit rule kicks in
1049$(sort $(filter %/built-in$(built_in_suffix),$(IMAGE-deps))): $(IMAGE-builddirs) ;
1050endif
1051
1052# Handle descending into subdirectories listed in $(IMAGE-dirs)
1053# Preset locale variables to speed up the build process. Limit locale
1054# tweaks to this spot to avoid wrong language settings when running
1055# make menuconfig etc.
1056# Error messages still appears in the original language
1057
1058PHONY += $(IMAGE-dirs)
1059$(IMAGE-dirs): scripts
1060	$(Q)$(MAKE) $(build)=$@ $(submodgoals)
1061
1062# clean - Delete most, but leave enough to build external modules
1063#
1064clean: rm-dirs  := $(CLEAN_DIRS)
1065clean: rm-files := $(CLEAN_FILES)
1066ifneq ($(SUBMODS),)
1067clean-dirs      := $(addprefix _clean_, $(IMAGE-builddirs))
1068else
1069clean-dirs      := $(addprefix _clean_, $(IMAGE-alldirs))
1070endif
1071
1072PHONY += $(clean-dirs) clean IMAGE-clean distclean subdir_clean
1073$(clean-dirs):
1074	$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
1075
1076IMAGE-clean:
1077	$(Q)$(call CMDRMFILE,$(IMAGE_FILE) $(IMAGE_MAP) \
1078		$(IMAGE_BIN) $(STR_BIN) $(IMAGE_HEX) $(IMAGE_RCF) $(IMAGE_LST) \
1079		$(addsuffix *$(suffix $(IMAGE_FILE)),$(basename $(IMAGE_FILE))) \
1080		$(addsuffix *$(suffix $(IMAGE_LST)),$(basename $(IMAGE_LST))) \
1081		$(IMAGE_LIB) $(IMAGE_LIB_LST) $(call append_lst_sec_name,$(IMAGE_LIB)) \
1082		$(addsuffix *$(suffix $(IMAGE_LIB)),$(basename $(IMAGE_LIB))) \
1083		$(addsuffix *$(suffix $(IMAGE_LIB_LST)),$(basename $(IMAGE_LIB_LST))) \
1084		$(IMAGE_CMSE_LIB) \
1085		$(IMAGE_VER) $(LDS_TARGET))
1086
1087distclean: clean
1088subdir_clean: clean
1089
1090clean: IMAGE-clean
1091
1092clean: $(clean-dirs)
1093	$(call cmd,rmdirs)
1094	$(call cmd,rmfiles)
1095ifeq ($(SUBMODS),)
1096	$(Q)$(call CMDRMFILER,.,*.o *.a *.s *.d)
1097endif
1098
1099PHONY += allclean
1100ifeq ($(KBUILD_OUTPUT),)
1101allclean: clean ;
1102else
1103ifeq ($(SUBMODS),)
1104quiet_cmd_allclean  = RMDIR   $(KBUILD_OUTPUT)
1105      cmd_allclean  = $(call CMDRMDIR,$(KBUILD_OUTPUT))
1106
1107allclean:
1108	+$(call cmd,allclean)
1109else
1110allclean: clean ;
1111endif
1112endif
1113
1114PHONY += libclean
1115quiet_cmd_libclean	= RMDIR   $(srctree)/$(BES_LIB_DIR)
1116      cmd_libclean  = $(call CMDRMDIR,$(srctree)/$(BES_LIB_DIR))
1117
1118libclean:
1119	+$(call cmd,libclean)
1120
1121quiet_cmd_predefined-macros = GEN     $@
1122      cmd_predefined-macros = $(CPP) $(filter-out -I% -D% -include%,$(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(C_ONLY_FLAGS)) \
1123                                     -x c -E -dM -o $@ $(devnull)
1124
1125PREDEF_MACRO_FILE := predefined-macros.txt
1126
1127$(PREDEF_MACRO_FILE): FORCE
1128	$(call cmd,predefined-macros)
1129
1130PHONY += predefined-macros
1131predefined-macros: $(PREDEF_MACRO_FILE) ;
1132
1133# FIXME Should go into a make.lib or something
1134# ===========================================================================
1135
1136quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN   $(wildcard $(rm-dirs)))
1137      cmd_rmdirs = $(if $(wildcard $(rm-dirs)),$(call CMDRMDIR,$(rm-dirs)))
1138
1139quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN   $(wildcard $(rm-files)))
1140      cmd_rmfiles = $(if $(wildcard $(rm-files)),$(call CMDRMFILE,$(rm-files)))
1141
1142# Shorthand for $(Q)$(MAKE) -f scripts/clean.mk obj=dir
1143# Usage:
1144# $(Q)$(MAKE) $(clean)=dir
1145clean := -f $(srctree)/scripts/clean.mk obj
1146
1147ifneq ($(WIN_PLAT),y)
1148# Generate tags for editors
1149# ---------------------------------------------------------------------------
1150quiet_cmd_tags = GEN     $@
1151      cmd_tags = $(CONFIG_SHELL) $(srctree)/tools/tags.sh $@
1152
1153tags TAGS cscope gtags: FORCE
1154	$(call cmd,tags)
1155endif
1156
1157HELP_TARGET := 2
1158
1159endif # ifneq ($(skip-makefile),1)
1160endif # ifneq ($(HELP_TARGET),1)
1161
1162# Help target
1163ifneq ($(HELP_TARGET),)
1164ifeq ($(HELP_TARGET),1)
1165include scripts/include.mk
1166endif
1167
1168help: FORCE
1169	$(call echo-help,Mandatory options:)
1170	$(call echo-help,  T=<targetBoard> - Select a target board configuration in config/)
1171	$(call echo-help,)
1172	$(call echo-help,Cleaning targets:)
1173	$(call echo-help,  clean           - Remove most generated files)
1174	$(call echo-help,  allclean        - Remove all generated files and the output directory if possible)
1175	$(call echo-help,)
1176	$(call echo-help,Generic targets:)
1177	$(call echo-help,  all             - Build all targets marked with [*])
1178	$(call echo-help,  lst             - Build the mixed source/assembly file of the final image)
1179	$(call echo-help,  lds             - Build the linker script file)
1180ifeq ($(HELP_TARGET),2)
1181	$(call echo-help,* $(IMAGE_FILE))
1182	$(call echo-help,                  - Build the final image)
1183endif
1184	$(call echo-help,  dir/            - Build all files in dir and below)
1185	$(call echo-help,  dir/file.[oisS] - Build specified target only)
1186	$(call echo-help,  dir/file.lst    - Build specified mixed source/assembly target only)
1187	$(call echo-help,                    (requires a recent binutils and recent build (System.map)))
1188	$(call echo-help,)
1189	$(call echo-help,  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build)
1190	$(call echo-help,  make V=2   [targets] 2 => give reason for rebuild of target)
1191	$(call echo-help,  make O=dir [targets] Locate all output files in "dir", including .config)
1192	$(call echo-help,  make W=n   [targets] Enable extra gcc checks, n=1,2,3 where)
1193	$(call echo-help,         1: warnings which may be relevant and do not occur too often)
1194	$(call echo-help,         2: warnings which occur quite often but may still be relevant)
1195	$(call echo-help,         3: more obscure warnings, can most likely be ignored)
1196	$(call echo-help,         Multiple levels can be combined with W=12 or W=123)
1197	$(call echo-help,)
1198	$(call echo-help,Execute "make" or "make all" to build all targets marked with [*])
1199
1200endif # ifneq ($(HELP_TARGET),)
1201
1202# Cancel implicit rules on top Makefile
1203ifeq ($(KBUILD_SRC),)
1204$(CURDIR)/Makefile Makefile: ;
1205else
1206$(KBUILD_SRC)/Makefile Makefile: ;
1207endif
1208
1209PHONY += FORCE
1210FORCE: ;
1211
1212# Debug makefile variables
1213ifneq ($(skip-makefile),1)
1214
1215ifeq ($(VAR_VAL_QUOTE),1)
1216val_quote_l := [
1217val_quote_r := ]
1218else
1219val_quote_l :=
1220val_quote_r :=
1221endif
1222
1223debug_var_list := $(patsubst get_var_%,%,$(filter get_var_%,$(MAKECMDGOALS)))
1224ifneq ($(debug_var_list),)
1225# Avoid expanding functions (e.g., shell functions) and recipe automatic variables
1226$(foreach v,$(debug_var_list),$(if $(filter $(v),$(.VARIABLES)),\
1227	$(info $(v)=$(val_quote_l)$(value $(v))$(val_quote_r)),\
1228	$(info $(v) is not set)))
1229endif
1230
1231ifneq ($(filter get_all_var,$(MAKECMDGOALS)),)
1232# Avoid expanding functions (e.g., shell functions) and recipe automatic variables
1233$(foreach c,$(sort $(.VARIABLES)),$(info $(c)=$(val_quote_l)$(value $(c))$(val_quote_r)))
1234endif
1235
1236get_var_%: FORCE ;
1237get_all_var: FORCE ;
1238endif
1239
1240# Declare the contents of the .PHONY variable as phony.  We keep that
1241# information in a variable so we can use it in if_changed and friends.
1242.PHONY: $(PHONY)
1243