########################################################################
TARGET	= libqlib2.a
TARGET2	= libqlib2.debug.a
DIR	= qlib2

SRCS	= qlib2_version.c drm_utils.c ms_utils.c ms_pack.c ms_unpack.c pack.c \
	qda_utils.c qtime.c sdr_utils.c unpack.c qutils.c 


HDR =	qlib2.h

HDRS =	qdefines.h msdatatypes.h timedef.h \
	qsteim.h sdr.h qda.h seismo.h data_hdr.h \
	qtime.h qutils.h qda_utils.h drm_utils.h sdr_utils.h \
	ms_utils.h ms_pack.h pack.h ms_unpack.h unpack.h
	
FHDR =	qlib2.inc

FHDRS =	qdefines.inc data_hdr.inc qfortran.inc

OBJS	= $(SRCS:%.c=%.o)

INCDIR= /usr/local/include
LIBDIR=	/usr/local/lib
MANDIR=	/usr/local/man
MANEXT=	3

RANLIB	= ranlib

.PRECIOUS:	$(TARGET)

BINDIR	= /usr/local/bin
MANDIR	= /usr/local/man
MANEXT	= 1

CC	= gcc 
COPT	= -O

# -Dfortran_suffix is required for fortran Compilers that use the BSD 
# convention of appending a "_" suffix to the subroutine or function name.
# -Dqlib2_fortran is required to compile the fortran interface routines.
# -DSUNOS4 is required for SunOS 4.1.x.
CFLAGS	= -Dfortran_suffix -Dqlib2_fortran  -DNO_LEAPSECONDS -g
#CFLAGS	= -Dfortran_suffix -Dqlib2_fortran -DSUNOS4

$(TARGET)  := CFLAGS += $(COPT)
$(TARGET2) := CFLAGS += 

########################################################################

all:	$(HDR) $(FHDR) $(TARGET) $(TARGET2)

$(HDR):	$(HDRS)
	cat $(HDRS)  | grep -v '#include "'> $@

$(FHDR): $(FHDRS)
	cat $(FHDRS) | grep -v '#include "'> $@

$(TARGET):	$(TARGET)($(OBJS))
	$(RANLIB) $@

$(TARGET2):	$(TARGET2)($(OBJS))
	$(RANLIB) $@

install_all:	install install_leapseconds install_man

install: #	$(HDR) $(FHDR) $(TARGET) $(TARGET2) leapseconds
	@echo QLIB2: Uncomment lines in qlib2/Makefile to install qlib2 
#	cp $(HDR) $(FHDR) drm_seismo.h $(INCDIR)/
#	cp $(TARGET) $(LIBDIR)/
#	(cd $(LIBDIR); $(RANLIB) $(TARGET))
#	cp $(TARGET2) $(LIBDIR)/
#	(cd $(LIBDIR); $(RANLIB) $(TARGET2))

install_leapseconds:	leapseconds
	cp leapseconds $(LIBDIR)/leapseconds

install_man:	qlib2.man
	cp qlib2.man $(MANDIR)/man$(MANEXT)/qlib2.$(MANEXT)
	
clean:
	rm -f *.o $(TARGET) $(TARGET2) $(HDR) $(FHDR)

veryclean:	clean
		-rm *~ *%

tar:	$(TARGET)
	(cd ..; tar cf - $(DIR)/*.c $(DIR)/*.h $(DIR)/Makefile \
		$(DIR)/*.inc $(DIR)/*.man $(DIR)/$(TARGET) \
		$(DIR)/README $(DIR)/CHANGES $(DIR)/leapseconds ) \
	| gzip > /tmp/$(DIR).tar.gz

$(QLIB2):	FORCE
	(cd ../qlib2; make)

FORCE:

cleandepend:
	makedepend

depend:	$(HDR) $(FHDR)
	makedepend $(CFLAGS) *.c
	sed -e "s/^[^ 	]*\.o/$(TARGET)(&)/" < Makefile > Makefile.new \
		&& mv Makefile.new Makefile

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