# $Id$
#-----------------------------------------------------------------------
#;  Copyright (C) 2004-2020
#;  Associated Universities, Inc. Washington DC, USA.
#;
#;  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 2 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, write to the Free
#;  Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
#;  MA 02139, USA.
#;
#;  Correspondence concerning this software should be addressed as follows:
#;         Internet email: bcotton@nrao.edu
#;         Postal address: W. D. Cotton
#;                         National Radio Astronomy Observatory
#;                         520 Edgemont Road
#;                         Charlottesville, VA 22903-2475 USA
#-----------------------------------------------------------------------
#    Makefile to build library routines
#    Obit software
#
#   Expects CC, CFLAGS, to be set by either environment variable 
#   or Make argument
#     CC is the compiler to use
#     CFLAGS is compile options
#     INCDIR directories with include files
#     LIB defines libraries and search paths,
#
#------------------------------------------------------------------------

top_srcdir = ..

CC = gcc
#CPPFLAGS = -msse -mavx -DHAVE_SSE=1 -DHAVE_AVX
CPPFLAGS = 
CFLAGS = -g -O3 -fPIC -msse
LDFLAGS = -L/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/lib -L/export/raid/bcotton/WDC.dir/buildObit/ObitBase/src/Obit/lib -L/export/ssd/bcotton/Git/Obit/other//lib -L/usr/lib64 -Wl,-rpath,/export/raid/bcotton/WDC.dir/buildObit/ObitBase/lib:/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/lib:/export/raid/bcotton/WDC.dir/buildObit/ObitBase/src/Obit/lib -lpng -lxmlrpc_server -lxmlrpc_client -lxmlrpc_server_abyss -lxmlrpc_xmlparse -lxmlrpc_xmltok -lxmlrpc_util -lxmlrpc_abyss -lxml2 -lcfitsio -lxmlrpc -lxmlrpc_util

ALL_CPPFLAGS = $(CPPFLAGS) -I$(top_srcdir)/include  -I/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/include \
	  \
	 -I/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/include/plplot  -DPACKAGE_NAME=\"Obit\" -DPACKAGE_TARNAME=\"obit\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"Obit\ 1.0\" -DPACKAGE_BUGREPORT=\"bcotton@nrao.edu\" -DPACKAGE=\"obit\" -DVERSION=\"1.0\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_UNISTD_H=1 -DHAVE_SSE=1 -DHAVE_LIBCFITSIO=1 -DHAVE_CFITSIO=1 -DHAVE__TMP_DUMMY1_FFTW3_H=1 -DHAVE_FFTW3=1 -DHAVE__TMP_DUMMY1_GSL_H=1 -DHAVE_GSL=1 -DHAVE__TMP_DUMMY1_XMLRPC_H=1 -DHAVE_XMLRPC=1 -DHAVE__TMP_DUMMY1_ZLIB_H=1 -DHAVE_ZLIB=1 -DHAVE_PLPLOT=1 -DHAVE_PYTHON=1 -DHAVE_FSEEKO=1 -DOBIT_THREADS_ENABLED=1
ALL_CFLAGS = $(CFLAGS) -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include     -I/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/include/plplot \
	 
ALL_LDFLAGS = $(LDFLAGS)  -L/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/lib      \
	 -L/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/lib 

LIBS = -L../lib/ -lObit -lcfitsio    -lfftw3f -lglib-2.0   \
	-lgsl -lgslcblas  -lplplot     -L/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/lib -L/export/raid/bcotton/WDC.dir/buildObit/ObitBase/src/Obit/lib -L/export/ssd/bcotton/Git/Obit/other//lib -L/usr/lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../.. -lpng -lxmlrpc_server -lxmlrpc_client -lxmlrpc_server_abyss -lxmlrpc_xmlparse -lxmlrpc_xmltok -lxmlrpc_util -lxmlrpc_abyss -lxml2 -lcfitsio -lxmlrpc -lgfortran -lm -lquadmath -lpthread -lgthread-2.0 -lglib-2.0  

CLIENT_CPPFLAGS = $(ALL_CPPFLAGS) -msse -mavx -DHAVE_SSE=1 -DHAVE_AVX  -I/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/include -I/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/include  -I/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/include -I/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/include 
CLIENT_CFLAGS = $(ALL_CFLAGS) 
CLIENT_LDFLAGS = $(ALL_LDFLAGS) -L/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/lib -L/export/raid/bcotton/WDC.dir/buildObit/ObitBase/src/Obit/lib -L/export/ssd/bcotton/Git/Obit/other//lib -L/usr/lib64 -Wl,-rpath,/export/raid/bcotton/WDC.dir/buildObit/ObitBase/lib:/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/lib:/export/raid/bcotton/WDC.dir/buildObit/ObitBase/src/Obit/lib -lpng -lxmlrpc_server -lxmlrpc_client -lxmlrpc_server_abyss -lxmlrpc_xmlparse -lxmlrpc_xmltok -lxmlrpc_util -lxmlrpc_abyss -lxml2 -lcfitsio -lxmlrpc -lxmlrpc_util -L/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/lib -L/export/raid/bcotton/WDC.dir/buildObit/ObitBase/src/Obit/lib -L/export/ssd/bcotton/Git/Obit/other//lib -L/usr/lib64 -Wl,-rpath,/export/raid/bcotton/WDC.dir/buildObit/ObitBase/lib:/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/lib:/export/raid/bcotton/WDC.dir/buildObit/ObitBase/src/Obit/lib -lpng -lxmlrpc_server -lxmlrpc_client -lxmlrpc_server_abyss -lxmlrpc_xmlparse -lxmlrpc_xmltok -lxmlrpc_util -lxmlrpc_abyss -lxml2 -lcfitsio -lxmlrpc -lxmlrpc_util   
CLIENT_LIBS = $(LIBS) -lz   -lxmlrpc_client -lcurl -L/export/ssd/bcotton/Git/Obit/trunk/other/lib/lib   -lxmlrpc  -lxmlrpc_xmlparse -lxmlrpc_xmltok -lxmlrpc_util -lpthread  -L/export/ssd/bcotton/Git/Obit/trunk/other/lib/lib   -lxmlrpc_client -lxmlrpc  -lxmlrpc_xmlparse -lxmlrpc_xmltok -lxmlrpc_util -lpthread -lcurl       

SERVER_CPPFLAGS = -msse -mavx -DHAVE_SSE=1 -DHAVE_AVX  -I/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/include -I/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/include  -I/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/include -I/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/include
SERVER_CFLAGS = 
SERVER_LDFLAGS = $(LDFLAGS) -L/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/lib -L/export/raid/bcotton/WDC.dir/buildObit/ObitBase/src/Obit/lib -L/export/ssd/bcotton/Git/Obit/other//lib -L/usr/lib64 -Wl,-rpath,/export/raid/bcotton/WDC.dir/buildObit/ObitBase/lib:/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/lib:/export/raid/bcotton/WDC.dir/buildObit/ObitBase/src/Obit/lib -lpng -lxmlrpc_server -lxmlrpc_client -lxmlrpc_server_abyss -lxmlrpc_xmlparse -lxmlrpc_xmltok -lxmlrpc_util -lxmlrpc_abyss -lxml2 -lcfitsio -lxmlrpc -lxmlrpc_util -L/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/lib -L/export/raid/bcotton/WDC.dir/buildObit/ObitBase/src/Obit/lib -L/export/ssd/bcotton/Git/Obit/other//lib -L/usr/lib64 -Wl,-rpath,/export/raid/bcotton/WDC.dir/buildObit/ObitBase/lib:/export/raid/bcotton/WDC.dir/buildObit/ObitBase/deps/lib:/export/raid/bcotton/WDC.dir/buildObit/ObitBase/src/Obit/lib -lpng -lxmlrpc_server -lxmlrpc_client -lxmlrpc_server_abyss -lxmlrpc_xmlparse -lxmlrpc_xmltok -lxmlrpc_util -lxmlrpc_abyss -lxml2 -lcfitsio -lxmlrpc -lxmlrpc_util 
SERVER_LIBS =   -L/export/ssd/bcotton/Git/Obit/trunk/other/lib/lib   -lxmlrpc_server_abyss -lxmlrpc_server -lxmlrpc_abyss -lssl -lcrypto    -lxmlrpc  -lxmlrpc_xmlparse -lxmlrpc_xmltok -lxmlrpc_util -lpthread   

# Use Swig to build interface, only needed to change interface
SWIG = /usr/bin/swig
SWIGLIB	   = 

# Libraries in case they've changed
MYLIBS := $(wildcard ../lib/lib*.a)

# Do everything in one big module
TARGETS := Obit 

all: $(TARGETS)

# Build shared library for python interface
$(TARGETS): setupdata.py $(MYLIBS)
	rm -rf build
	python2.7 makesetup.py
	python2.7 setup.py build install --install-lib=.
	python3 setup.py build install --install-lib=.

# Build python/Obit interface
#interface: Obit_wrap.c
#	echo "rebuild Obit/python interface"

# Use Swig to build python/c interface if necessary
#Obit_wrap.c: *.inc $(MYLIBS)
#	rm -f Obit_wrap.c
#	echo "%module Obit" > Obit.i
#	cat ObitTypeMaps.swig >> Obit.i
#	cat *.inc >> Obit.i
#	$(SWIG) -Wall -python -I$(SWIGLIB) -I$(SWIGLIB)/python Obit.i

# libObit.so for binary distribution, libObit.a for build from source:
Obit: Obit_wrap.c ../lib/libObit.so
	rm -rf build
	python makesetup.py
	python setup.py build install --install-lib=.
	python3 setup.py build install --install-lib=.

# Write compile/link info to setupdata.py
setupdata.py: Makefile
	echo "CFLAGS='$(ALL_CFLAGS)'">setupdata.py
	echo "CPPFLAGS='$(CLIENT_CPPFLAGS) $(SERVER_CPPFLAGS)'">>setupdata.py
	echo "LDFLAGS='$(CLIENT_LDFLAGS) $(SERVER_LDFLAGS)'">>setupdata.py
	echo "LIBS='$(CLIENT_LIBS) $(SERVER_LIBS)'">>setupdata.py

clean:
	rm -f Obit.i *.o *.so *.pyc	
	rm -rf build
