-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile.common
142 lines (125 loc) · 4.15 KB
/
Makefile.common
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#############################
# Makefile functions
#############################
# Saves initial values so that we can filter them later
VARS_OLD := $(.VARIABLES)
# Global Makefile settings
SHELL := /bin/bash
EXTRAMAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += $(EXTRAMAKEFLAGS)
# Global help target
.DEFAULT_GOAL: help
.PHONY: help
help: ## prints this message
@egrep -h '\s##\s' $(MAKEFILE_LIST) | sort \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-30s\033[0m %s\n", $$1, $$2}'
# Global reset
.PHONY: bleach_all
bleach_all: ## wipes the whole repo clean. Use with caution
@$(CD) $(BP_TOOLS_DIR); git clean -ffdx; git submodule deinit -f .
define bsg_fn_upper
$(shell echo $(1) | tr a-z A-Z)
endef
define bsg_fn_lower
$(shell echo $(1) | tr A-Z a-z)
endef
bsg_var_blank :=
define bsg_var_newline
$(bsg_var_blank)
endef
bsg_var_percent := %
define bsg_fn_patch_if_new
$(eval apply_stage_patch := git apply --ignore-whitespace --ignore-space-change)
$(eval apply_commit_patch := git am --ignore-whitespace --ignore-space-change)
$(eval check_patch := $(apply_stage_patch) --check --reverse)
$(eval src_root := $(1))
$(eval patch_root := $(2))
$(eval patch_list := $(wildcard $(patch_root)/*.patch))
$(eval patch_is_top := $(findstring patches,$(lastword $(subst /, ,$(dir $(patch_root))))))
for p in $(patch_list); \
do \
echo "Checking if patch $$p is applicable"; \
cd $(src_root); $(check_patch) $$p && continue; \
echo "Patch is unapplied..."; \
if [ ! -z "$$patch_is_top" ]; then \
echo "Applying patch to sub-directory $(src_root);" \
cd $(src_root); $(apply_commit_patch) $$p; \
echo "Patch applied!"; \
else \
echo "Applying patch to top-level $(src_root);" \
cd $(src_root); $(apply_stage_patch) $$p; \
echo "Patch applied!"; \
fi \
done
endef
define bsg_fn_build_tag
$(eval name := $(1))
$(eval src_dir := $(2))
$(eval touch_dir := $(3))
$(eval tag := $(4))
$(eval internal_target := $(src_dir)/.$(name)_build)
$(eval external_target := build.$(name))
$(eval rebuild_target := rebuild.$(name))
$(eval MAKEFLAGS := $(filter-out $(EXTRAMAKEFLAGS),$(MAKEFLAGS)))
$(external_target): | $(tag)
$(rebuild_target):
rm -f $(touch_dir)/$(name).*
+$(MAKE) $(tag)
$(tag):
+$(MAKE) $(internal_target)
touch $(tag)
endef
define bsg_fn_build_if_missing
$(eval name := $(1))
$(eval src_dir := $(2))
$(eval touch_dir := $(3))
$(eval tag := $(addprefix $(touch_dir)/$(name).,any))
$(call bsg_fn_build_tag,$(name),$(src_dir),$(touch_dir),$(tag))
endef
define bsg_fn_build_if_new
$(eval name := $(1))
$(eval src_dir := $(2))
$(eval touch_dir := $(3))
$(eval hash := $(shell cd $(src_dir); git rev-parse HEAD))
$(eval tag := $(addprefix $(touch_dir)/$(name).,$(hash)))
$(call bsg_fn_build_tag,$(name),$(src_dir),$(touch_dir),$(tag))
endef
define bsg_fn_info
$(eval $@_msg = $(1))
$(eval $@_prefix = "BSG-INFO: ")
echo "${$@_prefix} ${$@_msg}";
endef
define bsg_fn_warn
$(eval $@_msg = $(1))
$(eval $@_prefix = "BSG-WARN: ")
echo "${$@_prefix} ${$@_msg}";
endef
define bsg_fn_error
$(eval $@_msg = $(1))
$(eval $@_prefix = "BSG-ERROR: ")
echo "${$@_prefix} ${$@_msg}"; \
exit -1;
endef
#############################
# Paths
#############################
BP_TOOLS_DIR ?= $(TOP)
BP_TOOLS_PATCH_DIR ?= $(BP_TOOLS_DIR)/patches
BP_TOOLS_INSTALL_DIR ?= $(BP_TOOLS_DIR)/install
BP_TOOLS_MK_DIR ?= $(BP_TOOLS_DIR)/mk
BP_TOOLS_BIN_DIR ?= $(BP_TOOLS_INSTALL_DIR)/bin
BP_TOOLS_LIB_DIR ?= $(BP_TOOLS_INSTALL_DIR)/lib
BP_TOOLS_INCLUDE_DIR ?= $(BP_TOOLS_INSTALL_DIR)/include
BP_TOOLS_SHARE_DIR ?= $(BP_TOOLS_INSTALL_DIR)/share
BP_TOOLS_TOUCH_DIR ?= $(BP_TOOLS_INSTALL_DIR)/touchfiles
BP_TOOLS_WORK_DIR ?= $(BP_TOOLS_INSTALL_DIR)/work
BP_TOOLS_AXE_DIR ?= $(BP_TOOLS_DIR)/axe
BP_TOOLS_FAKERAM_DIR ?= $(BP_TOOLS_DIR)/bsg_fakeram
BP_TOOLS_SV2V_DIR ?= $(BP_TOOLS_DIR)/bsg_sv2v
BP_TOOLS_DROMAJO_DIR ?= $(BP_TOOLS_DIR)/dromajo
BP_TOOLS_SPIKE_DIR ?= $(BP_TOOLS_DIR)/riscv-isa-sim
BP_TOOLS_SURELOG_DIR ?= $(BP_TOOLS_DIR)/Surelog
BP_TOOLS_VERILATOR_DIR ?= $(BP_TOOLS_DIR)/verilator
BP_TOOLS_YOSYS_DIR ?= $(BP_TOOLS_DIR)/yosys
BP_TOOLS_YSLANG_DIR ?= $(BP_TOOLS_DIR)/yosys-slang
BSG_CADENV_DIR ?= $(BP_TOOLS_DIR)/bsg_cadenv