| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | # |
| 3 | # libhugetlbfs - Easy use of Linux hugepages |
| 4 | # Copyright (C) 2006 Andy Whitcroft, IBM Corporation |
| 5 | # |
| 6 | # This library is free software; you can redistribute it and/or |
| 7 | # modify it under the terms of the GNU Lesser General Public License |
| 8 | # as published by the Free Software Foundation; either version 2.1 of |
| 9 | # the License, or (at your option) any later version. |
| 10 | # |
| 11 | # This library is distributed in the hope that it will be useful, but |
| 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | # Lesser General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU Lesser General Public |
| 17 | # License along with this library; if not, write to the Free Software |
| 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | |
| 20 | if [scip-shell system . . `[`. "$#" -lt 1 ]; then |
| 21 | echoscip-shell system . . echo. "Usage: localversion <version file> <source> ..." 1>&2 |
| 22 | exit 1 |
| 23 | fi |
| 24 | file="$1" |
| 25 | |
| 26 | if [scip-shell system . . `[`. -f "$file" ]; then |
| 27 | read current_version <"$file" |
| 28 | fi |
| 29 | version="$current_version" |
| 30 | |
| 31 | modified=0 |
| 32 | |
| 33 | # GIT: check for a git tree. |
| 34 | mod=`gitscip-shell system . . git. diff-index HEAD 2>/dev/nullscip-shell filesystem . . `/dev/null`.` |
| 35 | if [scip-shell system . . `[`. "$?" -eq 0 ]; then |
| 36 | # This is a GIT repo, see if it was modified. |
| 37 | if [scip-shell system . . `[`. "$mod" != "" ]; then |
| 38 | modified=1 |
| 39 | else |
| 40 | # Subtle, if we are in a git archive and the repository |
| 41 | # is clean then update the time on the version file |
| 42 | # thus ensuring it will be correct in any tarball. |
| 43 | touchscip-shell system . . touch. "$file" |
| 44 | fi |
| 45 | |
| 46 | # Try and get a real "tag relative" version name for it. |
| 47 | version=`gitscip-shell system . . git. describe --tags HEAD 2>&1` |
| 48 | if [scip-shell system . . `[`. "$?" -ne 0 ]; then |
| 49 | # ok, desperation just take the commit id. |
| 50 | version=`gitscip-shell system . . git. log | awkscip-shell system . . awk. '{ print $2; exit }'` |
| 51 | version="commit<$version>" |
| 52 | fi |
| 53 | |
| 54 | else |
| 55 | if [scip-shell system . . `[`. ! -f "$file" ]; then |
| 56 | echoscip-shell system . . echo. 1>&2 "$0: ERROR: unversioned tarball" |
| 57 | echoscip-shell system . . echo. "#error UNVERSIONED tarball" >"$file.h" |
| 58 | exit 1 |
| 59 | fi |
| 60 | |
| 61 | # No version control, use the modification times |
| 62 | # of the source. |
| 63 | for s in "$@" |
| 64 | do |
| 65 | if [scip-shell system . . `[`. "$s" -nt "$file" ]; then |
| 66 | modified=1 |
| 67 | fi |
| 68 | done |
| 69 | fi |
| 70 | |
| 71 | if [scip-shell system . . `[`. "$current_version" != "$version" ]; then |
| 72 | echoscip-shell system . . echo. "version update: $version" |
| 73 | echoscip-shell system . . echo. "$version" >"$file" |
| 74 | fi |
| 75 | |
| 76 | # Update the c-define for this version, take the modification |
| 77 | # flags into account. |
| 78 | version_modified="$version" |
| 79 | [scip-shell system . . `[`. "$modified" -eq 1 ] && version_modified="$version_modified (modified)" |
| 80 | |
| 81 | if [scip-shell system . . `[`. -f "$file.h" ]; then |
| 82 | read d1 current_version_modified <"$file.h" |
| 83 | fi |
| 84 | if [scip-shell system . . `[`. "$current_version_modified" != "$version_modified" ]; then |
| 85 | echoscip-shell system . . echo. "version string: $version_modified" |
| 86 | echoscip-shell system . . echo. "// $version_modified" >"$file.h" |
| 87 | echoscip-shell system . . echo. "#define VERSION \"$version_modified\"" >>"$file.h" |
| 88 | fi |
| 89 | |
| 90 | exit 0 |