Add license headers where missing
[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 # Fuel@OPNFV 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                 git tag | awk "!/root/ && /${F_OPNFV_TAG}-fuel/" | while read F_TAG; do \
63                         SUB_FEATURE=`dirname $${F_TAG#${F_OPNFV_TAG}-fuel/}`; \
64                         echo "`tput setaf 2`-- exporting $$name ($$F_TAG)`tput sgr0`"; \
65                         mkdir -p $$SUB_DIR/$${SUB_FEATURE} && \
66                         git format-patch --no-signature --ignore-space-at-eol \
67                                 -o $$SUB_DIR/$$SUB_FEATURE -N $$F_TAG-root..$$F_TAG; \
68                         sed -i -e "1{/From: /!d}" -e "s/[[:space:]]*$$//" \
69                                 $$SUB_DIR/$$SUB_FEATURE/*.patch; \
70                 done'
71
72 # Apply patches from patch/* to respective submodules
73 # We rely on `make sub` and/or `make clean` to checkout correct base
74 .PHONY: patches-import
75 patches-import: sub .cachepatched
76
77 .cachepatched: ${FPATCHES}
78         @$(MAKE) clean
79         @cd ${F_GIT_ROOT} && git submodule -q foreach ' \
80                 SUB_DIR=${F_PATCH_DIR}/$$name; mkdir -p $$SUB_DIR && \
81                 git tag ${F_OPNFV_TAG}-root && \
82                 git checkout -q -b opnfv-fuel && \
83                 find $$SUB_DIR -type d | sort | while read p_dir; do \
84                         SUB_PATCHES=$$(ls $$p_dir/*.patch 2>/dev/null); \
85                         if [ -n "$$SUB_PATCHES" ]; then \
86                                 SUB_FEATURE=$${p_dir#$$SUB_DIR}; \
87                                 SUB_TAG=${F_OPNFV_TAG}-fuel$$SUB_FEATURE/patch; \
88                                 echo "`tput setaf 2`-- patching $$name ($$SUB_TAG)`tput sgr0`";\
89                                 git tag $$SUB_TAG-root && \
90                                 git am -3 --ignore-whitespace --patch-format=mbox \
91                                         --committer-date-is-author-date $$SUB_PATCHES && \
92                                 git tag $$SUB_TAG || exit 1; \
93                         fi \
94                 done && \
95                 git tag ${F_OPNFV_TAG}'
96         @touch $@
97
98 # Add copyright header to patch files if not already present
99 .PHONY: patches-copyright
100 patches-copyright:
101         @grep -e "Copyright (c)" -L ${FPATCHES} | while read p_file; do \
102                 ptmp=`mktemp` && \
103                 cat fuel-patch-copyright.template $$p_file > $$ptmp && \
104                 mv $$ptmp $$p_file; \
105         done
106
107 # Clean any changes made to submodules, checkout upstream Fuel root commit
108 .PHONY: clean
109 clean:
110         @cd ${F_GIT_ROOT} && git submodule -q foreach ' \
111                 git am -q --abort > /dev/null 2>&1; \
112                 git checkout -q -f ${F_OPNFV_TAG}-root > /dev/null 2>&1; \
113                 git branch -q -D opnfv-fuel > /dev/null 2>&1; \
114                 git tag | grep ${F_OPNFV_TAG} | xargs git tag -d > /dev/null 2>&1; \
115                 git reset -q --hard HEAD; \
116                 git clean -xdff'
117         @rm -f .cachepatched
118
119 .PHONY: deepclean
120 deepclean: clean
121         @cd ${F_GIT_ROOT} && git submodule deinit -f ${F_GIT_ROOT}
122         @rm -f .cache*
123
124 .PHONY: release
125 release: sub
126         $(MAKE) -f Makefile patches-import