##########################################################################
#                                                                        #
#      whitelister : a Whitelister Policy Daemon for Postfix             #
#      ~~~~~~~~~~~                                                       #
#                                                                        #
#  Copyright (C) 2005 AAEGE.org                                          #
#  Author : Pierre Habouzit <pierre.habouzit@m4x.org>                    #
#  ____________________________________________________________________  #
#                                                                        #
#  This program is free software; you can redistribute it and/or modify  #
#  it under the terms of the GNU General Public License as published by  #
#  the Free Software Foundation; either version 2 of the License, or     #
#  (at your option) any later version.                                   #
#                                                                        #
#  This program is distributed in the hope that it will be useful,       #
#  but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#  GNU General Public License for more details.                          #
#                                                                        #
#  You should have received a copy of the GNU General Public License     #
#  along with this program; if not, write to the Free Software           #
#  Foundation, Inc.,                                                     #
#  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               #
#                                                                        #
##########################################################################

VERSION = 0.7
PROGRAM = whitelister
PKG_DIST = $(PROGRAM)-$(VERSION)
REPO = $(shell svn info | grep URL | sed -e 's,URL *: *,,')

PKGS   = -package syslog
CFLAGS = -O2 -Wall -fPIC
CCLIB  = -cclib -lspf
CCOPT  = $(foreach opt,$(CFLAGS),-ccopt $(opt))

OCAMLC  = ocamlfind ocamlc   $(PKGS) $(CCOPT) $(CCLIB)
OCAMLOPT= ocamlfind ocamlopt $(PKGS) $(CCOPT) $(CCLIB)
OCAMLDEP= ocamlfind ocamldep $(PKGS)

BIB = str.cmxa unix.cmxa syslog.cmxa
CMX = spf.cmx policy.cmx rules.cmx server.cmx whitelister.cmx
COB = spfstubs.o

##############################################################

all: $(PROGRAM)

whitelister: $(COB) $(CMX)
	$(OCAMLOPT) -o $@ $(BIB) $^

headers: Makefile *.ml *.mli
	headache -h tpl/header $^

dist:
	@rm -rf $(PKG_DIST) $(PKG_DIST).tar.gz
	@svn export $(REPO) $(PKG_DIST)
	@rm -rf $(PKG_DIST)/debian
	@tar czf $(PKG_DIST).tar.gz $(PKG_DIST)
	@rm -rf $(PKG_DIST)
	@echo -e "\ndistribution built in $(PKG_DIST).tar.gz\n"


##############################################################

.SUFFIXES: .mli .ml .cmi .cmo .cmx .mll .mly .c .o

.c.o:
	$(OCAMLC) $(CCOPT) -c $<

.mli.cmi:
	$(OCAMLC) -c $<

.ml.cmo:
	$(OCAMLC) -c $<

.ml.cmx:
	$(OCAMLOPT) -c $<

.mll.ml:
	$(OCAMLLEX) $<

##############################################################
cleanbyte:
	rm -rf *.{cm?,o} *~

clean: cleanbyte
	rm -f $(PROGRAM)

.depend depend: *.ml *.mli
	rm -f .depend
	$(OCAMLDEP) *.ml *.mli > .depend

include .depend

