-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
225 lines (186 loc) · 5.9 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
# Copyright 2024 Robert Bosch GmbH
#
# SPDX-License-Identifier: Apache-2.0
################
## DSE Projects.
export DSE_CLIB_VERSION ?= 1.0.26
export DSE_MODELC_VERSION ?= 2.1.9
###############
## Docker Images.
GCC_BUILDER_IMAGE ?= ghcr.io/boschglobal/dse-gcc-builder:main
TESTSCRIPT_IMAGE ?= ghcr.io/boschglobal/dse-testscript:latest
SIMER_IMAGE ?= ghcr.io/boschglobal/dse-simer:$(DSE_MODELC_VERSION)
###############
## Tools (Container Images).
TOOL_DIRS = fmi
###############
## Build parameters.
export NAMESPACE = dse
export MODULE = fmi
export EXTERNAL_BUILD_DIR ?= /tmp/$(NAMESPACE).$(MODULE)
export PACKAGE_ARCH ?= linux-amd64
export PACKAGE_ARCH_LIST ?= $(PACKAGE_ARCH)
export CMAKE_TOOLCHAIN_FILE ?= $(shell pwd -P)/extra/cmake/$(PACKAGE_ARCH).cmake
SUBDIRS = $(NAMESPACE)
export MODELC_SANDBOX_DIR ?= $(shell pwd -P)/dse/modelc/build/_out
export MAKE_NPROC ?= $(shell nproc)
###############
## Package parameters.
export PACKAGE_VERSION ?= 0.0.1
DIST_DIR := $(shell pwd -P)/$(NAMESPACE)/build/_dist
OSS_DIR = $(NAMESPACE)/__oss__
PACKAGE_DOC_NAME = DSE FMI Library
PACKAGE_NAME = Fmi
PACKAGE_NAME_LC = fmi
PACKAGE_PATH = $(NAMESPACE)/dist
###############
## Test Parameters.
export HOST_DOCKER_WORKSPACE ?= $(shell pwd -P)
export TESTSCRIPT_E2E_DIR ?= tests/testscript/e2e
TESTSCRIPT_E2E_FILES = $(wildcard $(TESTSCRIPT_E2E_DIR)/*.txtar)
ifneq ($(CI), true)
DOCKER_BUILDER_CMD := docker run -it --rm \
--env CMAKE_TOOLCHAIN_FILE=/tmp/repo/extra/cmake/$(PACKAGE_ARCH).cmake \
--env EXTERNAL_BUILD_DIR=$(EXTERNAL_BUILD_DIR) \
--env GDB_CMD="$(GDB_CMD)" \
--env PACKAGE_ARCH=$(PACKAGE_ARCH) \
--env PACKAGE_VERSION=$(PACKAGE_VERSION) \
--volume $$(pwd):/tmp/repo \
--volume $(EXTERNAL_BUILD_DIR):$(EXTERNAL_BUILD_DIR) \
--volume ~/.ccache:/root/.ccache \
--workdir /tmp/repo \
$(GCC_BUILDER_IMAGE)
endif
default: build
.PHONY: build
build:
@${DOCKER_BUILDER_CMD} $(MAKE) do-build
.PHONY: package
package:
@${DOCKER_BUILDER_CMD} $(MAKE) do-package
.PHONY: test_tools
test_tools:
for d in $(TOOL_DIRS) ;\
do \
cd extra/tools/$$d ;\
make ;\
make test ;\
done;
.PHONY: fmi
fmi:
mkdir -p extra/tools/fmi/build/stage/lib
mkdir -p extra/tools/fmi/build/stage/lib32
mkdir -p extra/tools/fmi/build/stage/examples/fmimodelc/sim
touch extra/tools/fmi/build/stage/lib32/.nop
@if [ ${PACKAGE_ARCH} = "linux-amd64" ]; then \
cp dse/build/_out/fmimodelc/lib/libfmi2modelcfmu.so extra/tools/fmi/build/stage/lib/fmi2modelcfmu.so ;\
cp -r licenses -t extra/tools/fmi/build/stage ;\
cp -r dse/build/_out/fmimodelc/examples/network_fmu/fmu/resources/sim -t extra/tools/fmi/build/stage/examples/fmimodelc ;\
fi
@if [ ${PACKAGE_ARCH} = "linux-x86" ]; then \
cp dse/build/_out/fmimodelc/lib/libfmi2modelcfmu.so extra/tools/fmi/build/stage/lib32/fmi2modelcfmu_x86.so ;\
fi
@if [ ${PACKAGE_ARCH} = "linux-i386" ]; then \
cp dse/build/_out/fmimodelc/lib/libfmi2modelcfmu.so extra/tools/fmi/build/stage/lib32/fmi2modelcfmu_i386.so ;\
fi
.PHONY: tools
tools:
for d in $(TOOL_DIRS) ;\
do \
docker build -f extra/tools/$$d/build/package/Dockerfile \
--tag $$d:test extra/tools/$$d ;\
done;
do-test_cmocka-build:
$(MAKE) -C tests/cmocka build
do-test_cmocka-run:
$(MAKE) -C tests/cmocka run
test_cmocka:
ifeq ($(PACKAGE_ARCH), linux-amd64)
@${DOCKER_BUILDER_CMD} $(MAKE) do-test_cmocka-build
@${DOCKER_BUILDER_CMD} $(MAKE) do-test_cmocka-run
endif
.PHONY: test_e2e
test_e2e: do-test_testscript-e2e
do-test_testscript-e2e:
# Test debug;
# Additional logging: add '-v' to Testscript command (e.g. $(TESTSCRIPT_IMAGE) -v \).
# Retain work folder: add '-work' to Testscript command (e.g. $(TESTSCRIPT_IMAGE) -work \).
ifeq ($(PACKAGE_ARCH), linux-amd64)
@-docker kill simer
@set -eu; for t in $(TESTSCRIPT_E2E_FILES) ;\
do \
export ENTRYWORKDIR=$$(mktemp -d) ;\
echo "Running E2E Test: $$t (in $${ENTRYWORKDIR})" ;\
docker run -i --rm \
-e ENTRYHOSTDIR=$(HOST_DOCKER_WORKSPACE) \
-e ENTRYWORKDIR=$${ENTRYWORKDIR} \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(HOST_DOCKER_WORKSPACE):/repo \
-v $${ENTRYWORKDIR}:/workdir \
$(TESTSCRIPT_IMAGE) \
-e ENTRYHOSTDIR=$(HOST_DOCKER_WORKSPACE) \
-e ENTRYWORKDIR=$${ENTRYWORKDIR} \
-e REPODIR=/repo \
-e WORKDIR=/workdir \
-e SIMER=$(SIMER_IMAGE) \
-e FMI_IMAGE=$(FMI_IMAGE) \
-e FMI_TAG=$(FMI_TAG) \
$$t ;\
done;
endif
.PHONY: test
test: test_cmocka test_e2e
.PHONY: clean
clean:
@${DOCKER_BUILDER_CMD} $(MAKE) do-clean
for d in $(TOOL_DIRS) ;\
do \
rm -rf extra/tools/$$d/build/stage ;\
done;
docker images -qf dangling=true | xargs -r docker rmi
.PHONY: cleanall
cleanall:
@${DOCKER_BUILDER_CMD} $(MAKE) do-cleanall
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
docker images -qf dangling=true | xargs -r docker rmi
docker volume ls -qf dangling=true | xargs -r docker volume rm
docker images -q */*/$(NAMESPACE)-fmi | xargs -r docker rmi
.PHONY: oss
oss:
@${DOCKER_BUILDER_CMD} $(MAKE) do-oss
.PHONY: do-build
do-build:
@for d in $(SUBDIRS); do ($(MAKE) -C $$d build ); done
.PHONY: do-package
do-package:
@for d in $(SUBDIRS); do ($(MAKE) -C $$d package ); done
.PHONY: do-clean
do-clean:
@for d in $(SUBDIRS); do ($(MAKE) -C $$d clean ); done
$(MAKE) -C tests/cmocka clean
rm -rf $(OSS_DIR)
rm -rf doc_
rm -rvf *.zip
rm -rvf *.log
.PHONY: do-cleanall
do-cleanall: do-clean
@for d in $(SUBDIRS); do ($(MAKE) -C $$d cleanall ); done
$(MAKE) -C tests/cmocka cleanall
.PHONY: do-oss
do-oss:
$(MAKE) -C extra/external oss
.PHONY: generate
generate:
$(MAKE) -C doc generate
.PHONY: super-linter
super-linter:
docker run --rm --volume $$(pwd):/tmp/lint \
--env RUN_LOCAL=true \
--env DEFAULT_BRANCH=main \
--env IGNORE_GITIGNORED_FILES=true \
--env FILTER_REGEX_EXCLUDE="(doc/content/.*|extra/tools/fmi/vendor/.*)" \
--env VALIDATE_CPP=true \
--env VALIDATE_DOCKERFILE=true \
--env VALIDATE_MARKDOWN=true \
--env VALIDATE_YAML=true \
ghcr.io/super-linter/super-linter:slim-v6