blob: 7df68514ae5062df610bd2ab6a5bd3aa4aafe69c [file] [log] [blame]
Martin Rothcbaab7e2016-08-31 21:26:17 -06001##
2## This file is part of the coreboot project.
3##
4## Copyright (C) 2016 Google, Inc.
5##
6## This program is free software; you can redistribute it and/or modify
7## it under the terms of the GNU General Public License as published by
8## the Free Software Foundation; version 2 of the License.
9##
10## This program is distributed in the hope that it will be useful,
11## but WITHOUT ANY WARRANTY; without even the implied warranty of
12## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13## GNU General Public License for more details.
14##
15export top=$(abspath $(CURDIR)/../..)
16export crossgcc_version=$(shell $(top)/util/crossgcc/buildgcc --version | grep 'cross toolchain' | sed 's/^.*\sv//' | sed 's/\s.*$$//')
Martin Roth561f3682016-12-30 17:00:19 -070017export DOCKER:=$(shell $(SHELL) -c "command -v docker")
18
19# Version of the jenkins / sdk container
20export COREBOOT_CONTAINER_VERSION?=$(crossgcc_version)
21
22# Commit id to build from
23export DOCKER_COMMIT?=$(shell git log -n 1 --pretty=%h)
Martin Rothcbaab7e2016-08-31 21:26:17 -060024
Martin Roth9ee70ce2016-12-30 16:26:13 -070025test-docker:
Martin Rothcbaab7e2016-08-31 21:26:17 -060026 $(if $(DOCKER),,\
27 $(warning Docker command not found. Please install docker) \
28 $(warning https://docs.docker.com/engine/installation ) \
29 $(error halting))
30
Martin Roth9ee70ce2016-12-30 16:26:13 -070031test-docker-login: test-docker
Martin Rothcbaab7e2016-08-31 21:26:17 -060032 $(if $(shell if [ ! -f ~/.docker/config.json ]; then \
33 echo "docker authentication file not found"; fi), \
34 $(error Docker authentication file not found. Run 'docker login'))
35
Martin Roth9ee70ce2016-12-30 16:26:13 -070036coreboot-sdk: test-docker
Martin Roth561f3682016-12-30 17:00:19 -070037 @echo "Building coreboot SDK $(crossgcc_version) from commit $(DOCKER_COMMIT)"
38 cat coreboot-sdk/Dockerfile | \
39 sed "s/{{DOCKER_COMMIT}}/$(DOCKER_COMMIT)/" | \
40 sed "s/{{SDK_VERSION}}/$(COREBOOT_CONTAINER_VERSION)/" | \
41 $(DOCKER) build -t coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) -
Martin Rothcbaab7e2016-08-31 21:26:17 -060042
Martin Roth9ee70ce2016-12-30 16:26:13 -070043upload-coreboot-sdk: test-docker-login
Martin Roth561f3682016-12-30 17:00:19 -070044 $(DOCKER) push coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION)
Martin Rothcbaab7e2016-08-31 21:26:17 -060045
Martin Roth9ee70ce2016-12-30 16:26:13 -070046coreboot-jenkins-node: test-docker
Martin Roth561f3682016-12-30 17:00:19 -070047 cat coreboot-jenkins-node/Dockerfile | \
48 sed "s/{{SDK_VERSION}}/$(COREBOOT_CONTAINER_VERSION)/" | \
49 sed "s|{{SSH_KEY}}|$$(cat coreboot-jenkins-node/authorized_keys)|" | \
50 $(DOCKER) build -t coreboot/coreboot-jenkins-node:$(COREBOOT_CONTAINER_VERSION) -
Martin Rothcbaab7e2016-08-31 21:26:17 -060051
Martin Roth9ee70ce2016-12-30 16:26:13 -070052upload-coreboot-jenkins-node: test-docker-login
Martin Roth561f3682016-12-30 17:00:19 -070053 $(DOCKER) push coreboot/coreboot-jenkins-node:$(COREBOOT_CONTAINER_VERSION)
Martin Rothcbaab7e2016-08-31 21:26:17 -060054
Martin Roth9ee70ce2016-12-30 16:26:13 -070055docker-killall: test-docker
Martin Rothaf25fd72016-12-30 16:12:30 -070056 @if [ -n "$$($(DOCKER) ps | grep 'coreboot')" ]; then \
57 $(DOCKER) kill $$($(DOCKER) ps | grep 'coreboot' | cut -f1 -d ' '); \
58 fi
59
Martin Roth9ee70ce2016-12-30 16:26:13 -070060clean-coreboot-containers: docker-killall
Martin Rothcbaab7e2016-08-31 21:26:17 -060061 $(DOCKER) rm $(docker ps -a | grep 'coreboot' | sed 's|\s.*$||')
62
Martin Roth9ee70ce2016-12-30 16:26:13 -070063clean-coreboot-images: docker-killall
Martin Rothcbaab7e2016-08-31 21:26:17 -060064 $(DOCKER) rmi $(docker images | grep coreboot | sed 's|^\S\+\s\+\S\+\s\+||' | sed 's|\s.*$||')
65
Martin Roth9ee70ce2016-12-30 16:26:13 -070066docker-build-coreboot: test-docker
Martin Rothcbaab7e2016-08-31 21:26:17 -060067 $(DOCKER) run -u root -it -v $(top):/home/coreboot/coreboot \
Martin Roth561f3682016-12-30 17:00:19 -070068 --rm coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) \
Martin Rothcbaab7e2016-08-31 21:26:17 -060069 /bin/bash -c "cd /home/coreboot/coreboot && \
70 make clean && \
71 make $(BUILD_CMD)"
72 @echo "Enter root password to chown files to $$(whoami):$$(id -gn $$(whoami))"
73 @echo "Exiting now will leave built files owned by root"
74 sudo chown -R $$(whoami):$$(id -gn $$(whoami)) $(top)
75
Martin Roth9ee70ce2016-12-30 16:26:13 -070076docker-abuild: test-docker
Martin Rothcbaab7e2016-08-31 21:26:17 -060077 $(DOCKER) run -u root -it -v $(top):/home/coreboot/coreboot \
Martin Roth561f3682016-12-30 17:00:19 -070078 --rm coreboot/coreboot-sdk:$(COREBOOT_CONTAINER_VERSION) \
Martin Rothcbaab7e2016-08-31 21:26:17 -060079 /bin/bash -c "cd /home/coreboot/coreboot && \
80 make clean && \
81 util/abuild/abuild $(ABUILD_ARGS)"
82 @echo "Enter root password to chown files to $$(whoami):$$(id -gn $$(whoami))"
83 @echo "Exiting now will leave built files owned by root"
84 sudo chown -R $$(whoami):$$(id -gn $$(whoami)) $(top)
85
86help:
87 @echo "Commands for working with docker images:"
Martin Roth9ee70ce2016-12-30 16:26:13 -070088 @echo " coreboot-sdk - Build coreboot-sdk container"
Martin Rothcbaab7e2016-08-31 21:26:17 -060089 @echo " upload-coreboot-sdk - Upload coreboot-sdk to hub.docker.com"
Martin Roth9ee70ce2016-12-30 16:26:13 -070090 @echo " coreboot-jenkins-node - Build coreboot-jenkins-node container"
Martin Rothcbaab7e2016-08-31 21:26:17 -060091 @echo " upload-coreboot-jenkins-node - Upload coreboot-jenkins-node to hub.docker.com"
Martin Roth9ee70ce2016-12-30 16:26:13 -070092 @echo " clean-coreboot-containers - remove all docker coreboot containers"
93 @echo " clean-coreboot-images - remove all docker coreboot images"
Martin Rothcbaab7e2016-08-31 21:26:17 -060094 @echo
95 @echo "Commands for using docker images"
Martin Roth9ee70ce2016-12-30 16:26:13 -070096 @echo " docker-build-coreboot <BUILD_CMD=target> - Build coreboot under coreboot-sdk"
97 @echo " docker-abuild <ABUILD_ARGS='-a -B'> - Run abuild under coreboot-sdk"
Martin Roth561f3682016-12-30 17:00:19 -070098 @echo
99 @echo "Variables:"
100 @echo " COREBOOT_CONTAINER_VERSION = $(COREBOOT_CONTAINER_VERSION)"
101 @echo " DOCKER_COMMIT = $(DOCKER_COMMIT)"
Martin Rothcbaab7e2016-08-31 21:26:17 -0600102
Martin Roth9ee70ce2016-12-30 16:26:13 -0700103.PHONY: test-docker test-docker-login
104.PHONY: coreboot-jenkins-node upload-coreboot-jenkins-node
105.PHONY: coreboot-sdk upload-coreboot-sdk
106.PHONY: clean-coreboot-containers clean-coreboot-images
107.PHONY: docker-abuild
108.PHONY: help