# vim: set noexpandtab :

INCLUDES = -I/usr/local/include -I/usr/include/pgsql -I/usr/include/pgsql/internal -I/usr/local/pgsql/include/internal -I/usr/include/xbase -I/usr/local/pgsql/include -I/usr/local/include/xbase
OPTIMIZE=-O2
CFLAGS = -g -Wall $(OPTIMIZE)
CFLAGS += -Wno-deprecated
#CFLAGS = -g -Wall
#CFLAGS = -g -ggdb -Wall
# for xbase sys/locking problem in 1.8.0a
CFLAGS += -DHAVE_CONFIG_H
LIBS = -L/usr/local/pgsql/lib -lpq -lxbase

ifeq ($(OSTYPE),solaris)
# uncomment for Solaris
LIBS += -lsocket -lnsl
prefix=/usr/local
else
# -- LINUX DEFS --
LIBS += -lcrypt
CFLAGS += -DLINUX
prefix=/usr
endif

# CFLAGS += -static
CP=cp
CC=gcc
CXX=g++
INSTALL=/usr/bin/install -c

PROGS = pg2xbase xbase2pg xbaseconv xbasenew
HEADERS = xbase2pg.hh

convtable=$(prefix)/share/pg2xbase/convenctable

all: $(PROGS)

xbaseconv: xbaseconv.cpp $(HEADERS)
	$(CXX) $(INCLUDES) $(CFLAGS) -DCONVTABLE=\"$(convtable)\" -o $@ xbaseconv.cpp $(LIBS)
	chmod 0755 $@

xbasenew: xbasenew.cpp $(HEADERS)
	$(CXX) $(INCLUDES) $(CFLAGS) -DCONVTABLE=\"$(convtable)\" -o $@ xbasenew.cpp $(LIBS)
	chmod 0755 $@

pg2xbase: pg2xbase.cpp $(HEADERS)
	$(CXX) $(INCLUDES) $(CFLAGS) -o $@ pg2xbase.cpp $(LIBS)
	chmod 0755 $@

xbase2pg: xbase2pg.cpp $(HEADERS)
	$(CXX) $(INCLUDES) $(CFLAGS) -o $@ xbase2pg.cpp $(LIBS)
	chmod 0755 $@

clean:
	rm -f $(PROGS)

copydisk:
	mcopy *.cpp convenctable Makefile a:

dist:
	tar cvf - README INSTALL COPYING-2.0 *.h *.hh *.cpp *.1 convenctable Makefile | gzip -c > xbase2pg.tgz

install: xbase2pg pg2xbase xbasenew xbaseconv
	mkdir -p $(prefix)/bin/ $(prefix)/man/man1/
	mkdir -p $(prefix)/share/pg2xbase
	$(CP) $(PROGS) $(prefix)/bin/
	$(CP) convenctable $(convtable)
	$(CP) xbase2pg.1 pg2xbase.1 xbaseconv.1 xbasenew.1 $(prefix)/man/man1/
	
