#-----------------------------------------------------------------------------
# GNU makefile for building PGSBOX 3.3.
#
# This makefile assumes that you will be compiling with g77 and gcc, that
# WCSLIB 3.3 has already been built in ../C, and that the FORTRAN and C
# include files reside in ../FORTRAN and ../C (as in the distribution kit).
#
# It's quite likely that you will to modify it for your own purposes.
#
# $Id: Makefile,v 3.3 2003/10/22 08:38:10 mcalabre Exp $
#-----------------------------------------------------------------------------
# FORTRAN compiler and options.
FC := g77
FFLAGS := -O -Wimplicit -Wno-globals

# C compiler and options.
CC := gcc
CFLAGS := -O -Wall -Wno-parentheses

# Linker options.
LD := g77
LDFLAGS := -s

# Libraries required for building the test programs.
LIBS := -L../C -lwcs -lcpgplot -lpgplot_g77 -lpng -lz
LIBS += -L/usr/local/X11/lib -lX11

ifeq "$(FLAVOUR)" "Linux"
  LIBS := -L../C -lwcs -lcpgplot -lpgplot -lpng -L/usr/X11R6/lib -lX11
endif

%.o : %.c
	$(CC) $(CFLAGS) -I. -I../C -I/usr/local/include -c -o $@ $<

%.i : %.c
	-@ echo ""
	$(CC) $(CFLAGS) -I. -I../C -I/usr/local/include -E -o $@ $<

%.d : %.c
	-@ $(CC) $(CFLAGS) -I. -I../C -I/usr/local/include -E $< | \
	   sed -n -e 's|^# 1 "\([^/].*\.h\)".*|\1|p' | \
	   sort -u

%.o : %.F
	$(FC) $(FFLAGS) -I../FORTRAN -c -o $@ $<

%.o : %.f
	$(FC) $(FFLAGS) -I../FORTRAN -c -o $@ $<

.PHONY : all clean cleaner cleanest realclean test

all : pgtest cpgtest

test : all
	pgtest < /dev/null
	cpgtest < /dev/null

clean :
	$(RM) *.o *.i

realclean cleaner cleanest : clean
	$(RM) pgtest cpgtest

pgtest : pgtest.o pgsbox.o pgcrfn.o lngvel.o fscan.o pgwcsl.o
	-@ rm -f $@
	$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)

cpgtest : cpgtest.o cpgsbox.o pgsbox.o pgcrfn.o lngvel.o fscan.o pgwcsl.o
	-@ rm -f $@
	$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
