#
#  Standard macros
#
#----------------------------------------------------------------------------
# Project specific path defintions.
#----------------------------------------------------------------------------
LIBINCLDIR = ../include
LIBINSTDIR = ../lib

PROJDIR    = .
SRC        = $(PROJDIR)/src
INCL       = $(PROJDIR)/include
OBJ        = $(PROJDIR)/obj
LIB        = $(PROJDIR)/lib
BIN        = $(PROJDIR)/bin


#----------------------------------------------------------------------------
# LINCLUDES and LDEFINES are appended to CFLAGS and C++FLAGS
#----------------------------------------------------------------------------
LINCLUDES = -I$(INCL) -I$(LIBINCLDIR) 
#
# LDEFINES is added to compilation command line.
#
LDEFINES  = 

#----------------------------------------------------------------------------
# Include the appropriate compiler/platform definitions ...
#----------------------------------------------------------------------------
include ../etc/Makefile.platform

LIBS       = $(LIB)/libbtree.a
#
#
TARGET1    = $(BIN)/test
#
SRCFILES  = $(SRC)/btree.c \
				$(SRC)/test.c
#
HFILES     = $(INCL)/btree.h 

#
OBJ1       = $(OBJ)/test.o
# 
#
OBJS       = $(OBJ)/btree.o

ALLTARGETS = $(TARGET1)

all:	$(TARGET1) $(OBJ1)

$(LIBS):	$(OBJS) $(HFILES)
		$(AR) $(AR_PUTFLAGS) $(LIBS) $(OBJS)
		$(RANLIB) $(LIBS)
		@echo $(LIBS) " is up to date."

install: $(LIBS)
	$(INSTALL) $(INSTALLOPTS) $(HFILES) $(LIBINCLDIR)/.
	$(INSTALL) $(INSTALLOPTS) $(LIBS) $(LIBINSTDIR)/.

#
#  Making applications
#
$(TARGET1): $(LIBS) $(HFILES) $(OBJ1)
#	$(CCC) $(C++FLAGS) -o $@  $(OBJ1) $(LDFLAGS) $(LIBS)
	$(CC) $(CFLAGS) -o $@  $(OBJ1) $(LIBS) $(LDFLAGS)

#
# Creating object files
#
##
##	

test:  $(OBJ)/test.o $(LIBS)
	$(CC) $(CFLAGS) -o $(BIN)/$@ $(OBJ)/test.o $(LIBS) $(LDFLAGS)
	$(BIN)/test

$(OBJ)/test.o : $(SRC)/test.c
#	$(CCC) $(C++FLAGS) -c $(SRC)/test.c -o $@ 
	$(CC) $(CFLAGS) -c $(SRC)/test.c -o $@ 

$(OBJ)/btree.o : $(SRC)/btree.c
#	$(CCC) $(C++FLAGS) -c $(SRC)/btree.c -o $@ 
	$(CC) $(CFLAGS) -c $(SRC)/btree.c -o $@ 

clean :
	@rm -f core $(OBJ)/*.o 
	@rm -f $(ALLTARGETS)
	@rm -f $(LIBS)
	@cd ..; rm -f $(HFILES)
	@cd ..; rm -f $(LIBS)

export:
	mkdir -p $(EXPORT_DIR)
	@cd $(EXPORT_DIR); mkdir -p $(INCL)
	$(EXPORT) $(EXPORT_LIST) $(HFILES) $(EXPORT_DIR)/$(INCL)
	@cd $(EXPORT_DIR); mkdir -p $(SRC)
	$(EXPORT) $(EXPORT_LIST) $(SRCFILES) $(EXPORT_DIR)/$(SRC)
	@cd $(EXPORT_DIR); mkdir -p $(BIN)
	@cd $(EXPORT_DIR); mkdir -p $(LIB)
	@cd $(EXPORT_DIR); mkdir -p $(OBJ)
	@cp Makefile $(EXPORT_DIR)
