###########################################################################
#
# Makefile system for GILDAS softwares (2003-2013).
#
# Please be careful: element order often matters in makefiles.
#
###########################################################################

include $(gagadmdir)/Makefile.def

###########################################################################


### Build of pyclassfiller/_core.so ###

MOD_IDENTITY = _core

MOD_SOURCES = file.c module.c observation.c setter.c

MOD_DEPENDS = -lclassfiller -lclasscore -lclass

MOD_LIB_DIRS = $(PYTHON_LIB_DEP_PATH)

MOD_INC_DIRS =

MOD_EXTRAS =

### Patch pyclassfiller/_core.so under MacOS ###
ifeq ($(GAG_ENV_KIND),darwin)
# The _core.so is linked to the libclassfiller, libclasscore, and
# libclass. Under MacOS, the linker reuses the -install_name which
# was used when creating these libraries. We declare them with
# path @loader_path/../lib/ because they can be loaded either by
# another library in ../lib/, or either by a binary in ../bin/.
# But exception: the _core.so of this module is installed in the
# subdirectory ../python/pyclassfiller/ (because we need such a
# subdirectory for the pyclassfiller module!). Because of this,
# _core.so complains it can not find e.g. libclassfiller.so in
# ../lib (obviously). The patch here redefines the library paths
# properly, executing a dedicated command after the setup.py has
# created _core.so.
# Ideally this should be done at link time, but I could not find
# such option for the Mac linker.
LIB_PATH_OLD = @loader_path/../lib
LIB_PATH_NEW = @loader_path/../../lib
MOD_POST_SETUP = install_name_tool \
		-change $(LIB_PATH_OLD)/libclassfiller.$(SO_EXT) \
			$(LIB_PATH_NEW)/libclassfiller.$(SO_EXT) \
		-change $(LIB_PATH_OLD)/libclasscore.$(SO_EXT) \
			$(LIB_PATH_NEW)/libclasscore.$(SO_EXT) \
		-change $(LIB_PATH_OLD)/libclass.$(SO_EXT) \
			$(LIB_PATH_NEW)/libclass.$(SO_EXT) \
		$(builddir)/$(MOD_IDENTITY)$(PYTHON_SO_EXT)
endif

### Build of pyclassfiller/__init__.py ###

MOD_SUBDIR = pyclassfiller

MOD_FILES = __init__.py

###########################################################################

include $(gagadmdir)/Makefile.python

###########################################################################
