getver: rewrite from perl to shell+awk #535

People are more familiar with shell than perl at this point.
Fixes #535.
master
Mike Frysinger 2021-04-24 22:48:24 -04:00
parent 93e53a7b80
commit 27da3a23e7
7 changed files with 53 additions and 50 deletions

View File

@ -75,7 +75,7 @@ else (USE_EXT_GD)
MACRO(GV VER VAR)
execute_process(
COMMAND perl ${CMAKE_CURRENT_SOURCE_DIR}/config/getver.pl ${VER}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/config/getver.sh ${VER}
OUTPUT_VARIABLE ${VAR}
)
ENDMACRO(GV)

View File

@ -1,5 +1,5 @@
## Process this file with automake to produce Makefile.in -*-Makefile-*-
EXTRA_DIST = gdlib.pc.cmake gdlib.pc.in getlib.sh getver.pl
EXTRA_DIST = gdlib.pc.cmake gdlib.pc.in getlib.sh getver.sh
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = gdlib.pc

View File

@ -1,6 +1,6 @@
#!/bin/sh
GETVER="${0%/*}/getver.pl"
GETVER="${0%/*}/getver.sh"
GDLIB_MAJOR=$("${GETVER}" MAJOR)
GDLIB_MINOR=$("${GETVER}" MINOR)
GDLIB_REVISION=$("${GETVER}" RELEASE)

View File

@ -1,45 +0,0 @@
#!/usr/bin/env perl
# Simple script to extract the version number parts from src/gd.h. If
# called with the middle word of the version macro, it prints the
# value of that macro. If called with no argument, it outputs a
# human-readable version string. This must be run in the project
# root. It is used by configure.ac and docs/naturaldocs/run_docs.sh.
use strict;
use FindBin;
my $key = shift;
my @version_parts = ();
my $dir = $FindBin::Bin;
open FH, "<$dir/../src/gd.h" # old-style filehandle for max. portability
or die "Unable to open 'gd.h' for reading.\n";
while(<FH>) {
next unless m{version605b5d1778};
next unless /^#define\s+GD_([A-Z0-9]+)_VERSION+\s+(\S+)/;
my ($lk, $lv) = ($1, $2);
if ($lk eq $key) {
chomp $lv;
$lv =~ s/"//g;
print $lv; # no newline
exit(0); # success!
}
push @version_parts, $lv if (!$key);
}
close(FH);
if (scalar @version_parts == 4) {
my $result = join(".", @version_parts[0..2]);
$result .= $version_parts[3];
$result =~ s/"//g;
print $result;
exit(0);
}
exit(1); # failure

48
config/getver.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/sh
# Simple script to extract the version number parts from src/gd.h. If
# called with the middle word of the version macro, it prints the
# value of that macro. If called with no argument, it outputs a
# human-readable version string. This must be run in the project
# root. It is used by configure.ac and docs/naturaldocs/run_docs.sh.
TOPDIR="${0%/*}/.."
HEADER="${TOPDIR}/src/gd.h"
SENTINEL="/*version605b5d1778*/"
getpart() {
awk -vfield="GD_${1}_VERSION" -vsentinel="${SENTINEL}" '
$1 == "#define" && $2 == field && $NF == sentinel {
gsub(/^"/, "", $3)
gsub(/"$/, "", $3)
print $3
}
' "${HEADER}"
}
case $# in
0)
printf '%s.%s.%s%s\n' \
$(getpart MAJOR) \
$(getpart MINOR) \
$(getpart RELEASE) \
$(getpart EXTRA)
;;
1)
case $1 in
MAJOR|MINOR|RELEASE|EXTRA)
part=$(getpart "$1")
if [ -n "${part}" ]; then
printf '%s' "${part}"
fi
;;
*)
exit 1
;;
esac
;;
*)
echo "$0: error: script takes at most 1 arg"
exit 1
;;
esac

View File

@ -4,7 +4,7 @@
AC_PREREQ(2.64)
# We extract version numbers from src/versions.h
define([gv],[perl config/getver.pl ]$1)
define([gv],[config/getver.sh ]$1)
m4_define([gd_MAJOR],esyscmd(gv(MAJOR)))dnl
m4_define([gd_MINOR],esyscmd(gv(MINOR)))dnl

View File

@ -49,7 +49,7 @@ fi
echo "Found '$(nd)': $($(nd) -h | head -n1)"
# Library version number.
VERSION=$(cd ../../; perl config/getver.pl)
VERSION=$(cd ../../; config/getver.sh)
# Clear away old docs and ensure the doc dir. is present.
rm -rf html