blob: 0d3f57773c3dfe6bc29588df601d90369fc966cd [file] [log] [blame]
Joey Armstrongf128de82023-09-08 17:05:18 -04001#!/bin/bash
Joey Armstrong0003f1a2023-10-18 16:40:23 -04002# -*- makefile -*-
3# -----------------------------------------------------------------------
4# Copyright 2023 Open Networking Foundation (ONF) and the ONF Contributors
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17# -----------------------------------------------------------------------
18# SPDX-FileCopyrightText: 2023 Open Networking Foundation (ONF) and the ONF Contributors
19# SPDX-License-Identifier: Apache-2.0
20# -----------------------------------------------------------------------
21## Intent: This script will update a repository makefiles/ directory
22## by creating a hierarchy that will allow using library makefiles
23## and per-repository makefiles.
Joey Armstrongfedf45e2023-09-20 11:40:01 -040024## -----------------------------------------------------------------------
Joey Armstrongf128de82023-09-08 17:05:18 -040025
Joey Armstrong0003f1a2023-10-18 16:40:23 -040026##-------------------##
27##---] GLOBALS [---##
28##-------------------##
Joey Armstrongf128de82023-09-08 17:05:18 -040029set -euo pipefail
30
Joey Armstrong0003f1a2023-10-18 16:40:23 -040031## -----------------------------------------------------------------------
32## Intent: Display a message with formatting
33## -----------------------------------------------------------------------
34function banner()
35{
36 cat <<EOM
Joey Armstrongfedf45e2023-09-20 11:40:01 -040037
Joey Armstrong0003f1a2023-10-18 16:40:23 -040038** -----------------------------------------------------------------------
39** $*
40** -----------------------------------------------------------------------
41EOM
42 return
43}
44
45## -----------------------------------------------------------------------
46## Intent: Display an error mesage then exit with status
47## -----------------------------------------------------------------------
48function error()
49{
50 echo "ERROR: $*"
51 exit 1
52}
53
54##----------------##
55##---] MAIN [---##
56##----------------##
57
58## Avoid trashing a work-in-progress
59path='makefiles/local/include.mk'
60[[ -e "$path" ]] && { error "Detected upgrade path: $path"; }
61
62banner "Archive current directory"
63tar czvf ../backup-setup.tgz .
64
65## Migration patches should be simple and plentiful.
66if [[ ! -d makefiles-orig ]]; then
67 cat <<EOM
68
69* -----------------------------------------------------------------------
70* Replacing a repository makefile directory is deployed
71* by creating a few independent patches.
72* -----------------------------------------------------------------------
73 1) Rename the repository-specific makefiles directory.
74 1a) git mv makefiles makefiles-orig
75 1b) Update Makefile to "include makefiles-orig"
76
77 2) Create makefiles/
78 2a) add repo:onf-make as a submodule.
79 2b) create makefiles/local/
80 2c) relocate config files
81
82 3) Update Makefile to include makefiles/include.mk
83
84EOM
85 exit 1
86fi
Joey Armstrongfedf45e2023-09-20 11:40:01 -040087
Joey Armstrongf128de82023-09-08 17:05:18 -040088mkdir -p makefiles
Joey Armstrong0003f1a2023-10-18 16:40:23 -040089pushd makefiles || { error 'pushd makefiles failed'; }
Joey Armstrongf128de82023-09-08 17:05:18 -040090
Joey Armstrong0003f1a2023-10-18 16:40:23 -040091banner 'Adding repo:onf-make (library makefiles) as a submodule'
Joey Armstrongf128de82023-09-08 17:05:18 -040092git submodule add 'https://github.com/opencord/onf-make.git' onf-lib
93
Joey Armstrong0003f1a2023-10-18 16:40:23 -040094banner 'Install library/local loader include.mk'
95rsync -v --checksum onf-lib/makefiles_include_mk.ex include.mk
Joey Armstrongf128de82023-09-08 17:05:18 -040096
Joey Armstrong0003f1a2023-10-18 16:40:23 -040097banner 'Create project specific directory makefiles/local'
Joey Armstrongf128de82023-09-08 17:05:18 -040098mkdir -p local
99touch local/include.mk
Joey Armstrongf128de82023-09-08 17:05:18 -0400100
Joey Armstrong0003f1a2023-10-18 16:40:23 -0400101popd || { error 'popd makefiles failed'; }
Joey Armstrongf128de82023-09-08 17:05:18 -0400102
Joey Armstrong0003f1a2023-10-18 16:40:23 -0400103banner 'Prep work for pending checkin'
104git add makefiles/include.mk
105git add makefiles/local/include.mk
106git mv config.mk makefiles/config.mk
107git add makefiles
Joey Armstrongfedf45e2023-09-20 11:40:01 -0400108
Joey Armstrongf128de82023-09-08 17:05:18 -0400109# [EOF]