blob: 9013cc8788362f8aee368d2d017bcb7f7a14c7bd [file] [log] [blame]
Agathiyan Bragadeesh3bcff542023-08-04 14:05:28 +01001#!/bin/bash
Gilles Peskinedea4c7e2023-09-08 16:34:01 +02002
Gilles Peskine473f6362023-09-08 16:49:14 +02003print_usage()
4{
5 cat <<EOF
6Usage: $0 [OPTION]...
7Prepare the source tree for a release.
8
9Options:
10 -u Prepare for development (undo the release preparation)
11EOF
12}
Gilles Peskinedea4c7e2023-09-08 16:34:01 +020013
Agathiyan Bragadeesh3bcff542023-08-04 14:05:28 +010014# 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 Bragadeesh3bcff542023-08-04 14:05:28 +010028
29set -eu
30
Gilles Peskine473f6362023-09-08 16:49:14 +020031if [ $# -ne 0 ] && [ "$1" = "--help" ]; then
Agathiyan Bragadeesh3bcff542023-08-04 14:05:28 +010032 print_usage
Gilles Peskine473f6362023-09-08 16:49:14 +020033 exit
Agathiyan Bragadeesh3bcff542023-08-04 14:05:28 +010034fi
35
Gilles Peskine473f6362023-09-08 16:49:14 +020036unrelease= # if non-empty, we're in undo-release mode
37while 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
45done
46
47
48
49#### .gitignore processing ####
Agathiyan Bragadeesh3bcff542023-08-04 14:05:28 +010050
51GITIGNORES=$(find . -name ".gitignore")
52for GITIGNORE in $GITIGNORES; do
Gilles Peskine473f6362023-09-08 16:49:14 +020053 if [ -n "$unrelease" ]; then
Agathiyan Bragadeesh3bcff542023-08-04 14:05:28 +010054 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
62done
Gilles Peskine473f6362023-09-08 16:49:14 +020063
64
65
66#### Build scripts ####
67
68# GEN_FILES defaults on (non-empty) in development, off (empty) in releases
69if [ -n "$unrelease" ]; then
70 r=' yes'
71else
72 r=''
73fi
74sed -i 's/^\(GEN_FILES[ ?:]*=\)\([^#]*\)/\1'"$r/" Makefile */Makefile
75
76# GEN_FILES defaults on in development, off in releases
77if [ -n "$unrelease" ]; then
78 r='ON'
79else
80 r='OFF'
81fi
82sed -i 's/^\( *option *( *GEN_FILES *"[^"]*" *\)\([A-Za-z0-9][A-Za-z0-9]*\)/\1'"$r/" CMakeLists.txt