cleanup: Remove obsolete ln to clean_cache.sh
[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         @touch $@
46
47 # Clean any changes made to submodules, checkout Armband root commit
48 .PHONY: submodules-clean
49 submodules-clean: .submodules-init
50         @git submodule -q foreach ' \
51                 git am -q --abort 2>/dev/null; \
52                 git checkout -q -f ${A_OPNFV_TAG}-root 2>/dev/null; \
53                 git branch -q -D opnfv-armband 2>/dev/null; \
54                 git tag | grep ${A_OPNFV_TAG} | xargs git tag -d > /dev/null 2>&1; \
55                 git reset -q --hard HEAD; \
56                 git clean -xdff'
57         @rm -f .submodules-patched
58
59 # Generate patches from submodules
60 .PHONY: patches-export
61 patches-export: .submodules-init
62         @git submodule -q foreach ' \
63                 SUB_DIR=${A_PATCH_DIR}/$$name; \
64                 git tag | awk "!/root/ && /${A_OPNFV_TAG}-fuel/" | while read A_TAG; do \
65                         SUB_FEATURE=`dirname $${A_TAG#${A_OPNFV_TAG}-fuel/}`; \
66                         echo "`tput setaf 2`== exporting $$name ($$A_TAG)`tput sgr0`"; \
67                         mkdir -p $$SUB_DIR/$${SUB_FEATURE} && \
68                         git format-patch --no-signature --ignore-space-at-eol \
69                                 -o $$SUB_DIR/$$SUB_FEATURE -N $$A_TAG-root..$$A_TAG; \
70                         sed -i -e "1{/From: /!d}" -e "s/[[:space:]]*$$//" \
71                                 $$SUB_DIR/$$SUB_FEATURE/*.patch; \
72                 done'
73
74 # Apply patches from patches/* to respective submodules
75 .PHONY: patches-import
76 patches-import: .submodules-init .submodules-patched
77
78 .submodules-patched: ${A_PATCHES}
79         @$(MAKE) submodules-clean
80         @git submodule -q foreach ' \
81                 SUB_DIR=${A_PATCH_DIR}/$$name; mkdir -p $$SUB_DIR && \
82                 git tag ${A_OPNFV_TAG}-root && \
83                 git checkout -q -b opnfv-armband && \
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=${A_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 --whitespace=nowarn --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 ${A_OPNFV_TAG}'
97         # Staging Fuel@OPNFV patches
98         @ls -d ${F_PATCH_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`"; \
105                         else \
106                                 if [ -h $$A_PATCH ]; then \
107                                         echo "`tput setaf 3`* PHONY: $$R_PATCH`tput sgr0`"; \
108                                 else \
109                                         echo "`tput setaf 6`* Staging $$R_PATCH`tput sgr0`"; \
110                                         mkdir -p `dirname $$F_PATCH` && cp $$A_PATCH $$F_PATCH; \
111                                 fi; \
112                         fi' "$$SUB_NAME" \; || true ; \
113         done
114         @touch $@
115
116 ##############################################################################
117 # Fuel@OPNFV patch operations - to be used only during development
118 ##############################################################################
119 # Apply all Fuel@OPNFV patches, including Armband patches
120 .PHONY: fuel-patches-import
121 fuel-patches-import: .submodules-patched fuel-patches-clean
122         $(MAKE) -e -C ${F_PATCH_DIR} patches-import
123
124 .PHONY: fuel-patches-clean
125 fuel-patches-clean:
126         $(MAKE) -e -C ${F_PATCH_DIR} clean
127
128 # Add copyright header to patch files if not already present
129 .PHONY: patches-copyright
130 patches-copyright:
131         @grep -e "Copyright (c)" -L ${A_PATCHES} | while read p_file; do \
132                 ptmp=`mktemp` && \
133                 cat armband-patch-copyright.template $$p_file > $$ptmp && \
134                 mv $$ptmp $$p_file; \
135         done