######################################################################
#  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                 #
######################################################################


#
# Set the compiler and flags
#
CC	= cc
#CC	= gcc
CFLAGS	= -g

#
# Directories
#
ROOT     = ..
LIB      = ${ROOT}/libcbf.a
SRC      = ${ROOT}/src
INCLUDE  = ${ROOT}/include 

#
# 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_ascii.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)/cbf_write.c         \
            $(SRC)/cbf_write_binary.c  \
            $(SRC)/md5c.c
            
#
# Header files
#
HEADERS   =  ../include/cbf.h                  \
             ../include/cbf_alloc.h            \
             ../include/cbf_ascii.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     \
             ../include/cbf_write.h            \
             ../include/cbf_write_binary.h     \
             $(SRC)/global.h                   \
             $(SRC)/md5.h

#
# Compile the library and examples
#
all:	$(LIB) clean

#
# 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): $(SOURCE) $(MAROBJ) $(HEADERS) $(COMMONDEP)
	-rm -f *.o
	$(CC) $(CFLAGS) $(INCLUDES) $(WARNINGS) -c $(SOURCE)
	$(AR) cr $(LIB) *.o

#
# makecbf example program
#
#
# Remove all non-source files
#
empty:  clean
	@-rm -f  $(LIB)

#
# Remove temporary files
#
clean:
	@-rm -f core 
	@-rm -f *.o
	@-rm -f *.u
