# -*- makefile -*-

#  ONLY EDIT THIS FILE IF IT'S $NEMOLIB/makedefs
#    diff $NEMO/makedefs $NEMOLIB
#  ((the one in $NEMO is the configure generated one that gets copied))
#  ((to $NEMOLIB via the "make config_extra" command during the))
#  (("make build1" step of the install))

#  Note that the falcON tools (e.g. gyrfalcON) do not use this file.
#  See the $NEMO/usr/dehnen/utils/make.* files to figure out how
#  to tune these tools. Walter did a pretty darn good job, see if you
#  beat that!

#  DSO linking: might need to wrap offending libraries 
#       -Wl,--no-as-needed -lX11 -Wl,-as-needed
#  instead of 
#                          -lX11
#  Another option is to add -Wl,--no-as-needed to CFLAGS
#  This is the current default in configure (to use it)
#  Comment the next line if you do not want this, or use --without-dso
NEMO_CFLAGS1 = 


# handy for recursion


# Compilers:

CC  = gcc
FC  = gfortran
F77 = gfortran
CXX = g++

# HDF4 library
#HDF_INC=-I/local/include -I/usr/local/include -I/usr/include/hdf
#HDF_LIB=-ldf -ljpeg -lz -lsz
HDF_INC = -I/usr/include/hdf
HDF_LIB = -L/usr/lib -L/usr/lib/hdf -ldf -ljpeg -lz

#  HDF5 library
# --with-hdf5-incdir=   --with-hdf5-libdir=
#HDF5_INC = `pkg-config --cflags hdf5`
#HHD5_LIB = `pkg-config --libs hdf5`
HDF5_INC = 
HDF5_LIB = 

#  PNG library
#PNG_LIB = `pkg-config --libs libpng`
PNG_LIB = 

#  CFITSIO library
#CFITSIO_INC = `pkg-config --cflags cfitsio`
#CFITSIO_LIB = `pkg-config --libs cfitsio`
CFITSIO_INC = 
CFITSIO_LIB = 

#  MIRIAD library
MIRIAD_INC = 
MIRIAD_LIB = 

#	GSL
#GSL_INC = @GSL_CFLAGS@
#GSL_LIB = @GSL_LIBS@
GSL_INC = 
GSL_LIB =

#	PLPLOT
#PLPLOT_INC = -I/usr/include/plplot
#PLPLOT_LIB = -lplplot
PLPLOT_INC = 
PLPLOT_LIB = -lplplotd

#	FFTW
#       -lfftw3, or -lfftw3f or -lfftw3l (depending on precision library, for float or long double)
#       [actually still not used yet]
#FFTW_CFLAGS = @FFTW_CFLAGS@
#FFTW_LIBS   = @FFTW_LIBS@
FFTW_INC = 
FFTW_LIB =


#	READLINE
RDL_LIBS   = 

# LOADOBJ stuff; -DMACH=.....

MACH = -Dlinux -DSYSV


# 	Fortran: you need FLIBS if you link using 'cc' and link 
#	with (certain) fortran. See also F77_FUNC macros (config.h)
#	if you need to use fortran names from your C code, or if you
#	need to define C code that is to be called from Fortran

#       F77_CMAIN_FFLAGS is needed if you link with fortran, but main is in C
#  on older MacOS you need to remove any -lcrt1.o and -lcrt2.o (or the like) references
FLIBS =  -L/usr/lib/gcc/x86_64-linux-gnu/9 -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/9/../../.. -lgfortran -lm -lquadmath
FORLIBS = $(FLIBS)
F77_CMAIN_FFLAGS = 

# YAPPLIB: was removed from NEMORC.{gen,local}
# sometimes (for native cc/f77 compiler on solaris) you need to append $(FLIBS) here
# since FLIBS isn't computed properly
# Note for some PGPLOT devices (e.g. PNDRIV) you will need to add -lpng)
# for PLPLOT a choice between -lplplotd and -lplplotf needs to be consistent with
#  the definition triggered for pl_real in yapp_plplot.c !! this is not automated yet
#  via configure.
YAPPLIB = $(NEMOLIB)/yapp_pgplot.o -L$(NEMOLIB) -lcpgplot -lpgplot  $(XLIBS) $(FLIBS)

## C compiler:
#set opts="-rdynamic -ansi -fwritable-strings -Wconversion -Wnested-externs"
#exec gcc -fPIC -Dlinux -DSYSV -I$NEMOINC -I$NEMOLIB -L$NEMOLIB $opts $* $link
## Fortran compiler
#  some older gnu compilers may still need -fno-globals

INC_FLAGS = -I$(NEMOINC) -I$(NEMOLIB) -I$(NEMO)/opt/include -I/usr/include/hdf  

NEMO_CFLAGS =    -rdynamic  $(MACH) $(NEMO_CFLAGS1) $(INC_FLAGS)
NEMO_FFLAGS =   $(INC_FLAGS)
NEMO_LDFLAGS = 
NEMO_LIBS   = -L$(NEMOLIB) -L$(NEMO)/opt/lib          -lnemo -ldl $(GSL_LIBS) $(RDL_LIBS) $(CFITSIO_LIB) -lm 
NEMO_LIBSPP = -L$(NEMOLIB) -L$(NEMO)/opt/lib -lnemo++ -lnemo -ldl $(GSL_LIBS) $(RDL_LIBS) $(CFITSIO_LIB) -lm 

#			some graphics libraries:
GLLIBS = -lGLU -lGL
XLIBS  =   -lSM -lICE -lXext -lX11 

#			generic compile flags for C,Fortran,Linker
# If you must absolutely be pedantic, the following gnu compiler flags are the recommended ones
# (see GSL users guide - appendix A)
# PEDFLAG="-ansi -pedantic -Werror -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wtraditional -Wconversion -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align  -Wwrite-strings -Wnested-externs  -fshort-enums -fno-common -Dinline= -g -O4"
#   optimization only

OPT  = -g -O2 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
FOPT = -g -O2
LOPT = 
#   for shared libaries
CCSHARED = -fpic
#   everything 
CFLAGS  = $(OPT) $(CCSHARED) $(NEMO_CFLAGS)
FFLAGS  = $(OPT) $(CCSHARED) $(NEMO_FFLAGS)
LDFLAGS = $(OPT)             $(NEMO_LDFLAGS)
CPPFLAGS = 

RANLIB = ranlib

# -----------------------------------------------------------------------------
#  rules

.SUFFIXES:  .so .doc

#	NEMO compile rules

.o.a:
	@echo "***Skipping ar for $* at this stage"

.c.o:
	$(CC) $(CFLAGS) $(LOCAL_INC) -c $<

.cc.o:
	$(CXX) $(CFLAGS) $(LOCAL_INC) -c $<

.c.so:
	$(CC) $(CFLAGS) $(LOCAL_INC) -c $<
	ldso $*

.cc.so:
	$(CXX) $(CFLAGS) $(LOCAL_INC) -c $<
	ldso $*

.f.so:
	$(FC) $(FFLAGS) -c $<
	ldso $*

.c.a:
	$(CC) $(CFLAGS) $(LOCAL_INC) -c $<

.c:
	$(CC) $(CFLAGS) $(LOCAL_INC) -o $* $*.c $(NEMO_LIBS) $(LOCAL_LIB) $(FORLIBS) $(EL)

.cc:
	$(CXX) $(CFLAGS) $(LOCAL_INC) -o $* $*.c $(NEMO_LIBSPP) $(LOCAL_LIB) $(FORLIBS) $(EL)

.o:
	$(CC) $(CFLAGS) $(LOCAL_INC) -o $* $*.o $(NEMO_LIBS) $(LOCAL_LIB) $(FORLIBS) $(EL)


# -----------------------------------------------------------------------------


# some fortran code needs a REAL FUNCTIONS SECOND (e.g. scfm)
# this macro should point to the .o file (if needed)
# Sometimes it is FORLIBS, sometimes your etime.o or second.o

# On Solaris you need second.o; Linux can keep it blank (it's in libg2c)
# SECOND = $(NEMOLIB)/second.o

# xxxTYPE's:   falcON now uses      PLATFORM := $(shell uname -m)
PLATFORM := $(shell uname -m)


makedefs_help:
	@echo ========================================================================
	@echo NEMOVER=$(NEMOVER)
	@echo CC=$(CC)
	@echo CFLAGS=$(CFLAGS)
	@echo CPP=$(CPP)
	@echo CPPFLAGS=$(CPPFLAGS)
	@echo CXX=$(CXX)
	@echo CXXFLAGS=$(CXXFLAGS)
	@echo F77=$(F77)
	@echo FFLAGS=$(FFLAGS)
	@echo DEFS=$(DEFS)
	@echo CFLAGS=$(CFLAGS)
	@echo FFLAGS=$(FFLAGS)
	@echo LDFLAGS=$(LDFLAGS)
	@echo FC=$(F77)
	@echo LN_S=$(LN_S)
	@echo GLLIBS=$(GLLIBS)
	@echo XLIBS=$(XLIBS)
	@echo LIBS=-lgsl -lgslcblas -lm -ldl -lc -lc -lz 
	@echo RANLIB=$(RANLIB)
	@echo YAPPLIB=$(YAPPLIB)
	@echo PLATFORM=$(PLATFORM)
	@echo HOSTTYPE=$(HOSTTYPE)
	@echo MACHTYPE=$(MACHTYPE)
	@echo OSTYPE=$(OSTYPE)
	@echo ========================================================================


# this peculiar include will include a file LocalMakedefs in the local/current
# directory only if it is present, but not complain if not present. This is
# the recommended way to tailor a particular directory, e.g. for debugging
# you could add something like
#      NEMO_CFLAGS += -Wall -W -g
#
-include LocalMakedefs

