-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
123 lines (99 loc) · 3.67 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
.PHONY: all build build-container cmake format format-linux flash-stlink format-container shell image build-container clean clean-image clean-all flash-baseline
############################### Native Makefile ###############################
SHELL := /bin/bash
PROJECT_NAME ?= datalog
BUILD_DIR ?= build
FIRMWARE := $(BUILD_DIR)/$(PROJECT_NAME).bin
BUILD_TYPE ?= Debug
PLATFORM = $(if $(OS),$(OS),$(shell uname -s))
ifeq ($(PLATFORM),Windows_NT)
BUILD_SYSTEM ?= MinGW Makefiles
else
ifeq ($(PLATFORM),Linux)
BUILD_SYSTEM ?= Unix Makefiles
else
@echo "Unsuported platform"
exit 1
endif
endif
all: build
build: cmake
$(MAKE) -C $(BUILD_DIR) --no-print-directory
cmake: $(BUILD_DIR)/Makefile
$(BUILD_DIR)/Makefile: CMakeLists.txt
cmake \
-G "$(BUILD_SYSTEM)" \
-B$(BUILD_DIR) \
-DPROJECT_NAME=$(PROJECT_NAME) \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DDUMP_ASM=OFF
# Formats all user modified source files (add ones that are missing)
SRCS := $(shell find app -name '*.[ch]' -or -name '*.[ch]pp') app/main.c
format: $(addsuffix .format,$(SRCS))
%.format: %
clang-format -i $<
# Formats all CubeMX generated sources to unix style - removes \r from line endings
# Add any new directories, like Middlewares and hidden files
HIDDEN_FILES := .mxproject .project .cproject
FOUND_HIDDEN_FILES := $(shell for f in $(HIDDEN_FILES);do if [[ -e $$f ]]; then echo $$f;fi; done)
FORMAT_LINUX := $(shell find app drivers -name '*' -type f; find . -name '*.ioc') $(FOUND_HIDDEN_FILES)
format-linux: $(addsuffix .format-linux,$(FORMAT_LINUX))
%.format-linux: %
$(if $(filter $(PLATFORM),Linux),dos2unix -q $<,)
flash-stlink: build
st-flash --reset write $(FIRMWARE) 0x08000000
flash-baseline: baseline
st-flash --reset write baseline/HSDatalog_DummyData.bin 0x08000000
clean:
rm -rf $(BUILD_DIR)
################################## Container ##################################
UID ?= $(shell id -u)
GID ?= $(shell id -g)
USER ?= $(shell id -un)
GROUP ?= $(if $(filter $(PLATFORM), Windows_NT),$(shell id -un),$(shell id -gn))
ifeq ($(PLATFORM),Windows_NT)
WIN_PREFIX = winpty
WORKDIR_PATH = "//workdir"
WORKDIR_VOLUME = "/$$(pwd -W):/workdir"
else
WORKDIR_PATH = /workdir
WORKDIR_VOLUME = "$$(pwd):/workdir"
endif
CONTAINER_TOOL ?= docker
CONTAINER_FILE := Dockerfile
IMAGE_NAME := fedora-arm-embedded-dev
CONTAINER_NAME := fedora-arm-embedded-dev
NEED_IMAGE = $(shell $(CONTAINER_TOOL) image inspect $(IMAGE_NAME) 2> /dev/null > /dev/null || echo image)
# usefull if you have a always running container in the background: NEED_CONTAINER = $(shell $(CONTAINER_TOOL) container inspect $(CONTAINER_NAME) 2> /dev/null > /dev/null || echo container)
PODMAN_ARG = $(if $(filter $(CONTAINER_TOOL), podman),--userns=keep-id,)
CONTAINER_RUN = $(WIN_PREFIX) $(CONTAINER_TOOL) run \
--name $(CONTAINER_NAME) \
--rm \
-it \
$(PODMAN_ARG) \
-v $(WORKDIR_VOLUME) \
-w $(WORKDIR_PATH) \
--security-opt label=disable \
--hostname $(CONTAINER_NAME) \
$(IMAGE_NAME)
build-container: $(NEED_IMAGE)
$(CONTAINER_RUN) bash -lc 'make -j$(shell nproc)'
format-container:
$(CONTAINER_RUN) bash -lc 'make format -j$(shell nproc)'
format-linux-container:
$(CONTAINER_RUN) bash -lc 'make format-linux'
shell:
$(CONTAINER_RUN) bash -l
image: $(CONTAINER_FILE)
$(CONTAINER_TOOL) build \
-t $(IMAGE_NAME) \
-f=$(CONTAINER_FILE) \
--build-arg UID=$(UID) \
--build-arg GID=$(GID) \
--build-arg USERNAME=$(USER) \
--build-arg GROUPNAME=$(GROUP) \
.
clean-image:
$(CONTAINER_TOOL) container rm -f $(CONTAINER_NAME) 2> /dev/null > /dev/null || true
$(CONTAINER_TOOL) image rmi -f $(IMAGE_NAME) 2> /dev/null > /dev/null || true
clean-all: clean clean-image