#
# $Id$
#
# module Makefile
#(to be included from each module)
#
# History:
# --------
#  2007-03-29  if a module depends on SER_LIBS, it will be rebuilt on install
#               with the proper rpath; libraries will be automatically
#               installed if needed (andrei)
#

MOD_NAME=$(NAME:.so=)

# allow placing modules in separate directory apart from ser core
COREPATH ?=../..

ALLDEP=Makefile $(COREPATH)/Makefile.sources $(COREPATH)/Makefile.rules \
 $(COREPATH)/Makefile.modules $(COREPATH)/Makefile.defs

#override modules value, a module cannot have submodules
override modules=
override static_modules=
override static_modules_path=

# should be set in Makefile of apart module
# INCLUDES += -I$(COREPATH)

ifeq ($(MAKELEVEL), 0)
# make called directly in the module dir!

#$(warning "you should run make from the main ser directory")
ifneq ($(makefile_defs), 1)
$(error "the local makefile does not include Makefile.defs!")
endif

else
# called by the main Makefile

ALLDEP+=$(COREPATH)/Makefile

endif

include $(COREPATH)/Makefile.sources

ifeq (,$(filter $(MOD_NAME), $(static_modules)))
CFLAGS:=$(MOD_CFLAGS)
LDFLAGS:=$(MOD_LDFLAGS)
endif


include $(COREPATH)/Makefile.rules


$(modules_prefix)/$(modules_dir):
		mkdir -p $(modules_prefix)/$(modules_dir)

LIBS:=$(filter-out -ldl -lresolv, $(LIBS))


.PHONY: install
.PHONY: install-libs
install: install-libs $(NAME) $(modules_prefix)/$(modules_dir)
	$(INSTALL_TOUCH) $(modules_prefix)/$(modules_dir)/$(NAME)
	$(INSTALL_MODULES)  $(NAME)  $(modules_prefix)/$(modules_dir)

install-libs:
	@for lib in $(dir $(SER_LIBS)); do \
		$(MAKE) -C "$${lib}" install-if-newer ;\
	done