Makefile.am 8.95 KB
#############################################################################
# Makefile for gammalib Python extension module                             #
# ------------------------------------------------------------------------- #
# Copyright (C) 2011-2016 Juergen Knoedlseder                               #
# ------------------------------------------------------------------------- #
#                                                                           #
#  This program is free software: you can redistribute it and/or modify     #
#  it under the terms of the GNU General Public License as published by     #
#  the Free Software Foundation, either version 3 of the License, or        #
#  (at your option) any later version.                                      #
#                                                                           #
#  This program is distributed in the hope that it will be useful,          #
#  but WITHOUT ANY WARRANTY; without even the implied warranty of           #
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
#  GNU General Public License for more details.                             #
#                                                                           #
#  You should have received a copy of the GNU General Public License        #
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.    #
#                                                                           #
# ------------------------------------------------------------------------- #
# This Makefile will build the Python interface files (*.py) and the Python #
# wrapper files using SWIG (if available; otherwise we have to make sure    #
# the the files exist already). The Python distutils are used to build and  #
# install the Python modules (see file setup.py.in).                        #
#                                                                           #
# Process this file with automake to produce Makefile.in.                   #
#############################################################################

# Works only if Python is available
if WITH_PYTHON

# Set instrument specific SWIG targets
if WITH_INST_MWL
  MWL_SWIG_TARGETS = gammalib/mwl_wrap.cpp gammalib/mwl.py
  MWL_TESTS        = ../inst/mwl/test/test_MWL.py
endif
if WITH_INST_CTA
  CTA_SWIG_TARGETS = gammalib/cta_wrap.cpp gammalib/cta.py
  CTA_TESTS        = ../inst/cta/test/test_CTA.py
endif
if WITH_INST_LAT
  LAT_SWIG_TARGETS = gammalib/lat_wrap.cpp gammalib/lat.py
  LAT_TESTS        = ../inst/lat/test/test_LAT.py
endif
if WITH_INST_COM
  COM_SWIG_TARGETS = gammalib/com_wrap.cpp gammalib/com.py
  COM_TESTS        = ../inst/com/test/test_COM.py
endif
INST_SWIG_TARGETS = $(MWL_SWIG_TARGETS) \
                    $(CTA_SWIG_TARGETS) \
                    $(LAT_SWIG_TARGETS) \
                    $(COM_SWIG_TARGETS)

# Test scripts to be distributed in $(pyexecdir)/gammalib/tests
testscripts = gammalib/tests/__init__.py \
              ../test/test_python.py \
              ../test/test_GApplication.py \
              ../test/test_GFits.py \
              ../test/test_GLinalg.py \
              ../test/test_GModel.py \
              ../test/test_GNumerics.py \
              ../test/test_GObservation.py \
              ../test/test_GOptimizer.py \
              ../test/test_GSky.py \
              ../test/test_GSupport.py \
              ../test/test_GTest.py \
              ../test/test_GVO.py \
              ../test/test_GXml.py \
              ../test/test_GXspec.py \
              $(MWL_TESTS) $(CTA_TESTS) $(LAT_TESTS) $(COM_TESTS)
testdata    = ../test/data/initial_coords.txt \
              ../test/data/fk5_to_galactic.txt \
              ../test/data/file.fits.gz

# Distribute scripts
EXTRA_DIST       = $(testscripts) $(testdata)
testscriptsdir   = $(pyexecdir)/gammalib/tests
testscripts_DATA = $(testscripts)
testdatadir      = $(pyexecdir)/gammalib/tests/data
testdata_DATA    = $(testdata)

# Distribute test data
if WITH_INST_CTA
  testdatacta       = ../inst/cta/test/data/irf_1dc.xml \
                      ../inst/cta/test/data/irf_unbinned.xml \
                      ../inst/cta/test/data/crab_events.fits.gz \
                      ../inst/cta/test/data/crab_cntmap.fits.gz
  testdatactadir    = $(pyexecdir)/gammalib/tests/cta/data
  testdatacta_DATA  = $(testdatacta)
  testcaldbcta      = ../inst/cta/test/caldb/cta_dummy_irf.dat \
                      ../inst/cta/test/caldb/prod1_gauss.fits.gz \
                      ../inst/cta/test/caldb/prod1_king.fits.gz
  testcaldbctadir   = $(pyexecdir)/gammalib/tests/cta/caldb
  testcaldbcta_DATA = $(testcaldbcta)
  testdc1cta        = ../inst/cta/test/caldb/dc1/arf.fits.gz \
                      ../inst/cta/test/caldb/dc1/psf.fits.gz \
                      ../inst/cta/test/caldb/dc1/psf_magic.fits.gz \
                      ../inst/cta/test/caldb/dc1/rmf.fits.gz
  testdc1ctadir     = $(pyexecdir)/gammalib/tests/cta/caldb/dc1
  testdc1cta_DATA   = $(testdc1cta)
endif

# Sources that are required for the build. All targets in the list will be built
# before anything. These are honored by 'make all', 'make check' and 'make install'.
# We use this here to make sure that all these targets are build by swig before we
# start compiling the Python modules.
BUILT_SOURCES = gammalib/app_wrap.cpp  gammalib/app.py \
                gammalib/base_wrap.cpp gammalib/base.py \
                gammalib/fits_wrap.cpp gammalib/fits.py \
                gammalib/linalg_wrap.cpp gammalib/linalg.py \
                gammalib/model_wrap.cpp gammalib/model.py \
                gammalib/numerics_wrap.cpp gammalib/numerics.py \
                gammalib/obs_wrap.cpp gammalib/obs.py \
                gammalib/opt_wrap.cpp gammalib/opt.py \
                gammalib/sky_wrap.cpp gammalib/sky.py \
                gammalib/support_wrap.cpp gammalib/support.py \
                gammalib/test_wrap.cpp gammalib/test.py \
                gammalib/xml_wrap.cpp gammalib/xml.py \
                gammalib/xspec_wrap.cpp gammalib/xspec.py \
                gammalib/vo_wrap.cpp gammalib/vo.py \
                $(INST_SWIG_TARGETS)

# Dependencies. Obtain the list of dependencies by executing ls.
DEPFILES = $(shell ls gammalib/*.Pi 2> /dev/null)
include $(DEPFILES)

# Set files to be removed in clean. We remove only the SWIG interface files if SWIG
# is available to rebuild them. 
if HAVE_SWIG
  CLEAN_FILES = $(BUILT_SOURCES)
endif
CLEANFILES = $(CLEAN_FILES) $(DEPFILES)

# Set SWIG compile command
SWIGCOMPILE = $(SWIG) -c++ -python -Wall

# Things we want to do when 'make' is invoked.
all-local: build

# Build the gammalib extension module
build: $(BUILT_SOURCES)
	@PYTHON_BUILD_PREFIX@ $(PYTHON) setup.py build_ext
if IS_ELCAPITAN
	-for f in build/gammalib/_*.so; do \
		echo "Post process module "$$f; \
		install_name_tool -change $(libdir)/libgamma.2.dylib @rpath/libgamma.2.dylib $$f; \
		install_name_tool -add_rpath $(libdir) $$f; \
		install_name_tool -add_rpath $(abs_top_srcdir)/src/.libs $$f; \
	done
endif

# Do nothing for 'make check'
#check-local:

# Install the gammalib extension module
install-exec-local:
	$(PYTHON) setup.py install --prefix=$(prefix)

# Remove build directory and test libraries
clean-local:
	rm -rf build
	rm -rf gammalib/__init__.py? gammalib/_*.so gammalib/*.pyc

# Rules for building Python wrappers using SWIG. The rules are only active if
# SWIG is avialable. The is a general rule for core modules and specific rules
# for each instrument module.
if HAVE_SWIG

# Rule to build SWIG wrappers
swig: $(BUILT_SOURCES)

# General rule for core modules
%_wrap.cpp %.py: %.i
	if $(SWIGCOMPILE) -MMD -MF "$*.Tpi" -o $@ -outdir gammalib $<; \
	then mv -f "$*.Tpi" "$*.Pi"; else rm -f "$*.Tpi"; exit 1; fi

# Rule for MWL module
if WITH_INST_MWL
gammalib/mwl.py: gammalib/mwl_wrap.cpp
gammalib/mwl_wrap.cpp: $(top_srcdir)/inst/mwl/pyext/mwl.i
	if $(SWIGCOMPILE) -MMD -MF "gammalib/mwl.Tpi" -o gammalib/mwl_wrap.cpp -outdir gammalib $<; \
	then mv -f "gammalib/mwl.Tpi" "gammalib/mwl.Pi"; else rm -f "gammalib/mwl.Tpi"; exit 1; fi
endif

# Rule for CTA module
if WITH_INST_CTA
gammalib/cta.py: gammalib/cta_wrap.cpp
gammalib/cta_wrap.cpp: $(top_srcdir)/inst/cta/pyext/cta.i
	if $(SWIGCOMPILE) -MMD -MF "gammalib/cta.Tpi" -o gammalib/cta_wrap.cpp -outdir gammalib $<; \
	then mv -f "gammalib/cta.Tpi" "gammalib/cta.Pi"; else rm -f "gammalib/cta.Tpi"; exit 1; fi
endif

# Rule for LAT module
if WITH_INST_LAT
gammalib/lat.py: gammalib/lat_wrap.cpp
gammalib/lat_wrap.cpp: $(top_srcdir)/inst/lat/pyext/lat.i
	if $(SWIGCOMPILE) -MMD -MF "gammalib/lat.Tpi" -o gammalib/lat_wrap.cpp -outdir gammalib $<; \
	then mv -f "gammalib/lat.Tpi" "gammalib/lat.Pi"; else rm -f "gammalib/lat.Tpi"; exit 1; fi
endif

# Rule for COM module
if WITH_INST_COM
gammalib/com.py: gammalib/com_wrap.cpp
gammalib/com_wrap.cpp: $(top_srcdir)/inst/com/pyext/com.i
	if $(SWIGCOMPILE) -MMD -MF "gammalib/com.Tpi" -o gammalib/com_wrap.cpp -outdir gammalib $<; \
	then mv -f "gammalib/com.Tpi" "gammalib/com.Pi"; else rm -f "gammalib/com.Tpi"; exit 1; fi
endif

endif # HAVE_SWIG

endif # WITH_PYTHON