forked from LoveRetro/NextUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile.toolchain
More file actions
71 lines (56 loc) · 3.11 KB
/
Copy pathmakefile.toolchain
File metadata and controls
71 lines (56 loc) · 3.11 KB
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
# there is no reason to use this makefile manually
.PHONY: build clean _runtime_check
ifeq (,$(PLATFORM))
$(error please specify PLATFORM, eg. make PLATFORM=trimui)
endif
HOST_WORKSPACE=$(shell pwd)/workspace
GUEST_WORKSPACE=/root/workspace
GIT_IF_NECESSARY=toolchains/$(PLATFORM)-toolchain
INIT_IF_NECESSARY=toolchains/$(PLATFORM)-toolchain/.build
IMAGE_NAME=ghcr.io/loveretro/$(PLATFORM)-toolchain:latest
CONTAINER_RUNTIME ?= $(shell command -v docker 2>/dev/null || command -v podman 2>/dev/null)
ifeq (,$(CONTAINER_RUNTIME))
$(error Neither docker nor podman found in PATH)
endif
# Extra flags injected before the workspace bind mount. On SELinux-enforcing
# hosts (eg. Fedora Toolbox) set this to "--security-opt label=disable" so the
# container can read the mounted workspace.
CONTAINER_MOUNT_OPTS ?=
RUNTIME_MARKER := $(HOST_WORKSPACE)/.container_runtime
LAST_RUNTIME := $(shell cat $(RUNTIME_MARKER) 2>/dev/null)
CURRENT_RUNTIME := $(notdir $(CONTAINER_RUNTIME))
all: $(INIT_IF_NECESSARY)
$(CONTAINER_RUNTIME) run -it --rm $(CONTAINER_MOUNT_OPTS) -v $(HOST_WORKSPACE):$(GUEST_WORKSPACE) $(IMAGE_NAME) /bin/bash
$(INIT_IF_NECESSARY): $(GIT_IF_NECESSARY)
cd toolchains/$(PLATFORM)-toolchain && make .build
$(GIT_IF_NECESSARY):
mkdir -p toolchains
git clone https://github.com/LoveRetro/$(PLATFORM)-toolchain/ toolchains/$(PLATFORM)-toolchain
$(CONTAINER_RUNTIME) pull $(IMAGE_NAME) && touch toolchains/$(PLATFORM)-toolchain/.build
clean:
cd toolchains/$(PLATFORM)-toolchain && make clean
_runtime_check:
@if [ -n "$(LAST_RUNTIME)" ] && [ "$(LAST_RUNTIME)" != "$(CURRENT_RUNTIME)" ]; then \
echo "Container runtime changed ($(LAST_RUNTIME) -> $(CURRENT_RUNTIME)), cleaning workspace build artifacts..."; \
PREV=$$(command -v $(LAST_RUNTIME) 2>/dev/null); \
if [ -n "$$PREV" ]; then \
$$PREV run --rm $(CONTAINER_MOUNT_OPTS) -v $(HOST_WORKSPACE):$(GUEST_WORKSPACE) $(IMAGE_NAME) /bin/bash -c \
'find $(GUEST_WORKSPACE) -depth -user root -delete 2>/dev/null; true'; \
else \
echo "Error: previous runtime $(LAST_RUNTIME) not available to clean root-owned artifacts."; \
echo "Run: sudo rm -rf $(HOST_WORKSPACE)/*/build $(HOST_WORKSPACE)/$(PLATFORM)/other"; \
exit 1; \
fi; \
fi
build: $(INIT_IF_NECESSARY) _runtime_check
$(CONTAINER_RUNTIME) run --rm $(CONTAINER_MOUNT_OPTS) -v $(HOST_WORKSPACE):$(GUEST_WORKSPACE) -e COMPILE_CORES=$(COMPILE_CORES) $(IMAGE_NAME) /bin/bash -c '. ~/.bashrc && cd /root/workspace && make'
@echo "$(CURRENT_RUNTIME)" > $(RUNTIME_MARKER)
build-cores: $(INIT_IF_NECESSARY) _runtime_check
$(CONTAINER_RUNTIME) run --rm $(CONTAINER_MOUNT_OPTS) -v $(HOST_WORKSPACE):$(GUEST_WORKSPACE) -e COMPILE_CORES=$(COMPILE_CORES) $(IMAGE_NAME) /bin/bash -c '. ~/.bashrc && cd /root/workspace && make cores'
@echo "$(CURRENT_RUNTIME)" > $(RUNTIME_MARKER)
build-core: $(INIT_IF_NECESSARY) _runtime_check
ifndef CORE
$(error CORE is not set)
endif
$(CONTAINER_RUNTIME) run --rm $(CONTAINER_MOUNT_OPTS) -v $(HOST_WORKSPACE):$(GUEST_WORKSPACE) -e COMPILE_CORES=$(COMPILE_CORES) -e CORE=$(CORE) $(IMAGE_NAME) /bin/bash -c '. ~/.bashrc && cd /root/workspace && make core'
@echo "$(CURRENT_RUNTIME)" > $(RUNTIME_MARKER)