##############################################################################
#
# XVista Makefile  
#
#    Welcome to the XVista Makefile.  This has been verified to work on
#    only a few systems: SunOS 5.5 and Linux 3.0.  If you've got one
#    of those, you're in luck.  If not, you will probably have to
#    iterate several times to find a combination of the several 
#    Make macros that will work for you.  If you do figure it out,
#    please send me E-mail to tell me what you did!
#
#                Michael Richmond     Aug 1, 1996
#
#
#    You should consider modifying some or all of:
#
#    SYS               can be LINUX   for Linux
#                             SUN     for SunOS 5.5
#
#    INCS              directory in which X11 include files live, if not
#                      part of the standard include-file path
#
#    LIBS              the X11 libraries on your system
#
#
#    XGETUNSIGNED      should be 1    for X11 distributions in which 
#                                     the final argument "prop_return"
#                                     for XGetWindowProperty and 
#                                     XSetWindowProperty has type
#                                     "unsigned char **"
#                      should be 0    for systems which require that argument
#                                     to have type "signed char **"
#
#    CC                the name of your system's ANSI C compiler
#
#    CFLAGS            maybe you want -g, or maybe -O; lots of options
#                      if you're actually developing source code
#
#    XPLOT             define HELPFILE value to the directory in which the help
#                      file "xplot.help" is currently sitting
#
#    BINDIR            the directory into which you want executable code
#                      to be placed by "make install"
#
#
#############################################################################
#
#
#
# define this if you are running Linux
SYS=LINUX
INCS=
# define this if you're on a Sun
#SYS=SUN
#INCS=-I/usr/openwin/include

# some old versions of X11 libraries require "XGetWindowProperty" to take
#  a signed char ** for the last (12'th) argument.  If you have such
#  a system, set the following to 0
XGETUNSIGNED=1

# the RedHat 4.2 Linux distribution running on a Pentium Pro seems
#  to require swapping bytes when one reads and writes from/to FITS
#  files.  Strange.  Setting this equal to 1 will swap bytes.
SWAPBYTES=1

# define C-compiler stuff
#   note that on (my) Linux system, you need "-static" if you use "-g"
CC = gcc
CFLAGS= -ansi -g -static -Wall $(INCS) -DPROTO -D$(SYS) \
              -DXGETUNSIGNED=$(XGETUNSIGNED) -DSWAPBYTES=$(SWAPBYTES) 
#CFLAGS= -ansi -g -Wall $(INCS) -DPROTO -D$(SYS) \
#              -DXGETUNSIGNED=$(XGETUNSIGNED)

# the following stuff is needed for XPLOT
#  set HELPFILE to the exact path for xplot.help (from root)
#
#XPLOT=$(CFLAGS) -DHELPFILE=\"/your_path_here/xplot.help\"
#XPLOT=-DHELPFILE=\"/home/richmond/xvista/xplot.help\"
XPLOT=-DHELPFILE=\"/home/richmond/xvista/xplot.help\"

# define this to be the directory into which binaries are placed
BINDIR=./

# this line appropriate for LINUX
XLIBS=-L/usr/X11R6/lib -lX11 -ldl
# and this for Sun
#XLIBS=-L/usr/openwin/lib -lX11 




LIBOBJS=autospan.o boxdata.o do_axes.o error.o eval.o \
        exten.o findkey.o findsky.o fits.o gaussFit.o \
        getbox.o get_col.o getsym.o \
        solve_linear.o usleep.o

IMLOBJS=image.o image1.o windman.o

XPLOTLIBOBJS=xplotlib.o usleep.o adobe.o

EXECS=abx add addvec axes back bin box buffers ccdvec circle clip \
     comment convert cursor div divvec mask flip fold \
     hist imshift impatch implant let makeim makevec marks mash median mn \
     mul mulvec pfits phot profile propinit pstar ring rotate rowcol sky \
     smooth stars sub subvec swapbyte \
     tv window xplot sbig2fits


all: libvista.a libivista.a $(EXECS)
	echo 'all done' 

abx:	abx.o libvista.a
	$(CC) $(CFLAGS) -o abx abx.o -L. -lvista -lm

add:	add.o libvista.a
	$(CC) $(CFLAGS) -o add add.o -L. -lvista -lm
addvec:	addvec.o libvista.a
	$(CC) $(CFLAGS) -o addvec addvec.o -L. -lvista -lm
axes:	axes.o  libvista.a
	$(CC) $(CFLAGS) -o axes axes.o -L. -lvista -lm
back:	back.o  libvista.a
	$(CC) $(CFLAGS) -o back back.o -L. -lvista -lm
bin:	bin.o  libvista.a
	$(CC) $(CFLAGS) -o bin bin.o -L. -lvista -lm
box:	box.o libvista.a libivista.a int_box.o libxplot.a
	$(CC) $(CFLAGS) -o box box.o int_box.o -L. -livista -lvista \
                          -lxplot $(XLIBS) -lm
buffers:	buffers.o libvista.a
	$(CC) $(CFLAGS) -o buffers buffers.o -L. -lvista -lm
ccdvec:	ccdvec.o libvista.a
	$(CC) $(CFLAGS) -o ccdvec ccdvec.o -L. -lvista -lm
clip:	clip.o libvista.a
	$(CC) $(CFLAGS) -o clip clip.o -L. -lvista -lm
circle:	circle.o libvista.a libivista.a int_circle.o libxplot.a
	$(CC) $(CFLAGS) -o circle circle.o int_circle.o -L. \
                         -livista -lvista -lxplot $(XLIBS) -lm
comment:	comment.o libvista.a
	$(CC) $(CFLAGS) -o comment comment.o -L. -lvista -lm
convert:	convert.o  libvista.a
	$(CC) $(CFLAGS) -o convert convert.o -L. -lvista -lm
cursor:	cursor.o libvista.a libivista.a libxplot.a
	$(CC) $(CFLAGS) -o cursor cursor.o -L. -livista -lvista \
                          -lxplot $(XLIBS) -lm
div:	div.o  libvista.a
	$(CC) $(CFLAGS) -o div div.o -L. -lvista -lm
divvec:	divvec.o  libvista.a
	$(CC) $(CFLAGS) -o divvec divvec.o -L. -lvista -lm
mask: mask.o libvista.a
	$(CC) $(CFLAGS) -o mask mask.o -L. -lvista -lm
flip:	flip.o  libvista.a
	$(CC) $(CFLAGS) -o flip flip.o -L. -lvista -lm
fold:	fold.o  libvista.a
	$(CC) $(CFLAGS) -o fold fold.o -L. -lvista -lm
hist:	hist.o  libvista.a
	$(CC) $(CFLAGS) -o hist hist.o -L. -lvista -lm
impatch:	impatch.o libvista.a
	$(CC) $(CFLAGS) -o impatch impatch.o -L. -lvista -lm
imshift:	imshift.o interp.o  libvista.a
	$(CC) $(CFLAGS) -o imshift imshift.o interp.o -L. -lvista -lm
implant:	implant.o   libvista.a
	$(CC) $(CFLAGS) -o implant implant.o -L. -lvista -lm
let:	let.o  libvista.a
	$(CC) $(CFLAGS) -o let let.o -L. -lvista -lm
makeim:	makeim.o  libvista.a
	$(CC) $(CFLAGS) -o makeim makeim.o -L. -lvista -lm
makevec:	makevec.o  libvista.a
	$(CC) $(CFLAGS) -o makevec makevec.o -L. -lvista -lm
marks:	marks.o libvista.a libivista.a
	$(CC) $(CFLAGS) -o marks marks.o -L. -lvista $(XLIBS) -lm
mash:	mash.o  libvista.a
	$(CC) $(CFLAGS) -o mash mash.o -L. -lvista -lm
median:	median.o  libvista.a
	$(CC) $(CFLAGS) -o median median.o -L. -lvista -lm
mn:	mn.o  libvista.a
	$(CC) $(CFLAGS) -o mn mn.o -L. -lvista -lm
mul:	mul.o  libvista.a
	$(CC) $(CFLAGS) -o mul mul.o -L. -lvista -lm
mulvec:	mulvec.o  libvista.a
	$(CC) $(CFLAGS) -o mulvec mulvec.o -L. -lvista -lm
pfits: pfits.o libvista.a
	$(CC) $(CFLAGS) -o pfits pfits.o -L. -lvista -lm
phot:   phot.o  libvista.a
	$(CC) $(CFLAGS) -o phot phot.o -L. -lvista -lm
profile:   profile.o libvista.a
	$(CC) $(CFLAGS) -o profile profile.o -L. -lvista -lm
propinit:	propinit.o libivista.a libvista.a image.o libxplot.a
	$(CC) $(CFLAGS) -o propinit propinit.o image.o -L. \
                           -livista -lvista -lxplot $(XLIBS) -lm
pstar: pstar.o libvista.a
	$(CC) $(CFLAGS) -o pstar pstar.o -L. -lvista -lm
ring: ring.o libvista.a
	$(CC) $(CFLAGS) -o ring ring.o -L. -lvista -lm
rowcol:	rowcol.o  libvista.a
	$(CC) $(CFLAGS) -o rowcol rowcol.o -L. -lvista -lm
rotate:	rotate.o interp.o  libvista.a
	$(CC) $(CFLAGS) -o rotate rotate.o interp.o -L. -lvista -lm
sbig2fits:	sbig2fits.o  libvista.a
	$(CC) $(CFLAGS) -o sbig2fits sbig2fits.o -L. -lvista -lm
sky:	sky.o  libvista.a
	$(CC) $(CFLAGS) -o sky sky.o -L. -lvista -lm
smooth:	smooth.o  libvista.a
	$(CC) $(CFLAGS) -o smooth smooth.o -L. -lvista -lm
star_gauss.o: star_gauss.c stars.h
	$(CC) $(CFLAGS) -c star_gauss.c
stars:   stars.o stars1.o star_gauss.o  libvista.a libivista.a stars.h
	$(CC) $(CFLAGS) -o stars stars.o stars1.o star_gauss.o -L. \
                           -livista -lvista $(XLIBS) -lm
sub:	sub.o  libvista.a
	$(CC) $(CFLAGS) -o sub sub.o -L. -lvista -lm
subvec:	subvec.o  libvista.a
	$(CC) $(CFLAGS) -o subvec subvec.o -L. -lvista -lm
swapbyte: swapbyte.o  libvista.a
	$(CC) $(CFLAGS) -o swapbyte swapbyte.o -L. -lvista -lm

trail:	trail.o libvista.a
	$(CC) $(CFLAGS) -o trail trail.o -L. -lvista -lm

tv:	tv.o libvista.a libivista.a libxplot.a
	$(CC) $(CFLAGS) -o tv tv.o -L. -livista -lvista -lxplot $(XLIBS) -lm
window:	window.o libvista.a
	$(CC) $(CFLAGS) -o window window.o -L. -lvista -lm

xplotlib.o: xplotlib.c
	$(CC) -c $(CFLAGS) $(XPLOT) xplotlib.c

xplot:	xplot.c libxplot.a
	$(CC) $(CFLAGS) $(INCS) $(XPLOT) xplot.c -o xplot -L. -lvista -lxplot $(XLIBS) -lm


libvista.a: $(LIBOBJS) pcvista.h fits.h
	ar vr libvista.a $(LIBOBJS)
#	ranlib libvista.a

libivista.a: $(IMLOBJS) pcvista.h pcvimage.h pcvistax.h
	ar vr libivista.a $(IMLOBJS)
#	ranlib libivista.a

libxplot.a: $(XPLOTLIBOBJS) xplotlib.h
	ar vr libxplot.a $(XPLOTLIBOBJS)

links:
	ln $(EXECS) $(BINDIR)

clean: 
	/bin/rm -f *.o $(EXECS) lib*.a

tar:
	if test -d xvista; then \
	    /bin/rm -rf xvista/* ; \
	  else \
	    mkdir xvista ; \
	  fi;
	cp -r README CHANGES RELEASE Makefile TASS.example \
                 *.h *.c *.help man1 tests xvista
	tar -cvf ./xvista.tar xvista
	gzip -f xvista.tar
	/bin/rm -rf xvista

shar:
	shar README CHANGES RELEASE Makefile TASS.example \
                 *.h *.c *.help \
                 man1/*.1 man1/README \
                 tests/README tests/*.test tests/*.dat tests/*.sh \
                                                         > XVista9.shar

distr:
	/bin/rm -rf distrib
	mkdir distrib
	cp README CHANGES RELEASE Makefile TASS.example *.h *.c *.help distrib
	cp -r man1 distrib
	cp -r tests distrib
	/bin/rm -f distrib/fft* distrib/four* distrib/man1/fft* 
	cat distrib/man1/intro.1 | sed -e '/fft/d' > distrib/man1/foo
	mv distrib/man1/foo distrib/man1/intro.1
	(cd distrib; $(MAKE) tar; $(MAKE) shar)
	mv distrib/XVista9.tar distrib.tar
	mv distrib/XVista9.shar distrib.shar
