#  GNU make makefile
#

ifndef CLIPROOT
	CLIPROOT=$(shell cd ../../../; pwd)/cliproot
endif
include $(CLIPROOT)/include/Makefile.inc

LIBODBC=@LIBODBC@
LIBOOB=@LIBOOB@
CLIPINCLUDE=-I$(CLIPROOT)/include
C_FLAGS=-Wall -g -I.
#CC=gcc

TARGET=libclip-odbc$(DLLSUFF)
ATARGET=libclip-odbc.a
RTARGET=libclip-odbc$(DLLREALSUFF)
TARGET1=libclip-oob$(DLLSUFF)
RTARGET1=libclip-oob$(DLLREALSUFF)
OBJS=odbc_clip.o odbc.o

all:  $(TARGET) $(TARGET1) $(ATARGET)

$(TARGET): $(OBJS)
	$(CLIPROOT)/bin/clip_makeslib $(TARGET) $(OBJS) $(LIBODBC)

$(ATARGET): $(OBJS)
	$(CLIPROOT)/bin/clip_makelib $(ATARGET) $(OBJS) $(LIBODBC)

$(TARGET1): $(OBJS)
	[ "$(LIBOOB)" = '' ] || $(CLIPROOT)/bin/clip_makeslib $(TARGET1) $(LIBOOB) $(OBJS)

odbc_clip.o: odbc_clip.c odbc.ch
	$(CC) $(C_FLAGS) $(CLIPINCLUDE) -c odbc_clip.c

odbc.o: odbc.prg odbc.ch
	$(CLIPROOT)/bin/clip odbc.prg

install:
	$(CLIPROOT)/bin/clip_cp $(TARGET) $(DESTDIR)$(CLIPROOT)/lib
	$(CLIPROOT)/bin/clip_cp $(TARGET1) $(DESTDIR)$(CLIPROOT)/lib
	#[ "$(TARGET)" = "$(RTARGET)" ] || cp $(RTARGET) $(DESTDIR)$(CLIPROOT)/lib
	#[ "$(TARGET1)" = "$(RTARGET1)" ] || cp $(RTARGET1) $(DESTDIR)$(CLIPROOT)/lib
	mkdir -p $(DESTDIR)$(CLIPROOT)/doc/clip-odbc
	cp *.html $(DESTDIR)$(CLIPROOT)/doc/clip-odbc
	cp odbc.ch $(DESTDIR)$(CLIPROOT)/include
	mkdir -p $(DESTDIR)$(CLIPROOT)/doc/example/clip-odbc
	cp -R example/* $(DESTDIR)$(CLIPROOT)/doc/example/clip-odbc/

clean:
	rm -rf *.o odbc.c *.s *.bak *.a *.so *.dll *.exe odbc_ref.c *.ex *.nm

distclean: clean
	rm -f Makefile

