summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2021-04-24 22:48:24 -0400
committerMike Frysinger <vapier@gentoo.org>2021-04-24 22:48:24 -0400
commit27da3a23e71b4fd8cbd9c408ea189cd81680eb1c (patch)
tree7e3f6876537f8da4a106b7b00e068cec6733a650 /config
parent93e53a7b803c06df80c2ed7f7f0c0518ef146f57 (diff)
downloadlibgd-27da3a23e71b4fd8cbd9c408ea189cd81680eb1c.tar.gz
getver: rewrite from perl to shell+awk #535
People are more familiar with shell than perl at this point. Fixes #535.
Diffstat (limited to 'config')
-rw-r--r--config/Makefile.am2
-rwxr-xr-xconfig/getlib.sh2
-rwxr-xr-xconfig/getver.pl45
-rwxr-xr-xconfig/getver.sh48
4 files changed, 50 insertions, 47 deletions
diff --git a/config/Makefile.am b/config/Makefile.am
index 6416dda..c5a8bb5 100644
--- a/config/Makefile.am
+++ b/config/Makefile.am
@@ -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
diff --git a/config/getlib.sh b/config/getlib.sh
index 4835cf6..5070e30 100755
--- a/config/getlib.sh
+++ b/config/getlib.sh
@@ -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)
diff --git a/config/getver.pl b/config/getver.pl
deleted file mode 100755
index 52f1b58..0000000
--- a/config/getver.pl
+++ /dev/null
@@ -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
diff --git a/config/getver.sh b/config/getver.sh
new file mode 100755
index 0000000..589802f
--- /dev/null
+++ b/config/getver.sh
@@ -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