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

AST_MOD_DIR=$(libdir)/asterisk/modules
AST_ETC_DIR=/etc/asterisk

# Had to add -Wno-unused-but-set-variable because of linked lists macros of Asterisk 1.6 causing warnings
CFLAGS += -Werror -Wall -ggdb3 -O0 -fPIC -D_GNU_SOURCE -I../../../include
LDFLAGS += -L../../../lib

codec_module = codec_sangoma.so

codec_source = codec_sangoma.c

codec_conf = sangoma_codec.conf.sample

LIBS = -lsngtc_node

#For debugging only.
#LIBS=-lsng-tc
#CFLAGS+=-DSNGTC_DEBUG_HARD_LINK

.PHONY: all
all: $(codec_module)
AST11=$(shell grep error /usr/include/asterisk/version.h &> /dev/null && echo AST11)
#If AST11 is empty means we are running old asterisk (<11) version
ifneq ($(AST11), )
AST_VERSION=$(shell asterisk -V |cut -d ' ' -f 2| sed 's/\./0/g'|cut -c1-6)
VERSION_DEFINE+="-DASTERISK_VERSION_NUM=$(AST_VERSION)"
endif

%.so: %.c
	$(CC) $(CFLAGS) $(LDFLAGS) $(NEW_VERSION_DEFINE)$(VERSION_DEFINE) -DAST_MODULE=\"$*\" -DAST_MODULE_SELF_SYM=__internal_$*_self -shared -o $@ $^ $(LIBS)

.PHONY: clean
clean:
	rm -rf $(codec_module)

.PHONY: install
install: $(codec_module)
	install -m555 -D $(codec_module) $(DESTDIR)$(AST_MOD_DIR)/$(codec_module)
	install -m644 -D $(codec_conf) $(DESTDIR)$(AST_ETC_DIR)/$(codec_conf)

.PHONY: uninstall
uninstall:
	rm -f $(DESTDIR)$(AST_MOD_DIR)/$(codec_module)
	rm -f $(DESTDIR)$(AST_ETC_DIR)/$(codec_conf)

