MCP: Obsolete `fuel-patches-*` functionality
[armband.git] / Makefile
1 ##############################################################################
2 # Copyright (c) 2016,2017 Cavium, Enea AB and others.
3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
6 # http://www.apache.org/licenses/LICENSE-2.0
7 ##############################################################################
8
9 # NOTE: Armband patching consists of:
10 # - clone upstream repositories to git submodules, tracking remotes;
11 # - tag each submodule (before patching) with "${A_OPNFV_TAG}-root";
12 # - apply Armband patches for each submodule;
13 # - tag each submodule (after patching) with "${OPNFV_TAG}";
14 # - stage Fuel submodule patches by copying them to Fuel f_repos/patch dir;
15 # - pass updated repository info to Fuel@OPNFV build system
16 #   (e.g. FUEL_PLUGIN_ODL_CHANGE="${OPNFV_TAG}") via armband-fuel-config.mk;
17
18 # NOTE: Long-term goals (Armband repo should merge with Fuel@OPNFV):
19 # - all build related changes should affect Fuel@OPNFV, NOT Armband;
20 # - Armband make/build system should only handle patching non-Fuel submodules,
21 #   and then invoke Fuel@OPNFV's patch & build system;
22 # - Fuel@OPNFV is made aware of an Armband type build by passing
23 #   the "ARMBAND_BASE" env var;
24
25 SHELL = /bin/sh
26
27 export ARMBAND_BASE  := $(shell pwd)
28 export OPNFV_GIT_SHA := $(shell git rev-parse HEAD)
29 export REVSTATE
30
31 include armband-fuel-config.mk
32
33 all: release
34
35 # Fetch & update git submodules, checkout remote HEAD
36 .PHONY: submodules-init
37 submodules-init: .submodules-init
38
39 .submodules-init:
40         @if [ -n "${ARMBAND_TRACK_REMOTES}" ]; then \
41                 git submodule update --init --remote 2>/dev/null; \
42         else \
43                 git submodule update --init 2>/dev/null; \
44         fi
45         @ln -sf ${A_FUEL_BASE}/ci/clean_cache.sh ${ARMBAND_BASE}/ci/clean_cache.sh
46         @touch $@
47
48 # Clean any changes made to submodules, checkout Armband root commit
49 .PHONY: submodules-clean
50 submodules-clean: .submodules-init
51         @git submodule -q foreach ' \
52                 git am -q --abort 2>/dev/null; \
53                 git checkout -q -f ${A_OPNFV_TAG}-root 2>/dev/null; \
54                 git branch -q -D opnfv-armband 2>/dev/null; \
55                 git tag | grep ${A_OPNFV_TAG} | xargs git tag -d > /dev/null 2>&1; \
56                 git reset -q --hard HEAD; \
57                 git clean -xdff'
58         @rm -f .submodules-patched
59
60 # Generate patches from submodules
61 .PHONY: patches-export
62 patches-export: .submodules-init
63         @git submodule -q foreach ' \
64                 SUB_DIR=${A_PATCH_DIR}/$$name; \
65                 git tag | awk "!/root/ && /${A_OPNFV_TAG}-fuel/" | while read A_TAG; do \
66                         SUB_FEATURE=`dirname $${A_TAG#${A_OPNFV_TAG}-fuel/}`; \
67                         echo "`tput setaf 2`== exporting $$name ($$A_TAG)`tput sgr0`"; \
68                         mkdir -p $$SUB_DIR/$${SUB_FEATURE} && \
69                         git format-patch --no-signature --ignore-space-at-eol \
70                                 -o $$SUB_DIR/$$SUB_FEATURE -N $$A_TAG-root..$$A_TAG; \
71                         sed -i -e "1{/From: /!d}" -e "s/[[:space:]]*$$//" \
72                                 $$SUB_DIR/$$SUB_FEATURE/*.patch; \
73                 done'
74
75 # Apply patches from patches/* to respective submodules
76 .PHONY: patches-import
77 patches-import: .submodules-init .submodules-patched
78
79 .submodules-patched: ${A_PATCHES}
80         @$(MAKE) submodules-clean
81         @git submodule -q foreach ' \
82                 SUB_DIR=${A_PATCH_DIR}/$$name; mkdir -p $$SUB_DIR && \
83                 git tag ${A_OPNFV_TAG}-root && \
84                 git checkout -q -b opnfv-armband && \
85                 find $$SUB_DIR -type d | sort | while read p_dir; do \
86                         SUB_PATCHES=$$(ls $$p_dir/*.patch 2>/dev/null); \
87                         if [ -n "$$SUB_PATCHES" ]; then \
88                                 SUB_FEATURE=$${p_dir#$$SUB_DIR} \
89                                 SUB_TAG=${A_OPNFV_TAG}-fuel$$SUB_FEATURE/patch; \
90                                 echo "`tput setaf 2`== patching $$name ($$SUB_TAG)`tput sgr0`";\
91                                 git tag $$SUB_TAG-root && \
92                                 git am -3 --whitespace=nowarn --patch-format=mbox \
93                                         --committer-date-is-author-date $$SUB_PATCHES && \
94                                 git tag $$SUB_TAG || exit 1; \
95                         fi \
96                 done && \
97                 git tag ${A_OPNFV_TAG}'
98         @touch $@
99
100 # TODO: Bring back clean/debug/build after Fuel@OPNFV implements them for MCP