Skip to content

Commit 6825a95

Browse files
masahir0ytrini
authored andcommitted
kbuild: use Linux Kernel build scripts
Now we are ready to switch over to real Kbuild. This commit disables temporary scripts: scripts/{Makefile.build.tmp, Makefile.host.tmp} and enables real Kbuild scripts: scripts/{Makefile.build,Makefile.host,Makefile.lib}. This switch is triggered by the line in scripts/Kbuild.include -build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build.tmp obj +build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj We need to adjust some build scripts for U-Boot. But smaller amount of modification is preferable. Additionally, we need to fix compiler flags which are locally added or removed. In Kbuild, it is not allowed to change CFLAGS locally. Instead, ccflags-y, asflags-y, cppflags-y, CFLAGS_$(basetarget).o, CFLAGS_REMOVE_$(basetarget).o are prepared for that purpose. Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com> Tested-by: Gerhard Sittig <gsi@denx.de>
1 parent 22433fc commit 6825a95

77 files changed

Lines changed: 526 additions & 325 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 200 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,78 @@ else
4343
XECHO = :
4444
endif
4545

46+
# *DOCUMENTATION*
47+
# To see a list of typical targets execute "make help"
48+
# More info can be located in ./README
49+
# Comments in this file are targeted only to the developer, do not
50+
# expect to learn how to build the kernel reading this file.
51+
52+
# Do not:
53+
# o use make's built-in rules and variables
54+
# (this increases performance and avoids hard-to-debug behaviour);
55+
# o print "Entering directory ...";
56+
MAKEFLAGS += -rR --no-print-directory
57+
58+
# Avoid funny character set dependencies
59+
unexport LC_ALL
60+
LC_COLLATE=C
61+
LC_NUMERIC=C
62+
export LC_COLLATE LC_NUMERIC
63+
64+
# We are using a recursive build, so we need to do a little thinking
65+
# to get the ordering right.
66+
#
67+
# Most importantly: sub-Makefiles should only ever modify files in
68+
# their own directory. If in some directory we have a dependency on
69+
# a file in another dir (which doesn't happen often, but it's often
70+
# unavoidable when linking the built-in.o targets which finally
71+
# turn into vmlinux), we will call a sub make in that other dir, and
72+
# after that we are sure that everything which is in that other dir
73+
# is now up to date.
74+
#
75+
# The only cases where we need to modify files which have global
76+
# effects are thus separated out and done before the recursive
77+
# descending is started. They are now explicitly listed as the
78+
# prepare rule.
79+
80+
# To put more focus on warnings, be less verbose as default
81+
# Use 'make V=1' to see the full commands
82+
83+
ifeq ("$(origin V)", "command line")
84+
KBUILD_VERBOSE = $(V)
85+
endif
86+
ifndef KBUILD_VERBOSE
87+
KBUILD_VERBOSE = 0
88+
endif
89+
90+
# Call a source code checker (by default, "sparse") as part of the
91+
# C compilation.
92+
#
93+
# Use 'make C=1' to enable checking of only re-compiled files.
94+
# Use 'make C=2' to enable checking of *all* source files, regardless
95+
# of whether they are re-compiled or not.
96+
#
97+
# See the file "Documentation/sparse.txt" for more details, including
98+
# where to get the "sparse" utility.
99+
100+
ifeq ("$(origin C)", "command line")
101+
KBUILD_CHECKSRC = $(C)
102+
endif
103+
ifndef KBUILD_CHECKSRC
104+
KBUILD_CHECKSRC = 0
105+
endif
106+
107+
# Use make M=dir to specify directory of external module to build
108+
# Old syntax make ... SUBDIRS=$PWD is still supported
109+
# Setting the environment variable KBUILD_EXTMOD take precedence
110+
ifdef SUBDIRS
111+
KBUILD_EXTMOD ?= $(SUBDIRS)
112+
endif
113+
114+
ifeq ("$(origin M)", "command line")
115+
KBUILD_EXTMOD := $(M)
116+
endif
117+
46118
# kbuild supports saving output files in a separate directory.
47119
# To locate output files in a separate directory two syntaxes are supported.
48120
# In both cases the working directory must be the root of the kernel src.
@@ -107,8 +179,14 @@ endif # ifeq ($(KBUILD_SRC),)
107179
# We process the rest of the Makefile if this is the final invocation of make
108180
ifeq ($(skip-makefile),)
109181

182+
# If building an external module we do not care about the all: rule
183+
# but instead _all depend on modules
110184
PHONY += all
185+
ifeq ($(KBUILD_EXTMOD),)
111186
_all: all
187+
else
188+
_all: modules
189+
endif
112190

113191
srctree := $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))
114192
objtree := $(CURDIR)
@@ -119,24 +197,6 @@ VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
119197

120198
export srctree objtree VPATH
121199

122-
# Call a source code checker (by default, "sparse") as part of the
123-
# C compilation.
124-
#
125-
# Use 'make C=1' to enable checking of re-compiled files.
126-
#
127-
# See the linux kernel file "Documentation/sparse.txt" for more details,
128-
# including where to get the "sparse" utility.
129-
130-
ifdef C
131-
ifeq ("$(origin C)", "command line")
132-
CHECKSRC := $(C)
133-
endif
134-
endif
135-
ifndef CHECKSRC
136-
CHECKSRC = 0
137-
endif
138-
export CHECKSRC
139-
140200
OBJTREE := $(objtree)
141201
SPLTREE := $(OBJTREE)/spl
142202
TPLTREE := $(OBJTREE)/tpl
@@ -222,6 +282,78 @@ HOSTCFLAGS += $(call os_x_before, 10, 4, "-traditional-cpp")
222282
HOSTLDFLAGS += $(call os_x_before, 10, 5, "-multiply_defined suppress")
223283
endif
224284

285+
# Decide whether to build built-in, modular, or both.
286+
# Normally, just do built-in.
287+
288+
KBUILD_MODULES :=
289+
KBUILD_BUILTIN := 1
290+
291+
# If we have only "make modules", don't compile built-in objects.
292+
# When we're building modules with modversions, we need to consider
293+
# the built-in objects during the descend as well, in order to
294+
# make sure the checksums are up to date before we record them.
295+
296+
ifeq ($(MAKECMDGOALS),modules)
297+
KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
298+
endif
299+
300+
# If we have "make <whatever> modules", compile modules
301+
# in addition to whatever we do anyway.
302+
# Just "make" or "make all" shall build modules as well
303+
304+
# U-Boot does not need modules
305+
#ifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
306+
# KBUILD_MODULES := 1
307+
#endif
308+
309+
#ifeq ($(MAKECMDGOALS),)
310+
# KBUILD_MODULES := 1
311+
#endif
312+
313+
export KBUILD_MODULES KBUILD_BUILTIN
314+
export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
315+
316+
# Beautify output
317+
# ---------------------------------------------------------------------------
318+
#
319+
# Normally, we echo the whole command before executing it. By making
320+
# that echo $($(quiet)$(cmd)), we now have the possibility to set
321+
# $(quiet) to choose other forms of output instead, e.g.
322+
#
323+
# quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
324+
# cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
325+
#
326+
# If $(quiet) is empty, the whole command will be printed.
327+
# If it is set to "quiet_", only the short version will be printed.
328+
# If it is set to "silent_", nothing will be printed at all, since
329+
# the variable $(silent_cmd_cc_o_c) doesn't exist.
330+
#
331+
# A simple variant is to prefix commands with $(Q) - that's useful
332+
# for commands that shall be hidden in non-verbose mode.
333+
#
334+
# $(Q)ln $@ :<
335+
#
336+
# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
337+
# If KBUILD_VERBOSE equals 1 then the above command is displayed.
338+
339+
ifeq ($(KBUILD_VERBOSE),1)
340+
quiet =
341+
Q =
342+
else
343+
quiet=quiet_
344+
Q = @
345+
endif
346+
347+
# If the user is running make -s (silent mode), suppress echoing of
348+
# commands
349+
350+
ifneq ($(filter s% -s%,$(MAKEFLAGS)),)
351+
quiet=silent_
352+
endif
353+
354+
export quiet Q KBUILD_VERBOSE
355+
356+
225357
# Look for make include files relative to root of kernel src
226358
MAKEFLAGS += --include-dir=$(srctree)
227359

@@ -278,6 +410,31 @@ export DTC CHECK CHECKFLAGS
278410
export KBUILD_CPPFLAGS NOSTDINC_FLAGS UBOOTINCLUDE
279411
export KBUILD_CFLAGS KBUILD_AFLAGS
280412

413+
# When compiling out-of-tree modules, put MODVERDIR in the module
414+
# tree rather than in the kernel tree. The kernel tree might
415+
# even be read-only.
416+
export MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
417+
418+
# Files to ignore in find ... statements
419+
420+
RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS \
421+
-o -name .pc -o -name .hg -o -name .git \) -prune -o
422+
export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
423+
--exclude CVS --exclude .pc --exclude .hg --exclude .git
424+
425+
# ===========================================================================
426+
# Rules shared between *config targets and build targets
427+
428+
# Basic helpers built in scripts/
429+
PHONY += scripts_basic
430+
scripts_basic:
431+
$(Q)$(MAKE) $(build)=scripts/basic
432+
$(Q)rm -f .tmp_quiet_recordmcount
433+
434+
# To avoid any implicit rule to kick in, define an empty command.
435+
scripts/basic/%: scripts_basic ;
436+
437+
281438
KBUILD_CFLAGS += -Os #-fomit-frame-pointer
282439

283440
ifdef BUILD_TAG
@@ -333,6 +490,10 @@ endif
333490
endif
334491
endif
335492

493+
# FIX ME
494+
cpp_flags := $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
495+
c_flags := $(KBUILD_CFLAGS) $(cpp_flags)
496+
336497
# If board code explicitly specified LDSCRIPT or CONFIG_SYS_LDSCRIPT, use
337498
# that (or fail if absent). Otherwise, search for a linker script in a
338499
# standard location.
@@ -446,12 +607,12 @@ LIBS := $(sort $(LIBS-y))
446607
# Add GCC lib
447608
ifdef USE_PRIVATE_LIBGCC
448609
ifeq ("$(USE_PRIVATE_LIBGCC)", "yes")
449-
PLATFORM_LIBGCC = $(OBJTREE)/arch/$(ARCH)/lib/libgcc.o
610+
PLATFORM_LIBGCC = $(OBJTREE)/arch/$(ARCH)/lib/lib.a
450611
else
451612
PLATFORM_LIBGCC = -L $(USE_PRIVATE_LIBGCC) -lgcc
452613
endif
453614
else
454-
PLATFORM_LIBGCC := -L $(shell dirname `$(CC) $(CFLAGS) -print-libgcc-file-name`) -lgcc
615+
PLATFORM_LIBGCC := -L $(shell dirname `$(CC) $(c_flags) -print-libgcc-file-name`) -lgcc
455616
endif
456617
PLATFORM_LIBS += $(PLATFORM_LIBGCC)
457618
export PLATFORM_LIBS
@@ -701,35 +862,35 @@ u-boot: depend $(SUBDIR_TOOLS) $(OBJS) $(LIBS) u-boot.lds
701862
ifeq ($(CONFIG_KALLSYMS),y)
702863
smap=`$(call SYSTEM_MAP,u-boot) | \
703864
awk '$$2 ~ /[tTwW]/ {printf $$1 $$3 "\\\\000"}'` ; \
704-
$(CC) $(CFLAGS) -DSYSTEM_MAP="\"$${smap}\"" \
865+
$(CC) $(c_flags) -DSYSTEM_MAP="\"$${smap}\"" \
705866
-c $(srctree)/common/system_map.c -o common/system_map.o
706867
$(GEN_UBOOT) common/system_map.o
707868
endif
708869

709870
$(OBJS):
710871
@:
711872

712-
$(LIBS): depend $(SUBDIR_TOOLS)
713-
$(MAKE) $(build)=$(patsubst %/,%,$(dir $@))
873+
$(LIBS): depend $(SUBDIR_TOOLS) scripts_basic
874+
$(Q)$(MAKE) $(build)=$(patsubst %/,%,$(dir $@))
714875

715-
$(SUBDIRS): depend
716-
$(MAKE) $(build)=$@ all
876+
$(SUBDIRS): depend scripts_basic
877+
$(Q)$(MAKE) $(build)=$@
717878

718879
$(SUBDIR_EXAMPLES-y): u-boot
719880

720881
u-boot.lds: $(LDSCRIPT) depend
721-
$(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$< >$@
882+
$(CPP) $(cpp_flags) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$< >$@
722883

723-
nand_spl: $(TIMESTAMP_FILE) $(VERSION_FILE) depend
884+
nand_spl: $(TIMESTAMP_FILE) $(VERSION_FILE) depend scripts_basic
724885
$(MAKE) $(build)=nand_spl/board/$(BOARDDIR) all
725886

726887
u-boot-nand.bin: nand_spl u-boot.bin
727888
cat nand_spl/u-boot-spl-16k.bin u-boot.bin > u-boot-nand.bin
728889

729-
spl/u-boot-spl.bin: $(SUBDIR_TOOLS) depend
890+
spl/u-boot-spl.bin: $(SUBDIR_TOOLS) depend scripts_basic
730891
$(MAKE) obj=spl -f $(srctree)/spl/Makefile all
731892

732-
tpl/u-boot-tpl.bin: $(SUBDIR_TOOLS) depend
893+
tpl/u-boot-tpl.bin: $(SUBDIR_TOOLS) depend scripts_basic
733894
$(MAKE) obj=tpl -f $(srctree)/spl/Makefile all CONFIG_TPL_BUILD=y
734895

735896
# Explicitly make _depend in subdirs containing multiple targets to prevent
@@ -804,30 +965,30 @@ checkdtc:
804965
include/autoconf.mk.dep: include/config.h include/common.h
805966
@$(XECHO) Generating $@ ; \
806967
: Generate the dependancies ; \
807-
$(CC) -x c -DDO_DEPS_ONLY -M $(CFLAGS) $(CPPFLAGS) \
968+
$(CC) -x c -DDO_DEPS_ONLY -M $(c_flags) \
808969
-MQ include/autoconf.mk $(srctree)/include/common.h > $@ || \
809970
rm $@
810971

811972
include/autoconf.mk: include/config.h
812973
@$(XECHO) Generating $@ ; \
813974
: Extract the config macros ; \
814-
$(CPP) $(CFLAGS) -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && \
975+
$(CPP) $(c_flags) -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && \
815976
sed -n -f $(srctree)/tools/scripts/define2mk.sed $@.tmp > $@; \
816977
rm $@.tmp
817978

818979
# Auto-generate the spl-autoconf.mk file (which is included by all makefiles for SPL)
819980
include/tpl-autoconf.mk: include/config.h
820981
@$(XECHO) Generating $@ ; \
821982
: Extract the config macros ; \
822-
$(CPP) $(CFLAGS) -DCONFIG_TPL_BUILD -DCONFIG_SPL_BUILD\
983+
$(CPP) $(c_flags) -DCONFIG_TPL_BUILD -DCONFIG_SPL_BUILD\
823984
-DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && \
824985
sed -n -f $(srctree)/tools/scripts/define2mk.sed $@.tmp > $@; \
825986
rm $@.tmp
826987

827988
include/spl-autoconf.mk: include/config.h
828989
@$(XECHO) Generating $@ ; \
829990
: Extract the config macros ; \
830-
$(CPP) $(CFLAGS) -DCONFIG_SPL_BUILD -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && \
991+
$(CPP) $(c_flags) -DCONFIG_SPL_BUILD -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && \
831992
sed -n -f $(srctree)/tools/scripts/define2mk.sed $@.tmp > $@; \
832993
rm $@.tmp
833994

@@ -838,7 +999,7 @@ include/generated/generic-asm-offsets.h: lib/asm-offsets.s
838999
lib/asm-offsets.s: include/config.h $(srctree)/lib/asm-offsets.c
8391000
@mkdir -p lib
8401001
$(CC) -DDO_DEPS_ONLY \
841-
$(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR)) \
1002+
$(c_flags) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR)) \
8421003
-o $@ $(srctree)/lib/asm-offsets.c -c -S
8431004

8441005
include/generated/asm-offsets.h: $(CPUDIR)/$(SOC)/asm-offsets.s
@@ -849,7 +1010,7 @@ $(CPUDIR)/$(SOC)/asm-offsets.s: include/config.h
8491010
@mkdir -p $(CPUDIR)/$(SOC)
8501011
if [ -f $(srctree)/$(CPUDIR)/$(SOC)/asm-offsets.c ];then \
8511012
$(CC) -DDO_DEPS_ONLY \
852-
$(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR)) \
1013+
$(c_flags) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR)) \
8531014
-o $@ $(srctree)/$(CPUDIR)/$(SOC)/asm-offsets.c -c -S; \
8541015
else \
8551016
touch $@; \
@@ -900,15 +1061,15 @@ $(TIMESTAMP_FILE):
9001061
@cmp -s $@ $@.tmp && rm -f $@.tmp || mv -f $@.tmp $@
9011062

9021063
easylogo env gdb:
903-
$(MAKE) $(build)=tools/$@ MTD_VERSION=${MTD_VERSION}
1064+
$(Q)$(MAKE) $(build)=tools/$@ MTD_VERSION=${MTD_VERSION}
9041065

9051066
gdbtools: gdb
9061067

9071068
xmldocs pdfdocs psdocs htmldocs mandocs: tools/kernel-doc/docproc
908-
$(MAKE) U_BOOT_VERSION=$(U_BOOT_VERSION) $(build)=doc/DocBook $@
1069+
$(Q)$(MAKE) U_BOOT_VERSION=$(U_BOOT_VERSION) $(build)=doc/DocBook $@
9091070

9101071
tools-all: easylogo env gdb $(VERSION_FILE) $(TIMESTAMP_FILE)
911-
$(MAKE) $(build)=tools HOST_TOOLS_ALL=y
1072+
$(Q)$(MAKE) $(build)=tools HOST_TOOLS_ALL=y
9121073

9131074
.PHONY : CHANGELOG
9141075
CHANGELOG:
@@ -968,7 +1129,7 @@ clean:
9681129
@$(MAKE) -f $(srctree)/doc/DocBook/Makefile cleandocs
9691130
@find $(OBJTREE) -type f \
9701131
\( -name 'core' -o -name '*.bak' -o -name '*~' -o -name '*.su' \
971-
-o -name '*.o' -o -name '*.a' -o -name '*.exe' \
1132+
-o -name '*.o' -o -name '*.a' -o -name '*.exe' -o -name '*.cmd' \
9721133
-o -name '*.cfgtmp' \) -print \
9731134
| xargs rm -f
9741135

arch/arm/imx-common/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ obj-$(CONFIG_CMD_HDMIDETECT) += cmd_hdmidet.o
2525

2626
$(OBJTREE)/$(patsubst "%",%,$(CONFIG_IMX_CONFIG)).cfgtmp: $(OBJTREE)/%.cfgtmp : $(SRCTREE)/%
2727
mkdir -p $(dir $@)
28-
$(CC) -E -x c $< $(CPPFLAGS) -o $@
28+
$(CPP) $(cpp_flags) -x c -o $@ $<
2929

3030
$(OBJTREE)/u-boot.imx: $(OBJTREE)/u-boot.bin $(OBJTREE)/$(patsubst "%",%,$(CONFIG_IMX_CONFIG)).cfgtmp
3131
$(OBJTREE)/tools/mkimage -n $(filter-out %.bin,$^) -T imximage \

0 commit comments

Comments
 (0)