blob: d72ddae1938ea171d5e81aee715193779ff64d00 [file] [log] [blame]
Joey Armstrongf128de82023-09-08 17:05:18 -04001#!/bin/bash
Joey Armstrong0003f1a2023-10-18 16:40:23 -04002# -----------------------------------------------------------------------
Joey Armstrongf22de9d2024-04-26 11:37:52 -04003# Copyright 2023-2024 Open Networking Foundation Contributors
Joey Armstrong0003f1a2023-10-18 16:40:23 -04004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16# -----------------------------------------------------------------------
Joey Armstrongf22de9d2024-04-26 11:37:52 -040017# SPDX-FileCopyrightText: 2023-2024 Open Networking Foundation Contributors
Joey Armstrong0003f1a2023-10-18 16:40:23 -040018# SPDX-License-Identifier: Apache-2.0
19# -----------------------------------------------------------------------
20## Intent: This script will update a repository makefiles/ directory
21## by creating a hierarchy that will allow using library makefiles
22## and per-repository makefiles.
Joey Armstrongfedf45e2023-09-20 11:40:01 -040023## -----------------------------------------------------------------------
Joey Armstrongf128de82023-09-08 17:05:18 -040024
Joey Armstrong0003f1a2023-10-18 16:40:23 -040025##-------------------##
26##---] GLOBALS [---##
27##-------------------##
Joey Armstrongf128de82023-09-08 17:05:18 -040028set -euo pipefail
Joey Armstronga2db6cd2023-11-30 12:16:18 -050029# declare -g -i debug=1
Joey Armstrongf128de82023-09-08 17:05:18 -040030
Joey Armstrong0003f1a2023-10-18 16:40:23 -040031## -----------------------------------------------------------------------
Joey Armstrongf22de9d2024-04-26 11:37:52 -040032## Intent: Parse command line paths
33## -----------------------------------------------------------------------
34function program_paths()
35{
Joey Armstrong95a52432024-04-29 15:26:18 -040036 declare -g pgm
37 pgm="$(readlink --canonicalize-existing "$0")"
Joey Armstrongf22de9d2024-04-26 11:37:52 -040038 declare -g pgmbin="${pgm%/*}"
39 declare -g pgmroot="${pgmbin%/*}"
40 declare -g pgmname="${pgm%%*/}"
41
42 readonly pgm
43 readonly pgmbin
44 readonly pgmroot
Joey Armstrong95a52432024-04-29 15:26:18 -040045
46 # shellcheck disable=SC2034
Joey Armstrongf22de9d2024-04-26 11:37:52 -040047 readonly pgmname
48
49 return
50}
51program_paths
52
53## -----------------------------------------------------------------------
Joey Armstrong0003f1a2023-10-18 16:40:23 -040054## Intent: Display a message with formatting
55## -----------------------------------------------------------------------
56function banner()
57{
58 cat <<EOM
Joey Armstrongfedf45e2023-09-20 11:40:01 -040059
Joey Armstrong0003f1a2023-10-18 16:40:23 -040060** -----------------------------------------------------------------------
61** $*
62** -----------------------------------------------------------------------
63EOM
64 return
65}
66
67## -----------------------------------------------------------------------
68## Intent: Display an error mesage then exit with status
69## -----------------------------------------------------------------------
70function error()
71{
72 echo "ERROR: $*"
73 exit 1
74}
75
Joey Armstronga2db6cd2023-11-30 12:16:18 -050076##----------------##
77##---] MAIN [---##
78##----------------##
Joey Armstrongf22de9d2024-04-26 11:37:52 -040079
80# shellcheck disable=SC2034
Joey Armstronga2db6cd2023-11-30 12:16:18 -050081while [[ $# -gt 0 ]]; do
Joey Armstrongf22de9d2024-04-26 11:37:52 -040082 arg=$1; shift
83 case "$arg" in
84 debug) declare -g -i debug=1 ;;
85 *) error "Detected invalid switch [$arg]" ;;
86 esac
Joey Armstronga2db6cd2023-11-30 12:16:18 -050087done
88
Joey Armstrongf22de9d2024-04-26 11:37:52 -040089cp "$pgmroot/.pre-commit-config.yaml" .
Joey Armstronga2db6cd2023-11-30 12:16:18 -050090
Joey Armstrongf22de9d2024-04-26 11:37:52 -040091mkdir -p lf
92pushd lf || { error 'pushd makefiles failed'; }
Joey Armstrongf128de82023-09-08 17:05:18 -040093
Joey Armstrong0003f1a2023-10-18 16:40:23 -040094banner 'Adding repo:onf-make (library makefiles) as a submodule'
Joey Armstrongf22de9d2024-04-26 11:37:52 -040095git submodule add 'https://github.com/opencord/onf-make.git' onf-make
96# git checkout 1.0.0
97# git submodule update --remote --merge
98git submodule update --remote --recursive
Joey Armstrongf128de82023-09-08 17:05:18 -040099
Joey Armstrong0003f1a2023-10-18 16:40:23 -0400100banner 'Install library/local loader include.mk'
Joey Armstrongf22de9d2024-04-26 11:37:52 -0400101rsync -v --checksum "${pgmroot}/install/"* .
102
Joey Armstrongf128de82023-09-08 17:05:18 -0400103
Joey Armstrong0003f1a2023-10-18 16:40:23 -0400104banner 'Create project specific directory makefiles/local'
Joey Armstrongf128de82023-09-08 17:05:18 -0400105mkdir -p local
106touch local/include.mk
Joey Armstrongf128de82023-09-08 17:05:18 -0400107
Joey Armstrongf22de9d2024-04-26 11:37:52 -0400108popd || { error 'popd lf makefiles failed'; }
Joey Armstrongf128de82023-09-08 17:05:18 -0400109
Joey Armstrong0003f1a2023-10-18 16:40:23 -0400110banner 'Prep work for pending checkin'
Joey Armstrongf22de9d2024-04-26 11:37:52 -0400111git add lf
112
113[[ -f 'config.mk' ]] && { git mv 'config.mk' 'lf'; }
114git add lf
Joey Armstronga2db6cd2023-11-30 12:16:18 -0500115git status
Joey Armstrongfedf45e2023-09-20 11:40:01 -0400116
Joey Armstrongf128de82023-09-08 17:05:18 -0400117# [EOF]