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 ##############################################################################
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;
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;
26 export ARMBAND_BASE := $(shell pwd)
27 export OPNFV_GIT_SHA := $(shell git rev-parse HEAD)
30 include armband-fuel-config.mk
34 # Fetch & update git submodules, checkout remote HEAD
35 .PHONY: submodules-init
36 submodules-init: .submodules-init
39 @if [ -n "${ARMBAND_TRACK_REMOTES}" ]; then \
40 git submodule update --init --remote 2>/dev/null; \
42 git submodule update --init 2>/dev/null; \
44 @ln -sf ${A_FUEL_BASE}/ci/clean_cache.sh ${ARMBAND_BASE}/ci/clean_cache.sh
47 # Clean any changes made to submodules, checkout Armband root commit
48 .PHONY: submodules-clean
49 submodules-clean: .submodules-init
50 @test ! -d ${F_REPOS_DIR} || $(MAKE) fuel-patches-clean
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; \
58 @rm -f .submodules-patched
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; \
75 # Apply patches from patches/* to respective submodules
76 .PHONY: patches-import
77 patches-import: .submodules-init .submodules-patched
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 && git am -3 --whitespace=nowarn \
92 --committer-date-is-author-date $$SUB_PATCHES && \
93 git tag $$SUB_TAG || exit 1; \
96 git tag ${A_OPNFV_TAG}'
97 # Staging Fuel@OPNFV patches
98 @ls -d ${F_SUB_DIR}/* 2>/dev/null | while read p_sub_path; do \
99 SUB_NAME=`basename $$p_sub_path`; \
100 find ${A_PATCH_DIR}/$$SUB_NAME -name '*.patch' 2>/dev/null -exec sh -c '\
101 A_PATCH={}; R_PATCH=$${A_PATCH#${A_PATCH_DIR}/}; \
102 F_PATCH=${F_PATCH_DIR}/$${0}/armband/$${R_PATCH#$${0}/}; \
103 if [ -f $$F_PATCH ]; then \
104 echo "`tput setaf 3`* WARN: $$R_PATCH upstream.`tput sgr0`"; \
106 if [ -h $$A_PATCH ]; then \
107 echo "`tput setaf 3`* PHONY: $$R_PATCH`tput sgr0`"; \
109 echo "`tput setaf 6`* Staging $$R_PATCH`tput sgr0`"; \
110 mkdir -p `dirname $$F_PATCH` && cp $$A_PATCH $$F_PATCH; \
112 fi' "$$SUB_NAME" \; || true ; \
116 # Pass down clean/deepclean/build to Fuel@OPNFV
118 clean: .submodules-init
119 $(MAKE) -e --no-print-directory -C ${F_BUILD_DIR} clean
123 $(MAKE) -e --no-print-directory -C ${F_BUILD_DIR} deepclean
124 @git submodule deinit -f .
128 build: patches-import
129 $(MAKE) -e --no-print-directory -C ${F_BUILD_DIR} all
132 release: export LC_ALL=en_US.UTF-8
135 ##############################################################################
136 # Fuel@OPNFV patch operations - to be used only during development
137 ##############################################################################
139 # Apply all Fuel@OPNFV patches, including Armband patches
140 .PHONY: fuel-patches-import
141 fuel-patches-import: .submodules-patched fuel-patches-clean
142 $(MAKE) -e -C ${F_REPOS_DIR} patches-import
144 # Export Fuel@OPNFV patches, including Armband patches
145 .PHONY: fuel-patches-export
146 fuel-patches-export: .submodules-patched
147 $(MAKE) -e -C ${F_REPOS_DIR} patches-export
148 @ls -d ${F_PATCH_DIR}/* 2>/dev/null | while read p_sub_path; do \
149 SUB_NAME=`basename $$p_sub_path`; \
150 if [ -d $$p_sub_path/armband ]; then \
151 echo "`tput setaf 6`* Pulling $$SUB_NAME patches.`tput sgr0`"; \
152 cp -R $$p_sub_path/armband/* ${A_PATCH_DIR}/$$SUB_NAME && \
153 rm -rf $$p_sub_path/armband; \
157 .PHONY: fuel-patches-clean
159 $(MAKE) -e -C ${F_REPOS_DIR} clean