35190a1c90b503d931fd8786430e374e0b44d11b
[vpp.git] / Makefile
1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 WS_ROOT=$(CURDIR)
15 BR=$(WS_ROOT)/build-root
16 CCACHE_DIR?=$(BR)/.ccache
17 V?=0
18 GDB?=gdb
19
20 MINIMAL_STARTUP_CONF="unix { interactive } dpdk { no-pci socket-mem 1024 }"
21
22 GDB_ARGS= -ex "handle SIGUSR1 noprint nostop"
23
24 DEB_DEPENDS  = curl build-essential autoconf automake bison libssl-dev ccache
25 DEB_DEPENDS += debhelper dkms openjdk-7-jdk git libtool libganglia1-dev libapr1-dev
26 DEB_DEPENDS += libconfuse-dev git-review
27
28 ifneq ("$(wildcard $(STARTUP_DIR)/startup.conf),"")
29         STARTUP_CONF ?= $(STARTUP_DIR)/startup.conf
30 endif
31
32 .PHONY: help bootstrap wipe wipe-release build build-release rebuild rebuild-release
33 .PHONY: run run-release debug debug-release build-vat run-vat pkg-deb pkg-rpm
34
35 help:
36         @echo "Make Targets:"
37         @echo " bootstrap           - prepare tree for build"
38         @echo " wipe                - wipe all products of debug build "
39         @echo " wipe-release        - wipe all products of release build "
40         @echo " build               - build debug binaries"
41         @echo " build-release       - build release binaries"
42         @echo " rebuild             - wipe and build debug binares"
43         @echo " rebuild-release     - wipe and build release binares"
44         @echo " run                 - run debug binary"
45         @echo " run-release         - run release binary"
46         @echo " debug               - run debug binary with debugger"
47         @echo " debug-release       - run release binary with debugger"
48         @echo " build-vat           - build vpp-api-test tool"
49         @echo " run-vat             - run vpp-api-test tool"
50         @echo " pkg-deb             - build DEB packages"
51         @echo " pkg-rpm             - build RPM packages"
52         @echo ""
53         @echo "Make Arguments:"
54         @echo " V=[0|1]             - set build verbosity level"
55         @echo " STARTUP_CONF=<path> - startup configuration file"
56         @echo "                       (e.g. /etc/vpp/startup.conf)"
57         @echo " STARTUP_DIR=<path>  - startup drectory (e.g. /etc/vpp)"
58         @echo "                       It also sets STARTUP_CONF if"
59         @echo "                       startup.conf file is present"
60         @echo " GDB=<path>          - gdb binary to use for debugging"
61         @echo ""
62         @echo "Current Argumernt Values:"
63         @echo " V            = $(V)"
64         @echo " STARTUP_CONF = $(STARTUP_CONF)"
65         @echo " STARTUP_DIR  = $(STARTUP_DIR)"
66         @echo " GDB          = $(GDB)"
67
68 $(BR)/.bootstrap.ok:
69 ifeq ("$(shell lsb_release -si)", "Ubuntu")
70         @MISSING=$$(apt-get install -y -qq -s $(DEB_DEPENDS) | grep "^Inst ") ; \
71         if [ -n "$$MISSING" ] ; then \
72           echo "\nPlease install missing packages: \n$$MISSING\n" ; \
73           exit 1 ; \
74         fi ; \
75         exit 0
76 endif
77         @echo "SOURCE_PATH = $(WS_ROOT)"                   > $(BR)/build-config.mk
78         @echo "#!/bin/bash\n"                              > $(BR)/path_setup
79         @echo 'export PATH=$(BR)/tools/ccache-bin:$$PATH' >> $(BR)/path_setup
80         @echo 'export PATH=$(BR)/tools/bin:$$PATH'        >> $(BR)/path_setup
81         @echo 'export CCACHE_DIR=$(CCACHE_DIR)'           >> $(BR)/path_setup
82         
83 ifeq ("$(wildcard /usr/bin/ccache )","")
84         @echo "WARNING: Please install ccache AYEC and re-run this script"
85 else
86         @rm -rf $(BR)/tools/ccache-bin
87         @mkdir -p $(BR)/tools/ccache-bin
88         @ln -s /usr/bin/ccache $(BR)/tools/ccache-bin/gcc
89         @ln -s /usr/bin/ccache $(BR)/tools/ccache-bin/g++
90 endif
91         @make -C $(BR) V=$(V) is_build_tool=yes vppapigen-install
92         @touch $@
93
94 bootstrap: $(BR)/.bootstrap.ok
95
96 define make
97         @make -C $(BR) V=$(V) PLATFORM=vpp TAG=$(1) $(2)
98 endef
99
100 build: $(BR)/.bootstrap.ok
101         $(call make,vpp_debug,vpp-install)
102
103 wipe: $(BR)/.bootstrap.ok
104         $(call make,vpp_debug,vpp-wipe)
105
106 rebuild: wipe build
107
108 build-release: $(BR)/.bootstrap.ok
109         $(call make,vpp,vpp-install)
110
111 wipe-release: $(BR)/.bootstrap.ok
112         $(call make,vpp,vpp-wipe)
113
114 rebuild-release: wipe-release build-release
115
116 STARTUP_DIR ?= $(PWD)
117 ifeq ("$(wildcard $(STARTUP_CONF))","")
118 define run
119         @echo "WARNING: STARTUP_CONF not defined or file doesn't exist."
120         @echo "         Running with minimal startup config: $(MINIMAL_STARTUP_CONF)\n"
121         @cd $(STARTUP_DIR) && sudo $(1) $(MINIMAL_STARTUP_CONF)
122 endef
123 else
124 define run
125         @cd $(STARTUP_DIR) && sudo $(1) -c $(STARTUP_CONF)
126 endef
127 endif
128
129 run:
130         $(call run, $(BR)/install-vpp_debug-native/vpp/bin/vpp)
131
132 run-release:
133         $(call run, $(BR)/install-vpp-native/vpp/bin/vpp)
134
135 debug:
136         $(call run, $(GDB) $(GDB_ARGS) --args $(BR)/install-vpp_debug-native/vpp/bin/vpp)
137
138 debug-release:
139         $(call run, $(GDB) $(GDB_ARGS) --args $(BR)/install-vpp-native/vpp/bin/vpp)
140
141 build-vat:
142         $(call make,vpp_debug,vpp-api-test-install)
143
144 run-vat:
145         @sudo $(BR)/install-vpp_debug-native/vpp-api-test/bin/vpp_api_test
146
147 pkg-deb:
148         $(call make,vpp,install-deb)
149
150 pkg-rpm:
151         $(call make,vpp,install-rpm)