COREPATH ?=../..
DEFSPATH ?=$(COREPATH)/..

include $(DEFSPATH)/Makefile.defs

LIB_LDFLAGS  += $(module_ldflags)
CPPFLAGS += -I $(COREPATH) -I $(COREPATH)/amci 
CFLAGS   += -Wall $(module_cflags)

ifdef USE_LIBSAMPLERATE
CPPFLAGS += -DUSE_LIBSAMPLERATE
LDFLAGS +=-lsamplerate
endif

audio_mod_dir = $(COREPATH)/lib

lib_name = $(plug_in_name).so
lib_full_name = $(audio_mod_dir)/$(lib_name)

srcs     = $(wildcard *.c)
hrds     = $(wildcard *.h)
objs     = $(srcs:.c=.o) $(module_extra_objs)
depends  = $(srcs:.c=.d)

.DEFAULT_GOAL := all
.PHONY: all
all: $(lib_full_name)

.PHONY: clean
clean: $(extra_clean)
	@rm -f $(objs) $(depends) $(lib_name)

.PHONY: install
install: $(lib_name) $(extra_install)
	mkdir -p $(DESTDIR)$(modules_prefix)/$(modules_dir)
	$(INSTALL_MODULES) $(lib_name) $(DESTDIR)$(modules_prefix)/$(modules_dir)

.PHONY: install-cfg
install-cfg : $(extra_install_cfg)

-include $(depends)

%.o: %.c $(DEFSPATH)/Makefile.defs
	$(CC) -MMD $(CPPFLAGS) $(CFLAGS) -c $< -o $@

$(lib_full_name): $(lib_name)
ifneq ($(lib_full_name),$(lib_name))
ifneq ($(lib_full_name),./$(lib_name))
	cp $(lib_name) $(lib_full_name)
endif
endif

$(lib_name): $(objs)  Makefile
	$(LD) -o $(lib_name) $(objs) $(LIB_LDFLAGS)
