building as static library too

This commit is contained in:
Mohamed Boussaffa
2016-03-13 01:48:33 +08:00
parent d8a0b8f674
commit d33acbe3c7
6 changed files with 16 additions and 24 deletions

1
.gitignore vendored
View File

@@ -5,3 +5,4 @@ TAGS
*~
nethogs.project
libnethogs.so
libnethogs.a

View File

@@ -15,7 +15,7 @@ runtests: test
CFLAGS?=-Wall -Wextra
CXXFLAGS?=-Wall -Wextra
OBJS=packet.o connection.o process.o refresh.o decpcap.o cui.o inode2prog.o conninode.o devices.o
OBJS=packet.o connection.o process.o decpcap.o cui.o inode2prog.o conninode.o devices.o
NCURSES_LIBS?=-lncurses
@@ -52,8 +52,6 @@ decpcap_test: decpcap_test.cpp decpcap.o
#-lefence
refresh.o: refresh.cpp refresh.h nethogs.h
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c refresh.cpp
process.o: process.cpp process.h nethogs.h
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c process.cpp
packet.o: packet.cpp packet.h nethogs.h

View File

@@ -2,7 +2,7 @@ prefix := /usr/local
libdir := $(prefix)/lib
incdir := $(prefix)/include
all: libnethogs.so
all: libnethogs.so libnethogs.a
LDFLAGS:= -shared
CXXINCLUDES :=
@@ -22,7 +22,7 @@ else
CXXFLAGS?=-Wall -Wextra -O3 -fPIC $(VISIBILITY) $(CXXINCLUDES)
endif
OBJ_NAMES= libnethogs.o packet.o connection.o process.o refresh.o decpcap.o inode2prog.o conninode.o devices.o
OBJ_NAMES= libnethogs.o packet.o connection.o process.o decpcap.o inode2prog.o conninode.o devices.o
OBJS=$(addprefix $(ODIR)/,$(OBJ_NAMES))
#$(info $(OBJS))
@@ -34,29 +34,27 @@ OBJS=$(addprefix $(ODIR)/,$(OBJ_NAMES))
install: libnethogs.so
install -d -m 755 $(DESTDIR)$(libdir)
install -m 755 libnethogs.so $(DESTDIR)$(libdir)
@echo
@echo "Installed libnethogs.so to $(DESTDIR)$(libdir)"
@echo
install -m 755 libnethogs.a $(DESTDIR)$(libdir)
@echo "Installed libnethogs.a to $(DESTDIR)$(libdir)"
install -d -m 755 $(DESTDIR)$(incdir)
install -m 755 libnethogs.h $(DESTDIR)$(incdir)
@echo
@echo "Installed libnethogs.h to $(DESTDIR)$(incdir)"
@echo
ldconfig
uninstall:
rm $(DESTDIR)$(libdir)/libnethogs.so
rm $(DESTDIR)$(libdir)/libnethogs.a
rm $(DESTDIR)$(incdir)/libnethogs.h
ldconfig
libnethogs.so: $(OBJS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(OBJS) -o $@ -lpcap
#-lefence
libnethogs.a: $(OBJS)
$(AR) rcs $@ $(OBJS)
$(ODIR)/refresh.o: refresh.cpp refresh.h nethogs.h
@mkdir -p $(ODIR)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c refresh.cpp
#-lefence
$(ODIR)/process.o: process.cpp process.h nethogs.h
@mkdir -p $(ODIR)
@@ -94,6 +92,7 @@ $(ODIR)/libnethogs.o: libnethogs.cpp libnethogs.h
clean:
rm -f $(OBJS)
rm -f libnethogs.so
rm -f libnethogs.a
mkdir -p $(ODIR)
rmdir -p --ignore-fail-on-non-empty $(ODIR)

View File

@@ -32,7 +32,6 @@
#include <ncurses.h>
#include "nethogs.h"
#include "process.h"
#include "refresh.h"
std::string * caption;
extern const char version[];

View File

@@ -118,8 +118,7 @@ int Process::getLastPacket()
/** Get the kb/s values for this process */
void Process::getkbps (float * recvd, float * sent)
{
u_int32_t sum_sent = 0,
sum_recv = 0;
u_int32_t sum_sent = 0, sum_recv = 0;
/* walk though all this process's connections, and sum
* them up */
@@ -157,8 +156,7 @@ void Process::getkbps (float * recvd, float * sent)
/** get total values for this process */
void Process::gettotal( u_int32_t * recvd, u_int32_t * sent)
{
u_int32_t sum_sent = 0,
sum_recv = 0;
u_int32_t sum_sent = 0, sum_recv = 0;
ConnList * curconn = this->connections;
while (curconn != NULL)
{
@@ -175,8 +173,7 @@ void Process::gettotal( u_int32_t * recvd, u_int32_t * sent)
void Process::gettotalmb(float * recvd, float * sent)
{
u_int32_t sum_sent = 0,
sum_recv = 0;
u_int32_t sum_sent = 0, sum_recv = 0;
gettotal(&sum_recv, &sum_sent);
*recvd = tomb(sum_recv);
*sent = tomb(sum_sent);
@@ -185,8 +182,7 @@ void Process::gettotalmb(float * recvd, float * sent)
/** get total values for this process */
void Process::gettotalkb(float * recvd, float * sent)
{
u_int32_t sum_sent = 0,
sum_recv = 0;
u_int32_t sum_sent = 0, sum_recv = 0;
gettotal(&sum_recv, &sum_sent);
*recvd = tokb(sum_recv);
*sent = tokb(sum_sent);
@@ -194,8 +190,7 @@ void Process::gettotalkb(float * recvd, float * sent)
void Process::gettotalb(float * recvd, float * sent)
{
u_int32_t sum_sent = 0,
sum_recv = 0;
u_int32_t sum_sent = 0, sum_recv = 0;
gettotal(&sum_recv, &sum_sent);
//std::cout << "Total sent: " << sum_sent << std::endl;
*sent = sum_sent;

View File