#
# This file is a Makefile for Funtools.  If it has the name "Makefile.in"
# then it is a template for a Makefile;  to generate the actual Makefile,
# run "./configure", which is a configuration script generated by the
# "autoconf" program (constructs like "@foo@" will get replaced in the
# actual Makefile.
#

PACKAGE = @PACKAGE_NAME@
VERSION = @PACKAGE_VERSION@

DISTNAME = funtools-${VERSION}
DISTDIR = ../export/${DISTNAME}
FTPDIR	= ../ftp

#----------------------------------------------------------------
# Things you can change to personalize the Makefile for your own
# site (you can make these changes in either Makefile.in or
# Makefile, but changes to Makefile will get lost if you re-run
# the configuration script).
#----------------------------------------------------------------

# Default top-level directories in which to install architecture-
# specific files (exec_prefix) and machine-independent files such
# as scripts (prefix).  The values specified here may be overridden
# at configure-time with the --exec-prefix and --prefix options
# to the "configure" script.

prefix =		@prefix@
exec_prefix =		@exec_prefix@

# The following definition can be set to non-null for special systems
# like AFS with replication.  It allows the pathnames used for installation
# to be different than those used for actually reference files at
# run-time.  INSTALL_ROOT is prepended to $prefix and $exec_prefix
# when installing files.
INSTALL_ROOT = $(DESTDIR)

# Directory in which to install the .a or .so binary for the FUNTOOLS library:
LIB_INSTALL_DIR =	$(INSTALL_ROOT)$(exec_prefix)/lib

# Directory in which to install the program wish:
BIN_INSTALL_DIR =	$(INSTALL_ROOT)$(exec_prefix)/bin

# Directory in which to install the funtools.h include file:
INCLUDE_INSTALL_DIR =	$(INSTALL_ROOT)$(prefix)/include/funtools

# Top-level directory for manual entries:
MAN_INSTALL_DIR =	$(INSTALL_ROOT)$(prefix)/share/man

# Top-level directory for share entries:
MAN_SHARE_DIR =		$(INSTALL_ROOT)$(prefix)/share/funtools

# util files are in the util subdirectory
UTIL_INC =		-I./util
# UTIL_LIBS =		-L./util -lutil

# fitsy files are in the fitsy subdirectory
FITSY_INC =		-I./fitsy
# FITSY_LIBS =		-L./fitsy -lfitsy

# wcs files are in the wcs subdirectory
WCS_INC =		-I./wcs
# WCS_LIBS =		-L./wcs -lwcs

# filter files are in the filter subdirectory
FILTER_INC =        	-I./filter
# FILTER_LIBS =		-L./filter -lfilter

# extra includes for compiling
INCLUDES =		$(UTIL_INC) $(FILTER_INC) $(WCS_INC) $(FITSY_INC)

# extra libs
EXTRA_LIBS =		@EXTRA_LIBS@

# the full set of libraries for linking
LIBS = 			$(UTIL_LIBS) $(FILTER_LIBS) $(WCS_LIBS) $(FITSY_LIBS) \
			$(EXTRA_LIBS) -lm

# To change the compiler switches, for example to change from -O
# to -g, change the following line:
CFLAGS = 		@CFLAGS@

# To add ld switches, change the following line:
LDFLAGS =		@LDFLAGS@

# whether to set the FPU in double round mode
USE_FPU_DOUBLE =	@USE_FPU_DOUBLE@

# Some versions of make, like SGI's, use the following variable to
# determine which shell to use for executing commands:
SHELL =			/bin/sh

# extra modules added by configure.in to fix OS bugs
EXTRA_OBJS = 		@EXTRA_OBJS@

# special definitions for funcalc (based on filter configuration)
FUNCALC_CC =		@FILTER_CC@
FUNCALC_CFLAGS =	@FILTER_CFLAGS@

# if enabled-shared was specified, this will exand to "shlib" and trigger
# building of the shared library
DOSHARED =	@DOSHARED@
DOMAINLIB =	@DOMAINLIB@

# There are just too many different versions of "install" around;
# better to use the install-sh script that comes with the distribution,
# which is slower but guaranteed to work.

INSTALL = 		@srcdir@/install-sh -c
INSTALL_PROGRAM =	${INSTALL}
INSTALL_DATA =		${INSTALL} -m 644

# which awk-like program do we have?
PRE=			@PRE@
POST=			@POST@
AWK =			@AWK@
PIPEGLUE =		@PIPEGLUE@
GUNZIP =		@GUNZIP@
GNUPLOT =		@GNUPLOT@

#----------------------------------------------------------------
# The information below is modified by the configure script when
# Makefile is generated from Makefile.in.  You shouldn't normally
# modify any of this stuff by hand.
#----------------------------------------------------------------

AC_FLAGS =		@DEFS@
RANLIB =		@RANLIB@
EXE =			@EXEEXT@

#----------------------------------------------------------------
# The information below should be usable as is.  The configure
# script won't modify it and you shouldn't need to modify it
# either.
#----------------------------------------------------------------

CC  =		@CC@

CC_SWITCHES =	-I. ${CFLAGS} ${CPPFLAGS} @USE_DL@ ${INCLUDES} ${AC_FLAGS}

DEPEND_SWITCHES = -I. ${CFLAGS} ${INCLUDES} ${AC_FLAGS}

SRCS =		funcol.c funcopy.c funtab.c funim.c funinfo.c \
		funopen.c funopenp.c funparam.c funtext.c funwcs.c \
		funview.c funutil.c

OBJS =		funcol.o funcopy.o funtab.o funim.o funinfo.o \
		funopen.o funopenp.o funparam.o funtext.o funwcs.o \
		funview.o funutil.o

# these are all the modules going into the "normal" funtools library
LIBOBJS =	${OBJS}

# the default library for this package
DEFLIB =	@DEFLIB@

# the actual library we are building (if this is a subpackage)
LIB =		@LIB@

# this is used in the link line
# LLIB =	$(LIB)
LLIB =		@LLIB@

# libraries containing main as subroutines
MAINLIB =	lib$(PACKAGE)MainLib.a

PROGS =		funcalc funcen funcnts funcone fundisp funhead funhist \
		funimage funjoin funmerge funsky funtable

MAINLIBOBJS =	funcalc_main.o funcen_main.o funcnts_main.o funcone_main.o \
		fundisp_main.o funhead_main.o funhist_main.o \
		funimage_main.o funmerge_main.o funsky_main.o funtable_main.o \
		funjoin_main.o 

PROGS2 =	_sort

TEMPLATES =	funcnts_plot.tmpl funhist_plot.tmpl funcnts_sed.tmpl \
		funtools_ds9.tmpl funds9.tmpl funtbl.tmpl funindex.tmpl

SCRIPTS =	funcnts.plot funhist.plot funcnts.sed funds9 funtbl funindex

DS9HELPERS =	funtools.ds9

FILES =		funcalc.sed

DEVEL =		

# Subdirectories to run make in for the primary targets.

SUBLIBS =	util fitsy wcs filter

SUBDIRS =	$(SUBLIBS) gnu funtest faq

all:		lib progs progs2 scripts ds9helpers

progs:		$(PROGS)

progs2:		$(PROGS2)

scripts:	$(SCRIPTS)

ds9helpers:	$(DS9HELPERS)

devel:		$(DEVEL)

libutil:	FORCE
		@(echo Making libutil.a in util ...; \
		  cd util; $(MAKE) libutil; mv libutil.a ..)

sublib:		FORCE
		@for dir in $(SUBLIBS); do \
		   echo " "; \
		   echo Making library in $$dir ...; \
		   (cd $$dir; $(MAKE)) ; \
		done

lib:		$(LIB) $(DOMAINLIB) $(DOSHARED)

$(LIB):		sublib $(LIBOBJS)
		ar cruv $(LIB) $(LIBOBJS)
		$(RANLIB) $(LIB)

funmainlib.c:	$(MAINLIBOBJS) mkfunmainlib
		echo $(PROGS) | ./mkfunmainlib > funmainlib.c;

shlib:		sublib $(LIBOBJS)
		@(rm -rf $(PACKAGE)tmp; mkdir $(PACKAGE)tmp; \
		(cd $(PACKAGE)tmp && ar x ../$(LIB)); \
		CC='$(CC)' CXX=$(CXX) \
		./mklib -o $(PACKAGE) $(PACKAGE)tmp/*.o; \
		rm -rf $(PACKAGE)tmp;)

mainlib:	$(MAINLIBOBJS) funmainlib.o lex.calc.o
		@(ar cruv lib$(PACKAGE)MainLib.a \
		$(MAINLIBOBJS) funmainlib.o lex.calc.o; \
		$(RANLIB) lib$(PACKAGE)MainLib.a)

shmainlib:	mainlib
		@(rm -rf $(PACKAGE)tmp; mkdir $(PACKAGE)tmp; \
		(cd $(PACKAGE)tmp && ar x ../lib$(PACKAGE)MainLib.a); \
		CC='$(CC)' CXX='$(CXX)' \
		./mklib -o $(PACKAGE)MainLib -L. -lfuntools $(PACKAGE)tmp/*.o;\
		rm -rf $(PACKAGE)tmp;)

tclfun:		$(LIB) tclmainlib.o tclfun.o
		@(ar cruv libtclfun.a tclmainlib.o tclfun.o; \
		$(RANLIB) libtclfun.a)

shtclfun:	tclfun
		@(rm -rf $(PACKAGE)tmp; mkdir $(PACKAGE)tmp; \
		(cd $(PACKAGE)tmp && ar x ../$(LIB) && ar x ../libtclfun.a); \
		CC='$(CC)' CXX='$(CXX)' \
		./mklib -o tclfun $(PACKAGE)tmp/*.o; \
		rm -rf $(PACKAGE)tmp; \
		test -r pkgIndex.tcl && mv pkgIndex.tcl pkgIndex.tcl-old; \
		SHLIB=libtclfun.so; \
		test -r libtclfun.dylib && SHLIB=libtclfun.dylib; \
		echo "pkg_mkIndex -direct . $${SHLIB}; exit" | tclsh;)

tclfun.c:	FORCE
		echo $(PROGS) | ./mkfunmainlib -tcl > tclfun.c


tclmainlib.o:	util/tclmainlib.c
		$(CC) -c $(CC_SWITCHES) util/tclmainlib.c

funcalc:	funcalc.o lex.calc.o lib
		$(CC) $(LDFLAGS) funcalc.o lex.calc.o -o funcalc \
		$(LLIB) $(LIBS)

funcen:		funcen.o lib
		$(CC) $(LDFLAGS) funcen.o -o funcen $(LLIB) $(LIBS)

funcnts:	funcnts.o lib
		$(CC) $(LDFLAGS) funcnts.o -o funcnts $(LLIB) $(LIBS)

funcone:	funcone.o lib
		$(CC) $(LDFLAGS) funcone.o -o funcone $(LLIB) $(LIBS)

fundisp:	fundisp.o lib
		$(CC) $(LDFLAGS) fundisp.o -o fundisp $(LLIB) $(LIBS)

funhist:	funhist.o lib
		$(CC) $(LDFLAGS) funhist.o -o funhist $(LLIB) $(LIBS)

funhead:	funhead.o lib
		$(CC) $(LDFLAGS) funhead.o -o funhead $(LLIB) $(LIBS)

funimage:	funimage.o lib
		$(CC) $(LDFLAGS) funimage.o -o funimage $(LLIB) $(LIBS)

funjoin:	funjoin.o lib
		$(CC) $(LDFLAGS) funjoin.o -o funjoin $(LLIB) $(LIBS)

funmerge:	funmerge.o lib
		$(CC) $(LDFLAGS) funmerge.o -o funmerge $(LLIB) $(LIBS)

funsky:	funsky.o lib
		$(CC) $(LDFLAGS) funsky.o -o funsky $(LLIB) $(LIBS)

funtable:	funtable.o lib
		$(CC) $(LDFLAGS) funtable.o -o funtable $(LLIB) $(LIBS)

_sort:		FORCE
		@(echo " "; echo "Making in gnu ..."; cd gnu; $(MAKE))

funcalc_main.o:	funcalc.c
		$(CC) -c $(CC_SWITCHES) -Dmain="funcalc_main" \
		-o funcalc_main.o funcalc.c
funcen_main.o:	funcen.c
		$(CC) -c $(CC_SWITCHES) -Dmain="funcen_main" \
		-o funcen_main.o funcen.c

funcnts_main.o:	funcnts.c
		$(CC) -c $(CC_SWITCHES) -Dmain="funcnts_main" \
		-o funcnts_main.o funcnts.c
funcone_main.o:	funcone.c
		$(CC) -c $(CC_SWITCHES) -Dmain="funcone_main" \
		-o funcone_main.o funcone.c
fundisp_main.o:	fundisp.c
		$(CC) -c $(CC_SWITCHES) -Dmain="fundisp_main" \
		-o fundisp_main.o fundisp.c
funhist_main.o:	funhist.c
		$(CC) -c $(CC_SWITCHES) -Dmain="funhist_main" \
		-o funhist_main.o funhist.c
funhead_main.o:	funhead.c
		$(CC) -c $(CC_SWITCHES) -Dmain="funhead_main" \
		-o funhead_main.o funhead.c
funimage_main.o:	funimage.c
		$(CC) -c $(CC_SWITCHES) -Dmain="funimage_main" \
		-o funimage_main.o funimage.c
funjoin_main.o:	funjoin.c
		$(CC) -c $(CC_SWITCHES) -Dmain="funjoin_main" \
		-o funjoin_main.o funjoin.c
funmerge_main.o:	funmerge.c
		$(CC) -c $(CC_SWITCHES) -Dmain="funmerge_main" \
		-o funmerge_main.o funmerge.c
funsky_main.o:	funsky.c
		$(CC) -c $(CC_SWITCHES) -Dmain="funsky_main" \
		-o funsky_main.o funsky.c

funtable_main.o:	funtable.c
		$(CC) -c $(CC_SWITCHES) -Dmain="funtable_main" \
		-o funtable_main.o funtable.c

funcnts.plot:	funcnts_plot.tmpl
		sed -e 's#AWK#$(AWK)#g' funcnts_plot.tmpl > funcnts.plot
		chmod +x funcnts.plot

funhist.plot:	funhist_plot.tmpl
		sed -e 's#AWK#$(AWK)#g' funhist_plot.tmpl > funhist.plot
		chmod +x funhist.plot

funds9:		funds9.tmpl
		sed -e 's#AWK#$(AWK)#g;s#GNUPLOT#$(GNUPLOT)#g' funds9.tmpl > funds9
		chmod +x funds9

funtbl:		funtbl.tmpl
		sed -e 's#AWK#$(AWK)#g;' funtbl.tmpl > funtbl
		chmod +x funtbl

funindex:	funindex.tmpl
		cp -p funindex.tmpl funindex
		chmod +x funindex

funcnts.sed:	funcnts_sed.tmpl
		cp funcnts_sed.tmpl funcnts.sed
		chmod +x funcnts.sed

funtools.ds9:	funtools_ds9.tmpl
		sed -e 's#PRE#$(PRE)#g;s#POST#$(POST)#g;s#GUNZIP#$(GUNZIP)#g' funtools_ds9.tmpl > funtools.ds9

diff:
		@-(for file in "`ls *.c`";				\
		    do							\
			echo $$file;					\
			diff /soft/saord/funtools-*/$$file .;	\
		    done;)

install::	install-binaries

install::	$(DOSHARED)_install

install::
		@for dir in $(SUBDIRS); do \
		   echo " "; \
		   echo Installing in $$dir ...; \
		   (cd $$dir; $(MAKE) INSTALL_ROOT=$(INSTALL_ROOT) INCLUDE_INSTALL_DIR=$(INCLUDE_INSTALL_DIR) $@) ; \
		done

install::	install-man

install::	install-share

install::	install-data

FORCE:

# Note: before running ranlib below, must cd to target directory because
# some ranlibs write to current directory, and this might not always be
# possible (e.g. if installing as root).

# this nop-op gets executed if we are not building shared libraries
_install:

shlib_install:
	@-(for i in `ls *.so* *.dylib *.sl 2>/dev/null` ; \
	   do \
	   if [ -h $$i ] ; then \
		echo "Installing link $$i" ; \
		tar cf - $$i | (cd $(LIB_INSTALL_DIR); tar xf -) ; \
	   else \
		echo "Installing $$i" ; \
		$(INSTALL_DATA) $$i $(LIB_INSTALL_DIR)/$$i ; \
		chmod 555 $(LIB_INSTALL_DIR)/$$i; \
	   fi; \
	   done;)

install-binaries: lib $(PROGS) $(SCRIPTS) $(DS9HELPERS)
	@for i in $(LIB_INSTALL_DIR) $(INCLUDE_INSTALL_DIR) $(BIN_INSTALL_DIR) ; \
	    do \
	    if [ ! -d $$i ] ; then \
		echo "Making directory $$i"; \
		mkdir -p $$i; \
		chmod 755 $$i; \
		else true; \
		fi; \
	    done;
	@if [ "$(LIB)" ] ; then \
	    XLIB=`basename $(LIB)`; \
	    echo "Installing $$XLIB"; \
	    $(INSTALL_DATA) $$XLIB $(LIB_INSTALL_DIR)/$$XLIB; \
	    (cd $(LIB_INSTALL_DIR); $(RANLIB) $$XLIB); \
	    chmod 555 $(LIB_INSTALL_DIR)/$$XLIB; \
        fi;
	@echo "Installing funtools.h"
	@$(INSTALL_DATA) funtools.h $(INCLUDE_INSTALL_DIR)/funtools.h
	@echo "Installing funtoolsP.h"
	@$(INSTALL_DATA) funtoolsP.h $(INCLUDE_INSTALL_DIR)/funtoolsP.h
	@for i in $(PROGS) ; \
	    do \
	        echo "Installing $$i$(EXE)" ; \
		$(INSTALL_PROGRAM) $$i$(EXE) $(BIN_INSTALL_DIR)/$$i$(EXE) ; \
	    done;
	@for i in $(SCRIPTS) ; \
	    do \
	        echo "Installing $$i" ; \
		$(INSTALL_PROGRAM) $$i $(BIN_INSTALL_DIR)/$$i ; \
	    done;
	@for i in $(DS9HELPERS) ; \
	    do \
		echo "Installing $$i" ; \
		$(INSTALL_DATA) $$i $(BIN_INSTALL_DIR)/$$i ; \
	    done;
	@for i in $(FILES) ; \
	    do \
		echo "Installing $$i" ; \
		$(INSTALL_DATA) $$i $(BIN_INSTALL_DIR)/$$i ; \
	    done;

install-man:
	@if [ ! -d $(MAN_INSTALL_DIR) ] ; then \
	    echo "Making directory $(MAN_INSTALL_DIR)"; \
	    mkdir $(MAN_INSTALL_DIR); \
	    chmod 755 $(MAN_INSTALL_DIR); \
	    else true; \
	fi;
	@-(for i in `ls ./man/man?/*.?` ; \
	    do \
		B=`basename $$i`; \
		E=`echo $$i | awk -F. '{print $$NF}'`; \
		M="$(MAN_INSTALL_DIR)/man$$E"; \
		if [ ! -d $$M ] ; then \
		    echo "Making directory $$M"; \
		    mkdir $$M; \
		    chmod 755 $$M; \
		    else true; \
		fi; \
		echo "Installing $$B" ; \
		$(INSTALL_DATA) $$i $$M/$$B; \
	    done;)

install-share:
	@if [ ! -d $(MAN_SHARE_DIR) ] ; then \
	    echo "Making directory $(MAN_SHARE_DIR)"; \
	    mkdir -p $(MAN_SHARE_DIR); \
	    chmod 755 $(MAN_SHARE_DIR); \
	    else true; \
	fi;
	@-(for i in `ls ./doc/sman/fun?.*` ; \
	    do \
		B=`basename $$i`; \
		echo "Installing $$B" ; \
		$(INSTALL_DATA) $$i $(MAN_SHARE_DIR)/$$B; \
	    done;)

install-data: install-pkgconfig

install-pkgconfig:
	@-(mkdir -p $(LIB_INSTALL_DIR)/pkgconfig; \
	echo "Installing funtools.pc" ; \
	$(INSTALL_DATA) funtools.pc $(LIB_INSTALL_DIR)/pkgconfig;)

Makefile:	Makefile.in
		$(SHELL) config.status

RM =		rm -f

topclean:
		$(RM) *.a *.so *.so.? *.so.?.? *.o *.dylib \
			$(PROGS) tmain \
			$(SCRIPTS) $(DS9HELPERS) \
			$(DEVEL) *.exe \
			core core.[0-9]* errs *pure* .nfs* \
			foo* *~ *.log \#* TAGS *.E a.out errors \
			gmon.out *.pg *.bak \
			config.info config.log \
			doc/*~ doc/*.bak
		$(RM) -r autom4te.cache

binclean:
		$(RM) ./lib/* ./include/* ./bin/*

subclean:
		for dir in $(SUBDIRS); do \
		  echo making clean in subdir $$dir ; \
		  (cd $$dir; if [ -f Makefile ]; then $(MAKE) clean; fi); \
		done

clean:		topclean binclean subclean

pclean:
		$(RM) $(PROGS) $(DEVEL)

distclean:	clean
		$(RM) Makefile config.status config.cache config.log funtools.pc

Distclean:	distclean
		for dir in $(SUBDIRS); do \
		  echo making clean in $$dir ; \
		  (cd $$dir; if [ -f Makefile ]; then $(MAKE) distclean; fi); \
		done


depend:
		makedepend -- $(DEPEND_SWITCHES) -- $(SRCS)

.c.o:
		$(CC) -c $(CC_SWITCHES) $<

funopen.o:	funopen.c funtools.h funtoolsP.h
funparam.o:	funparam.c funtools.h funtoolsP.h
funim.o:	funim.c funtools.h funtoolsP.h
funtab.o:	funtab.c funtools.h funtoolsP.h
funcol.o:	funcol.c funtools.h funtoolsP.h
funcopy.o:	funcopy.c funtools.h funtoolsP.h
funutil.o:	funutil.c funtools.h funtoolsP.h
funview.o:	funview.c funtools.h funtoolsP.h
funwcs.o:	funwcs.c funtools.h funtoolsP.h
funinfo.o:	funinfo.c funtools.h funtoolsP.h
funimage.o:	funimage.c funtools.h funtoolsP.h
funhist.o:	funhist.c funtools.h funtoolsP.h
fundisp.o:	fundisp.c funtools.h funtoolsP.h
funhead.o:	funhead.c funtools.h funtoolsP.h
funcnts.o:	funcnts.c funtools.h funtoolsP.h
funcen.o:	funcen.c funtools.h funtoolsP.h
funcone.o:	funcone.c funtools.h funtoolsP.h
funjoin.o:	funjoin.c funtools.h funtoolsP.h
funmerge.o:	funmerge.c funtools.h funtoolsP.h
funsky.o:	funsky.c funtools.h funtoolsP.h
funtable.o:	funtable.c funtools.h funtoolsP.h chandra.h
funcalc.o:	funcalc.c calc.h funtools.h funtoolsP.h
		$(CC) -c $(CC_SWITCHES) $< \
		-DFUN_INCLUDE="\"-I${prefix}/include\"" \
		-DFUNCALC_CC="$(FUNCALC_CC)" \
		-DFUNCALC_CFLAGS="$(FUNCALC_CFLAGS)" \
		-DFUN_LIB="\"-L${exec_prefix}/lib -lfuntools ${EXTRA_LIBS} -lm\""
lex.calc.o:	 lex.calc.c tabcalc_c.h

headers:	tabcalc_c.h
tabcalc_c.h:	tabcalc.c
		$(RM) tabcalc_c.h
		./inc.sed TABCALC_C < tabcalc.c > tabcalc_c.h

# remake the parser
LEX =		flex -Pcalc

parser:		calc.l
		@($(LEX) calc.l; \
		sed "s/yytext_ptr/calctext_ptr/g" < lex.calc.c > nlex.calc.c; \
		mv nlex.calc.c lex.calc.c)

funtools.h:	configure.ac
		@($(RM) -r ofuntools.h; \
		MAJOR=`echo "${VERSION}" | awk -F. '{print $$1}'`; \
		MINOR=`echo "${VERSION}" | awk -F. '{print $$2}'`; \
		PATCH=`echo "${VERSION}" | awk -F. '{print $$3}'`; \
		sed "s/^#define FUN_VERSION.*/#define FUN_VERSION \"$(VERSION)\"/;s/^#define FUN_MAJOR_VERSION.*/#define FUN_MAJOR_VERSION $${MAJOR}/;s/^#define FUN_MINOR_VERSION.*/#define FUN_MINOR_VERSION $${MINOR}/;s/^#define FUN_PATCH_LEVEL.*/#define FUN_PATCH_LEVEL $${PATCH}/;" < funtools.h > nfuntools.h; \
		mv funtools.h ofuntools.h; \
		mv nfuntools.h funtools.h)


#
# Target to create a proper FUNTOOLS distribution from information in the
# master source directory.  DISTDIR must be defined to indicate where
# to put the distribution.  DISTDIR must be an absolute path name.
#

configure:	configure.ac
		autoconf

Configure:	FORCE
		@for dir in $(SUBDIRS); do \
		   if [ -x $$dir/configure ]; then \
		     echo " "; \
		     echo Autoconf in $$dir ...; \
		     (cd $$dir; autoconf) ; \
		   fi; \
		done

Confiles:	
		@(for dir in $(SUBDIRS); do \
		   echo " "; \
		   echo Copying configure files to $$dir ...; \
		   cp -p aclocal.m4 tcl.m4 gcc33.m4 \
			conf.h.in config.sub config.guess install-sh $$dir; \
		done)

dist:		configure
		($(RM) -r $(DISTDIR); \
		mkdir $(DISTDIR); \
		cp -p README INSTALL COPYING $(DISTDIR)/.; \
		cp -p *.c *.h *.l $(DISTDIR)/.; \
		cp -p Makefile.in $(DISTDIR)/.; \
		chmod 664 $(DISTDIR)/Makefile.in; \
		cp -p conf.h.in $(DISTDIR)/.; \
		chmod 664 $(DISTDIR)/conf.h.in; \
		cp -p configure.ac $(DISTDIR)/.; \
		chmod 644 $(DISTDIR)/configure.ac; \
		cp -p  *.m4 $(DISTDIR)/.; \
		chmod 644 $(DISTDIR)/*.m4; \
		cp -p configure $(DISTDIR)/.; \
		chmod 755 $(DISTDIR)/configure; \
		cp -p config.sub config.guess $(DISTDIR)/.; \
		chmod 755 $(DISTDIR)/config.sub $(DISTDIR)/config.guess; \
		cp -p saoconfig $(DISTDIR)/.; \
		chmod 775 $(DISTDIR)/saoconfig; \
		cp -p install-sh $(DISTDIR)/.; \
		chmod +x $(DISTDIR)/install-sh; \
		cp -p funtools.pc.in $(DISTDIR)/.; \
		chmod +x $(DISTDIR)/funtools.pc.in; \
		cp -p inc.sed $(DISTDIR)/.; \
		chmod +x $(DISTDIR)/inc.sed; \
		cp -p mklib $(DISTDIR)/.; \
		chmod +x $(DISTDIR)/mklib; \
		cp -p mkfunmainlib $(DISTDIR)/.; \
		chmod +x $(DISTDIR)/mkfunmainlib; \
		cp -pR util filter fitsy wcs gnu $(DISTDIR)/.;\
		cp -pR funtest txt faq $(DISTDIR)/.;\
		cp -p $(TEMPLATES) $(DISTDIR)/.; \
		cp -p $(FILES) $(DISTDIR)/.; \
		mkdir $(DISTDIR)/doc; \
		cp -p ./doc/*.html ./doc/*.c  $(DISTDIR)/doc/.; \
		cp -p ./doc/*.ps ./doc/*.pdf $(DISTDIR)/doc/.; \
		cp -p ./doc/Makefile $(DISTDIR)/doc/.; \
		cp -p ./doc/szlong.c $(DISTDIR)/doc/.; \
		mkdir $(DISTDIR)/doc/sman; \
		cp -p ./doc/sman/* $(DISTDIR)/doc/sman/.; \
		mkdir $(DISTDIR)/man; \
		cp -p -R ./man/* $(DISTDIR)/man/.)

release:	dist
		(cd $(DISTDIR); cd ..; \
		tar cf - $(DISTNAME) | \
		gzip -9 -c > $(FTPDIR)/$(DISTNAME).tar.gz)

tar:
		($(RM) -r config.cache; \
		cd ..; \
		tar cf - $(DISTNAME) | gzip -9 -c > $(DISTNAME).tar.gz)

errcheck:
		@-egrep 'error|warning|ld:|collect2:|make:' foo | egrep -v "^lex.*but not used"

itar:
		(cd doc/sman; \
		tar cf - . | gzip -9 -c > ../../../$(DISTNAME)-iman.tar.gz)

sman:
		@(cd doc && $(MAKE) index)

docs:
		@(cd doc; $(MAKE))

untar:
		(make clean; cd ..; \
		$(RM) -r o$(DISTNAME); mv $(DISTNAME) o$(DISTNAME); \
		tar xfz $(DISTNAME).tar.gz)

pure:		funcalc.pure funcen.pure funcnts.pure funcone.pure \
		fundisp.pure funhead.pure funimage.pure funhist.pure \
		funmerge.pure funsky.pure funtable.pure \
		funjoin.pure 

funcen.pure:	lib funcen.o
		purify $(CC) $(LDFLAGS) funcen.o -o funcen.pure \
		$(LLIB) $(LIBS)

funcnts.pure:	lib funcnts.o
		purify $(CC) $(LDFLAGS) funcnts.o -o funcnts.pure \
		$(LLIB) $(LIBS)

funcone.pure:	lib funcone.o
		purify $(CC) $(LDFLAGS) funcone.o -o funcone.pure \
		$(LLIB) $(LIBS)

fundisp.pure:	lib fundisp.o
		purify $(CC) $(LDFLAGS) fundisp.o -o fundisp.pure \
		$(LLIB) $(LIBS)

funhead.pure:	lib funhead.o
		purify $(CC) $(LDFLAGS) funhead.o -o funhead.pure \
		$(LLIB) $(LIBS)

funsky.pure:	lib funsky.o
		purify $(CC) $(LDFLAGS) funsky.o -o funsky.pure \
		$(LLIB) $(LIBS)

funtable.pure:	lib funtable.o
		purify $(CC) $(LDFLAGS) funtable.o -o funtable.pure \
		$(LLIB) $(LIBS)

funimage.pure:	lib funimage.o
		purify $(CC) $(LDFLAGS) funimage.o -o funimage.pure \
		$(LLIB) $(LIBS)

funhist.pure:	lib funhist.o
		purify $(CC) $(LDFLAGS) funhist.o -o funhist.pure \
		$(LLIB) $(LIBS)

funjoin.pure:	lib funjoin.o
		purify $(CC) $(LDFLAGS) funjoin.o -o funjoin.pure \
		$(LLIB) $(LIBS)

funmerge.pure:	lib funmerge.o
		purify $(CC) $(LDFLAGS) funmerge.o -o funmerge.pure \
		$(LLIB) $(LIBS)

funcalc.pure:	lib funcalc.o lex.calc.o
		purify $(CC) $(LDFLAGS) funcalc.o lex.calc.o \
		-o funcalc.pure $(LLIB) $(LIBS)

# DO NOT DELETE THIS LINE -- make depend depends on it.
