Anas Nashif | 7aa584d | 2015-08-03 15:42:21 -0400 | [diff] [blame] | 1 | # vim: filetype=make |
Anas Nashif | c47769b | 2015-10-09 06:23:01 -0400 | [diff] [blame] | 2 | # |
| 3 | |
Juan Manuel Cruz | 5516bca | 2016-04-27 10:15:14 -0500 | [diff] [blame] | 4 | UNAME := $(shell uname) |
| 5 | ifeq (MINGW, $(findstring MINGW, $(UNAME))) |
Juan Manuel Cruz | 2bf22ae | 2016-08-22 17:22:07 -0500 | [diff] [blame] | 6 | DQUOTE = ' |
| 7 | # ' |
Juan Manuel Cruz | 5516bca | 2016-04-27 10:15:14 -0500 | [diff] [blame] | 8 | PROJECT_BASE ?= $(shell sh -c "pwd -W") |
| 9 | else |
Juan Manuel Cruz | 2bf22ae | 2016-08-22 17:22:07 -0500 | [diff] [blame] | 10 | DQUOTE = " |
| 11 | # " |
Louise Mendoza | 0c3f05b | 2015-12-30 16:17:36 -0600 | [diff] [blame] | 12 | PROJECT_BASE ?= $(CURDIR) |
Juan Manuel Cruz | 5516bca | 2016-04-27 10:15:14 -0500 | [diff] [blame] | 13 | endif |
| 14 | |
Andy Ross | 72f00d9 | 2016-08-23 12:32:20 -0700 | [diff] [blame] | 15 | ifdef BOARD |
Kumar Gala | 8d35760 | 2016-10-19 15:13:41 -0500 | [diff] [blame] | 16 | KBUILD_DEFCONFIG_PATH=$(wildcard $(ZEPHYR_BASE)/boards/*/*/$(BOARD)_defconfig) |
Andy Ross | 72f00d9 | 2016-08-23 12:32:20 -0700 | [diff] [blame] | 17 | ifeq ($(KBUILD_DEFCONFIG_PATH),) |
| 18 | $(error Board $(BOARD) not found!) |
| 19 | endif |
| 20 | else |
| 21 | $(error BOARD is not defined!) |
| 22 | endif |
| 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. |
| 29 | ifndef O |
| 30 | PRISTINE_O = outdir |
| 31 | O = $(PROJECT_BASE)/outdir/$(BOARD) |
| 32 | else |
| 33 | PRISTINE_O = $(O) |
| 34 | endif |
Anas Nashif | fde80d7 | 2015-08-22 14:40:43 -0400 | [diff] [blame] | 35 | |
Andrew Boie | ca12bbb | 2015-07-22 16:15:43 -0700 | [diff] [blame] | 36 | # 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 Nashif | 182a646 | 2015-11-27 10:04:08 -0500 | [diff] [blame] | 38 | # Need to create the directory first to make realpath happy |
Anas Nashif | 71d2215 | 2016-01-30 05:36:52 -0500 | [diff] [blame] | 39 | |
| 40 | ifneq ($(MAKECMDGOALS),help) |
Andrew Boie | ca12bbb | 2015-07-22 16:15:43 -0700 | [diff] [blame] | 41 | $(shell mkdir -p $(O)) |
Anas Nashif | 182a646 | 2015-11-27 10:04:08 -0500 | [diff] [blame] | 42 | override O := $(realpath $(O)) |
Anas Nashif | 71d2215 | 2016-01-30 05:36:52 -0500 | [diff] [blame] | 43 | endif |
Dirk Brandewie | 6fa99f8 | 2015-06-01 09:48:10 -0700 | [diff] [blame] | 44 | |
Anas Nashif | 45a7e5d | 2017-04-18 16:42:09 -0400 | [diff] [blame] | 45 | export ARCH QEMU_EXTRA_FLAGS PROJECT_BASE |
Juan Manuel Cruz | 9e4b2bb | 2015-05-05 17:21:55 -0500 | [diff] [blame] | 46 | |
Anas Nashif | 71d2215 | 2016-01-30 05:36:52 -0500 | [diff] [blame] | 47 | override CONF_FILE := $(strip $(subst $(DQUOTE),,$(CONF_FILE))) |
Anas Nashif | 2ce8d30 | 2015-10-03 10:24:57 -0400 | [diff] [blame] | 48 | |
Andrew Boie | 9132a13 | 2015-07-17 12:03:52 -0700 | [diff] [blame] | 49 | SOURCE_DIR ?= $(PROJECT_BASE)/src/ |
Juan Manuel Cruz | 941059c | 2016-08-26 17:24:13 -0500 | [diff] [blame] | 50 | override SOURCE_DIR := $(realpath $(SOURCE_DIR)) |
Yonattan Louise | 4a2ce3c | 2015-12-30 17:38:26 -0600 | [diff] [blame] | 51 | override SOURCE_DIR := $(subst \,/,$(SOURCE_DIR)) |
Kumar Gala | 23af1e9 | 2016-06-03 09:51:56 -0500 | [diff] [blame] | 52 | override SOURCE_DIR_PARENT := $(patsubst %, %/.., $(SOURCE_DIR)) |
| 53 | override SOURCE_DIR_PARENT := $(abspath $(SOURCE_DIR_PARENT)) |
| 54 | override SOURCE_DIR_PARENT := $(subst \,/,$(SOURCE_DIR_PARENT)) |
| 55 | export SOURCE_DIR SOURCE_DIR_PARENT |
Juan Manuel Cruz | 988236f | 2015-05-21 11:08:16 -0500 | [diff] [blame] | 56 | |
Juan Manuel Cruz | dc2b1f1 | 2015-05-26 16:50:44 -0500 | [diff] [blame] | 57 | ifeq ("$(origin V)", "command line") |
| 58 | KBUILD_VERBOSE = $(V) |
| 59 | endif |
| 60 | ifndef KBUILD_VERBOSE |
| 61 | KBUILD_VERBOSE = 0 |
| 62 | endif |
| 63 | |
| 64 | ifeq ($(KBUILD_VERBOSE),1) |
| 65 | Q = |
| 66 | S = |
| 67 | else |
| 68 | Q = @ |
| 69 | S = -s |
| 70 | endif |
| 71 | |
Caio Marcelo de Oliveira Filho | e450b2d | 2016-05-20 11:54:53 -0300 | [diff] [blame] | 72 | export CFLAGS |
| 73 | |
Kumar Gala | 5ccf529 | 2016-06-03 13:34:18 -0500 | [diff] [blame] | 74 | zephyrmake = +$(MAKE) -C $(ZEPHYR_BASE) O=$(1) \ |
Juan Manuel Cruz | 2bf22ae | 2016-08-22 17:22:07 -0500 | [diff] [blame] | 75 | PROJECT=$(PROJECT_BASE) SOURCE_DIR=$(DQUOTE)$(SOURCE_DIR)$(DQUOTE) $(2) |
Anas Nashif | fde80d7 | 2015-08-22 14:40:43 -0400 | [diff] [blame] | 76 | |
Anas Nashif | a0cf03b | 2016-05-14 21:56:35 -0400 | [diff] [blame] | 77 | BOARDCONFIG = $(O)/.board_$(BOARD) |
| 78 | |
Anas Nashif | fbed1e4 | 2015-08-28 15:42:03 -0400 | [diff] [blame] | 79 | DOTCONFIG = $(O)/.config |
| 80 | |
| 81 | all: $(DOTCONFIG) |
Anas Nashif | fde80d7 | 2015-08-22 14:40:43 -0400 | [diff] [blame] | 82 | $(Q)$(call zephyrmake,$(O),$@) |
Juan Manuel Cruz | 4ee8a8e | 2015-02-21 16:05:51 -0600 | [diff] [blame] | 83 | |
Anas Nashif | a49762c | 2016-02-01 22:24:21 -0500 | [diff] [blame] | 84 | debug: $(DOTCONFIG) |
| 85 | $(Q)$(call zephyrmake,$(O),$@) |
Anas Nashif | 51be9a5 | 2016-01-15 12:18:53 -0500 | [diff] [blame] | 86 | |
| 87 | flash: $(DOTCONFIG) |
| 88 | $(Q)$(call zephyrmake,$(O),$@) |
| 89 | |
Anas Nashif | 2bc9d69 | 2017-01-07 16:31:34 -0500 | [diff] [blame] | 90 | run: $(DOTCONFIG) |
| 91 | $(Q)$(call zephyrmake,$(O),$@) |
| 92 | |
Kumar Gala | 9455172 | 2017-03-09 01:20:20 -0600 | [diff] [blame] | 93 | ifeq ($(MAKECMDGOALS),debugserver) |
jing wang | cea9bb9 | 2016-11-10 13:34:19 +0800 | [diff] [blame] | 94 | ARCH = $(notdir $(subst /$(BOARD),,$(wildcard $(ZEPHYR_BASE)/boards/*/$(BOARD)))) |
Anas Nashif | 16753b7 | 2017-07-31 12:27:45 -0400 | [diff] [blame] | 95 | BOARD_DIR = $(dir $(wildcard $(ZEPHYR_BASE)/boards/*/*/$(BOARD)_defconfig)) |
| 96 | -include $(BOARD_DIR)/Makefile.board |
Anas Nashif | 54634d6 | 2016-02-01 19:42:54 -0500 | [diff] [blame] | 97 | -include $(ZEPHYR_BASE)/scripts/Makefile.toolchain.$(ZEPHYR_GCC_VARIANT) |
| 98 | BOARD_NAME = $(BOARD) |
| 99 | export BOARD_NAME |
| 100 | endif |
Anas Nashif | 6d9ed99 | 2017-01-07 13:22:21 -0500 | [diff] [blame] | 101 | |
Anas Nashif | 54634d6 | 2016-02-01 19:42:54 -0500 | [diff] [blame] | 102 | debugserver: FORCE |
Anas Nashif | 6d9ed99 | 2017-01-07 13:22:21 -0500 | [diff] [blame] | 103 | $(Q)$(CONFIG_SHELL) $(ZEPHYR_BASE)/scripts/support/$(DEBUG_SCRIPT) debugserver |
Anas Nashif | 54634d6 | 2016-02-01 19:42:54 -0500 | [diff] [blame] | 104 | |
Andy Gross | 47eb5bf | 2017-04-18 23:36:01 -0500 | [diff] [blame] | 105 | initconfig: $(DOTCONFIG) |
Anas Nashif | f5e3be2 | 2015-10-03 17:49:46 -0400 | [diff] [blame] | 106 | |
Anas Nashif | a0cf03b | 2016-05-14 21:56:35 -0400 | [diff] [blame] | 107 | $(BOARDCONFIG): |
| 108 | @rm -f $(O)/.board_* |
| 109 | @touch $@ |
| 110 | |
Anas Nashif | 6361be2 | 2016-05-22 12:34:06 -0400 | [diff] [blame] | 111 | ram_report: initconfig |
| 112 | $(Q)$(call zephyrmake,$(O),$@) |
| 113 | |
| 114 | rom_report: initconfig |
| 115 | $(Q)$(call zephyrmake,$(O),$@) |
| 116 | |
Andy Gross | 47eb5bf | 2017-04-18 23:36:01 -0500 | [diff] [blame] | 117 | outputexports: initconfig |
| 118 | $(Q)$(call zephyrmake,$(O),$@) |
| 119 | |
Andy Gross | c8112aa | 2017-04-18 23:43:58 -0500 | [diff] [blame] | 120 | dts: initconfig |
| 121 | $(Q)$(call zephyrmake,$(O),$@) |
| 122 | |
Andy Gross | 1e72c1e | 2017-06-06 21:23:33 -0500 | [diff] [blame] | 123 | config-sanitycheck: dts |
| 124 | $(Q)$(call zephyrmake,$(O),$@) |
| 125 | |
Anas Nashif | fa2e18b | 2015-10-14 17:42:59 -0400 | [diff] [blame] | 126 | menuconfig: initconfig |
| 127 | $(Q)$(call zephyrmake,$(O),$@) |
| 128 | |
Anas Nashif | 71d2215 | 2016-01-30 05:36:52 -0500 | [diff] [blame] | 129 | help: |
| 130 | $(Q)$(MAKE) -s -C $(ZEPHYR_BASE) $@ |
| 131 | |
Anas Nashif | fbed1e4 | 2015-08-28 15:42:03 -0400 | [diff] [blame] | 132 | # Catch all |
| 133 | %: |
| 134 | $(Q)$(call zephyrmake,$(O),$@) |
Juan Manuel Cruz | 52c9d87 | 2015-06-05 11:08:43 -0500 | [diff] [blame] | 135 | |
Anas Nashif | a0cf03b | 2016-05-14 21:56:35 -0400 | [diff] [blame] | 136 | $(DOTCONFIG): $(BOARDCONFIG) $(KBUILD_DEFCONFIG_PATH) $(CONF_FILE) |
Anas Nashif | e80edfc | 2015-08-28 14:22:29 -0400 | [diff] [blame] | 137 | $(Q)$(CONFIG_SHELL) $(ZEPHYR_BASE)/scripts/kconfig/merge_config.sh \ |
Anas Nashif | 66cfcc2 | 2016-12-21 14:38:37 -0500 | [diff] [blame] | 138 | -q -m -O $(O) $(KBUILD_DEFCONFIG_PATH) $(OVERLAY_CONFIG) $(CONF_FILE) \ |
Inaky Perez-Gonzalez | 2748231 | 2016-08-31 15:19:11 -0700 | [diff] [blame] | 139 | $(wildcard $(O)/*.conf) |
Anas Nashif | c4ad67d | 2015-11-26 20:39:26 -0500 | [diff] [blame] | 140 | $(Q)$(MAKE) $(S) -C $(ZEPHYR_BASE) O=$(O) PROJECT=$(PROJECT_BASE) oldnoconfig |
Anas Nashif | fde80d7 | 2015-08-22 14:40:43 -0400 | [diff] [blame] | 141 | |
| 142 | pristine: |
Andy Ross | 72f00d9 | 2016-08-23 12:32:20 -0700 | [diff] [blame] | 143 | $(Q)rm -rf $(PRISTINE_O) |
Juan Manuel Cruz | 9e4b2bb | 2015-05-05 17:21:55 -0500 | [diff] [blame] | 144 | |
Anas Nashif | f5e3be2 | 2015-10-03 17:49:46 -0400 | [diff] [blame] | 145 | PHONY += FORCE initconfig |
Anas Nashif | e80edfc | 2015-08-28 14:22:29 -0400 | [diff] [blame] | 146 | FORCE: |
Anas Nashif | fde80d7 | 2015-08-22 14:40:43 -0400 | [diff] [blame] | 147 | |
Juan Manuel Cruz | 4ee8a8e | 2015-02-21 16:05:51 -0600 | [diff] [blame] | 148 | .PHONY: $(PHONY) |