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

AST_MOD_DIR=/usr/lib/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), )
VERSION_DEFINE="-DNEW_VERSION_INCLUDE"
endif

%.so: %.c
	$(CC) $(CFLAGS) $(LDFLAGS) $(VERSION_DEFINE) -DAST_MODULE=\"$*\" -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)

