1a8e1175bSopenharmony_ci#!/bin/bash
2a8e1175bSopenharmony_ci
3a8e1175bSopenharmony_ciprint_usage()
4a8e1175bSopenharmony_ci{
5a8e1175bSopenharmony_ci    cat <<EOF
6a8e1175bSopenharmony_ciUsage: $0 [OPTION]...
7a8e1175bSopenharmony_ciPrepare the source tree for a release.
8a8e1175bSopenharmony_ci
9a8e1175bSopenharmony_ciOptions:
10a8e1175bSopenharmony_ci  -u    Prepare for development (undo the release preparation)
11a8e1175bSopenharmony_ciEOF
12a8e1175bSopenharmony_ci}
13a8e1175bSopenharmony_ci
14a8e1175bSopenharmony_ci# Copyright The Mbed TLS Contributors
15a8e1175bSopenharmony_ci# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
16a8e1175bSopenharmony_ci
17a8e1175bSopenharmony_ciset -eu
18a8e1175bSopenharmony_ci
19a8e1175bSopenharmony_ciif [ $# -ne 0 ] && [ "$1" = "--help" ]; then
20a8e1175bSopenharmony_ci    print_usage
21a8e1175bSopenharmony_ci    exit
22a8e1175bSopenharmony_cifi
23a8e1175bSopenharmony_ci
24a8e1175bSopenharmony_ciunrelease= # if non-empty, we're in undo-release mode
25a8e1175bSopenharmony_ciwhile getopts u OPTLET; do
26a8e1175bSopenharmony_ci    case $OPTLET in
27a8e1175bSopenharmony_ci        u) unrelease=1;;
28a8e1175bSopenharmony_ci        \?)
29a8e1175bSopenharmony_ci            echo 1>&2 "$0: unknown option: -$OPTLET"
30a8e1175bSopenharmony_ci            echo 1>&2 "Try '$0 --help' for more information."
31a8e1175bSopenharmony_ci            exit 3;;
32a8e1175bSopenharmony_ci    esac
33a8e1175bSopenharmony_cidone
34a8e1175bSopenharmony_ci
35a8e1175bSopenharmony_ci
36a8e1175bSopenharmony_ci
37a8e1175bSopenharmony_ci#### .gitignore processing ####
38a8e1175bSopenharmony_ci
39a8e1175bSopenharmony_ciGITIGNORES=$(find . -name ".gitignore")
40a8e1175bSopenharmony_cifor GITIGNORE in $GITIGNORES; do
41a8e1175bSopenharmony_ci    if [ -n "$unrelease" ]; then
42a8e1175bSopenharmony_ci        sed -i '/###START_COMMENTED_GENERATED_FILES###/,/###END_COMMENTED_GENERATED_FILES###/s/^#//' $GITIGNORE
43a8e1175bSopenharmony_ci        sed -i 's/###START_COMMENTED_GENERATED_FILES###/###START_GENERATED_FILES###/' $GITIGNORE
44a8e1175bSopenharmony_ci        sed -i 's/###END_COMMENTED_GENERATED_FILES###/###END_GENERATED_FILES###/' $GITIGNORE
45a8e1175bSopenharmony_ci    else
46a8e1175bSopenharmony_ci        sed -i '/###START_GENERATED_FILES###/,/###END_GENERATED_FILES###/s/^/#/' $GITIGNORE
47a8e1175bSopenharmony_ci        sed -i 's/###START_GENERATED_FILES###/###START_COMMENTED_GENERATED_FILES###/' $GITIGNORE
48a8e1175bSopenharmony_ci        sed -i 's/###END_GENERATED_FILES###/###END_COMMENTED_GENERATED_FILES###/' $GITIGNORE
49a8e1175bSopenharmony_ci    fi
50a8e1175bSopenharmony_cidone
51a8e1175bSopenharmony_ci
52a8e1175bSopenharmony_ci
53a8e1175bSopenharmony_ci
54a8e1175bSopenharmony_ci#### Build scripts ####
55a8e1175bSopenharmony_ci
56a8e1175bSopenharmony_ci# GEN_FILES defaults on (non-empty) in development, off (empty) in releases
57a8e1175bSopenharmony_ciif [ -n "$unrelease" ]; then
58a8e1175bSopenharmony_ci    r=' yes'
59a8e1175bSopenharmony_cielse
60a8e1175bSopenharmony_ci    r=''
61a8e1175bSopenharmony_cifi
62a8e1175bSopenharmony_cised -i 's/^\(GEN_FILES[ ?:]*=\)\([^#]*\)/\1'"$r/" Makefile */Makefile
63a8e1175bSopenharmony_ci
64a8e1175bSopenharmony_ci# GEN_FILES defaults on in development, off in releases
65a8e1175bSopenharmony_ciif [ -n "$unrelease" ]; then
66a8e1175bSopenharmony_ci    r='ON'
67a8e1175bSopenharmony_cielse
68a8e1175bSopenharmony_ci    r='OFF'
69a8e1175bSopenharmony_cifi
70a8e1175bSopenharmony_cised -i '/[Oo][Ff][Ff] in development/! s/^\( *option *( *GEN_FILES  *"[^"]*"  *\)\([A-Za-z0-9][A-Za-z0-9]*\)/\1'"$r/" CMakeLists.txt
71