include ../../../../../main.mk

# sources directories
srcdir = ../../source
vpath %.c $(srcdir) : $(srcdir)/util
vpath %.h $(srcdir) : $(srcdir)/util

my_name = SngTcpServer2
my_lib = lib$(my_name).so

includes=               \
   Array.h              \
   config.h             \
   Client.h             \
   Connection.h         \
   ConnectionTable.h    \
   ConnectionManager.h  \
   GenericClient.h      \
   List.h               \
   Log.h                \
   Message.h            \
   MessageQueue.h       \
   Mutex.h              \
   Queue.h              \
   QueueManager.h       \
   Semaf.h              \
   Server.h             \
   Socket.h             \
   Thread.h             \
   Time.h               \
   Timeout.h

objects=                \
   Array.o              \
   Client.o             \
   Connection.o         \
   ConnectionTable.o    \
   ConnectionManager.o  \
   GenericClient.o      \
   List.o               \
   Log.o                \
   Message.o            \
   MessageQueue.o       \
   Mutex.o              \
   Queue.o              \
   QueueManager.o       \
   Semaf.o              \
   Server.o             \
   Socket.o             \
   Thread.o             \
   Time.o               \
   Timeout.o            

CFLAGS += -Wall -Wextra -DREENTRANT -fpack-struct 

# Linux runtime thread support
LDFLAGS += -lpthread

.PHONY: all
all: $(my_lib)

# rule for compilation of c files
%.o: %.c $(includes)
	@echo
	@echo "* compiling $<"
	$(CC) -g -c -fPIC $(CFLAGS) $(CPPFLAGS) $<
	@echo

# creation of library
$(my_lib): $(objects)
	@echo
	@echo "* linking $@"
	$(CC) -shared -Wl,-soname,$(my_lib) $(LDFLAGS) -o $@ $^
	@echo

# removing files to force rebuilding
.PHONY: clean
clean:
	@echo
	@echo "* cleaning files"
	@-rm $(my_lib) $(objects) > /dev/null 2>&1
	@echo

