blob: e034dd65a5cee9ecbd922a4898ce9d3e0805bb10 [file] [log] [blame]
Anas Nashif7aa584d2015-08-03 15:42:21 -04001# vim: filetype=make
Anas Nashifc47769b2015-10-09 06:23:01 -04002#
3
Juan Manuel Cruz5516bca2016-04-27 10:15:14 -05004UNAME := $(shell uname)
5ifeq (MINGW, $(findstring MINGW, $(UNAME)))
Juan Manuel Cruz2bf22ae2016-08-22 17:22:07 -05006DQUOTE = '
7# '
Juan Manuel Cruz5516bca2016-04-27 10:15:14 -05008PROJECT_BASE ?= $(shell sh -c "pwd -W")
9else
Juan Manuel Cruz2bf22ae2016-08-22 17:22:07 -050010DQUOTE = "
11# "
Louise Mendoza0c3f05b2015-12-30 16:17:36 -060012PROJECT_BASE ?= $(CURDIR)
Juan Manuel Cruz5516bca2016-04-27 10:15:14 -050013endif
14
Andy Ross72f00d92016-08-23 12:32:20 -070015ifdef BOARD
Kumar Gala8d357602016-10-19 15:13:41 -050016KBUILD_DEFCONFIG_PATH=$(wildcard $(ZEPHYR_BASE)/boards/*/*/$(BOARD)_defconfig)
Andy Ross72f00d92016-08-23 12:32:20 -070017ifeq ($(KBUILD_DEFCONFIG_PATH),)
18$(error Board $(BOARD) not found!)
19endif
20else
21$(error BOARD is not defined!)
22endif
23
24# Choose a default output directory if one wasn't supplied. Note that
25# PRISTINE_O depends on whether this is default or not. If building
26# in-tree, we want to remove the whole outdir and not just the BOARD
27# specified (thus "pristine"). Out of tree, we can obviously remove
28# only what we were told to build.
29ifndef O
30PRISTINE_O = outdir
31O = $(PROJECT_BASE)/outdir/$(BOARD)
32else
33PRISTINE_O = $(O)
34endif
Anas Nashiffde80d72015-08-22 14:40:43 -040035
Andrew Boieca12bbb2015-07-22 16:15:43 -070036# Turn O into an absolute path; we call the main Kbuild with $(MAKE) -C
37# which changes the working directory, relative paths don't work right.
Anas Nashif182a6462015-11-27 10:04:08 -050038# Need to create the directory first to make realpath happy
Anas Nashif71d22152016-01-30 05:36:52 -050039
40ifneq ($(MAKECMDGOALS),help)
Andrew Boieca12bbb2015-07-22 16:15:43 -070041$(shell mkdir -p $(O))
Anas Nashif182a6462015-11-27 10:04:08 -050042override O := $(realpath $(O))
Anas Nashif71d22152016-01-30 05:36:52 -050043endif
Dirk Brandewie6fa99f82015-06-01 09:48:10 -070044
Anas Nashif45a7e5d2017-04-18 16:42:09 -040045export ARCH QEMU_EXTRA_FLAGS PROJECT_BASE
Juan Manuel Cruz9e4b2bb2015-05-05 17:21:55 -050046
Anas Nashif71d22152016-01-30 05:36:52 -050047override CONF_FILE := $(strip $(subst $(DQUOTE),,$(CONF_FILE)))
Anas Nashif2ce8d302015-10-03 10:24:57 -040048
Andrew Boie9132a132015-07-17 12:03:52 -070049SOURCE_DIR ?= $(PROJECT_BASE)/src/
Juan Manuel Cruz941059c2016-08-26 17:24:13 -050050override SOURCE_DIR := $(realpath $(SOURCE_DIR))
Yonattan Louise4a2ce3c2015-12-30 17:38:26 -060051override SOURCE_DIR := $(subst \,/,$(SOURCE_DIR))
Kumar Gala23af1e92016-06-03 09:51:56 -050052override SOURCE_DIR_PARENT := $(patsubst %, %/.., $(SOURCE_DIR))
53override SOURCE_DIR_PARENT := $(abspath $(SOURCE_DIR_PARENT))
54override SOURCE_DIR_PARENT := $(subst \,/,$(SOURCE_DIR_PARENT))
55export SOURCE_DIR SOURCE_DIR_PARENT
Juan Manuel Cruz988236f2015-05-21 11:08:16 -050056
Juan Manuel Cruzdc2b1f12015-05-26 16:50:44 -050057ifeq ("$(origin V)", "command line")
58 KBUILD_VERBOSE = $(V)
59endif
60ifndef KBUILD_VERBOSE
61 KBUILD_VERBOSE = 0
62endif
63
64ifeq ($(KBUILD_VERBOSE),1)
65 Q =
66 S =
67else
68 Q = @
69 S = -s
70endif
71
Caio Marcelo de Oliveira Filhoe450b2d2016-05-20 11:54:53 -030072export CFLAGS
73
Kumar Gala5ccf5292016-06-03 13:34:18 -050074zephyrmake = +$(MAKE) -C $(ZEPHYR_BASE) O=$(1) \
Juan Manuel Cruz2bf22ae2016-08-22 17:22:07 -050075 PROJECT=$(PROJECT_BASE) SOURCE_DIR=$(DQUOTE)$(SOURCE_DIR)$(DQUOTE) $(2)
Anas Nashiffde80d72015-08-22 14:40:43 -040076
Anas Nashifa0cf03b2016-05-14 21:56:35 -040077BOARDCONFIG = $(O)/.board_$(BOARD)
78
Anas Nashiffbed1e42015-08-28 15:42:03 -040079DOTCONFIG = $(O)/.config
80
81all: $(DOTCONFIG)
Anas Nashiffde80d72015-08-22 14:40:43 -040082 $(Q)$(call zephyrmake,$(O),$@)
Juan Manuel Cruz4ee8a8e2015-02-21 16:05:51 -060083
Anas Nashifa49762c2016-02-01 22:24:21 -050084debug: $(DOTCONFIG)
85 $(Q)$(call zephyrmake,$(O),$@)
Anas Nashif51be9a52016-01-15 12:18:53 -050086
87flash: $(DOTCONFIG)
88 $(Q)$(call zephyrmake,$(O),$@)
89
Anas Nashif2bc9d692017-01-07 16:31:34 -050090run: $(DOTCONFIG)
91 $(Q)$(call zephyrmake,$(O),$@)
92
Kumar Gala94551722017-03-09 01:20:20 -060093ifeq ($(MAKECMDGOALS),debugserver)
jing wangcea9bb92016-11-10 13:34:19 +080094ARCH = $(notdir $(subst /$(BOARD),,$(wildcard $(ZEPHYR_BASE)/boards/*/$(BOARD))))
Anas Nashif16753b72017-07-31 12:27:45 -040095BOARD_DIR = $(dir $(wildcard $(ZEPHYR_BASE)/boards/*/*/$(BOARD)_defconfig))
96-include $(BOARD_DIR)/Makefile.board
Anas Nashif54634d62016-02-01 19:42:54 -050097-include $(ZEPHYR_BASE)/scripts/Makefile.toolchain.$(ZEPHYR_GCC_VARIANT)
98BOARD_NAME = $(BOARD)
99export BOARD_NAME
100endif
Anas Nashif6d9ed992017-01-07 13:22:21 -0500101
Anas Nashif54634d62016-02-01 19:42:54 -0500102debugserver: FORCE
Anas Nashif6d9ed992017-01-07 13:22:21 -0500103 $(Q)$(CONFIG_SHELL) $(ZEPHYR_BASE)/scripts/support/$(DEBUG_SCRIPT) debugserver
Anas Nashif54634d62016-02-01 19:42:54 -0500104
Andy Gross47eb5bf2017-04-18 23:36:01 -0500105initconfig: $(DOTCONFIG)
Anas Nashiff5e3be22015-10-03 17:49:46 -0400106
Anas Nashifa0cf03b2016-05-14 21:56:35 -0400107$(BOARDCONFIG):
108 @rm -f $(O)/.board_*
109 @touch $@
110
Anas Nashif6361be22016-05-22 12:34:06 -0400111ram_report: initconfig
112 $(Q)$(call zephyrmake,$(O),$@)
113
114rom_report: initconfig
115 $(Q)$(call zephyrmake,$(O),$@)
116
Andy Gross47eb5bf2017-04-18 23:36:01 -0500117outputexports: initconfig
118 $(Q)$(call zephyrmake,$(O),$@)
119
Andy Grossc8112aa2017-04-18 23:43:58 -0500120dts: initconfig
121 $(Q)$(call zephyrmake,$(O),$@)
122
Andy Gross1e72c1e2017-06-06 21:23:33 -0500123config-sanitycheck: dts
124 $(Q)$(call zephyrmake,$(O),$@)
125
Anas Nashiffa2e18b2015-10-14 17:42:59 -0400126menuconfig: initconfig
127 $(Q)$(call zephyrmake,$(O),$@)
128
Anas Nashif71d22152016-01-30 05:36:52 -0500129help:
130 $(Q)$(MAKE) -s -C $(ZEPHYR_BASE) $@
131
Anas Nashiffbed1e42015-08-28 15:42:03 -0400132# Catch all
133%:
134 $(Q)$(call zephyrmake,$(O),$@)
Juan Manuel Cruz52c9d872015-06-05 11:08:43 -0500135
Anas Nashifa0cf03b2016-05-14 21:56:35 -0400136$(DOTCONFIG): $(BOARDCONFIG) $(KBUILD_DEFCONFIG_PATH) $(CONF_FILE)
Anas Nashife80edfc2015-08-28 14:22:29 -0400137 $(Q)$(CONFIG_SHELL) $(ZEPHYR_BASE)/scripts/kconfig/merge_config.sh \
Anas Nashif66cfcc22016-12-21 14:38:37 -0500138 -q -m -O $(O) $(KBUILD_DEFCONFIG_PATH) $(OVERLAY_CONFIG) $(CONF_FILE) \
Inaky Perez-Gonzalez27482312016-08-31 15:19:11 -0700139 $(wildcard $(O)/*.conf)
Anas Nashifc4ad67d2015-11-26 20:39:26 -0500140 $(Q)$(MAKE) $(S) -C $(ZEPHYR_BASE) O=$(O) PROJECT=$(PROJECT_BASE) oldnoconfig
Anas Nashiffde80d72015-08-22 14:40:43 -0400141
142pristine:
Andy Ross72f00d92016-08-23 12:32:20 -0700143 $(Q)rm -rf $(PRISTINE_O)
Juan Manuel Cruz9e4b2bb2015-05-05 17:21:55 -0500144
Anas Nashiff5e3be22015-10-03 17:49:46 -0400145PHONY += FORCE initconfig
Anas Nashife80edfc2015-08-28 14:22:29 -0400146FORCE:
Anas Nashiffde80d72015-08-22 14:40:43 -0400147
Juan Manuel Cruz4ee8a8e2015-02-21 16:05:51 -0600148.PHONY: $(PHONY)