Repository navigation
Expand file tree
/
Copy pathmakefile.toolchain
More file actions
81 lines (64 loc) · 4 KB
/
Copy pathmakefile.toolchain
File metadata and controls
81 lines (64 loc) · 4 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
72
73
74
75
76
77
78
79
80
81
# 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
TOOLCHAIN_NAME=$(PLATFORM)
GIT_IF_NECESSARY=toolchains/$(TOOLCHAIN_NAME)-toolchain
INIT_IF_NECESSARY=toolchains/$(TOOLCHAIN_NAME)-toolchain/.build
IMAGE_NAME=ghcr.io/loveretro/$(TOOLCHAIN_NAME)-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/$(TOOLCHAIN_NAME)-toolchain && make .build
$(GIT_IF_NECESSARY):
mkdir -p toolchains
git clone https://github.com/LoveRetro/$(TOOLCHAIN_NAME)-toolchain/ toolchains/$(TOOLCHAIN_NAME)-toolchain
$(CONTAINER_RUNTIME) pull $(IMAGE_NAME) && touch toolchains/$(TOOLCHAIN_NAME)-toolchain/.build
clean:
cd toolchains/$(TOOLCHAIN_NAME)-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
# The platform reaches the guest build through the environment only, never as a
# `make PLATFORM=...` argument. A command-line variable lands in MAKEOVERRIDES and
# overrides same-named assignments in *every* recursive make, including each core's
# own `PLATFORM = libretro` (picodrive, pcsx_rearmed) — those then build without
# their libretro frontend and link to an entry-point-less stub. Environment values
# lose to a makefile assignment, which is what workspace/makefile expects.
build: $(INIT_IF_NECESSARY) _runtime_check
$(CONTAINER_RUNTIME) run --rm $(CONTAINER_MOUNT_OPTS) -v $(HOST_WORKSPACE):$(GUEST_WORKSPACE) -e COMPILE_CORES=$(COMPILE_CORES) -e PLATFORM=$(PLATFORM) -e UNION_PLATFORM=$(PLATFORM) $(IMAGE_NAME) /bin/bash -c '. ~/.bashrc && export PLATFORM=$(PLATFORM) UNION_PLATFORM=$(PLATFORM) && 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) -e PLATFORM=$(PLATFORM) -e UNION_PLATFORM=$(PLATFORM) $(IMAGE_NAME) /bin/bash -c '. ~/.bashrc && export PLATFORM=$(PLATFORM) UNION_PLATFORM=$(PLATFORM) && 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) -e PLATFORM=$(PLATFORM) -e UNION_PLATFORM=$(PLATFORM) $(IMAGE_NAME) /bin/bash -c '. ~/.bashrc && export PLATFORM=$(PLATFORM) UNION_PLATFORM=$(PLATFORM) && cd /root/workspace && make core'
@echo "$(CURRENT_RUNTIME)" > $(RUNTIME_MARKER)