#-----------------------------------------------------------------------------
# GNU makefile for building WCSLIB.
#
# Summary of the main targets
# ---------------------------
#    all:       Build the library
#    clean:     Delete intermediate object files.
#    realclean: clean, and also delete executables and the object library.
#    test:      Compile and run the test programs.
#    show_all:  Print the values of all variables used.
#
# $Id: Makefile,v 1.1 1995/01/31 03:42:48 mcalabre Exp $
#-----------------------------------------------------------------------------
# Set FORTRAN compiler and options.
# Sun and DEC
  FFLAGS  := -u -O
# Convex
# FFLAGS  := -O3

# Uncomment this if your FORTRAN compiler doesn't have COSD, SIND, TAND,
# ACOSD, ASIND, ATAND, and ATAN2D as intrinsic functions.
# WCSTRIG := wcstrig.o

# Set or reset linker options here if needed.
  LDFLAGS := -s

# PGPLOT object library; used by tproj2 and twcs to plot test grids.
  PGPLOTLIB := -lpgplot -lX11

#-----------------------------------------------------------------------------
# You shouldn't need to change anything below here.

LIBRARY := libwcs_f.a
MODULES := proj.o \
           wcs.o  \
           sph.o  \
           $(WCSTRIG)

ifneq "$(PGPLOTLIB)" ""
   TPROJ2 = tproj2
   TWCS   = twcs
endif

%.o : %.f
	-@ echo ""
	$(FC) $(FFLAGS) -c $<

.PHONY : all clean lib realclean test

all : lib

lib : $(LIBRARY)

$(LIBRARY) : $(MODULES:%=$(LIBRARY)(%))
	ranlib $(LIBRARY)

clean :
	- $(RM) *.o *.i a.out core

realclean : clean
	- $(RM) tproj1 tproj2 tsph twcs $(LIBRARY)

test : tproj1 $(TPROJ2) tsph $(TWCS)
	-@ echo ""
	-@ echo "Running WCSLIB test programs:"
	-@ tproj1
        ifdef TPROJ2
	   -@ echo ""
	   -@ tproj2 < /dev/null
        endif
	-@ echo ""
	-@ tsph
        ifdef TWCS
	   -@ echo ""
	   -@ twcs
        endif

tproj1 tsph : % : %.f $(LIBRARY)
	-@ echo ""
	   $(FC) $(FFLAGS) $(LDFLAGS) -o $@ $< $(LIBRARY)
	   $(RM) $@.o

tproj2 twcs : % : %.f $(LIBRARY)
	-@ echo ""
	   $(FC) $(FFLAGS) $(LDFLAGS) -o $@ $< $(LIBRARY) $(PGPLOTLIB)
	   $(RM) $@.o

show_all :
	-@ echo "FC        := $(FC)"
	-@ echo "FFLAGS    := $(FFLAGS)"
	-@ echo "WCSTRIG   := $(WCSTRIG)"
	-@ echo "LDFLAGS   := $(LDFLAGS)"
	-@ echo "PGPLOTLIB := $(PGPLOTLIB)"
	-@ echo "LIBRARY   := $(LIBRARY)"
	-@ echo "MODULES   := $(MODULES)"
	-@ echo "TPROJ2    := $(TPROJ2)"
	-@ echo "TWCS      := $(TWCS)"
