brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 2183e2e Raw
87 lines · bash
1#!/usr/bin/env bash2#===-- get-llvm-version.sh - Get LLVM Version from sources -----------------===#3#4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5# See https://llvm.org/LICENSE.txt for license information.6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7#8#===------------------------------------------------------------------------===#9#10# Extract the current LLVM version from the CMake files. 11#12#===------------------------------------------------------------------------===#13 14cmake_file=$(dirname $0)/../../../cmake/Modules/LLVMVersion.cmake15function usage() {16    echo "usage: `basename $0`"17    echo ""18    echo "Calling this script with now options will output the full version: e.g. 19.1.0"19    echo " --cmake-file      Path to cmake file with the version (default: $cmake_file)20    echo " You can use at most one of the following options:21    echo " --major           Print the major version."22    echo " --minor           Print the minor version."23    echo " --patch           Print the patch version."24}25 26print=""27 28while [ $# -gt 0 ]; do29    case $1 in30        --cmake-file )31            shift32    	    cmake_file="$1"33    	    ;;34        --major)35            if [ -n "$print" ]; then36                echo "Only one of --major, --minor, --patch is allowed"37                exit 138            fi39            print="major"40            ;;41        --minor)42            if [ -n "$print" ]; then43                echo "Only one of --major, --minor, --patch is allowed"44                exit 145            fi46            print="minor"47            ;;48        --patch)49            if [ -n "$print" ]; then50                echo "Only one of --major, --minor, --patch is allowed"51                exit 152            fi53            print="patch"54            ;;55        --help | -h | -\? )56            usage57            exit 058            ;;59        * )60            echo "unknown option: $1"61            usage62            exit 163            ;;64    esac65    shift66done67 68major=`grep -o 'LLVM_VERSION_MAJOR[[:space:]]\+\([0-9]\+\)' $cmake_file  | grep -o '[0-9]\+'`69minor=`grep -o 'LLVM_VERSION_MINOR[[:space:]]\+\([0-9]\+\)' $cmake_file  | grep -o '[0-9]\+'`70patch=`grep -o 'LLVM_VERSION_PATCH[[:space:]]\+\([0-9]\+\)' $cmake_file  | grep -o '[0-9]\+'`71 72case $print in73    major)74        echo "$major"75        ;;76    minor)77        echo "$minor"78        ;;79    patch)80        echo "$patch"81        ;;82    *)83        echo "$major.$minor.$patch"84        ;;85esac86 87