|
| 1 | +THIS_MK_ABSPATH := $(abspath $(lastword $(MAKEFILE_LIST))) |
| 2 | +THIS_MK_DIR := $(dir $(THIS_MK_ABSPATH)) |
| 3 | + |
| 4 | +# Enable pipefail for all commands |
| 5 | +SHELL=/bin/bash -o pipefail |
| 6 | + |
| 7 | +# Enable second expansion |
| 8 | +.SECONDEXPANSION: |
| 9 | + |
| 10 | +# Clear all built in suffixes |
| 11 | +.SUFFIXES: |
| 12 | + |
| 13 | +NOOP := |
| 14 | +SPACE := $(NOOP) $(NOOP) |
| 15 | +COMMA := , |
| 16 | +HOSTNAME := $(shell hostname) |
| 17 | + |
| 18 | +############################################################################## |
| 19 | +# Environment check |
| 20 | +############################################################################## |
| 21 | + |
| 22 | + |
| 23 | +############################################################################## |
| 24 | +# Configuration |
| 25 | +############################################################################## |
| 26 | +WORK_ROOT := $(abspath $(THIS_MK_DIR)/work) |
| 27 | +INSTALL_RELATIVE_ROOT ?= install |
| 28 | +INSTALL_ROOT ?= $(abspath $(THIS_MK_DIR)/$(INSTALL_RELATIVE_ROOT)) |
| 29 | + |
| 30 | +PYTHON3 ?= python3 |
| 31 | +VENV_DIR := venv |
| 32 | +VENV_PY := $(VENV_DIR)/bin/python |
| 33 | +VENV_PIP := $(VENV_DIR)/bin/pip |
| 34 | +ifneq ($(https_proxy),) |
| 35 | +PIP_PROXY := --proxy $(https_proxy) |
| 36 | +else |
| 37 | +PIP_PROXY := |
| 38 | +endif |
| 39 | +VENV_PIP_INSTALL := $(VENV_PIP) install $(PIP_PROXY) --timeout 90 --trusted-host pypi.org --trusted-host files.pythonhosted.org |
| 40 | + |
| 41 | +############################################################################## |
| 42 | +# Set default goal before any targets. The default goal here is "test" |
| 43 | +############################################################################## |
| 44 | +DEFAULT_TARGET := all |
| 45 | + |
| 46 | +.DEFAULT_GOAL := default |
| 47 | +.PHONY: default |
| 48 | +default: $(DEFAULT_TARGET) |
| 49 | + |
| 50 | + |
| 51 | +############################################################################## |
| 52 | +# Makefile starts here |
| 53 | +############################################################################## |
| 54 | + |
| 55 | + |
| 56 | +############################################################################### |
| 57 | +# Design Targets |
| 58 | +############################################################################### |
| 59 | + |
| 60 | +# Initialize variables |
| 61 | +ALL_TARGET_STEM_NAMES = |
| 62 | +ALL_PRE_PREP_TARGETS = |
| 63 | +ALL_PREP_TARGETS = |
| 64 | +ALL_IP_UPGRADE_TARGETS = |
| 65 | +ALL_GENERATE_DESIGN_TARGETS = |
| 66 | +ALL_PACKAGE_DESIGN_TARGETS = |
| 67 | +ALL_BUILD_TARGETS = |
| 68 | +ALL_SW_BUILD_TARGETS = |
| 69 | +ALL_TEST_TARGETS = |
| 70 | +ALL_INSTALL_SOF_TARGETS = |
| 71 | +ALL_TARGET_ALL_NAMES = |
| 72 | + |
| 73 | +# Define function to create targets |
| 74 | +define create_targets_on_subdir |
| 75 | +ALL_TARGET_STEM_NAMES += $(addprefix $(strip $(1))-,$(strip $(2))) |
| 76 | +ALL_PRE_PREP_TARGETS += $(addsuffix -pre-prep,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 77 | +ALL_PREP_TARGETS += $(addsuffix -prep,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 78 | +ALL_IP_UPGRADE_TARGETS += $(addsuffix -ip-upgrade,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 79 | +ALL_GENERATE_DESIGN_TARGETS += $(addsuffix -generate-design,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 80 | +ALL_PACKAGE_DESIGN_TARGETS += $(addsuffix -package-design,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 81 | +ALL_BUILD_TARGETS += $(addsuffix -build,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 82 | +ALL_SW_BUILD_TARGETS += $(addsuffix -sw-build,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 83 | +ALL_TEST_TARGETS += $(addsuffix -test,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 84 | +ALL_INSTALL_SOF_TARGETS += $(addsuffix -install-sof,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 85 | +ALL_TARGET_ALL_NAMES += $(addsuffix -all,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 86 | + |
| 87 | + |
| 88 | +$(strip $(1))-%-pre-prep : venv |
| 89 | + $(MAKE) --no-print-directory -C $(strip $(1)) $$*-pre-prep |
| 90 | + |
| 91 | +$(strip $(1))-%-prep : venv |
| 92 | + $(MAKE) --no-print-directory -C $(strip $(1)) $$*-prep |
| 93 | + |
| 94 | +$(strip $(1))-%-ip-upgrade : venv |
| 95 | + $(MAKE) --no-print-directory -C $(strip $(1)) $$*-ip-upgrade |
| 96 | + |
| 97 | +$(strip $(1))-%-generate-design : venv |
| 98 | + $(MAKE) --no-print-directory -C $(strip $(1)) $$*-generate-design |
| 99 | + |
| 100 | +$(strip $(1))-%-package-design : |
| 101 | + $(MAKE) --no-print-directory -C $(strip $(1)) $$*-package-design INSTALL_ROOT=$(INSTALL_ROOT)/$(strip $(3)) |
| 102 | + |
| 103 | +$(strip $(1))-%-build : |
| 104 | + $(MAKE) --no-print-directory -C $(strip $(1)) $$*-build |
| 105 | + |
| 106 | +$(strip $(1))-%-sw-build : |
| 107 | + $(MAKE) --no-print-directory -C $(strip $(1)) $$*-sw-build |
| 108 | + |
| 109 | +$(strip $(1))-%-test : |
| 110 | + $(MAKE) --no-print-directory -C $(strip $(1)) $$*-test |
| 111 | + |
| 112 | +$(strip $(1))-%-install-sof : |
| 113 | + $(MAKE) --no-print-directory -C $(strip $(1)) $$*-install-sof INSTALL_ROOT=$(INSTALL_ROOT)/$(strip $(3)) |
| 114 | + |
| 115 | +.PHONY: $(addsuffix -all,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 116 | +$(addsuffix -all,$(addprefix $(strip $(1))-,$(strip $(2)))): venv |
| 117 | + $(MAKE) $(addsuffix -pre-prep,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 118 | + $(MAKE) $(addsuffix -generate-design,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 119 | + $(MAKE) $(addsuffix -package-design,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 120 | + $(MAKE) $(addsuffix -prep,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 121 | + $(MAKE) $(addsuffix -build,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 122 | + $(MAKE) $(addsuffix -sw-build,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 123 | + $(MAKE) $(addsuffix -test,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 124 | + $(MAKE) $(addsuffix -install-sof,$(addprefix $(strip $(1))-,$(strip $(2)))) |
| 125 | + |
| 126 | +endef |
| 127 | + |
| 128 | +# Create rules for subdirs |
| 129 | +TARGET_SUBDIR := \ |
| 130 | + a3cw135-devkit-oobe |
| 131 | + |
| 132 | +# Create the subdir recipes by recurinsively calling the create_targets_on_subdir on each TARGET_SUBDIR |
| 133 | +define create_subdir_targets |
| 134 | +$(foreach target, $(shell make --no-print-directory -q -C $(1) print-targets), $(eval $(call create_targets_on_subdir, $(1), $(target), designs))) |
| 135 | +endef |
| 136 | +$(foreach subdir,$(TARGET_SUBDIR),$(eval $(call create_subdir_targets,$(subdir)))) |
| 137 | + |
| 138 | +############################################################################### |
| 139 | +# UTILITY TARGETS |
| 140 | +############################################################################### |
| 141 | +# Deep clean using git |
| 142 | +.PHONY: dev-clean |
| 143 | +dev-clean : |
| 144 | + rm -rf $(INSTALL_ROOT) $(WORK_ROOT) |
| 145 | + git clean -dfx --exclude=/.vscode --exclude=.lfsconfig |
| 146 | + |
| 147 | +# Using git |
| 148 | +.PHONY: dev-update |
| 149 | +dev-update : |
| 150 | + git pull |
| 151 | + git submodule update --init --recursive |
| 152 | + |
| 153 | +.PHONY: clean |
| 154 | +clean: |
| 155 | + rm -rf $(INSTALL_ROOT) $(WORK_ROOT) |
| 156 | + git clean -dfx --exclude=/.vscode --exclude=.lfsconfig --exclude=$(VENV_DIR) |
| 157 | + |
| 158 | +# Prep workspace |
| 159 | +venv: |
| 160 | + $(PYTHON3) -m venv $(VENV_DIR) |
| 161 | + $(VENV_PIP_INSTALL) --upgrade pip |
| 162 | + $(VENV_PIP_INSTALL) -r requirements.txt |
| 163 | + |
| 164 | + |
| 165 | +.PHONY: venv-freeze |
| 166 | +venv-freeze: |
| 167 | + $(VENV_PIP) freeze > requirements.txt |
| 168 | + sed -i -e 's/==/~=/g' requirements.txt |
| 169 | + |
| 170 | +.PHONY: prepare-tools |
| 171 | +prepare-tools : venv |
| 172 | + |
| 173 | +# Include not_shipped Makefile if present |
| 174 | +-include not_shipped/Makefile.mk |
| 175 | + |
| 176 | +############################################################################### |
| 177 | +# Toplevel Targets |
| 178 | +############################################################################### |
| 179 | +.PHONY: pre-prep |
| 180 | +pre-prep: $(ALL_PRE_PREP_TARGETS) |
| 181 | + |
| 182 | +.PHONY: prep |
| 183 | +prep: $(ALL_PREP_TARGETS) |
| 184 | + |
| 185 | +.PHONY: ip-upgrade |
| 186 | +ip-upgrade: $(ALL_IP_UPGRADE_TARGETS) |
| 187 | + |
| 188 | +.PHONY: generate-designs |
| 189 | +generate-designs: $(ALL_GENERATE_DESIGN_TARGETS) |
| 190 | + |
| 191 | +.PHONY: package-designs |
| 192 | +package-designs: $(ALL_PACKAGE_DESIGN_TARGETS) |
| 193 | + |
| 194 | +# Build options |
| 195 | +.PHONY: build |
| 196 | +build: $(ALL_BUILD_TARGETS) |
| 197 | + |
| 198 | +# SW-Build options |
| 199 | +.PHONY: sw-build |
| 200 | +sw-build: $(ALL_SW_BUILD_TARGETS) |
| 201 | + |
| 202 | +# Run all tests |
| 203 | +.PHONY: test |
| 204 | +test : build |
| 205 | + |
| 206 | +.PHONY: install-sof |
| 207 | +install-sof: $(ALL_INSTALL_SOF_TARGETS) |
| 208 | + |
| 209 | +.PHONY: all |
| 210 | +all: $(ALL_TARGET_ALL_NAMES) |
| 211 | + |
| 212 | +############################################################################### |
| 213 | +# HELP |
| 214 | +############################################################################### |
| 215 | +.PHONY: help |
| 216 | +help: |
| 217 | + $(info GHRD Build) |
| 218 | + $(info ----------------) |
| 219 | + $(info All Targets : $(ALL_TARGET_ALL_NAMES)) |
| 220 | + $(info Stem names : $(ALL_TARGET_STEM_NAMES)) |
| 221 | + $(info Pre-Prep Targets : $(ALL_PRE_PREP_TARGETS)) |
| 222 | + $(info Prep Targets : $(ALL_PREP_TARGETS)) |
| 223 | + $(info Build Targets : $(ALL_BUILD_TARGETS)) |
| 224 | + $(info Test Targets : $(ALL_TEST_TARGETS)) |
| 225 | + $(info Package Targets : $(ALL_PACKAGE_DESIGN_TARGETS)) |
| 226 | + |
0 commit comments