Merge "Revert "docs: Release Notes: Add Label""
[armband.git] / Makefile
1 ##############################################################################
2 # Copyright (c) 2016 Cavium
3 # Copyright (c) 2016 Enea AB and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 # NOTE: Armband patching consists of:
11 # - clone upstream repositories to git submodules, tracking remotes;
12 # - tag each submodule (before patching) with "${A_OPNFV_TAG}-root";
13 # - apply Armband patches for each submodule;
14 # - tag each submodule (after patching) with "${OPNFV_TAG}";
15 # - stage Fuel submodule patches by copying them to Fuel f_repos/patch dir;
16 # - pass updated repository info to Fuel@OPNFV build system
17 #   (e.g. FUEL_PLUGIN_ODL_CHANGE="${OPNFV_TAG}") via armband-fuel-config.mk;
18
19 # NOTE: Long-term goals (Armband repo should merge with Fuel@OPNFV):
20 # - all build related changes should affect Fuel@OPNFV, NOT Armband;
21 # - Armband make/build system should only handle patching non-Fuel submodules,
22 #   and then invoke Fuel@OPNFV's patch & build system;
23 # - Fuel@OPNFV is made aware of an Armband type build by passing
24 #   the "ARMBAND_BASE" env var;
25
26 SHELL = /bin/sh
27
28 export ARMBAND_BASE  := $(shell pwd)
29 export OPNFV_GIT_SHA := $(shell git rev-parse HEAD)
30 export REVSTATE
31
32 include armband-fuel-config.mk
33
34 all: release
35
36 # Fetch & update git submodules, checkout remote HEAD
37 .PHONY: submodules-init
38 submodules-init: .submodules-init
39
40 .submodules-init:
41         @if [ -n "${ARMBAND_TRACK_REMOTES}" ]; then \
42                 git submodule update --init --remote 2>/dev/null; \
43         else \
44                 git submodule update --init 2>/dev/null; \
45         fi
46         @ln -sf ${A_FUEL_BASE}/ci/clean_cache.sh ${ARMBAND_BASE}/ci/clean_cache.sh
47         @touch $@
48
49 # Clean any changes made to submodules, checkout Armband root commit
50 .PHONY: submodules-clean
51 submodules-clean: .submodules-init
52         @test ! -d ${F_REPOS_DIR} || $(MAKE) fuel-patches-clean
53         @git submodule -q foreach ' \
54                 git am -q --abort 2>/dev/null; \
55                 git checkout -q -f ${A_OPNFV_TAG}-root 2>/dev/null; \
56                 git branch -q -D opnfv-armband 2>/dev/null; \
57                 git tag | grep ${A_OPNFV_TAG} | xargs git tag -d > /dev/null 2>&1; \
58                 git reset -q --hard HEAD; \
59                 git clean -xdff'
60         @rm -f .submodules-patched
61
62 # Generate patches from submodules
63 .PHONY: patches-export
64 patches-export: .submodules-init
65         @git submodule -q foreach ' \
66                 SUB_DIR=${A_PATCH_DIR}/$$name; \
67                 git tag | awk "!/root/ && /${A_OPNFV_TAG}-fuel/" | while read A_TAG; do \
68                         SUB_FEATURE=`dirname $${A_TAG#${A_OPNFV_TAG}-fuel/}`; \
69                         echo "`tput setaf 2`== exporting $$name ($$A_TAG)`tput sgr0`"; \
70                         mkdir -p $$SUB_DIR/$${SUB_FEATURE} && \
71                         git format-patch --no-signature --ignore-space-at-eol \
72                                 -o $$SUB_DIR/$$SUB_FEATURE -N $$A_TAG-root..$$A_TAG; \
73                         sed -i -e "1{/From: /!d}" -e "s/[[:space:]]*$$//" \
74                                 $$SUB_DIR/$$SUB_FEATURE/*.patch; \
75                 done'
76
77 # Apply patches from patches/* to respective submodules
78 .PHONY: patches-import
79 patches-import: .submodules-init .submodules-patched
80
81 .submodules-patched: ${A_PATCHES}
82         @$(MAKE) submodules-clean
83         @git submodule -q foreach ' \
84                 SUB_DIR=${A_PATCH_DIR}/$$name; mkdir -p $$SUB_DIR && \
85                 git tag ${A_OPNFV_TAG}-root && \
86                 git checkout -q -b opnfv-armband && \
87                 find $$SUB_DIR -type d | sort | while read p_dir; do \
88                         SUB_PATCHES=$$(ls $$p_dir/*.patch 2>/dev/null); \
89                         if [ -n "$$SUB_PATCHES" ]; then \
90                                 SUB_FEATURE=$${p_dir#$$SUB_DIR} \
91                                 SUB_TAG=${A_OPNFV_TAG}-fuel$$SUB_FEATURE/patch; \
92                                 echo "`tput setaf 2`== patching $$name ($$SUB_TAG)`tput sgr0`";\
93                                 git tag $$SUB_TAG-root && \
94                                 git am -3 --whitespace=nowarn --patch-format=mbox \
95                                         --committer-date-is-author-date $$SUB_PATCHES && \
96                                 git tag $$SUB_TAG || exit 1; \
97                         fi \
98                 done && \
99                 git tag ${A_OPNFV_TAG}'
100         # Staging Fuel@OPNFV patches
101         @ls -d ${F_SUB_DIR}/* 2>/dev/null | while read p_sub_path; do \
102                 SUB_NAME=`basename $$p_sub_path`; \
103                 find ${A_PATCH_DIR}/$$SUB_NAME -name '*.patch' 2>/dev/null -exec sh -c '\
104                         A_PATCH={}; R_PATCH=$${A_PATCH#${A_PATCH_DIR}/}; \
105                         F_PATCH=${F_PATCH_DIR}/$${0}/armband/$${R_PATCH#$${0}/}; \
106                         if [ -f $$F_PATCH ]; then \
107                                 echo "`tput setaf 3`* WARN: $$R_PATCH upstream.`tput sgr0`"; \
108                         else \
109                                 if [ -h $$A_PATCH ]; then \
110                                         echo "`tput setaf 3`* PHONY: $$R_PATCH`tput sgr0`"; \
111                                 else \
112                                         echo "`tput setaf 6`* Staging $$R_PATCH`tput sgr0`"; \
113                                         mkdir -p `dirname $$F_PATCH` && cp $$A_PATCH $$F_PATCH; \
114                                 fi; \
115                         fi' "$$SUB_NAME" \; || true ; \
116         done
117         @touch $@
118
119 # Pass down debug/clean/deepclean/build to Fuel@OPNFV
120 .PHONY: clean debug
121 clean: .submodules-init
122 debug: fuel-patches-import
123 clean debug:
124         $(MAKE) -e --no-print-directory -C ${F_BUILD_DIR} $@
125
126 .PHONY: deepclean
127 deepclean: clean
128         $(MAKE) -e --no-print-directory -C ${F_BUILD_DIR} deepclean
129         @git submodule deinit -f .
130         @rm -f .submodules*
131
132 .PHONY: build
133 build: patches-import
134         $(MAKE) -e --no-print-directory -C ${F_BUILD_DIR} all
135
136 .PHONY: release
137 release: export LC_ALL=en_US.UTF-8
138 release: build
139
140 ##############################################################################
141 # Fuel@OPNFV patch operations - to be used only during development
142 ##############################################################################
143
144 # Apply all Fuel@OPNFV patches, including Armband patches
145 .PHONY: fuel-patches-import
146 fuel-patches-import: .submodules-patched fuel-patches-clean
147         $(MAKE) -e -C ${F_REPOS_DIR} patches-import
148
149 # Export Fuel@OPNFV patches, including Armband patches
150 .PHONY: fuel-patches-export
151 fuel-patches-export: .submodules-patched
152         $(MAKE) -e -C ${F_REPOS_DIR} patches-export
153         @ls -d ${F_PATCH_DIR}/* 2>/dev/null | while read p_sub_path; do \
154                 SUB_NAME=`basename $$p_sub_path`; \
155                 if [ -d $$p_sub_path/armband ]; then \
156                         echo "`tput setaf 6`* Pulling $$SUB_NAME patches.`tput sgr0`"; \
157                         cp -R $$p_sub_path/armband/* ${A_PATCH_DIR}/$$SUB_NAME && \
158                                 rm -rf $$p_sub_path/armband; \
159                 fi \
160         done
161
162 .PHONY: fuel-patches-clean
163 fuel-patches-clean:
164         $(MAKE) -e -C ${F_REPOS_DIR} clean