# ----------
# Makefile for src/slonik
#
#	Copyright (c) 2003-2009, PostgreSQL Global Development Group
#	Author: Jan Wieck, Afilias USA INC.
#
#	$Id: Makefile,v 1.24.2.3 2009-08-17 17:39:58 devrim Exp $
# ----------

slony_subdir = src/slonik
slony_top_builddir = ../..
SLFILEDESC="Slony command interpreter"
include $(slony_top_builddir)/Makefile.global

ifeq ($(PORTNAME), aix)
  CFLAGS += -D_LARGE_FILES
endif

CFLAGS += -I$(slony_top_builddir) -DPGSHARE="\"$(pgsharedir)\"" -DPG_VERSION_MAJOR=$(PG_VERSION_MAJOR)
ifneq ($(PG_VERSION_MAJOR), 7)
LDFLAGS += -lpgport
endif

PROG		= slonik

ifeq ($(PORTNAME), win)
PROG            = slonik.exe
endif
ifeq ($(PORTNAME), win32)
PROG            = slonik.exe
endif
LDFLAGS += $(filter -lcrypto -lz, $(LIBS))

OBJS		= 			\
	slonik.o			\
	dbutil.o			\
	parser.o $(WIN32RES)            \
	../parsestatements/scanner.o

DISTFILES = Makefile $(wildcard *.c) $(wildcard *.h) $(wildcard *.l) $(wildcard *.y)

ALL =					\
	$(PROG)


all:	$(ALL)

$(PROG):	$(OBJS)
	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROG)
slonik.o:			slonik.c slonik.h
dbutil.o:			dbutil.c slonik.h
parser.o:			parser.c scan.c

parser.c:			parser.y slonik.h
ifdef YACC
	$(YACC) -d $(YFLAGS) $<
	mv -f y.tab.c parser.c
else
	@echo "Missing yacc $< $@"
	@exit 1
endif

scan.c:				scan.l slonik.h
ifdef FLEX 
	$(FLEX) $(FLEXFLAGS) -o'$@' $<
else
	@echo "Missing flex $< $@"
	@exit
endif

clean distclean:
	rm -f $(ALL) $(OBJS) $(PROG).core

maintainer-clean:	clean
	rm -f parser.c scan.c y.tab.h

install: all installdirs
	$(INSTALL_SCRIPT) $(PROG) $(DESTDIR)$(slonbindir)


installdirs:
	$(mkinstalldirs) $(DESTDIR)$(slonbindir)


distdir: $(DISTFILES)
	mkdir $(distdir)/$(subdir)
	-chmod 777 $(distdir)/$(subdir)
	for file in $(DISTFILES) ; do \
      cp $$file $(distdir)/$(subdir)/$$file || exit; \
    done
