Skip to content

Commit

Permalink
ioping: keep VERSION right in ioping.c
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
  • Loading branch information
koct9i committed Sep 8, 2015
1 parent 522fd2c commit a01558f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
17 changes: 9 additions & 8 deletions Makefile
Expand Up @@ -13,7 +13,8 @@ DOCS=README LICENSE changelog
SPEC=ioping.spec

PACKAGE=ioping
VERSION=$(shell cat version)
EXTRA_VERSION:=$(shell test -d .git && git describe --tags --dirty=+ | sed 's/^v[^-]*//;s/-/./g')
VERSION:=$(shell sed -ne 's/\# define VERSION \"\(.*\)\"/\1/p' ioping.c)${EXTRA_VERSION}
DISTDIR=$(PACKAGE)-$(VERSION)
DISTFILES=$(SRCS) $(MANS) $(DOCS) $(SPEC) Makefile
PACKFILES=$(BINS) $(MANS) $(MANS_F) $(DOCS)
Expand All @@ -28,10 +29,10 @@ TARGET=win32
BINS:=$(BINS:=.exe)
endif

all: version $(BINS)
all: $(BINS)

version: $(DISTFILES)
test ! -d .git || git describe --tags --dirty=+ | sed 's/^v//;s/-/./g' > $@
version:
@echo ${VERSION}

clean:
$(RM) -f $(OBJS) $(BINS) $(MANS_F)
Expand All @@ -45,8 +46,8 @@ install: $(BINS) $(MANS)
mkdir -p $(DESTDIR)$(MAN1DIR)
install -m 644 $(MANS) $(DESTDIR)$(MAN1DIR)

%.o: %.c version
$(CC) $(CFLAGS) -DVERSION=\"${VERSION}\" -c -o $@ $<
%.o: %.c
$(CC) $(CFLAGS) -DEXTRA_VERSION=\"${EXTRA_VERSION}\" -c -o $@ $<

%.ps: %.1
man -t ./$< > $@
Expand All @@ -60,7 +61,7 @@ install: $(BINS) $(MANS)
$(BINS): $(OBJS)
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS)

dist: version $(DISTFILES)
dist: $(DISTFILES)
tar -cz --transform='s,^,$(DISTDIR)/,S' $^ -f $(DISTDIR).tar.gz

binary-tgz: $(PACKFILES)
Expand All @@ -71,4 +72,4 @@ binary-zip: $(PACKFILES)
${STRIP} ${BINS}
zip ${PACKAGE}-${VERSION}-${TARGET}.zip $^

.PHONY: all clean install dist
.PHONY: all clean install dist version
15 changes: 9 additions & 6 deletions ioping.c
Expand Up @@ -18,6 +18,14 @@
*
*/

#ifndef VERSION
# define VERSION "0.9"
#endif

#ifndef EXTRA_VERSION
# define EXTRA_VERSION ""
#endif

#define _GNU_SOURCE
#define _FILE_OFFSET_BITS 64

Expand Down Expand Up @@ -249,14 +257,9 @@ void usage(void)
);
}

#ifndef VERSION
# warning ioping version undefined
# define VERSION ""
#endif

void version(void)
{
fprintf(stderr, "ioping %s\n", VERSION);
fprintf(stderr, "ioping %s\n", VERSION EXTRA_VERSION);
}

struct suffix {
Expand Down
2 changes: 1 addition & 1 deletion ioping.spec
@@ -1,5 +1,5 @@
Name: ioping
Version: %(cat version)
Version: %(make version)
Release: 1%{?dist}
Summary: simple disk I/O latency monitoring tool

Expand Down

0 comments on commit a01558f

Please sign in to comment.