aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 5c8504be584324c81c3871b43947b0dce012e949 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
##############################################################################
# Copyright (c) 2016,2017 Cavium, Enea AB and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

# NOTE: Armband patching consists of:
# - clone upstream repositories to git submodules, tracking remotes;
# - tag each submodule (before patching) with "${A_OPNFV_TAG}-root";
# - apply Armband patches for each submodule;
# - tag each submodule (after patching) with "${OPNFV_TAG}";
# - stage Fuel submodule patches by copying them to Fuel f_repos/patch dir;
# - pass updated repository info to Fuel@OPNFV build system
#   (e.g. FUEL_PLUGIN_ODL_CHANGE="${OPNFV_TAG}") via armband-fuel-config.mk;

# NOTE: Long-term goals (Armband repo should merge with Fuel@OPNFV):
# - all build related changes should affect Fuel@OPNFV, NOT Armband;
# - Armband make/build system should only handle patching non-Fuel submodules,
#   and then invoke Fuel@OPNFV's patch & build system;
# - Fuel@OPNFV is made aware of an Armband type build by passing
#   the "ARMBAND_BASE" env var;

SHELL = /bin/sh

export ARMBAND_BASE  := $(shell pwd)
export OPNFV_GIT_SHA := $(shell git rev-parse HEAD)
export REVSTATE

include armband-fuel-config.mk

all: release

# Fetch & update git submodules, checkout remote HEAD
.PHONY: submodules-init
submodules-init: .submodules-init

.submodules-init:
	@if [ -n "${ARMBAND_TRACK_REMOTES}" ]; then \
		git submodule update --init --remote 2>/dev/null; \
	else \
		git submodule update --init 2>/dev/null; \
	fi
	@ln -sf ${A_FUEL_BASE}/ci/clean_cache.sh ${ARMBAND_BASE}/ci/clean_cache.sh
	@touch $@

# Clean any changes made to submodules, checkout Armband root commit
.PHONY: submodules-clean
submodules-clean: .submodules-init
	@git submodule -q foreach ' \
		git am -q --abort 2>/dev/null; \
		git checkout -q -f ${A_OPNFV_TAG}-root 2>/dev/null; \
		git branch -q -D opnfv-armband 2>/dev/null; \
		git tag | grep ${A_OPNFV_TAG} | xargs git tag -d > /dev/null 2>&1; \
		git reset -q --hard HEAD; \
		git clean -xdff'
	@rm -f .submodules-patched

# Generate patches from submodules
.PHONY: patches-export
patches-export: .submodules-init
	@git submodule -q foreach ' \
		SUB_DIR=${A_PATCH_DIR}/$$name; \
		git tag | awk "!/root/ && /${A_OPNFV_TAG}-fuel/" | while read A_TAG; do \
			SUB_FEATURE=`dirname $${A_TAG#${A_OPNFV_TAG}-fuel/}`; \
			echo "`tput setaf 2`== exporting $$name ($$A_TAG)`tput sgr0`"; \
			mkdir -p $$SUB_DIR/$${SUB_FEATURE} && \
			git format-patch --no-signature --ignore-space-at-eol \
				-o $$SUB_DIR/$$SUB_FEATURE -N $$A_TAG-root..$$A_TAG; \
			sed -i -e "1{/From: /!d}" -e "s/[[:space:]]*$$//" \
				$$SUB_DIR/$$SUB_FEATURE/*.patch; \
		done'

# Apply patches from patches/* to respective submodules
.PHONY: patches-import
patches-import: .submodules-init .submodules-patched

.submodules-patched: ${A_PATCHES}
	@$(MAKE) submodules-clean
	@git submodule -q foreach ' \
		SUB_DIR=${A_PATCH_DIR}/$$name; mkdir -p $$SUB_DIR && \
		git tag ${A_OPNFV_TAG}-root && \
		git checkout -q -b opnfv-armband && \
		find $$SUB_DIR -type d | sort | while read p_dir; do \
			SUB_PATCHES=$$(ls $$p_dir/*.patch 2>/dev/null); \
			if [ -n "$$SUB_PATCHES" ]; then \
				SUB_FEATURE=$${p_dir#$$SUB_DIR} \
				SUB_TAG=${A_OPNFV_TAG}-fuel$$SUB_FEATURE/patch; \
				echo "`tput setaf 2`== patching $$name ($$SUB_TAG)`tput sgr0`";\
				git tag $$SUB_TAG-root && \
				git am -3 --whitespace=nowarn --patch-format=mbox \
					--committer-date-is-author-date $$SUB_PATCHES && \
				git tag $$SUB_TAG || exit 1; \
			fi \
		done && \
		git tag ${A_OPNFV_TAG}'
	@touch $@

# TODO: Bring back clean/debug/build after Fuel@OPNFV implements them for MCP