[docs] Refresh for Gambia release
[fuel.git] / mcp / patches / Makefile
1 ##############################################################################
2 # Copyright (c) 2015,2016,2017 Ericsson AB, Enea AB and others.
3 # stefan.k.berg@ericsson.com
4 # jonas.bjurel@ericsson.com
5 # Alexandru.Avadanii@enea.com
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 include config.mk
13
14 SHELL = /bin/sh
15 FPATCHES = $(shell find ${F_PATCH_DIR} -name '*.patch')
16
17 # NOTE: Mechanism overview is presented in ./README.md.
18
19 # Submodule consistent states:
20 #   - NOT initialized (submodule trees are not populated at all);
21 #   - initialized, bound to saved commits;
22 #   - initialized, tracking remote origin (only for FUEL_TRACK_REMOTES);
23 #   - patched (local patches are applied);
24
25 # In order to keep things sort of separate, we should only pass up (to main
26 # Makefile) the fully-patched repos, and gather any fingerprinting info here.
27
28 # OPNFV Fuel relies on upstream git repos (one per component) in 1 of 2 ways:
29 #   - pinned down to tag objects (e.g. "9.0.1")
30 #   - tracking upstream remote HEAD on a stable or master branch
31 # FIXME(alav): Should we support mixed cases? (e.g. pin down only fuel-main)
32
33 # To enable remote tracking, set the following var to any non-empty string.
34 # Leaving this var empty will bind each git submodule to its saved commit.
35 FUEL_TRACK_REMOTES ?=
36
37 .PHONY: all
38 all: release
39
40 ##############################################################################
41 # git submodule operations - to be used stand-alone or from parent Makefile
42 ##############################################################################
43
44 # Fetch & update git submodules, checkout remote HEAD or saved commit
45 # Also gather fingerprints for parent gitinfo_fuel.txt.
46 .PHONY: sub
47 sub: .cachefuelinfo
48
49 .cachefuelinfo:
50         @if [ -n "${FUEL_TRACK_REMOTES}" ]; then \
51                 cd ${F_GIT_ROOT} && git submodule update --init --remote 2>/dev/null; \
52         else \
53                 cd ${F_GIT_ROOT} && git submodule update --init 2>/dev/null; \
54         fi
55         @touch $@
56
57 # Generate patches from submodules
58 .PHONY: patches-export
59 patches-export: sub
60         @git submodule -q foreach ' \
61                 SUB_DIR=${F_PATCH_DIR}/$$name; \
62                 rm -rf $$SUB_DIR/*; \
63                 git tag | awk "!/root/ && /${F_OPNFV_TAG}-fuel/" | while read F_TAG; do \
64                         SUB_FEATURE=`dirname $${F_TAG#${F_OPNFV_TAG}-fuel/}`; \
65                         echo "`tput setaf 2`-- exporting $$name ($$F_TAG)`tput sgr0`"; \
66                         mkdir -p $$SUB_DIR/$${SUB_FEATURE} && \
67                         git format-patch --no-signature --ignore-space-at-eol \
68                                 -o $$SUB_DIR/$$SUB_FEATURE -N $$F_TAG-root..$$F_TAG; \
69                         sed -i -e "1{/From: /!d}" -e "s/[[:space:]]*$$//" \
70                                 $$SUB_DIR/$$SUB_FEATURE/*.patch; \
71                 done'
72
73 # Apply patches from patch/* to respective submodules
74 # We rely on `make sub` and/or `make clean` to checkout correct base
75 .PHONY: patches-import
76 patches-import: sub .cachepatched
77
78 .cachepatched: ${FPATCHES}
79         @$(MAKE) clean
80         @cd ${F_GIT_ROOT} && git submodule -q foreach ' \
81                 SUB_DIR=${F_PATCH_DIR}/$$name; mkdir -p $$SUB_DIR && \
82                 git tag ${F_OPNFV_TAG}-root && \
83                 git checkout -q -b opnfv-fuel && \
84                 find $$SUB_DIR -type d | sort | while read p_dir; do \
85                         SUB_PATCHES=$$(ls $$p_dir/*.patch 2>/dev/null); \
86                         if [ -n "$$SUB_PATCHES" ]; then \
87                                 SUB_FEATURE=$${p_dir#$$SUB_DIR}; \
88                                 SUB_TAG=${F_OPNFV_TAG}-fuel$$SUB_FEATURE/patch; \
89                                 echo "`tput setaf 2`-- patching $$name ($$SUB_TAG)`tput sgr0`";\
90                                 git tag $$SUB_TAG-root && \
91                                 git am -3 --ignore-whitespace --patch-format=mbox \
92                                         --committer-date-is-author-date $$SUB_PATCHES && \
93                                 git tag $$SUB_TAG || exit 1; \
94                         fi \
95                 done && \
96                 git tag ${F_OPNFV_TAG}'
97         @touch $@
98
99 # Add copyright header to patch files if not already present
100 .PHONY: patches-copyright
101 patches-copyright:
102         @grep -e "Copyright (c)" -L ${FPATCHES} | while read p_file; do \
103                 ptmp=`mktemp` && \
104                 cat fuel-patch-copyright.template $$p_file > $$ptmp && \
105                 mv $$ptmp $$p_file; \
106         done
107
108 # Clean any changes made to submodules, checkout upstream Fuel root commit
109 .PHONY: clean
110 clean:
111         @cd ${F_GIT_ROOT} && git submodule -q foreach ' \
112                 git am -q --abort > /dev/null 2>&1; \
113                 git checkout -q -f ${F_OPNFV_TAG}-root > /dev/null 2>&1; \
114                 git branch -q -D opnfv-fuel > /dev/null 2>&1; \
115                 git tag | grep ${F_OPNFV_TAG} | xargs git tag -d > /dev/null 2>&1; \
116                 git reset -q --hard HEAD; \
117                 git clean -xdff'
118         @rm -f .cachepatched
119
120 .PHONY: deepclean
121 deepclean: clean
122         @cd ${F_GIT_ROOT} && git submodule deinit -f ${F_GIT_ROOT}
123         @rm -f .cache*
124
125 .PHONY: release
126 release: sub
127         $(MAKE) -f Makefile patches-import