AM_CFLAGS = @pois_CFLAGS@

AM_CFLAGS += $(PSLIB_CFLAGS)
AM_CFLAGS += $(SWIG_TARGET_CPPFLAGS)
AM_CFLAGS += -DPS_ALLOW_MALLOC
AM_CFLAGS += -I../src

LIBS       = $(AM_LIBS)
LIBS      += $(SWIG_TARGET_LIBS)

SWIG += -w451
SWIG += $(SWIG_TARGET_OPT)
SWIG += $(PSLIB_CFLAGS)
SWIG += -Drestrict= -Dinline=

AM_CFLAGS += -I../src
#
# Libraries to install
#
SWIG_LIB_NAMES =     poisSwig       psLibSwig       xpaSwig
lib_LTLIBRARIES = libpoisSwig.la libpsLibSwig.la libxpaSwig.la

BUILT_SOURCES = \
	psLibSwig.py psLibSwig_wrap.c \
	xpaSwig.py xpaSwig_wrap.c
#
# PSLib wrappers
#
libpsLibSwig_la_LDFLAGS  = -module
libpsLibSwig_la_LIBADD   = $(PSLIB_LIBS)

libpsLibSwig_la_SOURCES = \
	psLibSwig_wrap.c \
	psLibForSwig.c psLibForSwig.h

psLibSwig.py psLibSwig_wrap.c : psLibSwig.i p_psSwig.i
	$(SWIG) $(PS_INCLUDES) psLibSwig.i
#
# Now for XPA
#
libxpaSwig_la_LIBADD       = $(PSLIB_LIBS)
libxpaSwig_la_LIBADD      += -lxpa

libxpaSwig_la_LDFLAGS = -module
libxpaSwig_la_SOURCES = \
	xpaSwig_wrap.c \
	simpleFits.c

xpaSwig.py xpaSwig_wrap.c : xpaSwig.i p_psSwig.i
	$(SWIG) $(PS_INCLUDES) xpaSwig.i
	@case "$(SWIG)" in \
	  *-perl*) \
		perl -pi -e 's/([a-zA-Z0-9_]+Array)/_xpa_\1/g' xpaSwig_wrap.c;; \
	esac
#
# And the pois modules
#
libpoisSwig_la_LDFLAGS = -module
libpoisSwig_la_SOURCES = \
	poisSwig_wrap.c
libpoisSwig_la_LIBADD = ../src/libpois.la

poisSwig.py poisSwig_wrap.c : poisSwig.i ../src/pois.h p_psSwig.i
	$(SWIG) $(PS_INCLUDES) -I../src poisSwig.i
	@case "$(SWIG)" in \
	  *-perl*) \
		perl -pi -e 's/([a-zA-Z0-9_]+Array)/_pois_\1/g' poisLib_wrap.c;; \
	esac
#
# Patch up name of .so file for the sake of python
#
install-exec-hook:
	cd $(prefix)/lib && \
	for f in $(SWIG_LIB_NAMES); do \
	   $(LN_S) -f `perl -ne "if(/dlname='([^']+)'/) { print \\$$1; exit }" lib$$f.la` _$$f.so; \
	done

uninstall-local:
	for f in $(SWIG_LIB_NAMES); do $(RM) $(prefix)/lib/_$$f.so; done

CLEANFILES = Makefile Makefile.in \
	*_wrap.c *.pyc poisSwig.py psLibSwig.py xpaSwig.py *~ core core.*
