#
# MIDCOM Timer library
#
# Copyright (C) 2005, Ranch Networks, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
#
# Author : Srivatsa Chivukula <srivatsa@ranchnetworks.com>
#

AR = ar
LDCONFIG = /sbin/ldconfig
CC = gcc

# Set root directory
prefix = ./


# Set source files directory
sourcedir = $(prefix)src/

# Set include files directory
includedir = $(prefix)/

#  Set library target directory
libdir = $(prefix)

# Set midcom include directories
INCLUDE = -I$(includedir) -I$(prefix)

# Set pthread directory
PTHREAD_LIB_DIR = -L.

# Set pthread include files directory (not required for system directories like /usr/include)
PTHREAD_INCLUDE_DIR =

# set posix pthread libraries
PTHREAD_LIBS = -lpthread -lstdc++

# 
INCLUDE_DIR = $(INCLUDE) $(PTHREAD_INCLUDE_DIR)


# OS extension for executables
# if it is Windows set the variable to ".exe"
# for unix like leave it blank
#EXEC_EXTENSION = .exe

# Compilation flags
CFLAGS+=

# AR flags
LDFLAGS+=

SRC_DIR =

DEFS = -DPOSIX

CFLAGS+=-Wall -Wstrict-prototypes -Wmissing-prototypes #-Werror
SOFLAGS = -Wl,-hlibtimer.so.1
LDCONFIG_FLAGS+=-n

STATIC_LIBRARY=libtimer.a
DYNAMIC_LIBRARY=libtimer.so.1.0


STATIC_OBJS = $(sourcedir)voipSem.o          \
              $(sourcedir)voipTimer.o        \
              $(sourcedir)voipTimerManager.o

DYNAMIC_OBJS = $(sourcedir)voipSem.lo          \
              $(sourcedir)voipTimer.lo        \
              $(sourcedir)voipTimerManager.lo

CONFIGURE_FILES = Makefile

all: $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY) timer_sample

$(STATIC_LIBRARY): $(STATIC_OBJS)
	$(AR) rcs $(STATIC_LIBRARY) $(STATIC_OBJS)
	ranlib $(STATIC_LIBRARY)

$(DYNAMIC_LIBRARY) : $(DYNAMIC_OBJS)
	$(CC) -shared $(SOFLAGS) -o $@ $(DYNAMIC_OBJS)
	$(LDCONFIG) $(LDCONFIG_FLAGS) .
	ln -sf libtimer.so.1 libtimer.so

timer_sample: $(prefix)timer_sample.o $(prefix)$(STATIC_LIBRARY)
	$(CC) $(prefix)timer_sample.o  $(PTHREAD_LIB_DIR)   $(PTHREAD_LIBS) $(STATIC_LIBRARY) $(CFLAGS) -o $(prefix)timer_sample

%.o : %.c
	$(CC) $(CFLAGS) $(INCLUDE_DIR) $(DEFS) -o $@ -c $<

%.o : %.cpp
	$(CC) $(CFLAGS) $(INCLUDE_DIR) $(DEFS) -o $@ -c $<

%.lo : %.cpp
	$(CC) -fPIC $(CFLAGS) $(INCLUDE_DIR) $(DEFS) -o $@ -c $<

clean: 
	rm -f *.o *.so *.lo *.so.1 *.so.1.0
	rm -f $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
	rm -f $(STATIC_OBJS) $(DYNAMIC_OBJS) $(prefix)timer_sample.o $(prefix)timer_sample$(EXEC_EXTENSION)

