blob: aac2d87fff9f95e4b77bdf8dbbe245682f62b7ef [file] [log] [blame]
Joey Armstrong695ba5c2023-01-20 11:17:49 -05001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrong541aafc2024-02-28 09:54:53 -05003# Copyright 2016-2024 Open Networking Foundation Contributors
Matt Jeanneretc7b437c2019-05-13 12:33:08 -04004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Joey Armstrong695ba5c2023-01-20 11:17:49 -050016# -----------------------------------------------------------------------
Joey Armstrong541aafc2024-02-28 09:54:53 -050017# SPDX-FileCopyrightText: 2017-2024 Open Networking Foundation Contributors
18# SPDX-License-Identifier: Apache-2.0
19# -----------------------------------------------------------------------
Joey Armstrong695ba5c2023-01-20 11:17:49 -050020
21.PHONY: help
22.DEFAULT_GOAL := help
23
Joey Armstrong695ba5c2023-01-20 11:17:49 -050024##--------------------##
25##---] INCLUDES [---##
26##--------------------##
Joey Armstrong99a72d02023-06-09 10:26:42 -040027include config.mk
28include makefiles/include.mk
Joey Armstrong695ba5c2023-01-20 11:17:49 -050029
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040030# Variables
31VERSION ?= $(shell cat ./VERSION)
32
33## Docker related
34DOCKER_REGISTRY ?=
35DOCKER_REPOSITORY ?=
36DOCKER_BUILD_ARGS ?=
37DOCKER_TAG ?= ${VERSION}
38ONOS_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-onos:${DOCKER_TAG}
39
40## Docker labels. Only set ref and commit date if committed
41DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040042DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
Matt Jeanneret805f76e2019-05-16 16:18:26 -040043DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD)
44
45ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0)
46 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)
47else
48 DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD)+dirty
49endif
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040050
51.PHONY: docker-build
52
Matteo Scandoloc209e802021-06-07 16:59:30 +020053# For each makefile target, add ## <description> on the target line and it will be listed by 'make help'
Joey Armstrong695ba5c2023-01-20 11:17:49 -050054help :: ## Print help for each Makefile target
Joey Armstrong541aafc2024-02-28 09:54:53 -050055 @echo "Usage: $(MAKE) [options] [target] ..."
56
57 @printf ' %-33.33s %s' 'test' \
58 'Run repository based test suites (test=)'
59 @printf ' %-33.33s %s' 'test-bats' \
60 'Invoke bats harness shell test suites (wip)'
61 @printf ' %-33.33s %s' 'test-release' \
62 'Verify released VERSION does ont contain dev/SNAPSHOT apps'
63
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040064 @echo
Joey Armstrong695ba5c2023-01-20 11:17:49 -050065 @grep --no-filename '^[[:alpha:]_-]*:.* ##' $(MAKEFILE_LIST) \
66 | sort \
67 | awk 'BEGIN {FS=":.* ## "}; {printf " %-25s : %s\n", $$1, $$2};'
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040068
69## Docker targets
70
Joey Armstrong7c3a1e02023-07-01 16:21:24 -040071## -----------------------------------------------------------------------
72## -----------------------------------------------------------------------
Matteo Scandoloc209e802021-06-07 16:59:30 +020073build: docker-build ## alias for "docker-build"
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040074
Joey Armstrong7c3a1e02023-07-01 16:21:24 -040075## -----------------------------------------------------------------------
76## -----------------------------------------------------------------------
Matteo Scandoloc209e802021-06-07 16:59:30 +020077local-onosapps: ## if LOCAL_ONOSAPPS=true runs the get-local-oars.sh
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040078 mkdir -p local_imports/oar
79ifdef LOCAL_ONOSAPPS
Joey Armstrong4048c1f2022-12-17 22:24:42 -050080 $(RM) -r local_imports/oar
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040081 ./get-local-oars.sh
82endif
83
Joey Armstrong7c3a1e02023-07-01 16:21:24 -040084## -----------------------------------------------------------------------
85## Intent: build docker image
86## use DOCKER_REGISTRY, DOCKER_REPOSITORY and DOCKER_TAG to customize
87## -----------------------------------------------------------------------
88docker-build: local-onosapps ## build docker image
Matt Jeanneretc7b437c2019-05-13 12:33:08 -040089 docker build $(DOCKER_BUILD_ARGS) \
90 -t ${ONOS_IMAGENAME} \
91 --build-arg LOCAL_ONOSAPPS=$(LOCAL_ONOSAPPS) \
92 --build-arg org_label_schema_version="${VERSION}" \
93 --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
94 --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
95 --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
96 --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
97 -f Dockerfile.voltha-onos .
98
Joey Armstrong7c3a1e02023-07-01 16:21:24 -040099## -----------------------------------------------------------------------
100## -----------------------------------------------------------------------
Joey Armstrong541aafc2024-02-28 09:54:53 -0500101test := $(null)
102
103ifdef TEST-BATS
104 test += test-bats
105endif
106
107ifdef RELEASE
108 test += test-release
109endif
110
111test :: $(test) ## verify that if the version is released we're not pointing to SNAPSHOT apps
112
113## -----------------------------------------------------------------------
114## Intent: Shell script testing with the bats test harness.
115## Usage: make test TEST-BATS=1
116## -----------------------------------------------------------------------
117test-bats:
118 $(HIDE)$(MAKE) -C test/bats $@
119
120## -----------------------------------------------------------------------
121## Intent: Release based testing.
122## -----------------------------------------------------------------------
123## Usage:
124## make test-release
125## make test RELEASE=1
126## -----------------------------------------------------------------------
127## Legacy: VERSION validation has been defined as a default repository
128## based test. The target should be isolated and should only
129## be required durring a release cycle.
130## -----------------------------------------------------------------------
131test-release :
Matteo Scandoloc209e802021-06-07 16:59:30 +0200132 bash tests/version-check.sh
133
Joey Armstrong541aafc2024-02-28 09:54:53 -0500134## -----------------------------------------------------------------------
135## -----------------------------------------------------------------------
Matteo Scandoloc209e802021-06-07 16:59:30 +0200136docker-push: ## push to docker registy: use DOCKER_REGISTRY, DOCKER_REPOSITORY and DOCKER_TAG to customize
Matt Jeanneretc7b437c2019-05-13 12:33:08 -0400137 docker push ${ONOS_IMAGENAME}
138
Joey Armstrong541aafc2024-02-28 09:54:53 -0500139## -----------------------------------------------------------------------
140## -----------------------------------------------------------------------
Joey Armstrong99a72d02023-06-09 10:26:42 -0400141clean :: ## clean the build environment
Joey Armstrong4048c1f2022-12-17 22:24:42 -0500142 $(RM) -r local_imports
Matt Jeanneretc7b437c2019-05-13 12:33:08 -0400143
Joey Armstrong541aafc2024-02-28 09:54:53 -0500144## -----------------------------------------------------------------------
145## -----------------------------------------------------------------------
Joey Armstronga9deb692023-06-30 18:13:01 -0400146sterile :: clean
147
Matt Jeanneretc7b437c2019-05-13 12:33:08 -0400148# end file