INSTALL_PROGRAM ?= $(INSTALL)
INSTALL_DATA ?= $(INSTALL) -m 644
MKDIR_P := mkdir -p
+VERSION := $(shell ./version-gen.sh dss version.c)
-VERSION_STRING = 1.0.1
+units := dss str file exec sig daemon df tv snap ipc dss.lsg version
+objs := $(addsuffix .o, $(units))
+deps := $(addsuffix .d, $(units))
-dss_objects := dss.o str.o file.o exec.o sig.o daemon.o df.o tv.o snap.o ipc.o dss.lsg.o
all: dss dss.1
man: dss.1
+$(objs): dss.lsg.h Makefile
+-include $(deps)
-DSS_CPPFLAGS := -DVERSION_STRING='"$(VERSION_STRING)"'
DSS_CPPFLAGS += -Wunused-macros
DSS_CFLAGS := -Wno-sign-compare -g -Wunused -Wundef
DSS_CFLAGS += -Wbad-function-cast
DSS_CFLAGS += -Wshadow
-Makefile.deps: $(wildcard *.c *.h)
- $(CC) -MM -MG $(DSS_CPPFLAGS) $(CPPFLAGS) $(DSS_CFLAGS) $(CFLAGS) *.c > $@
-
--include Makefile.deps
-
-dss: $(dss_objects)
- $(CC) -o $@ $(dss_objects) $(LDFLAGS) -llopsub
-
-%.o: %.c Makefile
- $(CC) -c $(DSS_CPPFLAGS) $(CPPFLAGS) $(DSS_CFLAGS) $(CFLAGS) $<
-
+version.c:
+ ./version-gen.sh dss version.c > /dev/null
+dss: $(objs)
+ $(CC) -o $@ $(objs) $(LDFLAGS) -llopsub
+%.o: %.c
+ $(CC) -c -o $@ $(DSS_CPPFLAGS) $(CPPFLAGS) $(DSS_CFLAGS) $(CFLAGS) \
+ -MMD -MF $(*F).d -MT $@ $<
%.lsg.h: %.suite
lopsubgen --gen-h=$@ < $<
%.lsg.c: %.suite
lopsubgen --gen-c=$@ < $<
%.1: %.suite
- lopsubgen --gen-man=$@ --version-string=$(VERSION_STRING) < $<
+ lopsubgen --gen-man=$@ --version-string=$(VERSION) < $<
%.1.html: %.1
groff -m man -Thtml -P -l -P -r $< | sed -e '1,/^<body>/d; /^<\/body>/,$$d' > $@
clean:
- rm -f *.o dss dss.1 dss.1.html Makefile.deps *~ index.html dss.lsg.h dss.lsg.c
+ rm -f *.[od] dss dss.1 *.html dss.lsg.[ch] version.c
ifneq ($(findstring strip, $(MAKECMDGOALS)),)
strip_option := -s
return install_sighandler(SIGCHLD);
}
+const char *dss_version(void);
static void handle_version_and_help(void)
{
char *txt;
else if (OPT_GIVEN(DSS, HELP))
txt = lls_short_help(CMD_PTR(DSS));
else if (OPT_GIVEN(DSS, VERSION))
- txt = make_message("%s\n", VERSION_STRING);
+ txt = make_message("%s\n", dss_version());
else
return;
printf("%s", txt);
--- /dev/null
+#!/bin/sh
+
+# SPDX-License-Identifier: GPL-3.0-only
+
+package="$1"
+version_file="$2"
+
+ver='unnamed_version'
+# First try git, then gitweb, then default.
+if [ -e '.git' -o -e '../.git' ]; then
+ git_ver=$(git describe --abbrev=4 --always HEAD 2>/dev/null)
+ [ -z "$git_ver" ] && git_ver="$ver"
+ # update stat information in index to match working tree
+ git update-index -q --refresh > /dev/null
+ # if there are differences (exit code 1), the working tree is dirty
+ git diff-index --quiet HEAD || git_ver=$git_ver-dirty
+ ver=$git_ver
+elif [ "${PWD%%-*}" = $package- ]; then
+ ver=${PWD##*/$package-}
+fi
+ver=${ver#v}
+
+echo "$ver"
+[ -z "${version_file}" ] && exit 0
+# update version file if necessary
+content="const char *${package}_version(void) {return \"$ver\";};"
+[ -r "$version_file" ] && echo "$content" | cmp -s - $version_file && exit 0
+[ "$version_file" = "${version_file%/*}" ] || mkdir -p ${version_file%/*}
+printf '%s\n' "$content" > $version_file