#!/usr/bin/make -f
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/rules/ocaml.mk
include /usr/share/cdbs/1/class/makefile.mk

PKGNAME = libocamlnet-ocaml-dev

DESTDIR = $(CURDIR)/debian/tmp
OCAMLFIND_DESTDIR = $(DESTDIR)$(OCAML_STDLIB_DIR)

DEB_MAKE_CLEAN_TARGET = distclean
DEB_MAKE_BUILD_TARGET = all
DEB_MAKE_INSTALL_TARGET = install DESTDIR=$(DESTDIR) OCAMLFIND_DESTDIR=$(OCAMLFIND_DESTDIR)

ifeq ($(OCAML_HAVE_OCAMLOPT),yes)
DEB_MAKE_BUILD_TARGET += opt
endif

DEB_DH_COMPRESS_ARGS = -X.ml
# OCaml custom bytecode binaries can't be striped
DEB_STRIP_EXCLUDE += usr/bin/netplex-admin
DEB_STRIP_EXCLUDE += usr/bin/ocamlrpcgen

# For Debian GNU/kFreeBSD and GNU/Hurd ports
NO_RPC_AUTH_LOCAL  = $(findstring freebsd,$(DEB_HOST_ARCH))
NO_RPC_AUTH_LOCAL += $(findstring hurd,$(DEB_HOST_ARCH))

CFGFLAGS =
CFGFLAGS += -enable-gtk2 -enable-ssl
CFGFLAGS += -with-nethttpd -prefer-netcgi2 -with-rpc-auth-dh
CFGFLAGS += -bindir /usr/bin -datadir /usr/share/ocamlnet
CFGFLAGS += -enable-apache -apache /usr/sbin/apache2 -apxs /usr/bin/apxs2

configure/$(PKGNAME):: debian/configure-stamp
debian/configure-stamp:
	./configure $(CFGFLAGS)
ifneq "" "$(NO_RPC_AUTH_LOCAL)"
	sed -i -n '/rpc.auth.local/!p' debian/*.install
endif
	touch debian/configure-stamp
clean::
	rm -f debian/configure-stamp
	rm -Rf src/netcgi2-apache/.libs/
