summaryrefslogtreecommitdiffstats
path: root/util/manibuilder/Makefile
blob: 2313717a8ccdd0ff6f340b73daf38a5fd7cb64c1 (plain)
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
QUIET_TEST := @

include Makefile.targets

CC := ccache cc
MAKECMD := make

spc :=
spc := $(spc) $(spc)

stem = $(word 1,$(subst :,$(spc),$(subst \:,$(spc),$(1))))
ident = $(subst :,_,$(subst \:,_,$(1)))

PKGSRC_MIRROR = http://cdn.netbsd.org/
NETBSD_MIRROR = http://ftp.de.netbsd.org/

anita\:amd64-build: PKGSRC_PATH=pub/pkgsrc/packages/NetBSD/amd64/7.1/All
anita\:amd64-build: NETBSD_IMAGE=pub/NetBSD/NetBSD-7.1/amd64/

anita\:i386-build: PKGSRC_PATH=pub/pkgsrc/packages/NetBSD/i386/7.1/All
anita\:i386-build: NETBSD_IMAGE=pub/NetBSD/NetBSD-7.1/i386/

$(addsuffix -build,$(ANITA_TAGS)): %-build: Dockerfile.anita anita-wrapper.sh
	$(QUIET_SETUP)docker build . -f $< -t mani/$* \
		--build-arg PKG_PATH=$(PKGSRC_MIRROR)$(PKGSRC_PATH) \
		--build-arg INST_IMG=$(NETBSD_MIRROR)$(NETBSD_IMAGE)

define build_template
Dockerfile.$(call ident,$(1)): Dockerfile.$(call stem,$(1)) mani-wrapper.sh
	$(QUIET_SETUP)sed -e 's|^FROM manibase|FROM $(2)/$(1)|' $$< >$$@

.INTERMEDIATE: Dockerfile.$(call ident,$(1))

$(1)-build: Dockerfile.$(call ident,$(1))
	$(QUIET_SETUP)docker build . -f $$< -t mani/$(1)
endef

$(foreach tag,$(MULTIARCH_TAGS), \
	$(eval $(call build_template,$(tag),multiarch)))

djgpp\:6.1.0-build: %-build: Dockerfile.djgpp mani-wrapper.sh
	$(QUIET_SETUP)docker build . -f $< -t mani/$*

$(addsuffix -check-build,$(ALL_TAGS)): %-check-build:
	$(QUIET_SETUP)\
	[ $$(docker image ls -q mani/$*) ] \
		|| $(MAKE) $*-build $(if $(QUIET_SETUP),>/dev/null 2>/dev/null)

$(filter centos%,$(MULTIARCH_TAGS)) anita\:sparc: CC=cc
djgpp\:6.1.0: CC=ccache i586-pc-msdosdjgpp-gcc
djgpp\:6.1.0: STRIP=i586-pc-msdosdjgpp-strip
djgpp\:6.1.0: LIBS_BASE=../
djgpp\:6.1.0: TARGET=strip
$(ANITA_TAGS): MAKECMD=gmake
$(ALL_TAGS): export QUIET_SETUP=$(QUIET_TEST)
$(ALL_TAGS): %: %-check-build
	$(QUIET_TEST)docker rm -f mani_$(call ident,$*) >/dev/null 2>&1 || true
	$(QUIET_TEST)\
	docker run \
		--env IDENT=$(call ident,$*) \
		--volume manicache:/home/mani/.ccache \
		--name mani_$(call ident,$*) mani/$* \
		"git fetch origin $${TEST_REVISION:-master} && \
		 git checkout FETCH_HEAD && \
		 $(MAKECMD) clean && $(MAKECMD) -j$${CPUS:-1} CC='$(CC)' \
		 $(if $(STRIP),STRIP='$(STRIP)') \
		 $(if $(LIBS_BASE),LIBS_BASE='$(LIBS_BASE)') \
		 $(TARGET)" \
		$(if $(QUIET_TEST),>/dev/null 2>&1) || echo $*: $$?

$(addsuffix -shell,$(ALL_TAGS)): %-shell: %-check-build
	$(QUIET_SETUP)\
	if [ $$(docker ps -a -q -f name=mani_$(call ident,$*)) ]; then \
		docker commit mani_$(call ident,$*) mani_run/$* && \
		docker run --rm -it \
			--env IDENT=$(call ident,$*) \
			--volume manicache:/home/mani/.ccache \
			--entrypoint /bin/sh mani_run/$* \
			/home/mani/mani-wrapper.sh \
			$(patsubst %,"%",$(SHELL_ARG)); \
		docker image rm mani_run/$*; \
	else \
		docker run --rm -it \
			--env IDENT=$(call ident,$*) \
			--volume manicache:/home/mani/.ccache \
			mani/$* $(patsubst %,"%",$(SHELL_ARG)); \
	fi

.PHONY: $(foreach s,-build -check-build -shell, $(addsuffix $(s),$(ALL_TAGS)))

register:
	docker build . \
		-f Dockerfile.qemu-user-static \
		-t mani/qemu-user-static:register
	docker run --rm --privileged mani/qemu-user-static:register --reset

.PHONY: register