# ####################### ArchTOIPipe ###########################
# ##### LAL (Orsay) / IN2P3-CNRS  DAPNIA/SPP (Saclay) / CEA #####
# ###############################################################
#   Top level makefile to build ArchTOIPipe library with SOPHYA
# Usage : make -f SMakefile mkmf
#         make -f SMakefile libs
#         make -f SMakefile slb 
# ###############################################################

# include files defining compiler/linker options 
include SMakefile.h
include ${DPCBASEREP}/Include/Makefile.slb

LIBF =  $(MYLIB)libKernel.a $(MYLIB)libProcessors.a $(MYLIB)libProcWSophya.a

defaut: libs

all: libs slb


libs: archlibs
slb: archslb

archlibs: Kernel Processors ProcWSophya

#--- Create directory and copy includes for install
depend:
ifdef ARCHPDEVREP
ifdef EROSCXX
	@echo "ArchTOIPipe will be installed under:"
	@echo "  $(ARCHPDEVREP)/Include" 
	@echo "  $(ARCHPDEVREP)/`uname`-$(EROSCXX)" 
	./crerep_pipe $(ARCHPDEVREP) `uname`-$(EROSCXX); \
#	./makefileuser.csh; \
	./mkmflien -copy ; \
else
	@echo "Variable EROSCXX must be define with setenv"
endif
else
	@echo "Variable ARCHPDEVREP must be define with setenv"
endif
#--------------------------------------------------------------------

#--- Create library module Makefiles
mkmf:
	@echo 'Running ./smkmf'
	./smkmf
#--------------------------------------------------------------------

.PHONY:  Kernel
Kernel:
	if [ -d Kernel ] ; then cd  Kernel ; $(MAKE) ; fi

.PHONY:  Processors
Processors:
	if [ -d Processors ] ; then cd  Processors ; $(MAKE) ; fi

.PHONY:  ProcWSophya
ProcWSophya:
	if [ -d ProcWSophya ] ; then cd  ProcWSophya ; $(MAKE) ; fi

#  Shared library creation part of the Makefile
 
#  List of libraries (.a)
PSLB =  $(MYLIB)libKernel.a $(MYLIB)libProcessors.a $(MYLIB)libProcWSophya.a

#  List of external library references
EXTLIBL  = -L$(EXTLIBPATH) -lcfitsio -lfftw -lrfftw -lxastro
EXTSLBL  = -L$(EXTSLBPATH) -lcfitsio -lfftw -lrfftw -lxastro

# defining the other external libraries needed on different systems

# On Linux   lapack and blas and f2c/g2c ere needed
ifeq ($(MACHEROS),Linux)
#EXTLIB = $(EXTLIBL) -llapack -lblas -lf2c
#EXTSLB = $(EXTSLBL) -llapack -lblas -lf2c
EXTLIB = $(EXTLIBL) -llapack -lblas -lg2c
EXTSLB = $(EXTSLBL) -llapack -lblas -lg2c
endif

# On OSF1 libdxml contains Lapack, but the fortran support library is needed
ifeq ($(MACHEROS),OSF1)
EXTLIB = $(EXTLIBL) -ldxml -lfor
EXTSLB = $(EXTSLBL) -ldxml -lfor
endif

# On IRIX , complib.sgimath contains Lapack
ifeq ($(MACHEROS),IRIX64)
EXTLIB = $(EXTLIBL) -lcomplib.sgimath 
EXTSLB = $(EXTSLBL) -lcomplib.sgimath 
endif



# XPILIBS = $(LIBXPIPATH) $(LIBXPILIST)

# --- Shared lib name (extension) depending on OS 
SLBNAME = $(MYSLB)libpipe.so
ifeq ($(MACHEROS),Darwin)
SLBNAME = $(MYSLB)libpipe.dylib
endif
 
#  main dependence list
archslb : $(SLBNAME) 

# List of .o files for each module
# OBJKernel = $(shell echo `cat ./Kernel/objlist.list `)
# OBJProcessors = $(shell echo `cat ./Processors/objlist.list `)
# OBJProcWSophya = $(shell echo `cat ./ProcWSophya/objlist.list `)
OBJKernel = $(shell echo `cat ./Kernel/Kernel.o.list `)
OBJProcessors = $(shell echo `cat ./Processors/Processors.o.list `)
OBJProcWSophya = $(shell echo `cat ./ProcWSophya/ProcWSophya.o.list `)

ALLOBJS = $(OBJKernel) $(OBJProcessors) $(OBJProcWSophya) 
 
# Building ArchTOIPipe shared library
$(SLBNAME) : $(PSLB)
	cd  $(OBJ); \
	$(CMDSHLCXX) -o $(SLBNAME)  \
	$(FGSHLACXX) $(ALLOBJS)  $(FGSHLNCXX)\
	-L$(SLB) -lsophya -lextsophya $(EXTLIB) $(LIBLSHL)
 
 

clean:
	if [ -d $(MYLIB) ] ; then cd $(MYLIB)/. ; rm -f *.a  ; fi
	if [ -d $(MYSLB) ] ; then cd $(MYSLB)/. ; rm -f *.so ; fi
	if [ -d $(OBJ) ] ; then cd $(OBJ)/. ; rm -f *.o  rm -rf cxxrep* ; fi

