Skip to content

Commit

Permalink
Determine version based on git tag or pwd (fixes #92)
Browse files Browse the repository at this point in the history
  • Loading branch information
raboof committed Jul 12, 2016
1 parent a1efe5b commit 9defe58
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export VERSION := 0
export SUBVERSION := 8
export MINORVERSION := 3-SNAPSHOT
export VERSION := $(shell ./determineVersion.sh)

#export PREFIX := /usr
export PREFIX ?= /usr/local
Expand All @@ -9,9 +7,9 @@ all: nethogs decpcap_test test
$(MAKE) -C src -f MakeApp.mk $@
$(MAKE) -C src -f MakeLib.mk $@

.PHONY:
.PHONY: tgz
tgz: clean
cd .. ; tar czvf nethogs-$(VERSION).$(SUBVERSION).$(MINORVERSION).tar.gz --exclude-vcs nethogs/*
git archive --prefix="nethogs-$(VERSION)/" -o "../nethogs-$(VERSION).tar.gz" HEAD

check:
$(MAKE) -C src -f MakeApp.mk $@
Expand Down
3 changes: 3 additions & 0 deletions determineVersion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

(git describe 2>/dev/null || pwd | sed -e "s/.*\\///" | sed -e "s/[^-]*//") | tail -c +2
8 changes: 3 additions & 5 deletions src/MakeApp.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ OBJS=packet.o connection.o process.o decpcap.o cui.o inode2prog.o conninode.o de

NCURSES_LIBS?=-lncurses

.PHONY: tgz

.PHONY: check uninstall
check:
@echo "Not implemented"
Expand All @@ -29,9 +27,9 @@ uninstall:
rm $(DESTDIR)$(sbin)/nethogs || true

nethogs: main.cpp nethogs.cpp $(OBJS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) main.cpp $(OBJS) -o nethogs -lpcap -lm ${NCURSES_LIBS} -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -DMINORVERSION=\"$(MINORVERSION)\"
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) main.cpp $(OBJS) -o nethogs -lpcap -lm ${NCURSES_LIBS} -DVERSION=\"$(VERSION)\"
nethogs_testsum: nethogs_testsum.cpp $(OBJS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) nethogs_testsum.cpp $(OBJS) -o nethogs_testsum -lpcap -lm ${NCURSES_LIBS} -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -DMINORVERSION=\"$(MINORVERSION)\"
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) nethogs_testsum.cpp $(OBJS) -o nethogs_testsum -lpcap -lm ${NCURSES_LIBS} -DVERSION=\"$(VERSION)\"

decpcap_test: decpcap_test.cpp decpcap.o
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) decpcap_test.cpp decpcap.o -o decpcap_test -lpcap -lm
Expand All @@ -53,7 +51,7 @@ conninode.o: conninode.cpp nethogs.h conninode.h
#devices.o: devices.cpp devices.h
# $(CXX) $(CXXFLAGS) -c devices.cpp
cui.o: cui.cpp cui.h nethogs.h
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c cui.cpp -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -DMINORVERSION=\"$(MINORVERSION)\"
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c cui.cpp -DVERSION=\"$(VERSION)\"

TESTS=conninode_test

Expand Down
7 changes: 3 additions & 4 deletions src/MakeLib.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
LIBRARY=libnethogs.so
LIBNAME=$(LIBRARY).$(LIBVERSION).$(LIBSUBVERSION).$(LIBMINORVERSION)
LIBVERSION=$(VERSION)
LIBNAME=$(LIBRARY).$(LIBVERSION)
SO_NAME=$(LIBRARY).$(LIBVERSION)

libdir := $(PREFIX)/lib
Expand Down Expand Up @@ -38,8 +39,6 @@ OBJS=$(addprefix $(ODIR)/,$(OBJ_NAMES))

#$(info $(OBJS))

.PHONY: tgz

.PHONY: uninstall

install: $(LIBNAME)
Expand Down Expand Up @@ -102,7 +101,7 @@ $(ODIR)/devices.o: devices.cpp devices.h

$(ODIR)/libnethogs.o: libnethogs.cpp libnethogs.h
@mkdir -p $(ODIR)
$(CXX) $(CXXFLAGS) -o $@ -c libnethogs.cpp -DVERSION=\"$(LIBVERSION)\" -DSUBVERSION=\"$(LIBSUBVERSION)\" -DMINORVERSION=\"$(LIBMINORVERSION)\"
$(CXX) $(CXXFLAGS) -o $@ -c libnethogs.cpp -DVERSION=\"$(LIBVERSION)\"

.PHONY: clean
clean:
Expand Down
2 changes: 1 addition & 1 deletion src/nethogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bool bughuntmode = false;
bool sortRecv = true;
// viewMode: kb/s or total
int viewMode = VIEWMODE_KBPS;
const char version[] = " version " VERSION "." SUBVERSION "." MINORVERSION;
const char version[] = " version " VERSION;

timeval curtime;

Expand Down

0 comments on commit 9defe58

Please sign in to comment.