blob: b7de7c3031c2f7e2783880098a0aa14100eefa6b [file] [log] [blame]
Zsolt Haraszti8fa9da02016-09-10 17:34:03 -07001#
2# Copyright 2016 the original author or authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
Nathan Knuthedc88da2016-09-17 00:28:05 -070017ifeq ($(VOLTHA_BASE)_set,_set)
18$(error To get started, please source the env.sh file)
19endif
20
Nathan Knuth84dfd2e2016-09-16 15:06:34 -070021include setup.mk
22
Zsolt Haraszti41612482016-09-21 12:26:20 -070023VENVDIR := venv-$(shell uname -s | tr '[:upper:]' '[:lower:]')
Zsolt Haraszti8fa9da02016-09-10 17:34:03 -070024
Nathan Knuth84dfd2e2016-09-16 15:06:34 -070025.PHONY: $(DIRS) $(DIRS_CLEAN) $(DIRS_FLAKE8) flake8
26
Nathan Knuth5157de02016-09-16 15:20:37 -070027default: build
28
Nathan Knuth84dfd2e2016-09-16 15:06:34 -070029## New directories can be added here
30DIRS:=\
Nathan Knuthdaa1f6e2016-09-17 00:17:31 -070031voltha \
Nathan Knuthedc88da2016-09-17 00:28:05 -070032voltha/northbound/openflow \
33voltha/northbound/openflow/agent \
34voltha/northbound/openflow/oftest
Nathan Knuth84dfd2e2016-09-16 15:06:34 -070035
36## If one directory depends on another directory that
37## dependency can be expressed here
38##
39## For example, if the Tibit directory depended on the eoam
40## directory being built first, then that can be expressed here.
41## driver/tibit: eoam
42
43# Parallel Build
44$(DIRS):
45 @echo " MK $@"
46 $(Q)$(MAKE) -C $@
47
48# Parallel Clean
49DIRS_CLEAN = $(addsuffix .clean,$(DIRS))
50$(DIRS_CLEAN):
51 @echo " CLEAN $(basename $@)"
52 $(Q)$(MAKE) -C $(basename $@) clean
53
54# Parallel Flake8
55DIRS_FLAKE8 = $(addsuffix .flake8,$(DIRS))
56$(DIRS_FLAKE8):
57 @echo " FLAKE8 $(basename $@)"
Nathan Knuth950dff22016-09-17 16:12:34 -070058 -$(Q)$(MAKE) -C $(basename $@) flake8
Zsolt Haraszti8fa9da02016-09-10 17:34:03 -070059
Zsolt Haraszti8fa9da02016-09-10 17:34:03 -070060help:
61 @echo "Usage: make [<target>]"
62 @echo "where available targets are:"
63 @echo
64 @echo "build : Build the Voltha docker image (default target)"
Zsolt Harasztib71c2a02016-09-12 13:12:07 -070065 @echo "clean : Remove files created by the build and tests"
Nathan Knutha6b09e32016-09-21 16:26:09 -070066 @echo "distclean : Remove venv directory"
Zsolt Haraszti8fa9da02016-09-10 17:34:03 -070067 @echo "fetch : Pre-fetch artifacts for subsequent local builds"
Nathan Knuthc0a80c82016-09-16 15:17:45 -070068 @echo "flake8 : Run specifically flake8 tests"
Zsolt Haraszti8fa9da02016-09-10 17:34:03 -070069 @echo "help : Print this help"
Zsolt Haraszti51af3392016-09-10 22:18:45 -070070 @echo "rebuild-venv : Rebuild local Python virtualenv from scratch"
71 @echo "venv : Build local Python virtualenv if did not exist yet"
72 @echo "utest : Run all unit tests"
Zsolt Haraszti8fa9da02016-09-10 17:34:03 -070073 @echo
74
Zsolt Haraszti32dda552016-09-27 09:17:29 -070075build: utest build-protos docker-base
76 docker build -t cord/voltha -f Dockerfile.voltha .
77
78docker-base: .docker-base-built
79
80.docker-base-built: Dockerfile.base Makefile requirements.txt
81 docker build -t cord/voltha-base -f Dockerfile.base .
82 touch .docker-base-built
Zsolt Haraszti51af3392016-09-10 22:18:45 -070083
Zsolt Harasztia54f2ac2016-09-21 15:54:15 -070084build-protos:
85 make -C voltha/core/protos
86
87install-protoc:
88 make -C voltha/core/protos install-protoc
89
Zsolt Harasztib71c2a02016-09-12 13:12:07 -070090clean:
91 find voltha -name '*.pyc' | xargs rm -f
92
Nathan Knutha6b09e32016-09-21 16:26:09 -070093distclean: clean
94 rm -rf ${VENVDIR}
95
Zsolt Haraszti51af3392016-09-10 22:18:45 -070096fetch:
Zsolt Harasztif2da1d02016-09-13 23:21:35 -070097 docker pull consul:latest
98 docker pull fluent/fluentd:latest
99 docker pull gliderlabs/registrator:latest
Zsolt Haraszti0650d1a2016-09-26 17:29:25 -0700100 docker pull ubuntu:xenial
Zsolt Haraszti51af3392016-09-10 22:18:45 -0700101
102purge-venv:
Zsolt Haraszti8fa9da02016-09-10 17:34:03 -0700103 rm -fr ${VENVDIR}
Zsolt Haraszti51af3392016-09-10 22:18:45 -0700104
105rebuild-venv: purge-venv venv
106
107venv: ${VENVDIR}/.built
108
109${VENVDIR}/.built:
110 @ virtualenv ${VENVDIR}
111 @ . ${VENVDIR}/bin/activate && \
Zsolt Haraszti41612482016-09-21 12:26:20 -0700112 pip install --upgrade pip; \
Zsolt Haraszti8fa9da02016-09-10 17:34:03 -0700113 if ! pip install -r requirements.txt; \
114 then \
115 echo "On MAC OS X, if the installation failed with an error \n'<openssl/opensslv.h>': file not found,"; \
116 echo "see the BUILD.md file for a workaround"; \
Zsolt Haraszti51af3392016-09-10 22:18:45 -0700117 else \
Zsolt Haraszti41612482016-09-21 12:26:20 -0700118 uname -s > ${VENVDIR}/.built; \
Zsolt Haraszti8fa9da02016-09-10 17:34:03 -0700119 fi
120
Zsolt Haraszti51af3392016-09-10 22:18:45 -0700121utest: venv
122 @ echo "Executing all unit tests"
123 . ${VENVDIR}/bin/activate && \
124 nosetests tests
Nathan Knuth84dfd2e2016-09-16 15:06:34 -0700125
126flake8: $(DIRS_FLAKE8)