Agathiyan Bragadeesh | 3bcff54 | 2023-08-04 14:05:28 +0100 | [diff] [blame] | 1 | #!/bin/bash |
Gilles Peskine | dea4c7e | 2023-09-08 16:34:01 +0200 | [diff] [blame] | 2 | |
Gilles Peskine | 473f636 | 2023-09-08 16:49:14 +0200 | [diff] [blame^] | 3 | print_usage() |
| 4 | { |
| 5 | cat <<EOF |
| 6 | Usage: $0 [OPTION]... |
| 7 | Prepare the source tree for a release. |
| 8 | |
| 9 | Options: |
| 10 | -u Prepare for development (undo the release preparation) |
| 11 | EOF |
| 12 | } |
Gilles Peskine | dea4c7e | 2023-09-08 16:34:01 +0200 | [diff] [blame] | 13 | |
Agathiyan Bragadeesh | 3bcff54 | 2023-08-04 14:05:28 +0100 | [diff] [blame] | 14 | # Copyright The Mbed TLS Contributors |
| 15 | # SPDX-License-Identifier: Apache-2.0 |
| 16 | # |
| 17 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 18 | # not use this file except in compliance with the License. |
| 19 | # You may obtain a copy of the License at |
| 20 | # |
| 21 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 22 | # |
| 23 | # Unless required by applicable law or agreed to in writing, software |
| 24 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 25 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 26 | # See the License for the specific language governing permissions and |
| 27 | # limitations under the License. |
Agathiyan Bragadeesh | 3bcff54 | 2023-08-04 14:05:28 +0100 | [diff] [blame] | 28 | |
| 29 | set -eu |
| 30 | |
Gilles Peskine | 473f636 | 2023-09-08 16:49:14 +0200 | [diff] [blame^] | 31 | if [ $# -ne 0 ] && [ "$1" = "--help" ]; then |
Agathiyan Bragadeesh | 3bcff54 | 2023-08-04 14:05:28 +0100 | [diff] [blame] | 32 | print_usage |
Gilles Peskine | 473f636 | 2023-09-08 16:49:14 +0200 | [diff] [blame^] | 33 | exit |
Agathiyan Bragadeesh | 3bcff54 | 2023-08-04 14:05:28 +0100 | [diff] [blame] | 34 | fi |
| 35 | |
Gilles Peskine | 473f636 | 2023-09-08 16:49:14 +0200 | [diff] [blame^] | 36 | unrelease= # if non-empty, we're in undo-release mode |
| 37 | while getopts u OPTLET; do |
| 38 | case $OPTLET in |
| 39 | u) unrelease=1;; |
| 40 | \?) |
| 41 | echo 1>&2 "$0: unknown option: -$OPTLET" |
| 42 | echo 1>&2 "Try '$0 --help' for more information." |
| 43 | exit 3;; |
| 44 | esac |
| 45 | done |
| 46 | |
| 47 | |
| 48 | |
| 49 | #### .gitignore processing #### |
Agathiyan Bragadeesh | 3bcff54 | 2023-08-04 14:05:28 +0100 | [diff] [blame] | 50 | |
| 51 | GITIGNORES=$(find . -name ".gitignore") |
| 52 | for GITIGNORE in $GITIGNORES; do |
Gilles Peskine | 473f636 | 2023-09-08 16:49:14 +0200 | [diff] [blame^] | 53 | if [ -n "$unrelease" ]; then |
Agathiyan Bragadeesh | 3bcff54 | 2023-08-04 14:05:28 +0100 | [diff] [blame] | 54 | sed -i '/###START_COMMENTED_GENERATED_FILES###/,/###END_COMMENTED_GENERATED_FILES###/s/^# //' $GITIGNORE |
| 55 | sed -i 's/###START_COMMENTED_GENERATED_FILES###/###START_GENERATED_FILES###/' $GITIGNORE |
| 56 | sed -i 's/###END_COMMENTED_GENERATED_FILES###/###END_GENERATED_FILES###/' $GITIGNORE |
| 57 | else |
| 58 | sed -i '/###START_GENERATED_FILES###/,/###END_GENERATED_FILES###/s/^/# /' $GITIGNORE |
| 59 | sed -i 's/###START_GENERATED_FILES###/###START_COMMENTED_GENERATED_FILES###/' $GITIGNORE |
| 60 | sed -i 's/###END_GENERATED_FILES###/###END_COMMENTED_GENERATED_FILES###/' $GITIGNORE |
| 61 | fi |
| 62 | done |
Gilles Peskine | 473f636 | 2023-09-08 16:49:14 +0200 | [diff] [blame^] | 63 | |
| 64 | |
| 65 | |
| 66 | #### Build scripts #### |
| 67 | |
| 68 | # GEN_FILES defaults on (non-empty) in development, off (empty) in releases |
| 69 | if [ -n "$unrelease" ]; then |
| 70 | r=' yes' |
| 71 | else |
| 72 | r='' |
| 73 | fi |
| 74 | sed -i 's/^\(GEN_FILES[ ?:]*=\)\([^#]*\)/\1'"$r/" Makefile */Makefile |
| 75 | |
| 76 | # GEN_FILES defaults on in development, off in releases |
| 77 | if [ -n "$unrelease" ]; then |
| 78 | r='ON' |
| 79 | else |
| 80 | r='OFF' |
| 81 | fi |
| 82 | sed -i 's/^\( *option *( *GEN_FILES *"[^"]*" *\)\([A-Za-z0-9][A-Za-z0-9]*\)/\1'"$r/" CMakeLists.txt |