######################################################################
#  Makefile - command file for make to create CBFlib                 #
#                                                                    #
# Version 0.6 13 January 1999                                       #
#                                                                    #
#             Paul Ellis (ellis@ssrl.slac.stanford.edu) and          #
#          Herbert J. Bernstein (yaya@bernstein-plus-sons.com)       #
#                                                                    #
#                 PLEASE READ doc/CBFlib_NOTICES.txt                 #
######################################################################

#
# Program to use to pack shars
#
SHAR	= /usr/bin/shar
#SHAR	= /usr/local/bin/gshar


#
# Directories
#
ROOT     = .
LIB      = $(ROOT)/lib
BIN      = $(ROOT)/bin
SRC      = $(ROOT)/src
INCLUDE  = $(ROOT)/include
EXAMPLES = $(ROOT)/examples

#
# Include directories
#
INCLUDES = -I$(INCLUDE) -I$(SRC)

######################################################################
#  You should not need to make modifications below this line         #
######################################################################

#
# Suffixes of files to be used or built
#
.SUFFIXES:	.c .o

#
# Common dependencies
#
COMMONDEP = Makefile

#
# Source files
#
SOURCE   =  $(SRC)/cbf.c               \
            $(SRC)/cbf_alloc.c         \
            $(SRC)/cbf_binary.c        \
            $(SRC)/cbf_byte_offset.c   \
            $(SRC)/cbf_canonical.c     \
            $(SRC)/cbf_codes.c         \
            $(SRC)/cbf_compress.c      \
            $(SRC)/cbf_context.c       \
            $(SRC)/cbf_file.c          \
            $(SRC)/cbf_lex.c           \
            $(SRC)/cbf_packed.c        \
            $(SRC)/cbf_predictor.c     \
            $(SRC)/cbf_read_binary.c   \
            $(SRC)/cbf_read_mime.c     \
            $(SRC)/cbf_string.c        \
            $(SRC)/cbf_stx.c           \
            $(SRC)/cbf_tree.c          \
            $(SRC)/cbf_uncompressed.c  \
            $(SRC)/md5c.c              \
	    $(SRC)/cbfwrap.c           \
	    $(SRC)/img.c


#
# Header files
#
HEADERS   =  $(INCLUDE)/cbf.h                  \
             $(INCLUDE)/cbf_alloc.h            \
             $(INCLUDE)/cbf_binary.h           \
             $(INCLUDE)/cbf_byte_offset.h      \
             $(INCLUDE)/cbf_canonical.h        \
             $(INCLUDE)/cbf_codes.h            \
             $(INCLUDE)/cbf_compress.h         \
             $(INCLUDE)/cbf_context.h          \
             $(INCLUDE)/cbf_file.h             \
             $(INCLUDE)/cbf_lex.h              \
             $(INCLUDE)/cbf_packed.h           \
             $(INCLUDE)/cbf_predictor.h        \
             $(INCLUDE)/cbf_read_binary.h      \
             $(INCLUDE)/cbf_read_mime.h        \
             $(INCLUDE)/cbf_string.h           \
             $(INCLUDE)/cbf_stx.h              \
             $(INCLUDE)/cbf_tree.h             \
             $(INCLUDE)/cbf_uncompressed.h     \
             $(SRC)/global.h                   \
	     $(SRC)/img.h                      \
             $(SRC)/md5.h




#
# Compile the library and examples
#
all:	$(LIB) $(BIN)
	touch $(LIB)/libcbf.a
	/bin/rm $(LIB)/libcbf.a
	touch junk.o
	/bin/rm *.o
	make $(LIB)/libcbf.a
#
# Directories
#
$(LIB):
	mkdir $(LIB)

$(BIN):
	mkdir $(BIN)

#
# Parser
#
#$(SRC)/cbf_stx.c: $(SRC)/cbf.stx
#	bison -d $(SRC)/cbf.stx
#	mv $(SRC)/cbf.stx.tab.c $(SRC)/cbf_stx.c
#	mv $(SRC)/cbf.stx.tab.h $(INCLUDE)/cbf_stx.h

#
# CBF library
#
$(LIB)/libcbf.a: $(SOURCE) $(HEADERS) $(COMMONDEP)
	$(CC) $(CFLAGS) $(INCLUDES) $(WARNINGS) -c $(SOURCE)
	$(AR) cr $@ *.o

#
# cbfwrap example program put here by Harry Powell 14.07.2000
#
$(BIN)/wrapper: $(LIB)/libcbf.a $(EXAMPLES)/wrapper.f 
	${FCOMP} -O3 -c -o $(EXAMPLES)/wrapper.o $(EXAMPLES)/wrapper.f
	${FLINK} -O3 -L$(LIB) \
	-lcbf -lm -o $(BIN)/wrapper $(EXAMPLES)/wrapper.o


