forked from batocera-linux/batocera.linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
132 lines (108 loc) · 4.09 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
PROJECT_DIR := $(shell pwd)
DL_DIR ?= $(PROJECT_DIR)/dl
OUTPUT_DIR ?= $(PROJECT_DIR)/output
CCACHE_DIR ?= $(PROJECT_DIR)/buildroot-ccache
LOCAL_MK ?= $(PROJECT_DIR)/batocera.mk
EXTRA_PKGS ?=
-include $(LOCAL_MK)
DOCKER_REPO := batocera
IMAGE_NAME := batocera.linux-build
TARGETS := $(sort $(shell find $(PROJECT_DIR)/configs/ -name 'b*' | sed -n 's/.*\/batocera-\(.*\)_defconfig/\1/p'))
UID := $(shell id -u)
GID := $(shell id -g)
USER := $(shell whoami)
$(if $(shell which docker 2>/dev/null),, $(error "docker not found!"))
UC = $(shell echo '$1' | tr '[:lower:]' '[:upper:]')
vars:
@echo "Supported targets: $(TARGETS)"
@echo "Project directory: $(PROJECT_DIR)"
@echo "Download directory: $(DL_DIR)"
@echo "Build directory: $(OUTPUT_DIR)"
@echo "ccache directory: $(CCACHE_DIR)"
@echo "Extra options: $(EXTRA_OPTS)"
@echo "Docker options: $(DOCKER_OPTS)"
build-docker-image:
docker build . -t $(DOCKER_REPO)/$(IMAGE_NAME)
@touch .ba-docker-image-available
.ba-docker-image-available:
@docker pull $(DOCKER_REPO)/$(IMAGE_NAME)
@touch .ba-docker-image-available
batocera-docker-image: .ba-docker-image-available
update-docker-image:
-@rm .ba-docker-image-available > /dev/null
@$(MAKE) batocera-docker-image
publish-docker-image:
@docker push $(DOCKER_REPO)/$(IMAGE_NAME):latest
output-dir-%:
@mkdir -p $(OUTPUT_DIR)/$*
ccache-dir:
@mkdir -p $(CCACHE_DIR)
%-supported:
$(if $(findstring $*, $(TARGETS)),,$(error "$* not supported!"))
%-clean: batocera-docker-image %-supported output-dir-%
@docker run -it --init --rm \
-v $(PROJECT_DIR):/build \
-v $(DL_DIR):/build/buildroot/dl \
-v $(OUTPUT_DIR)/$*:/$* \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
-u $(UID):$(GID) \
batocera/batocera.linux-build \
make O=/$* BR2_EXTERNAL=/build -C /build/buildroot clean
%-config: batocera-docker-image %-supported output-dir-%
@cp -f $(PROJECT_DIR)/configs/batocera-$*_defconfig $(PROJECT_DIR)/configs/batocera-$*_defconfig-tmp
@for opt in $(EXTRA_OPTS); do \
echo $$opt >> $(PROJECT_DIR)/configs/batocera-$*_defconfig ; \
done
@docker run -it --init --rm \
-v $(PROJECT_DIR):/build \
-v $(DL_DIR):/build/buildroot/dl \
-v $(OUTPUT_DIR)/$*:/$* \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
-u $(UID):$(GID) \
batocera/batocera.linux-build \
make O=/$* BR2_EXTERNAL=/build -C /build/buildroot batocera-$*_defconfig
@mv -f $(PROJECT_DIR)/configs/batocera-$*_defconfig-tmp $(PROJECT_DIR)/configs/batocera-$*_defconfig
%-build: batocera-docker-image %-supported %-config ccache-dir
@docker run -it --rm \
-v $(PROJECT_DIR):/build \
-v $(DL_DIR):/build/buildroot/dl \
-v $(OUTPUT_DIR)/$*:/$* \
-v $(CCACHE_DIR):/home/$(USER)/.buildroot-ccache \
-u $(UID):$(GID) \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
$(DOCKER_OPTS) \
batocera/batocera.linux-build \
make O=/$* BR2_EXTERNAL=/build -C /build/buildroot $(CMD)
%-shell: batocera-docker-image %-supported output-dir-%
@docker run -it --rm \
-v $(PROJECT_DIR):/build \
-v $(DL_DIR):/build/buildroot/dl \
-v $(OUTPUT_DIR)/$*:/$* -w /$* \
-v $(CCACHE_DIR):/home/$(USER)/.buildroot-ccache \
-u $(UID):$(GID) \
$(DOCKER_OPTS) \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
batocera/batocera.linux-build
%-cleanbuild: %-clean %-build
@echo
%-pkg:
$(if $(PKG),,$(error "PKG not specified!"))
@$(MAKE) $*-build CMD=$(PKG)
%-webserver: output-dir-%
$(if $(wildcard $(OUTPUT_DIR)/$*/images/batocera/*),,$(error "$* not built!"))
$(if $(shell which python 2>/dev/null),,$(error "python not found!"))
python -m http.server --directory $(OUTPUT_DIR)/$*/images/batocera
%-rsync: output-dir-%
$(eval TMP := $(call UC, $*)_IP)
$(if $(shell which rsync 2>/dev/null),, $(error "rsync not found!"))
$(if $($(TMP)),,$(error "$(TMP) not set!"))
rsync -e "ssh -o 'UserKnownHostsFile /dev/null' -o StrictHostKeyChecking=no" -av $(OUTPUT_DIR)/$*/target/ root@$($(TMP)):/
%-tail: output-dir-%
@tail -F $(OUTPUT_DIR)/$*/build/build-time.log
%-toolchain: %-config
@$(MAKE) $*-build CMD=toolchain
@$(MAKE) $*-build CMD=llvm