aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--meson.build2
-rwxr-xr-xscripts/version-bump.sh160
-rw-r--r--src/Makefile23
4 files changed, 177 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index e3ed0ef..4de58df 100644
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,9 @@ export LIBDIR ?= $(PREFIX)/lib
export BINDIR ?= $(PREFIX)/bin
export MANDIR ?= $(PREFIX)/share/man
+export TINYALSA_VERSION_MAJOR = $(shell scripts/version-bump.sh -s print major)
+export TINYALSA_VERSION = $(shell scripts/version-bump.sh -s print )
+
.PHONY: all
all:
$(MAKE) -C src
diff --git a/meson.build b/meson.build
index d7e3a99..dda722d 100644
--- a/meson.build
+++ b/meson.build
@@ -1,5 +1,5 @@
project ('tinyalsa', 'c',
- version : run_command(find_program('scripts/version.py')).stdout().strip(),
+ version : run_command(find_program('scripts/version-bump.sh'), 'print', '-s').stdout().strip(),
meson_version : '>= 0.48.0')
tinyalsa_includes = include_directories('.', 'include')
diff --git a/scripts/version-bump.sh b/scripts/version-bump.sh
new file mode 100755
index 0000000..6378801
--- /dev/null
+++ b/scripts/version-bump.sh
@@ -0,0 +1,160 @@
+#!/bin/bash
+
+# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# Project configuration variables
+#
+# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+VERSION_FILE="include/tinyalsa/version.h"
+
+# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# Scripts internal variables
+#
+# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+LF="\n"
+PARAMS=""
+
+# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# Helper functions
+#
+# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+die()
+{
+ echo "Error: $@" 1>&2
+ exit 1
+}
+
+print_usage()
+{
+ echo "Usage: $0 [OPTIONS] ACTION"
+ echo
+ echo "Available options:"
+ echo " -s,--script Format output in \"script\" mode (no trailing newline)."
+ echo
+ echo "Available actions:"
+ echo " print [minor|major|patch] Print the current version."
+ echo
+ echo "Please run this script from the project root folder."
+}
+
+
+# Gets a part of the version from the project version file (version.h).
+# Takes one argument: the matching version identifier in the version file.
+get_version_part()
+{
+ local V=$(grep -m 1 "^#define\([ \t]*\)${1}" ${VERSION_FILE} | sed 's/[^0-9]*//g')
+
+ [ ! -z ${V} ] || die "Could not get ${1} from ${VERSION_FILE}"
+
+ echo ${V}
+}
+
+
+# Gets the complete version from the version file.
+get_version()
+{
+ [ -f ${VERSION_FILE} ] || die "No ${VERSION_FILE} found! Is this the project root?";
+
+ VERSION_MAJOR=$(get_version_part "TINYALSA_VERSION_MAJOR")
+ VERSION_MINOR=$(get_version_part "TINYALSA_VERSION_MINOR")
+ VERSION_PATCH=$(get_version_part "TINYALSA_VERSION_PATCH")
+}
+
+# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# Actions implementations / functions
+#
+# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+print_version()
+{
+ get_version
+
+ if [ -z $1 ]; then
+ printf "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}${LF}"
+ else
+ case "$1" in
+ major)
+ printf "${VERSION_MAJOR}${LF}"
+ ;;
+ minor)
+ printf "${VERSION_MINOR}${LF}"
+ ;;
+ patch)
+ printf "${VERSION_PATCH}${LF}"
+ ;;
+ *)
+ die "Unknown part \"$1\" (must be one of minor, major and patch)."
+ ;;
+ esac
+ fi
+
+ return 0
+}
+
+# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# Command Line parsing
+#
+# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+parse_command()
+{
+ if [ "$#" -eq "0" ]; then
+ print_usage
+ exit 1
+ fi
+
+ case "$1" in
+ print)
+ print_version "$2"
+ exit $?
+ ;;
+ *)
+ die "Unsupported action \"$1\"."
+ ;;
+ esac
+}
+
+# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# Main
+#
+# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+set -e
+trap "set +e" 0
+
+# Checking parameters
+if [ "$#" -eq "0" ]; then
+ print_usage
+ exit 0
+fi
+
+while [ "$#" -ne "0" ]; do
+ case "$1" in
+ -s|--script)
+ unset LF
+ shift
+ ;;
+ --)
+ shift
+ break
+ ;;
+ -*|--*=)
+ die "Unsupported flag \"$1\"."
+ ;;
+ *)
+ PARAMS="$PARAMS ${1}"
+ shift
+ ;;
+ esac
+done
+
+# set positional arguments in their proper place
+set -- "${PARAMS}"
+
+parse_command ${PARAMS}
+
+# The script should never reach this place.
+die "Internal error. Please report this."
diff --git a/src/Makefile b/src/Makefile
index d33c9f1..fde31e4 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -18,6 +18,9 @@ override CFLAGS := $(WARNINGS) $(INCLUDE_DIRS) -fPIC $(CFLAGS)
VPATH = ../include/tinyalsa
OBJECTS = limits.o mixer.o pcm.o
+LIBVERSION_MAJOR = $(TINYALSA_VERSION_MAJOR)
+LIBVERSION = $(TINYALSA_VERSION)
+
.PHONY: all
all: libtinyalsa.a libtinyalsa.so
@@ -30,28 +33,28 @@ mixer.o: mixer.c mixer.h
libtinyalsa.a: $(OBJECTS)
$(AR) $(ARFLAGS) $@ $^
-libtinyalsa.so: libtinyalsa.so.1
+libtinyalsa.so: libtinyalsa.so.$(LIBVERSION_MAJOR)
ln -sf $< $@
-libtinyalsa.so.1: libtinyalsa.so.1.1.1
+libtinyalsa.so.$(LIBVERSION_MAJOR): libtinyalsa.so.$(LIBVERSION)
ln -sf $< $@
-libtinyalsa.so.1.1.1: $(OBJECTS)
- $(LD) $(LDFLAGS) -shared -Wl,-soname,libtinyalsa.so.1 $^ -o $@
+libtinyalsa.so.$(LIBVERSION): $(OBJECTS)
+ $(LD) $(LDFLAGS) -shared -Wl,-soname,libtinyalsa.so.$(LIBVERSION_MAJOR) $^ -o $@
.PHONY: clean
clean:
rm -f libtinyalsa.a
rm -f libtinyalsa.so
- rm -f libtinyalsa.so.1
- rm -f libtinyalsa.so.1.1.1
+ rm -f libtinyalsa.so.$(LIBVERSION_MAJOR)
+ rm -f libtinyalsa.so.$(LIBVERSION)
rm -f $(OBJECTS)
.PHONY: install
-install: libtinyalsa.a libtinyalsa.so.1
+install: libtinyalsa.a libtinyalsa.so.$(LIBVERSION_MAJOR)
install -d $(DESTDIR)$(LIBDIR)/
install libtinyalsa.a $(DESTDIR)$(LIBDIR)/
- install libtinyalsa.so.1.1.1 $(DESTDIR)$(LIBDIR)/
- ln -sf libtinyalsa.so.1.1.1 $(DESTDIR)$(LIBDIR)/libtinyalsa.so.1
- ln -sf libtinyalsa.so.1 $(DESTDIR)$(LIBDIR)/libtinyalsa.so
+ install libtinyalsa.so.$(LIBVERSION) $(DESTDIR)$(LIBDIR)/
+ ln -sf libtinyalsa.so.$(LIBVERSION) $(DESTDIR)$(LIBDIR)/libtinyalsa.so.$(LIBVERSION_MAJOR)
+ ln -sf libtinyalsa.so.$(LIBVERSION_MAJOR) $(DESTDIR)$(LIBDIR)/libtinyalsa.so