-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile_Bricklet.mk
81 lines (73 loc) · 3 KB
/
Makefile_Bricklet.mk
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
DOCKER_LOCK_FILE := "$(ROOT_DIR)/DOCKER_LOCK"
INTERACTIVE := $(shell [ -t 0 ] && echo 1)
ifdef INTERACTIVE
DOCKER_FLAGS := -it
else
DOCKER_FLAGS :=
endif
.PHONY: $(MAKECMDGOALS) check cmake make clean
# Always go to the targets check, cmake and make.
# "check" checks if the tf docker dev environment is installed and calls it
# "cmake" calls cmake and generates the Makefile
# "make" calls the Makefile generated by cmake with the CMD given to this Makefile
all $(MAKECMDGOALS): check cmake make
check:
# First we check if the temporary file is there and delete it.
# It might still be there if a PC crashed mid build or similar
@if [ -f "$(DOCKER_LOCK_FILE)" ]; then \
rm $(DOCKER_LOCK_FILE); \
fi
# Then we check if bricklib/brickletlib is symlinked correctly
@if [ ! -d "src/bricklib" ]; then \
echo "Could not find bricklib. Please symlink bricklib into src/ folder."; \
exit 1; \
fi
@if [ ! -d "src/brickletlib" ]; then \
echo "Could not find brickletlib. Please symlink brickletlib into src/ folder."; \
exit 1; \
fi
# Then we check if docker is available and if the build_environment_c container
# is available. If both is the case, we start the docker container, call this
# Makefile in the docker container and write a temporary file
@if command -v docker >/dev/null 2>&1 ; then \
if [ $$(docker images -q tinkerforge/build_environment_c:latest) ]; then \
echo "Using docker image to build."; \
docker run $(DOCKER_FLAGS) \
-v $(ROOT_DIR)/../:/$(ROOT_DIR)/../ -u $$(id -u):$$(id -g) \
-v $(BRICKLIB_PATH)/:$(BRICKLIB_PATH)/: -u $$(id -u):$$(id -g) \
-v $(BRICKLETLIB_PATH)/:$(BRICKLETLIB_PATH)/: -u $$(id -u):$$(id -g) \
tinkerforge/build_environment_c:latest /bin/bash \
-c "cd $(ROOT_DIR) ; make $(MAKECMDGOALS)" && \
touch $(DOCKER_LOCK_FILE); \
else \
echo "No docker image found, using local toolchain."; \
fi \
fi
cmake:
# If there is the temporary file, we are currently outside of the docker container
# and the docker container is running. In this case we do nothing. Otherwise
# we generate a Makefile with cmake
# Because of a bug in cmake we have to call it two times... For the second
# execution the toolchain files are already defined
@if [ ! -f $(DOCKER_LOCK_FILE) ]; then \
if [ ! -f "build/Makefile" ]; then \
mkdir -p build; \
cmake -E chdir build/ cmake -DCMAKE_TOOLCHAIN_FILE=$(BRICKLIB_PATH)/toolchains/arm-none-eabi.cmake ../; \
cmake -E chdir build/ cmake ../; \
fi \
fi
make:
# If there is the temporary file, we are currently outside of the docker container
# and the docker container is running. In this case we delete the temporary file,
# since this is the last target run outside of the docker container.
# Otherwise we call the Makefile generated by cmake.
@if [ ! -f $(DOCKER_LOCK_FILE) ]; then \
cd build/; \
make $(MAKECMDGOALS); \
else \
rm $(DOCKER_LOCK_FILE); \
fi
clean:
# In case of a clean we just remove the whole build/ directory. Doesn't matter if
# if we are inside or outside of the docker container here.
@rm -rf build/