Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 1 | #!/bin/bash |
Joey Armstrong | 0003f1a | 2023-10-18 16:40:23 -0400 | [diff] [blame] | 2 | # -*- 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 Armstrong | fedf45e | 2023-09-20 11:40:01 -0400 | [diff] [blame] | 24 | ## ----------------------------------------------------------------------- |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 25 | |
Joey Armstrong | 0003f1a | 2023-10-18 16:40:23 -0400 | [diff] [blame] | 26 | ##-------------------## |
| 27 | ##---] GLOBALS [---## |
| 28 | ##-------------------## |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 29 | set -euo pipefail |
Joey Armstrong | a2db6cd | 2023-11-30 12:16:18 -0500 | [diff] [blame] | 30 | # declare -g -i debug=1 |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 31 | |
Joey Armstrong | 0003f1a | 2023-10-18 16:40:23 -0400 | [diff] [blame] | 32 | ## ----------------------------------------------------------------------- |
| 33 | ## Intent: Display a message with formatting |
| 34 | ## ----------------------------------------------------------------------- |
| 35 | function banner() |
| 36 | { |
| 37 | cat <<EOM |
Joey Armstrong | fedf45e | 2023-09-20 11:40:01 -0400 | [diff] [blame] | 38 | |
Joey Armstrong | 0003f1a | 2023-10-18 16:40:23 -0400 | [diff] [blame] | 39 | ** ----------------------------------------------------------------------- |
| 40 | ** $* |
| 41 | ** ----------------------------------------------------------------------- |
| 42 | EOM |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | ## ----------------------------------------------------------------------- |
| 47 | ## Intent: Display an error mesage then exit with status |
| 48 | ## ----------------------------------------------------------------------- |
| 49 | function error() |
| 50 | { |
| 51 | echo "ERROR: $*" |
| 52 | exit 1 |
| 53 | } |
| 54 | |
Joey Armstrong | a2db6cd | 2023-11-30 12:16:18 -0500 | [diff] [blame] | 55 | ## ----------------------------------------------------------------------- |
| 56 | ## Intent: Archive current directory before we begin |
| 57 | ## ----------------------------------------------------------------------- |
| 58 | function archive_sandbox() |
| 59 | { |
| 60 | local abs="$(realpath --canonicalize-existing '.')" |
| 61 | local dir="${abs##*/}" |
| 62 | local ts="$(date '+%Y%m%d%H%M%S')" |
| 63 | local prefix="../${dir}-all/backups" |
Joey Armstrong | 0003f1a | 2023-10-18 16:40:23 -0400 | [diff] [blame] | 64 | |
Joey Armstrong | a2db6cd | 2023-11-30 12:16:18 -0500 | [diff] [blame] | 65 | banner "Archive current directory ($dir)" |
Joey Armstrong | 0003f1a | 2023-10-18 16:40:23 -0400 | [diff] [blame] | 66 | |
Joey Armstrong | a2db6cd | 2023-11-30 12:16:18 -0500 | [diff] [blame] | 67 | # make sterile >/dev/null # nuke lingering .venv/ installs |
| 68 | # make clean-all >/dev/null # nuke lingering .venv/ installs |
Joey Armstrong | 0003f1a | 2023-10-18 16:40:23 -0400 | [diff] [blame] | 69 | |
Joey Armstrong | a2db6cd | 2023-11-30 12:16:18 -0500 | [diff] [blame] | 70 | declare -a targs=() |
| 71 | targs+=('--create') |
| 72 | |
| 73 | ## Set archive compression level |
| 74 | local compress='bzip2' |
| 75 | local ext |
| 76 | case "$compress" in |
| 77 | bzip2) targs+=('--bzip2'); ext='bz2' ;; |
| 78 | gzip) targs+=('--gzip'); ext='tgz' ;; |
| 79 | zstd) targs+=('--zstd'); ext='zst' ;; |
| 80 | *) error "Detected invalid compression [$compress]" ;; |
| 81 | esac |
| 82 | |
| 83 | local out="${prefix}/${ts}.${ext}" |
| 84 | |
| 85 | targs+=('--file' "$out") |
| 86 | |
| 87 | mkdir -p "$prefix" |
| 88 | tar "${targs[@]}" '.' |
| 89 | /bin/ls -l "$out" |
| 90 | return |
| 91 | } |
| 92 | |
| 93 | ## ----------------------------------------------------------------------- |
| 94 | ## Intent: Install feature enabling makefile. |
| 95 | ## ----------------------------------------------------------------------- |
| 96 | function install_config_mk |
| 97 | { |
| 98 | local dst='makefiles/config.mk' |
| 99 | if [[ -f "$dst" ]]; then |
| 100 | : |
| 101 | elif [[ -f 'config.mk' ]]; then |
| 102 | git mv config.mk "$dst" |
| 103 | else |
| 104 | rsync -v --checksum makefiles/onf-lib/config.mk "$dst" |
| 105 | fi |
| 106 | |
| 107 | return |
| 108 | } |
| 109 | |
| 110 | ## ----------------------------------------------------------------------- |
| 111 | ## Intent: Re-home existing local makefiles/ into makefiles/local |
| 112 | ## ----------------------------------------------------------------------- |
| 113 | function patch_detection() |
| 114 | { |
| 115 | [[ ! -d makefiles ]] && return |
| 116 | |
| 117 | ## Migration patches should be simple and plentiful. |
| 118 | if [[ ! -d makefiles-orig ]]; then |
| 119 | cat <<EOM |
Joey Armstrong | 0003f1a | 2023-10-18 16:40:23 -0400 | [diff] [blame] | 120 | |
| 121 | * ----------------------------------------------------------------------- |
| 122 | * Replacing a repository makefile directory is deployed |
| 123 | * by creating a few independent patches. |
| 124 | * ----------------------------------------------------------------------- |
| 125 | 1) Rename the repository-specific makefiles directory. |
| 126 | 1a) git mv makefiles makefiles-orig |
| 127 | 1b) Update Makefile to "include makefiles-orig" |
| 128 | |
| 129 | 2) Create makefiles/ |
| 130 | 2a) add repo:onf-make as a submodule. |
| 131 | 2b) create makefiles/local/ |
| 132 | 2c) relocate config files |
| 133 | |
| 134 | 3) Update Makefile to include makefiles/include.mk |
| 135 | |
| 136 | EOM |
Joey Armstrong | a2db6cd | 2023-11-30 12:16:18 -0500 | [diff] [blame] | 137 | exit 1 |
| 138 | fi |
| 139 | return |
| 140 | } |
| 141 | |
| 142 | ##----------------## |
| 143 | ##---] MAIN [---## |
| 144 | ##----------------## |
| 145 | while [[ $# -gt 0 ]]; do |
| 146 | arg=$1; shift |
| 147 | case "$arg" in |
| 148 | debug) declare -g -i debug=1 ;; |
| 149 | *) error "Detected invalid switch [$arg]" ;; |
| 150 | esac |
| 151 | done |
| 152 | |
| 153 | ## Avoid trashing a work-in-progress |
| 154 | path='makefiles/local/include.mk' |
| 155 | [[ -e "$path" ]] && { error "Detected upgrade path: $path"; } |
| 156 | |
| 157 | archive_sandbox |
| 158 | patch_detection |
Joey Armstrong | fedf45e | 2023-09-20 11:40:01 -0400 | [diff] [blame] | 159 | |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 160 | mkdir -p makefiles |
Joey Armstrong | 0003f1a | 2023-10-18 16:40:23 -0400 | [diff] [blame] | 161 | pushd makefiles || { error 'pushd makefiles failed'; } |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 162 | |
Joey Armstrong | 0003f1a | 2023-10-18 16:40:23 -0400 | [diff] [blame] | 163 | banner 'Adding repo:onf-make (library makefiles) as a submodule' |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 164 | git submodule add 'https://github.com/opencord/onf-make.git' onf-lib |
| 165 | |
Joey Armstrong | 0003f1a | 2023-10-18 16:40:23 -0400 | [diff] [blame] | 166 | banner 'Install library/local loader include.mk' |
| 167 | rsync -v --checksum onf-lib/makefiles_include_mk.ex include.mk |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 168 | |
Joey Armstrong | 0003f1a | 2023-10-18 16:40:23 -0400 | [diff] [blame] | 169 | banner 'Create project specific directory makefiles/local' |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 170 | mkdir -p local |
| 171 | touch local/include.mk |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 172 | |
Joey Armstrong | 0003f1a | 2023-10-18 16:40:23 -0400 | [diff] [blame] | 173 | popd || { error 'popd makefiles failed'; } |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 174 | |
Joey Armstrong | 0003f1a | 2023-10-18 16:40:23 -0400 | [diff] [blame] | 175 | banner 'Prep work for pending checkin' |
| 176 | git add makefiles/include.mk |
| 177 | git add makefiles/local/include.mk |
Joey Armstrong | a2db6cd | 2023-11-30 12:16:18 -0500 | [diff] [blame] | 178 | install_config_mk |
Joey Armstrong | 0003f1a | 2023-10-18 16:40:23 -0400 | [diff] [blame] | 179 | git add makefiles |
Joey Armstrong | a2db6cd | 2023-11-30 12:16:18 -0500 | [diff] [blame] | 180 | git status |
Joey Armstrong | fedf45e | 2023-09-20 11:40:01 -0400 | [diff] [blame] | 181 | |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 182 | # [EOF] |