1c87c5fbaSopenharmony_ci#! /bin/bash
2c87c5fbaSopenharmony_ci
3c87c5fbaSopenharmony_ciif ! test -f configure.ac; then
4c87c5fbaSopenharmony_ci    >&2 echo "$(basename $0): script must be called from the package's top directory"
5c87c5fbaSopenharmony_ci    exit 1
6c87c5fbaSopenharmony_cifi
7c87c5fbaSopenharmony_ci
8c87c5fbaSopenharmony_cideclare $(sed -ne '/^LIBCOAP_API_VERSION=[0-9]\+/{p; q}' configure.ac)
9c87c5fbaSopenharmony_ciNEW_VERSION=${1:-$LIBCOAP_API_VERSION}
10c87c5fbaSopenharmony_ci
11c87c5fbaSopenharmony_ciif test "x$NEW_VERSION" = "x$LIBCOAP_API_VERSION"; then
12c87c5fbaSopenharmony_ci    >&2 echo "no version change requested, exiting (current version is $LIBCOAP_API_VERSION)"
13c87c5fbaSopenharmony_ci    exit 1
14c87c5fbaSopenharmony_cifi
15c87c5fbaSopenharmony_ci
16c87c5fbaSopenharmony_ciecho $(basename $0): increase version $LIBCOAP_API_VERSION to $NEW_VERSION
17c87c5fbaSopenharmony_ci
18c87c5fbaSopenharmony_ci# command for move operations on version-controlled files and directories
19c87c5fbaSopenharmony_ciMV="git mv"
20c87c5fbaSopenharmony_cimove() {
21c87c5fbaSopenharmony_ci    source=$1
22c87c5fbaSopenharmony_ci    dest=$2
23c87c5fbaSopenharmony_ci    test -e "$1" && $MV "$1" "$2"
24c87c5fbaSopenharmony_ci}
25c87c5fbaSopenharmony_ci
26c87c5fbaSopenharmony_cimove include/coap$LIBCOAP_API_VERSION include/coap$NEW_VERSION
27c87c5fbaSopenharmony_cimove libcoap-$LIBCOAP_API_VERSION.pc.in libcoap-$NEW_VERSION.pc.in
28c87c5fbaSopenharmony_cimove libcoap-$LIBCOAP_API_VERSION.map libcoap-$NEW_VERSION.map
29c87c5fbaSopenharmony_cimove libcoap-$LIBCOAP_API_VERSION.sym libcoap-$NEW_VERSION.sym
30c87c5fbaSopenharmony_ci
31c87c5fbaSopenharmony_ci# sed pattern for include path prefix substitution
32c87c5fbaSopenharmony_cipat='\(#\s*include ["<]coap\)'$LIBCOAP_API_VERSION/
33c87c5fbaSopenharmony_ci
34c87c5fbaSopenharmony_cifind \( -name \*.h -o -name \*.c \) \
35c87c5fbaSopenharmony_ci     -exec grep -q "^$pat" {} \; -print | \
36c87c5fbaSopenharmony_ci    (while read fn ; do test -f ${fn}.in || sed -i "s,^$pat,\1$NEW_VERSION/,"  $fn ; done )
37c87c5fbaSopenharmony_ci
38c87c5fbaSopenharmony_ci# examples-code-check.c generates new files with include statements
39c87c5fbaSopenharmony_cised -i "s,$pat,\1$NEW_VERSION/," man/examples-code-check.c
40c87c5fbaSopenharmony_ci
41c87c5fbaSopenharmony_cipathpat='\(include/coap\)'$LIBCOAP_API_VERSION
42c87c5fbaSopenharmony_ci
43c87c5fbaSopenharmony_ci# autogen.sh
44c87c5fbaSopenharmony_cifor fn in autogen.sh .gitignore build-env/Dockerfile.* ; do
45c87c5fbaSopenharmony_ci    sed -i "s,$pathpat,\1$NEW_VERSION,g" $fn
46c87c5fbaSopenharmony_cidone
47c87c5fbaSopenharmony_ci
48c87c5fbaSopenharmony_ci# Adjust LIBCOAP_API_VERSION in CMakeLists.txt
49c87c5fbaSopenharmony_cised -i "s/^\(set(LIBCOAP_API_VERSION \+\)$LIBCOAP_API_VERSION\( *)\)/\1$NEW_VERSION\2/" CMakeLists.txt
50c87c5fbaSopenharmony_ci
51c87c5fbaSopenharmony_ci# Adjust LibCoAPIncludeDir in win32/libcoap.props
52c87c5fbaSopenharmony_cised -i "s/\(<LibCoAPIncludeDir>include\\\coap\)$LIBCOAP_API_VERSION/\1$NEW_VERSION/" win32/libcoap.props
53c87c5fbaSopenharmony_ci
54c87c5fbaSopenharmony_ci# Adjust API version in in win32/libcoap.vcxproj
55c87c5fbaSopenharmony_cised -i "s/\(<CustomBuild Include=\"\.\.\\\libcoap-\)$LIBCOAP_API_VERSION/\1$NEW_VERSION/" win32/libcoap.vcxproj win32/libcoap.vcxproj.filters
56c87c5fbaSopenharmony_cised -i "s/\(<TargetName>\$(ProjectName)-\)$LIBCOAP_API_VERSION/\1$NEW_VERSION/" win32/libcoap.vcxproj
57c87c5fbaSopenharmony_cised -i "s/\(libcoap-\)$LIBCOAP_API_VERSION/\1$NEW_VERSION/g" win32/install/install.vcxproj
58c87c5fbaSopenharmony_ci
59c87c5fbaSopenharmony_ci# Finally, increase LIBCOAP_API_VERSION in configure.ac and re-run autoconf
60c87c5fbaSopenharmony_cised -i "s/^\(LIBCOAP_API_VERSION=\)$LIBCOAP_API_VERSION/\1$NEW_VERSION/" configure.ac && autoreconf
61