-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
110 lines (80 loc) · 2.95 KB
/
Makefile
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
# Copyright 2013 The Pythia Authors.
# This file is part of Pythia.
#
# Pythia is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# Pythia is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Pythia. If not, see <http://www.gnu.org/licenses/>.
################################################################################
## Global parameters
# Output directory
export OUT_DIR := out
# Output directory for any vm-related files
export VM_OUT_DIR := out/vm
################################################################################
## Helper functions
# Enable secondary expansion
.SECONDEXPANSION:
# Absolute path to this root directory
export TOP_DIR := $(abspath .)
# The $~ variable contains the current subdirectory. This variable is only
# valid on first expansion.
~ := .
# The $(call include_subdirs, subdirs...) function includes the pythia.mk
# makefiles from the specified subdirectories, setting $~ accordingly.
define include_subdir_template =
~ := $~/$(1)
include $~/$(1)/pythia.mk
~ := $(patsubst %/$(1),%,$~)
endef
include_subdirs = \
$(foreach subdir,$(1),$(eval $(call include_subdir_template,$(subdir))))
# Targets and help formatting.
# Every phony target shall be defined with the
# $(call add_target,target,type,helpline) function, where name is the name of
# the target, type is the section in the help where the target belongs (see the
# HELP_*_TARGETS variables below) and helpline is a line of text.
define add_target_template =
.PHONY: $(1)
HELP_$(strip $(2))_TARGETS += printf " %-20s%s\n" "$(strip $(1))" "$(strip $(3))";
endef
add_target = $(eval $(call add_target_template,$(1),$(2),$(3)))
################################################################################
## Main makefile
HELP_GENERIC_TARGETS :=
HELP_BUILD_TARGETS :=
HELP_MISC_TARGETS :=
# Generic targets
$(call add_target, all, GENERIC, Build all targets)
all:
$(call add_target, check, GENERIC, Perform all tests)
check:
$(call add_target, clean, GENERIC, Remove build outputs, but keep downloaded files)
clean::
-rm -r $(OUT_DIR)
$(call add_target, clear, GENERIC, Remove all build outputs)
clear:: clean
$(call add_target, help, MISC, Print this help)
help:
@echo "Pythia build system."
@echo
@echo "Generic targets:"
@$(HELP_GENERIC_TARGETS)
@echo
@echo "Specific build targets:"
@$(HELP_BUILD_TARGETS)
@echo
@echo "Miscelaneous targets:"
@$(HELP_MISC_TARGETS)
# Include subdirectories
$(call include_subdirs, go vm environments tasks)
# Safeguard for not using $~ in second expansion
~ := tilde is not valid in commands
# vim:set ts=4 sw=4 noet: