-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
317 lines (266 loc) · 9.06 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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#####################################################################################################################
# @file Makefile
# @note Copyright (C) [2021-2024] Renesas Electronics Corporation and/or its affiliates
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, as published
# by the Free Software Foundation.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#####################################################################################################################
#####################################################################################################################
# Release Tag: 2-0-8
# Pipeline ID: 426834
# Commit Hash: 62f27b58
#####################################################################################################################
###################
# V A R I A B L E S
###################
ifndef ESMC_STACK
$(warning ESMC_STACK is not defined)
ESMC_STACK := renesas
$(warning Setting ESMC_STACK to $(ESMC_STACK) (default)...)
endif
# PLATFORM:
# PLATFORM := amd64 --> AMD64
# PLATFORM := arm64 --> ARM64
ifndef PLATFORM
$(warning PLATFORM is not defined)
PLATFORM := amd64
$(warning Setting PLATFORM to $(PLATFORM) (default)...)
endif
ifndef CROSS_COMPILE
$(warning CROSS_COMPILE is not defined)
endif
ifeq ($(PLATFORM),arm64)
override CROSS_COMPILE += /usr/bin/aarch64-linux-gnu-
$(warning Setting CROSS_COMPILE to $(CROSS_COMPILE))
endif
# DEVICE:
# DEVICE := generic --> Generic Device
# DEVICE := rsmu --> RSMU
ifndef DEVICE
$(warning DEVICE is not defined)
DEVICE := generic
$(warning Setting DEVICE to $(DEVICE) (default)...)
endif
ifndef SYNCED_DEBUG_MODE
$(warning SYNCED_DEBUG_MODE is not defined (SYNCED_DEBUG_MODE must be either 0 or 1))
override SYNCED_DEBUG_MODE := 0
$(warning Setting SYNCED_DEBUG_MODE to $(SYNCED_DEBUG_MODE) (default)...)
endif
PROJ_DIR := .
BUILD_DIR := build
BIN_DIR := $(BUILD_DIR)/bin
OBJ_DIR := $(BUILD_DIR)/obj
PKG_DIR := pkg
CFG_DIR := cfg
CFG_FILES := $(shell find $(CFG_DIR) -name "*.cfg")
TCS_FILES := $(shell find $(CFG_DIR) -name "*.tcs")
RBS_FILES := $(shell find $(CFG_DIR) -name "*.rbs")
LICENSE_FILE := COPYING
MAKEFILE := $(MAKEFILE_LIST)
README_FILE := README.md
COMMON_DIR := common
COMMON_SRC_FILES := $(shell find $(COMMON_DIR) -name "*.c")
CONTROL_DIR := control
CONTROL_SRC_FILES := $(shell find $(CONTROL_DIR) -name "*.c")
DEVICE_ROOT_DIR := device
DEVICE_ADAPTOR_DIR := $(DEVICE_ROOT_DIR)/device_adaptor
DEVICE_GENERIC_DIR := $(DEVICE_ROOT_DIR)/generic
DEVICE_RSMU_DIR := $(DEVICE_ROOT_DIR)/rsmu
DEVICE_ADAPTOR_SRC_FILES := $(shell find $(DEVICE_ADAPTOR_DIR) -name "*.c")
DEVICE_GENERIC_SRC_FILES := $(shell find $(DEVICE_GENERIC_DIR) -name "*.c")
DEVICE_RSMU_SRC_FILES := $(shell find $(DEVICE_RSMU_DIR) -name "*.c")
DEVICE_SRC_FILES := \
$(DEVICE_ADAPTOR_SRC_FILES) \
$(DEVICE_GENERIC_SRC_FILES) \
$(DEVICE_RSMU_SRC_FILES)
ESMC_DIR := esmc
ESMC_STACK_DIR := $(ESMC_DIR)/$(ESMC_STACK)
ESMC_ADAPTOR_DIR := esmc/esmc_adaptor
ESMC_STACK_SRC_FILES := $(shell find $(ESMC_STACK_DIR) -name "*.c")
MANAGEMENT_DIR := management
MANAGEMENT_SRC_FILES := $(shell find $(MANAGEMENT_DIR) -maxdepth 1 -name "*.c")
MONITOR_DIR := monitor
MONITOR_SRC_FILES := $(shell find $(MONITOR_DIR) -name "*.c")
SYNCED_FILE := synced.c
INCS := \
$(PROJ_DIR) \
$(COMMON_DIR) \
$(CONTROL_DIR) \
$(DEVICE_ADAPTOR_DIR) \
$(DEVICE_GENERIC_DIR) \
$(DEVICE_RSMU_DIR) \
$(ESMC_ADAPTOR_DIR) \
$(ESMC_STACK_DIR) \
$(MANAGEMENT_DIR) \
$(MONITOR_DIR)
PREFIXED_INCS := $(addprefix -I,$(INCS))
DEFINES := \
DEVICE=$(subst -,_,$(DEVICE)) \
SYNCED_DEBUG_MODE=$(SYNCED_DEBUG_MODE)
PREFIXED_DEFINES := $(addprefix -D,$(DEFINES))
SRC_FILES := \
$(COMMON_SRC_FILES) \
$(CONTROL_SRC_FILES) \
$(DEVICE_SRC_FILES) \
$(ESMC_STACK_SRC_FILES) \
$(MANAGEMENT_SRC_FILES) \
$(MONITOR_SRC_FILES) \
$(SYNCED_FILE)
OBJS := $(patsubst %.c,%.o,$(SRC_FILES))
OBJS := $(addprefix $(OBJ_DIR)/,$(OBJS))
SYNCED := $(BIN_DIR)/synced
SYNCED_CLI_OBJ_DIR := $(OBJ_DIR)/$(MANAGEMENT_DIR)/cli
SYNCED_CLI_DEFINES := \
DEVICE=$(DEVICE)
SYNCED_CLI_PREFIXED_DEFINES := $(addprefix -D,$(SYNCED_CLI_DEFINES))
SYNCED_CLI_FILE := synced_cli.c
SYNCED_CLI_SRC_FILES := \
$(COMMON_DIR)/common.c \
$(COMMON_DIR)/print.c \
$(SYNCED_CLI_FILE)
SYNCED_CLI_OBJS := $(patsubst %.c,%.o,$(SYNCED_CLI_SRC_FILES))
SYNCED_CLI_OBJS := $(addprefix $(SYNCED_CLI_OBJ_DIR)/,$(SYNCED_CLI_OBJS))
SYNCED_CLI := $(BIN_DIR)/synced_cli
CC := $(CROSS_COMPILE)gcc
CFLAGS := \
$(PREFIXED_DEFINES) \
-Wall \
-Werror \
-Wpedantic \
-Wextra
ifdef USER_CFLAGS
override CFLAGS += \
$(USER_CFLAGS)
endif
LDFLAGS := \
-pthread \
-lrt
ifdef USER_LDFLAGS
override LDFLAGS += \
$(USER_LDFLAGS)
endif
SYNCED_CLI_CFLAGS := \
$(SYNCED_CLI_PREFIXED_DEFINES) \
-Wall \
-Werror \
-Wpedantic \
-Wextra
.DEFAULT_GOAL := all
###############
# T A R G E T S
###############
# Target: all
.PHONY: all
all: clean synced synced-cli
# Target: clean
.PHONY: clean
clean:
@echo "#################################################"
@echo "#"
@echo "# C L E A N I N G B U I L D A R T I F A C T S"
@echo "#"
@echo "#################################################"
$(RM) -r $(SYNCED)
$(RM) -r $(SYNCED_CLI)
$(RM) -rf $(OBJ_DIR)
$(RM) -rf $(SYNCED_CLI_OBJ_DIR)
$(RM) -rf $(PKG_DIR)
# Target: synced
.PHONY: synced
synced: synced-header create-dirs $(SYNCED)
.PHONY: synced-header
synced-header:
@echo "###############################"
@echo "#"
@echo "# B U I L D I N G S Y N C E D"
@echo "#"
@echo "###############################"
@echo "ESMC_STACK: $(ESMC_STACK)"
@echo "PLATFORM: $(PLATFORM)"
@echo "CROSS_COMPILE: $(CROSS_COMPILE)"
@echo "DEVICE: $(DEVICE)"
@echo "SYNCED_DEBUG_MODE: $(SYNCED_DEBUG_MODE)"
.PHONY: create-dirs
create-dirs:
mkdir -p $(BIN_DIR)
mkdir -p $(OBJ_DIR)
mkdir -p $(SYNCED_CLI_OBJ_DIR)
$(OBJ_DIR)/%.o: %.c
mkdir -p $(dir $@)
$(CC) \
$(PREFIXED_INCS) \
$(CFLAGS) \
-o $@ \
-c $^
$(SYNCED): $(OBJS)
$(CC) \
-o $@ \
$^ \
$(LDFLAGS)
# Target: synced-cli
.PHONY: synced-cli
synced-cli: synced-cli-header create-dirs $(SYNCED_CLI)
.PHONY: synced-cli-header
synced-cli-header:
@echo "#######################################"
@echo "#"
@echo "# B U I L D I N G S Y N C E D C L I"
@echo "#"
@echo "#######################################"
$(SYNCED_CLI_OBJ_DIR)/%.o: %.c
mkdir -p $(dir $@)
$(CC) \
$(PREFIXED_INCS) \
$(SYNCED_CLI_CFLAGS) \
-o $@ \
-c $^
$(SYNCED_CLI): $(SYNCED_CLI_OBJS)
$(CC) \
-o $@ \
$^
# Target: help
.PHONY: help
help:
@echo "#########################################"
@echo "#"
@echo "# S Y N C E D M A K E F I L E H E L P"
@echo "#"
@echo "#########################################"
@echo "Makefile for synced program"
@echo " Makefile targets:"
@echo " all - Clean build artifacts, build synced binary executable, and build synced_cli binary executable"
@echo " clean - Clean build artifacts"
@echo " help - Display Makefile commands"
@echo " synced - Build synced binary executable"
@echo " synced_cli - Build synced_cli binary executable"
@echo " Makefile command line variables:"
@echo " ESMC_STACK - ESMC stack type"
@echo " e.g. Use Renesas ESMC stack: ESMC_STACK=renesas"
@echo " PLATFORM - Platform type"
@echo " e.g. Target AMD64 platform: PLATFORM=amd64"
@echo " e.g. Target ARM64 platform: PLATFORM=arm64"
@echo " CROSS_COMPILE - Cross-compiler"
@echo " e.g. Compile for ARM64: CROSS_COMPILE=/usr/bin/aarch64-linux-gnu-"
@echo " DEVICE - Device"
@echo " e.g. Employ generic device: DEVICE=generic"
@echo " e.g. Employ RSMU device: DEVICE=rsmu"
@echo " SYNCED_DEBUG_MODE - Debug mode enable"
@echo " e.g. Enable debug mode: SYNCED_DEBUG_MODE=1"
@echo " e.g. Disabled debug mode: SYNCED_DEBUG_MODE=0"
@echo " USER_CFLAGS - User-defined compiler flag(s)"
@echo " e.g. Compile with C99 standard: USER_CFLAGS=-std=c99"
@echo " e.g. Enable debug mode: USER_CFLAGS=-DSYNCED_DEBUG_MODE"
@echo " e.g. Compile with C99 standard and enable debug mode: USER_CFLAGS=\"-std=c99 -DSYNCED_DEBUG_MODE\""
@echo " USER_LDFLAGS - User-defined linker flag(s)"
@echo " e.g. Link C math library: USER_LDFLAGS=-lm"
@echo " e.g. Link C thread library: USER_LDFLAGS=-lpthread"
@echo " e.g. Link C math and thread libraries: USER_LDFLAGS=\"-lm -lpthread\""