From 27da3a23e71b4fd8cbd9c408ea189cd81680eb1c Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 24 Apr 2021 22:48:24 -0400 Subject: getver: rewrite from perl to shell+awk #535 People are more familiar with shell than perl at this point. Fixes #535. --- config/Makefile.am | 2 +- config/getlib.sh | 2 +- config/getver.pl | 45 --------------------------------------------- config/getver.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 47 deletions(-) delete mode 100755 config/getver.pl create mode 100755 config/getver.sh (limited to 'config') 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() { - 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 -- cgit v1.2.1