Blame build/get-version.sh

Packit 90a5c9
#!/bin/sh
Packit 90a5c9
#
Packit 90a5c9
# Licensed to the Apache Software Foundation (ASF) under one or more
Packit 90a5c9
# contributor license agreements.  See the NOTICE file distributed with
Packit 90a5c9
# this work for additional information regarding copyright ownership.
Packit 90a5c9
# The ASF licenses this file to You under the Apache License, Version 2.0
Packit 90a5c9
# (the "License"); you may not use this file except in compliance with
Packit 90a5c9
# the License.  You may obtain a copy of the License at
Packit 90a5c9
#
Packit 90a5c9
#     http://www.apache.org/licenses/LICENSE-2.0
Packit 90a5c9
#
Packit 90a5c9
# Unless required by applicable law or agreed to in writing, software
Packit 90a5c9
# distributed under the License is distributed on an "AS IS" BASIS,
Packit 90a5c9
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 90a5c9
# See the License for the specific language governing permissions and
Packit 90a5c9
# limitations under the License.
Packit 90a5c9
#
Packit 90a5c9
#
Packit 90a5c9
# extract version numbers from a header file
Packit 90a5c9
#
Packit 90a5c9
# USAGE: get-version.sh CMD VERSION_HEADER PREFIX
Packit 90a5c9
#   where CMD is one of: all, major, libtool
Packit 90a5c9
#   where PREFIX is the prefix to {MAJOR|MINOR|PATCH}_VERSION defines
Packit 90a5c9
#
Packit 90a5c9
#   get-version.sh all returns a dotted version number
Packit 90a5c9
#   get-version.sh major returns just the major version number
Packit 90a5c9
#   get-version.sh libtool returns a version "libtool -version-info" format
Packit 90a5c9
#
Packit 90a5c9
Packit 90a5c9
if test $# != 3; then
Packit 90a5c9
  echo "USAGE: $0 CMD INCLUDEDIR PREFIX"
Packit 90a5c9
  echo "  where CMD is one of: all, major"
Packit 90a5c9
  exit 1
Packit 90a5c9
fi
Packit 90a5c9
Packit 90a5c9
major_sed="/#define.*$3_MAJORVERSION/s/^.*\([0-9][0-9]*\).*$/\1/p"
Packit 90a5c9
minor_sed="/#define.*$3_MINORVERSION/s/^.*\([0-9][0-9]*\).*$/\1/p"
Packit 90a5c9
patch_sed="/#define.*$3_PATCHLEVEL/s/^[^0-9]*\([0-9][0-9a-z-]*\).*$/\1/p"
Packit 90a5c9
mmn_sed="/#define.*$3_MAJOR/s/^[^0-9]*\([0-9][0-9]*\).*$/\1/p"
Packit 90a5c9
major="`sed -n $major_sed $2`"
Packit 90a5c9
minor="`sed -n $minor_sed $2`"
Packit 90a5c9
patch="`sed -n $patch_sed $2`"
Packit 90a5c9
mmn="`sed -n $mmn_sed $2`"
Packit 90a5c9
Packit 90a5c9
if test "$1" = "all"; then
Packit 90a5c9
  echo ${major}.${minor}.${patch}
Packit 90a5c9
elif test "$1" = "major"; then
Packit 90a5c9
  echo ${major}
Packit 90a5c9
elif test "$1" = "mmn"; then
Packit 90a5c9
  echo ${mmn}
Packit 90a5c9
elif test "$1" = "epoch"; then
Packit 90a5c9
  printf "%02d%02d%03d" ${major} ${minor} ${patch}
Packit 90a5c9
elif test "$1" = "libtool"; then
Packit 90a5c9
  # Yes, ${minor}:${patch}:${minor} is correct due to libtool idiocy.
Packit 90a5c9
  echo ${minor}:${patch}:${minor}
Packit 90a5c9
else
Packit 90a5c9
  echo "ERROR: unknown version CMD ($1)"
Packit 90a5c9
  exit 1
Packit 90a5c9
fi