Commit 433b2f1e5a837426b3269a83a81bc572c3beaf75

Authored by Masahiro Yamada
Committed by Tom Rini
1 parent 7390643f7b

kbuild: change the top Makefile to more Kbuild-ish structure

This commit changes the top Makefile to handle various targets
nicely.
Make targets are divided into four categories:

 - mixed-targets
     We can call a configuration target and build targets
     at one command line like follows:
     $ make <board_name>_config u-boot

     They are handled one by one.

 - config targets
     <board_name>_config

 - no-dot-config-targets
     Targets we can run without board configuration such as
       clean, mrproper, distclean, TAGS, %docs, etc.

 - build targets
     The other target which need board configuration.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>

Showing 1 changed file with 167 additions and 123 deletions Side-by-side Diff

... ... @@ -203,34 +203,6 @@
203 203  
204 204 #########################################################################
205 205  
206   -# The "tools" are needed early, so put this first
207   -# Don't include stuff already done in $(LIBS)
208   -# The "examples" conditionally depend on U-Boot (say, when USE_PRIVATE_LIBGCC
209   -# is "yes"), so compile examples after U-Boot is compiled.
210   -SUBDIR_TOOLS = tools
211   -SUBDIRS = $(SUBDIR_TOOLS)
212   -
213   -.PHONY : $(SUBDIRS) $(VERSION_FILE) $(TIMESTAMP_FILE)
214   -
215   -ifeq (include/config.mk,$(wildcard include/config.mk))
216   -
217   -# Include autoconf.mk before config.mk so that the config options are available
218   -# to all top level build files. We need the dummy all: target to prevent the
219   -# dependency target in autoconf.mk.dep from being the default.
220   -all:
221   -sinclude include/autoconf.mk.dep
222   -sinclude include/autoconf.mk
223   -
224   -SUBDIR_EXAMPLES-y := examples/standalone
225   -SUBDIR_EXAMPLES-$(CONFIG_API) += examples/api
226   -ifndef CONFIG_SANDBOX
227   -SUBDIRS += $(SUBDIR_EXAMPLES-y)
228   -endif
229   -
230   -# load ARCH, BOARD, and CPU configuration
231   -include include/config.mk
232   -export ARCH CPU BOARD VENDOR SOC
233   -
234 206 # set default to nothing for native builds
235 207 ifeq ($(HOSTARCH),$(ARCH))
236 208 CROSS_COMPILE ?=
... ... @@ -377,15 +349,6 @@
377 349 CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
378 350 -Wbitwise -Wno-return-void -D__CHECK_ENDIAN__ $(CF)
379 351  
380   -# Use UBOOTINCLUDE when you must reference the include/ directory.
381   -# Needed to be compatible with the O= option
382   -UBOOTINCLUDE :=
383   -ifneq ($(OBJTREE),$(SRCTREE))
384   -UBOOTINCLUDE += -I$(OBJTREE)/include
385   -endif
386   -UBOOTINCLUDE += -I$(srctree)/include \
387   - -I$(srctree)/arch/$(ARCH)/include
388   -
389 352 KBUILD_CPPFLAGS := -D__KERNEL__
390 353  
391 354 KBUILD_CFLAGS := -Wall -Wstrict-prototypes \
... ... @@ -396,6 +359,7 @@
396 359 U_BOOT_VERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
397 360  
398 361 export VERSION PATCHLEVEL SUBLEVEL U_BOOT_VERSION
  362 +export ARCH CPU BOARD VENDOR SOC
399 363 export CONFIG_SHELL HOSTCC HOSTCFLAGS HOSTLDFLAGS CROSS_COMPILE AS LD CC
400 364 export CPP AR NM LDR STRIP OBJCOPY OBJDUMP
401 365 export MAKE AWK
402 366  
403 367  
404 368  
405 369  
406 370  
407 371  
408 372  
409 373  
410 374  
411 375  
412 376  
413 377  
414 378  
415 379  
416 380  
417 381  
... ... @@ -428,66 +392,85 @@
428 392 # To avoid any implicit rule to kick in, define an empty command.
429 393 scripts/basic/%: scripts_basic ;
430 394  
  395 +# To make sure we do not include .config for any of the *config targets
  396 +# catch them early, and hand them over to scripts/kconfig/Makefile
  397 +# It is allowed to specify more targets when calling make, including
  398 +# mixing *config targets and build targets.
  399 +# For example 'make oldconfig all'.
  400 +# Detect when mixed targets is specified, and make a second invocation
  401 +# of make so .config is not included in this case either (for *config).
431 402  
432   -KBUILD_CFLAGS += -Os #-fomit-frame-pointer
  403 +no-dot-config-targets := clean clobber mrproper distclean \
  404 + cscope TAGS %tags help %docs check% coccicheck \
  405 + backup
433 406  
434   -ifdef BUILD_TAG
435   -KBUILD_CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"'
  407 +config-targets := 0
  408 +mixed-targets := 0
  409 +dot-config := 1
  410 +
  411 +ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
  412 + ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
  413 + dot-config := 0
  414 + endif
436 415 endif
437 416  
438   -KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
  417 +ifeq ($(KBUILD_EXTMOD),)
  418 + ifneq ($(filter config %config,$(MAKECMDGOALS)),)
  419 + config-targets := 1
  420 + ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
  421 + mixed-targets := 1
  422 + endif
  423 + endif
  424 +endif
439 425  
440   -KBUILD_CFLAGS += -g
441   -# $(KBUILD_AFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
442   -# option to the assembler.
443   -KBUILD_AFLAGS += -g
  426 +ifeq ($(mixed-targets),1)
  427 +# ===========================================================================
  428 +# We're called with mixed targets (*config and build targets).
  429 +# Handle them one by one.
444 430  
445   -NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
446   -CHECKFLAGS += $(NOSTDINC_FLAGS)
  431 +%:: FORCE
  432 + $(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@
447 433  
448   -# Report stack usage if supported
449   -KBUILD_CFLAGS += $(call cc-option,-fstack-usage)
  434 +else
  435 +ifeq ($(config-targets),1)
  436 +# ===========================================================================
  437 +# *config targets only - make sure prerequisites are updated, and descend
  438 +# in scripts/kconfig to make the *config target
450 439  
451   -KBUILD_CFLAGS += $(call cc-option,-Wno-format-nonliteral)
  440 +# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
  441 +# KBUILD_DEFCONFIG may point out an alternative default configuration
  442 +# used for 'make defconfig'
452 443  
453   -# turn jbsr into jsr for m68k
454   -ifeq ($(ARCH),m68k)
455   -ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
456   -KBUILD_AFLAGS += -Wa,-gstabs,-S
457   -endif
458   -endif
  444 +%_config::
  445 + @$(MKCONFIG) -A $(@:_config=)
459 446  
460   -# load other configuration
461   -include $(TOPDIR)/config.mk
  447 +else
  448 +# ===========================================================================
  449 +# Build targets only - this includes vmlinux, arch specific targets, clean
  450 +# targets and others. In general all targets except *config targets.
462 451  
463   -ifneq ($(CONFIG_SYS_TEXT_BASE),)
464   -KBUILD_CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE)
465   -endif
  452 +# load ARCH, BOARD, and CPU configuration
  453 +-include include/config.mk
466 454  
467   -export CONFIG_SYS_TEXT_BASE
  455 +ifeq ($(dot-config),1)
  456 +# Read in config
  457 +-include include/autoconf.mk
  458 +-include include/autoconf.mk.dep
468 459  
469   -LDFLAGS_u-boot += -T u-boot.lds $(LDFLAGS_FINAL)
470   -ifneq ($(CONFIG_SYS_TEXT_BASE),)
471   -LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)
  460 +# load other configuration
  461 +include $(srctree)/config.mk
  462 +
  463 +ifeq ($(wildcard include/config.mk),)
  464 +$(error "System not configured - see README")
472 465 endif
473 466  
474   -# Targets which don't build the source code
475   -NON_BUILD_TARGETS = backup clean clobber distclean mrproper unconfig %_config
476   -
477   -# Only do the generic board check when actually building, not configuring
478   -ifeq ($(filter $(NON_BUILD_TARGETS),$(MAKECMDGOALS)),)
479 467 ifeq ($(__HAVE_ARCH_GENERIC_BOARD),)
480 468 ifneq ($(CONFIG_SYS_GENERIC_BOARD),)
481   -CHECK_GENERIC_BOARD = $(error Your architecture does not support generic board. \
  469 +$(error Your architecture does not support generic board. \
482 470 Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file)
483 471 endif
484 472 endif
485   -endif
486 473  
487   -# FIX ME
488   -cpp_flags := $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
489   -c_flags := $(KBUILD_CFLAGS) $(cpp_flags)
490   -
491 474 # If board code explicitly specified LDSCRIPT or CONFIG_SYS_LDSCRIPT, use
492 475 # that (or fail if absent). Otherwise, search for a linker script in a
493 476 # standard location.
... ... @@ -526,6 +509,73 @@
526 509 endif
527 510 endif
528 511  
  512 +else
  513 +
  514 +
  515 +endif # $(dot-config)
  516 +
  517 +KBUILD_CFLAGS += -Os #-fomit-frame-pointer
  518 +
  519 +ifdef BUILD_TAG
  520 +KBUILD_CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"'
  521 +endif
  522 +
  523 +KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
  524 +
  525 +KBUILD_CFLAGS += -g
  526 +# $(KBUILD_AFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
  527 +# option to the assembler.
  528 +KBUILD_AFLAGS += -g
  529 +
  530 +# Report stack usage if supported
  531 +KBUILD_CFLAGS += $(call cc-option,-fstack-usage)
  532 +
  533 +KBUILD_CFLAGS += $(call cc-option,-Wno-format-nonliteral)
  534 +
  535 +# turn jbsr into jsr for m68k
  536 +ifeq ($(ARCH),m68k)
  537 +ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
  538 +KBUILD_AFLAGS += -Wa,-gstabs,-S
  539 +endif
  540 +endif
  541 +
  542 +ifneq ($(CONFIG_SYS_TEXT_BASE),)
  543 +KBUILD_CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE)
  544 +endif
  545 +
  546 +export CONFIG_SYS_TEXT_BASE
  547 +
  548 +# Use UBOOTINCLUDE when you must reference the include/ directory.
  549 +# Needed to be compatible with the O= option
  550 +UBOOTINCLUDE :=
  551 +ifneq ($(OBJTREE),$(SRCTREE))
  552 +UBOOTINCLUDE += -I$(OBJTREE)/include
  553 +endif
  554 +UBOOTINCLUDE += -I$(srctree)/include \
  555 + -I$(srctree)/arch/$(ARCH)/include
  556 +
  557 +NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
  558 +CHECKFLAGS += $(NOSTDINC_FLAGS)
  559 +
  560 +# FIX ME
  561 +cpp_flags := $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
  562 +c_flags := $(KBUILD_CFLAGS) $(cpp_flags)
  563 +
  564 +# The "tools" are needed early, so put this first
  565 +# Don't include stuff already done in $(LIBS)
  566 +# The "examples" conditionally depend on U-Boot (say, when USE_PRIVATE_LIBGCC
  567 +# is "yes"), so compile examples after U-Boot is compiled.
  568 +SUBDIR_TOOLS = tools
  569 +SUBDIRS = $(SUBDIR_TOOLS)
  570 +
  571 +.PHONY : $(SUBDIRS) $(VERSION_FILE) $(TIMESTAMP_FILE)
  572 +
  573 +SUBDIR_EXAMPLES-y := examples/standalone
  574 +SUBDIR_EXAMPLES-$(CONFIG_API) += examples/api
  575 +ifndef CONFIG_SANDBOX
  576 +SUBDIRS += $(SUBDIR_EXAMPLES-y)
  577 +endif
  578 +
529 579 #########################################################################
530 580 # U-Boot objects....order is important (i.e. start must be first)
531 581  
... ... @@ -675,6 +725,11 @@
675 725 endif
676 726 endif
677 727  
  728 +LDFLAGS_u-boot += -T u-boot.lds $(LDFLAGS_FINAL)
  729 +ifneq ($(CONFIG_SYS_TEXT_BASE),)
  730 +LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)
  731 +endif
  732 +
678 733 all: $(ALL-y) $(SUBDIR_EXAMPLES-y)
679 734  
680 735 u-boot.dtb: checkdtc u-boot
681 736  
... ... @@ -867,11 +922,34 @@
867 922 $(LIBS): depend $(SUBDIR_TOOLS) scripts_basic
868 923 $(Q)$(MAKE) $(build)=$(patsubst %/,%,$(dir $@))
869 924  
870   -$(SUBDIRS): depend scripts_basic
  925 +$(SUBDIRS): scripts_basic $(TIMESTAMP_FILE) $(VERSION_FILE)
871 926 $(Q)$(MAKE) $(build)=$@
872 927  
873 928 $(SUBDIR_EXAMPLES-y): u-boot
874 929  
  930 +#
  931 +# Auto-generate the autoconf.mk file (which is included by all makefiles)
  932 +#
  933 +# This target actually generates 2 files; autoconf.mk and autoconf.mk.dep.
  934 +# the dep file is only include in this top level makefile to determine when
  935 +# to regenerate the autoconf.mk file.
  936 +
  937 +quiet_cmd_autoconf_dep = GEN $@
  938 + cmd_autoconf_dep = $(CC) -x c -DDO_DEPS_ONLY -M $(c_flags) \
  939 + -MQ include/autoconf.mk $(srctree)/include/common.h > $@ || rm $@
  940 +
  941 +include/autoconf.mk.dep: include/config.h include/common.h
  942 + $(call cmd,autoconf_dep)
  943 +
  944 +quiet_cmd_autoconf = GEN $@
  945 + cmd_autoconf = \
  946 + $(CPP) $(c_flags) -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && \
  947 + sed -n -f $(srctree)/tools/scripts/define2mk.sed $@.tmp > $@; \
  948 + rm $@.tmp
  949 +
  950 +include/autoconf.mk: include/config.h
  951 + $(call cmd,autoconf)
  952 +
875 953 u-boot.lds: $(LDSCRIPT) depend
876 954 $(CPP) $(cpp_flags) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$< >$@
877 955  
... ... @@ -948,29 +1026,6 @@
948 1026 false; \
949 1027 fi
950 1028  
951   -#
952   -# Auto-generate the autoconf.mk file (which is included by all makefiles)
953   -#
954   -# This target actually generates 2 files; autoconf.mk and autoconf.mk.dep.
955   -# the dep file is only include in this top level makefile to determine when
956   -# to regenerate the autoconf.mk file.
957   -
958   -quiet_cmd_autoconf_dep = GEN $@
959   - cmd_autoconf_dep = $(CC) -x c -DDO_DEPS_ONLY -M $(c_flags) \
960   - -MQ include/autoconf.mk $(srctree)/include/common.h > $@ || rm $@
961   -
962   -include/autoconf.mk.dep: include/config.h include/common.h
963   - $(call cmd,autoconf_dep)
964   -
965   -quiet_cmd_autoconf = GEN $@
966   - cmd_autoconf = \
967   - $(CPP) $(c_flags) -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && \
968   - sed -n -f $(srctree)/tools/scripts/define2mk.sed $@.tmp > $@; \
969   - rm $@.tmp
970   -
971   -include/autoconf.mk: include/config.h
972   - $(call cmd,autoconf)
973   -
974 1029 quiet_cmd_offsets = GEN $@
975 1030 cmd_offsets = $(srctree)/tools/scripts/make-asm-offsets $< $@
976 1031  
977 1032  
... ... @@ -1003,18 +1058,7 @@
1003 1058 $(call cmd,soc_asm-offsets.s)
1004 1059  
1005 1060 #########################################################################
1006   -else # !config.mk
1007   -all u-boot.hex u-boot.srec u-boot.bin \
1008   -u-boot.img u-boot.dis u-boot \
1009   -$(filter-out tools,$(SUBDIRS)) \
1010   -depend dep tags ctags etags cscope System.map:
1011   - @echo "System not configured - see README" >&2
1012   - @ exit 1
1013 1061  
1014   -tools: $(VERSION_FILE) $(TIMESTAMP_FILE)
1015   - $(MAKE) $(build)=$@ all
1016   -endif # config.mk
1017   -
1018 1062 # ARM relocations should all be R_ARM_RELATIVE (32-bit) or
1019 1063 # R_AARCH64_RELATIVE (64-bit).
1020 1064 checkarmreloc: u-boot
1021 1065  
... ... @@ -1066,16 +1110,7 @@
1066 1110 cat COPYING | gzip -9 -c | ./tools/bin2header license_gzip > include/license.h
1067 1111 #########################################################################
1068 1112  
1069   -unconfig:
1070   - @rm -f include/config.h include/config.mk \
1071   - board/*/config.tmp board/*/*/config.tmp \
1072   - include/autoconf.mk include/autoconf.mk.dep \
1073   - include/spl-autoconf.mk \
1074   - include/tpl-autoconf.mk
1075 1113  
1076   -%_config:: unconfig
1077   - @$(MKCONFIG) -A $(@:_config=)
1078   -
1079 1114 #########################################################################
1080 1115  
1081 1116 clean:
... ... @@ -1151,8 +1186,14 @@
1151 1186 @rm -f dts/*.tmp
1152 1187 @rm -f $(addprefix spl/, u-boot-spl.ais, u-boot-spl-pad.ais)
1153 1188  
1154   -mrproper \
1155   -distclean: clobber unconfig
  1189 +mrproper: clobber
  1190 + @rm -f include/config.h include/config.mk \
  1191 + board/*/config.tmp board/*/*/config.tmp \
  1192 + include/autoconf.mk include/autoconf.mk.dep \
  1193 + include/spl-autoconf.mk \
  1194 + include/tpl-autoconf.mk
  1195 +
  1196 +distclean: mrproper
1156 1197 ifneq ($(OBJTREE),$(SRCTREE))
1157 1198 rm -rf *
1158 1199 endif
... ... @@ -1162,6 +1203,9 @@
1162 1203 gtar --force-local -zcvf `LC_ALL=C date "+$$F-%Y-%m-%d-%T.tar.gz"` $$F
1163 1204  
1164 1205 #########################################################################
  1206 +
  1207 +endif #ifeq ($(config-targets),1)
  1208 +endif #ifeq ($(mixed-targets),1)
1165 1209  
1166 1210 endif # skip-makefile
1167 1211