This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.include
146 lines (124 loc) · 4.43 KB
/
Makefile.include
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
142
143
144
145
146
#######################################################################
# Make environment variables
#######################################################################
# Build directories
BIN ?= $(CURDIR)/bin
BUILD ?= $(CURDIR)/build
TOOLS ?= $(CURDIR)/tools
# Make all paths absolute.
override BIN := $(abspath $(BIN))
override BUILD := $(abspath $(BUILD))
override TOOLS := $(abspath $(TOOLS))
SHELL=bash
# get host operating system
OS := $(shell uname -s)
# git command
GIT ?= git
# Quiet option, to output compile and link commands
QUIET ?= 1
ifeq ($(QUIET),1)
Q=@
MAKEFLAGS += --no-print-directory
else
Q=
endif
#######################################################################
# Begin targets
#######################################################################
IOTLAB_BASE_DIR ?= A8
IOTLAB_BUILD_DIR = $(IOTLAB_BASE_DIR)/$(notdir $(CURDIR))
IOTLAB_BUILD_NODE ?= $(firstword $(IOTLAB_NODE_ID_LIST))
HOSTNAME = $(shell hostname)
PREFIX = $(if $(PREFIX_DISABLE),,1> >(sed "s/^/$(1)> /") 2> >(sed "s/^/$(1)> /" >&2))
LOCAL = $(call PREFIX,$(HOSTNAME)) >&2
NODE = $(call PREFIX,node-a8-$(1))
# Where is the build running
ifeq ($(HOSTNAME),$(IOTLAB_SITE))
BUILD_ENV = iotlab-site
else
ifneq ($(shell hostname | grep -E 'node-a8-[[:digit:]]+'),)
IOTLAB_BUILD_NODE = $(shell hostname | sed -E 's/node-a8-([[:digit:]]+)/\1/')
BUILD_ENV = iotlab-node
else
BUILD_ENV = local
endif
endif
# Do not include iotlab-targets if in node build environment
ifneq ($(BUILD_ENV),iotlab-node)
# Include iot-lab targets
include $(CURDIR)/Makefile.iotlab
endif
# Check command dependencies
.PHONY = $(COMMANDS)
$(COMMANDS):
$(if $(shell which $@),,$(error "No $@ in PATH"))
# Prepare build in iotlab site
ifeq ($(BUILD_ENV),iotlab-site)
# Use correct path for gcc-arm-none-eabi
export PATH:=/opt/gcc-arm-none-eabi-7-2018-q2-update/bin/:$(PATH)
# Check that current directory is an inmediate subdirectory of IOTLAB_BASE_DIR to avoid
# rsyncing with a8-node
ifneq ($(HOME)/$(IOTLAB_BASE_DIR)/,$(dir $(CURDIR)))
$(error Build dir '$(notdir $(CURDIR))' must be an immediate subdirectory of $(HOME)/$(IOTLAB_BASE_DIR))
endif
endif
# Phony target to sync to site
.PHONY: iotlab-site-sync
iotlab-site-sync:
ifneq ($(BUILD_ENV),iotlab-site)
@echo "Syncing files with IoT-Lab site" $(LOCAL)
$(Q)$(call IOTLAB_SITE_RSYNC,$(CURDIR),$(IOTLAB_BASE_DIR),--exclude='.git' --exclude-from='.gitignore') $(LOCAL)
@echo "All files synced" $(LOCAL)
endif
# Run a target on all reserved nodes
.PHONY: iotlab-node-all-%
iotlab-node-all-%: iotlab-running iotlab-site-sync
$(eval ENV := $(subst R_,,$(foreach v, $(filter R_%,$(.VARIABLES)),$(v)=$($(v)))) QUIET=$(QUIET))
$(eval T := $(subst iotlab-node-all-,,$@))
ifeq ($(BUILD_ENV),iotlab-site)
@echo "Calling 'make $(T)' on IoT-Lab nodes $(IOTLAB_NODE_ID_LIST)" $(LOCAL)
$(Q) $(foreach id,$(IOTLAB_NODE_ID_LIST), \
$(call IOTLAB_A8_SSH,$(id),$(IOTLAB_BUILD_DIR),$(ENV) make $(T)) $(call NODE,$(id)); \
)
else
ifeq ($(BUILD_ENV),local)
@echo "Calling 'make $(T)' on IoT-Lab nodes $(IOTLAB_NODE_ID_LIST)" $(LOCAL)
$(Q) $(foreach id,$(IOTLAB_NODE_ID_LIST),\
$(call IOTLAB_A8_TUNNEL_SSH,$(id),$(IOTLAB_BUILD_DIR),$(ENV) make $(T)) $(call NODE,$(id)); \
)
else
$(Q)$(MAKE) $(T)
endif
endif
# Run targets in iotlab a8 node
.PHONY: iotlab-node-%
iotlab-node-%: iotlab-running iotlab-site-sync
$(eval ENV := $(subst R_,,$(foreach v, $(filter R_%,$(.VARIABLES)),$(v)=$($(v)))) QUIET=$(QUIET))
$(eval T := $(subst iotlab-node-,,$@))
$(eval ID := $(firstword $(subst -, ,$(T))))
$(if $(shell echo $(ID) | grep -E '^[[:digit:]]+$$'),\
$(eval T := $(subst iotlab-node-$(ID)-,,$@)),\
$(eval ID := $(IOTLAB_BUILD_NODE)))
ifeq ($(BUILD_ENV),iotlab-site)
@echo "Calling 'make $(T)' on IoT-Lab node $(ID)" $(LOCAL)
$(Q)$(call IOTLAB_A8_SSH,$(ID),$(IOTLAB_BUILD_DIR),$(ENV) make $(T)) $(call NODE,$(ID))
else
ifeq ($(BUILD_ENV),local)
@echo "Calling 'make $(T)' on IoT-Lab node $(ID)" $(LOCAL)
$(Q)$(call IOTLAB_A8_TUNNEL_SSH,$(ID),$(IOTLAB_BUILD_DIR),$(ENV) make $(T)) $(call NODE,$(ID))
else
$(Q)$(MAKE) $(T)
endif
endif
# Run targets in iotlab site
.PHONY: iotlab-site-%
iotlab-site-%: iotlab-site-sync
$(eval ENV := $(subst R_,,$(foreach v, $(filter R_%,$(.VARIABLES)),$(v)=$($(v)))) QUIET=$(QUIET))
$(eval T := $(subst iotlab-site-,,$@))
ifneq ($(BUILD_ENV),iotlab-site)
@echo "Calling 'make $(T)' on IoT-Lab site" $(LOCAL)
$(Q)$(call IOTLAB_SITE_SSH,$(IOTLAB_BUILD_DIR),$(ENV) make $(T)) $(LOCAL)
else
$(Q)$(MAKE) $(T)
endif
.DEFAULT_GOAL: all