|
| 1 | +ifneq ($(BUILD_WITH_COLORS),0) |
| 2 | + CL_RED="\033[1;31m" |
| 3 | + CL_GRN="\033[1;32m" |
| 4 | + CL_YLW="\033[1;33m" |
| 5 | + CL_BLU="\033[1;34m" |
| 6 | + CL_MAG="\033[1;35m" |
| 7 | + CL_CYN="\033[1;36m" |
| 8 | + CL_RST="\033[0m" |
| 9 | +endif |
| 10 | + |
| 11 | +# enable GCC colors by default (if supported) |
| 12 | +export GCC_COLORS ?= 1 |
| 13 | + |
| 14 | +# Utility variables. |
| 15 | +empty := |
| 16 | +space := $(empty) $(empty) |
| 17 | +comma := , |
| 18 | +# Note that make will eat the newline just before endef. |
| 19 | +define newline |
| 20 | + |
| 21 | + |
| 22 | +endef |
| 23 | +# Unfortunately you can't simply define backslash as \ or \\. |
| 24 | +backslash := \a |
| 25 | +backslash := $(patsubst %a,%,$(backslash)) |
| 26 | + |
| 27 | +# log functions |
| 28 | +# logi(message) |
| 29 | +define logi |
| 30 | + $(info $(shell echo -e ${CL_CYN}$(1)${CL_RST})) |
| 31 | +endef |
| 32 | +# logw(message) |
| 33 | +define logw |
| 34 | + $(info $(shell echo -e ${CL_YLW}$(1)${CL_RST})) |
| 35 | +endef |
| 36 | +# loge(message) |
| 37 | +define loge |
| 38 | + $(info $(shell echo -e ${CL_RED})) |
| 39 | + $(error $(shell echo -e "$(1)"${CL_RST})) |
| 40 | +endef |
| 41 | +# logv(message) |
| 42 | +define logv |
| 43 | + $(info $(shell echo -e $(1))) |
| 44 | +endef |
| 45 | + |
| 46 | +# Only use EFIDROID_BUILD_SHELL to wrap around bash. |
| 47 | +# DO NOT use other shells such as zsh. |
| 48 | +ifdef EFIDROID_BUILD_SHELL |
| 49 | + SHELL := $(EFIDROID_BUILD_SHELL) |
| 50 | +else |
| 51 | + # Use bash, not whatever shell somebody has installed as /bin/sh |
| 52 | + # This is repeated in config.mk, since envsetup.sh runs that file |
| 53 | + # directly. |
| 54 | + SHELL := /bin/bash |
| 55 | +endif |
| 56 | + |
| 57 | +# this turns off the suffix rules built into make |
| 58 | +.SUFFIXES: |
| 59 | + |
| 60 | +# this turns off the RCS / SCCS implicit rules of GNU Make |
| 61 | +% : RCS/%,v |
| 62 | +% : RCS/% |
| 63 | +% : %,v |
| 64 | +% : s.% |
| 65 | +% : SCCS/s.% |
| 66 | + |
| 67 | +# If a rule fails, delete $@. |
| 68 | +.DELETE_ON_ERROR: |
| 69 | + |
| 70 | +# Check for broken versions of make. |
| 71 | +# (Allow any version under Cygwin since we don't actually build the platform there.) |
| 72 | +ifeq (,$(findstring CYGWIN,$(shell uname -sm))) |
| 73 | + ifneq (1,$(strip $(shell expr $(MAKE_VERSION) \>= 3.81))) |
| 74 | + $(warning ********************************************************************************) |
| 75 | + $(warning * You are using version $(MAKE_VERSION) of make.) |
| 76 | + $(warning * EFIDroid can only be built by versions 3.81 and higher.) |
| 77 | + $(warning ********************************************************************************) |
| 78 | + $(error stopping) |
| 79 | + endif |
| 80 | +endif |
| 81 | + |
| 82 | +# identify host kernel |
| 83 | +KERNEL_NAME := $(shell uname -s) |
| 84 | +ifeq ($(KERNEL_NAME),Linux) |
| 85 | + HOSTTYPE := linux-x86 |
| 86 | +endif |
| 87 | +ifeq ($(KERNEL_NAME),Darwin) |
| 88 | + HOSTTYPE := darwin-x86 |
| 89 | +endif |
| 90 | +ifeq ($(HOSTTYPE),) |
| 91 | + $(call loge,Unsupprted host kernel $(KERNEL_NAME)) |
| 92 | +endif |
| 93 | + |
| 94 | +# clean macro |
| 95 | +CLEANSTEPS = |
| 96 | +# add-clean-step(target) |
| 97 | +define add-clean-step |
| 98 | + $(eval CLEANSTEPS += $(1)) |
| 99 | +endef |
| 100 | + |
| 101 | +# distclean macro |
| 102 | +DISTCLEANSTEPS = |
| 103 | +# add-distclean-step(target) |
| 104 | +define add-distclean-step |
| 105 | + $(eval DISTCLEANSTEPS += $(1)) |
| 106 | +endef |
| 107 | + |
| 108 | + |
| 109 | +# Absolute path of the present working direcotry. |
| 110 | +# This overrides the shell variable $PWD, which does not necessarily points to |
| 111 | +# the top of the source tree, for example when "make -C" is used in m/mm/mmm. |
| 112 | +PWD := $(shell pwd) |
| 113 | + |
| 114 | +TOP := . |
| 115 | +TOPDIR := |
| 116 | + |
| 117 | +BUILD_SYSTEM := $(TOPDIR)build/core |
| 118 | +OUT := $(TOPDIR)out |
| 119 | +HOST_OUT := $(OUT)/host |
| 120 | + |
| 121 | +# GCC |
| 122 | +GCC_DIR := $(PWD)/$(TOPDIR)prebuilts/gcc/$(HOSTTYPE) |
| 123 | +GCC_TARGET_DIR := $(GCC_DIR)/arm |
| 124 | +GCC_LINUX_GNUEABI := $(GCC_TARGET_DIR)/arm-linux-gnueabihf-4.9/bin/arm-linux-gnueabihf- |
| 125 | +GCC_EABI := $(GCC_TARGET_DIR)/arm-eabi-4.8/bin/arm-eabi- |
| 126 | + |
| 127 | +# This is the default target. It must be the first declared target. |
| 128 | +.PHONY: all |
| 129 | +DEFAULT_GOAL := all |
| 130 | +$(DEFAULT_GOAL): |
| 131 | + |
| 132 | +# Used to force goals to build. Only use for conditionally defined goals. |
| 133 | +.PHONY: FORCE |
| 134 | +FORCE: |
| 135 | + |
| 136 | +# Hi :) |
| 137 | +$(call logi,EFIDroid Build System) |
| 138 | + |
| 139 | +# These goals don't need to be built |
| 140 | +nobuild_goals := \ |
| 141 | + help out \ |
| 142 | + show_devices |
| 143 | + |
| 144 | +ifneq ($(filter $(nobuild_goals), $(MAKECMDGOALS)),) |
| 145 | + |
| 146 | + .PHONY: show_devices |
| 147 | + show_devices: |
| 148 | + @echo Devices: |
| 149 | + @for f in $(strip $(wildcard $(TOPDIR)device/*/*/config.mk)); do \ |
| 150 | + parts=($${f//\// });\ |
| 151 | + echo -e \\t$${parts[1]}/$${parts[2]}; \ |
| 152 | + done |
| 153 | + |
| 154 | + .PHONY: help |
| 155 | + help: |
| 156 | + @echo |
| 157 | + @echo "Common make targets:" |
| 158 | + @echo "----------------------------------------------------------------------------------" |
| 159 | + @echo "all Default target" |
| 160 | + @echo "clean run 'make clean' on all targets" |
| 161 | + @echo "distclean equivalent to rm -rf out/" |
| 162 | + @echo "help You're reading it right now" |
| 163 | + |
| 164 | + |
| 165 | + .PHONY: out |
| 166 | + out: |
| 167 | + @echo "I'm sure you're nice and all, but no thanks." |
| 168 | + |
| 169 | +else |
| 170 | + |
| 171 | + # add_cmake_target(type, outdir, sourcedir) |
| 172 | + define add_cmake_target |
| 173 | + $(strip \ |
| 174 | + $(eval name := $(lastword $(subst /, ,$(3)))) |
| 175 | + $(eval target := $(1)_$(name)) |
| 176 | + |
| 177 | + $(eval cmakeargs := ) |
| 178 | + $(if $(filter $(1),target), \ |
| 179 | + $(eval cmakeargs := -DCMAKE_C_COMPILER=$(PWD)/$(GCC_LINUX_GNUEABI)gcc) \ |
| 180 | + $(eval cmakeargs += -DCMAKE_CXX_COMPILER=$(PWD)/$(GCC_LINUX_GNUEABI)g++) \ |
| 181 | + ) |
| 182 | + |
| 183 | + $(eval .PHONY: $(target)) |
| 184 | + $(eval $(target): |
| 185 | + @$${call logi,Compiling $(1)/$(name) ...} |
| 186 | + @mkdir -p $(2)/$(name) |
| 187 | + @cd $(2)/$(name) && cmake $(cmakeargs) $(PWD)/$(TOPDIR)external/$(1)/$(name) && $$(MAKE) |
| 188 | + ) |
| 189 | + ) |
| 190 | + endef |
| 191 | + |
| 192 | + # load_task(path) |
| 193 | + define load_task |
| 194 | + $(strip \ |
| 195 | + $(eval include $(1)) |
| 196 | + ) |
| 197 | + endef |
| 198 | + |
| 199 | + # create main build dir |
| 200 | + $(shell mkdir -p ${OUT}) |
| 201 | + # create host build dir |
| 202 | + $(shell mkdir -p ${HOST_OUT}) |
| 203 | + |
| 204 | + # define host targets |
| 205 | + $(foreach p,$(wildcard $(TOPDIR)external/host/*),$(call add_cmake_target,host,$(HOST_OUT),$(p))) |
| 206 | + |
| 207 | + # check if device is set |
| 208 | + ifneq ($(DEVICEID),) |
| 209 | + |
| 210 | + # check if device config exists |
| 211 | + DEVICE_CONFIG = $(wildcard device/$(DEVICEID)/config.mk) |
| 212 | + ifeq ("","$(DEVICE_CONFIG)") |
| 213 | + $(call loge,device $(DEVICEID) doesn't exist) |
| 214 | + endif |
| 215 | + |
| 216 | + # include device config |
| 217 | + include $(DEVICE_CONFIG) |
| 218 | + |
| 219 | + # validate config |
| 220 | + ifeq ($(DEVICE_NAME),) |
| 221 | + $(call loge,DEVICE_NAME is not set) |
| 222 | + endif |
| 223 | + |
| 224 | + # extract vendor and device names |
| 225 | + VENDOR := $(shell (tmp=${DEVICEID};tmp=($${tmp//\// });echo $${tmp[0]})) |
| 226 | + DEVICE := $(shell (tmp=${DEVICEID};tmp=($${tmp//\// });echo $${tmp[1]})) |
| 227 | + TARGET_OUT := $(OUT)/target/product/$(DEVICE) |
| 228 | + |
| 229 | + $(call logi,Building for ${DEVICE_NAME} \(${VENDOR}/${DEVICE}\)) |
| 230 | + |
| 231 | + # create target build dir |
| 232 | + $(shell mkdir -p ${TARGET_OUT}) |
| 233 | + |
| 234 | + # define device targets |
| 235 | + $(foreach p,$(wildcard $(TOPDIR)external/target/*),$(call add_cmake_target,target,$(TARGET_OUT),$(p))) |
| 236 | + |
| 237 | + # include EDK2 first |
| 238 | + include $(BUILD_SYSTEM)/tasks/edk2.mk |
| 239 | + |
| 240 | + # load all other tasks |
| 241 | + $(foreach p,$(filter-out $(BUILD_SYSTEM)/tasks/edk2.mk,$(wildcard $(BUILD_SYSTEM)/tasks/*.mk)),$(call load_task,$(p))) |
| 242 | + |
| 243 | + else |
| 244 | + $(call logi,Building in host-only mode) |
| 245 | + endif |
| 246 | + |
| 247 | + .PHONY: clean |
| 248 | + clean: $(CLEANSTEPS) |
| 249 | + |
| 250 | + .PHONY: distclean |
| 251 | + distclean: $(DISTCLEANSTEPS) |
| 252 | + rm -Rf $(OUT) |
| 253 | + |
| 254 | +endif # nobuild_goals |
0 commit comments