aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2008-05-31 11:27:02 +0200
committerJohannes Berg <johannes@sipsolutions.net>2008-05-31 11:27:02 +0200
commitd1553f1417896deea5f534518a19ad92d9ecbcb9 (patch)
tree8e4650c8127b674790ca481307885a0a06214d18
parent5a2cb64e4da591bea59a38fc4363ace858063930 (diff)
downloaddovecot-antispam-d1553f1417896deea5f534518a19ad92d9ecbcb9.tar.gz
dovecot-antispam-d1553f1417896deea5f534518a19ad92d9ecbcb9.tar.xz
dovecot-antispam-d1553f1417896deea5f534518a19ad92d9ecbcb9.zip
auto-detect dovecot version
-rw-r--r--.gitignore2
-rw-r--r--Makefile53
-rw-r--r--antispam-plugin.h6
-rw-r--r--antispam-storage.c3
-rw-r--r--defconfig21
-rw-r--r--dovecot-version.c34
6 files changed, 75 insertions, 44 deletions
diff --git a/.gitignore b/.gitignore
index 81b36f5..3651e9b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@
*.so
.config
*~
+dovecot-version.h
+dovecot-version
diff --git a/Makefile b/Makefile
index e73b6a1..866c739 100644
--- a/Makefile
+++ b/Makefile
@@ -8,16 +8,16 @@ INSTALLDIR ?= $(moduledir)/imap
CFLAGS := $(CFLAGSORIG)
# includes/flags we need for building a dovecot plugin
-CFLAGS += -DHAVE_CONFIG_H
-CFLAGS += -I$(DOVECOT)/
-CFLAGS += -I$(DOVECOT)/src/
-CFLAGS += -I$(DOVECOT)/src/lib/
-CFLAGS += -I$(DOVECOT)/src/lib-storage/
-CFLAGS += -I$(DOVECOT)/src/lib-mail/
-CFLAGS += -I$(DOVECOT)/src/lib-imap/
-CFLAGS += -I$(DOVECOT)/src/lib-dict/
-CFLAGS += -I$(DOVECOT)/src/lib-index/
-CFLAGS += -I$(DOVECOT)/src/imap/
+INCS += -DHAVE_CONFIG_H
+INCS += -I$(DOVECOT)/
+INCS += -I$(DOVECOT)/src/
+INCS += -I$(DOVECOT)/src/lib/
+INCS += -I$(DOVECOT)/src/lib-storage/
+INCS += -I$(DOVECOT)/src/lib-mail/
+INCS += -I$(DOVECOT)/src/lib-imap/
+INCS += -I$(DOVECOT)/src/lib-dict/
+INCS += -I$(DOVECOT)/src/lib-index/
+INCS += -I$(DOVECOT)/src/imap/
# output name
LIBRARY_NAME ?= lib90_$(PLUGINNAME)_plugin.so
@@ -35,16 +35,6 @@ ifeq ("$(DEBUG_VERBOSE)", "1")
CFLAGS += -DCONFIG_DEBUG_VERBOSE
endif
-# dovecot version rules
-objs += antispam-storage-$(DOVECOT_VERSION).o
-ifeq ("$(DOVECOT_VERSION)", "1.0")
-CFLAGS += -DCONFIG_DOVECOT_10
-else
-ifeq ("$(DOVECOT_VERSION)", "1.1")
-CFLAGS += -DCONFIG_DOVECOT_11
-endif
-endif
-
# backend error check
ifeq ("$(BACKEND)", "")
error: verify_config
@@ -66,20 +56,29 @@ endif
# main make rules
CFLAGS += -fPIC -shared -Wall -Wextra -DPLUGINNAME=$(PLUGINNAME)
CC ?= "gcc"
+HOSTCC ?= "gcc"
-objs += antispam-plugin.o $(BACKEND).o
-ALL = $(LIBRARY_NAME)
+objs += antispam-plugin.o antispam-storage.o $(BACKEND).o
-all: verify_config $(ALL)
+all: verify_config $(LIBRARY_NAME)
-%.o: %.c $(CONFIG) antispam-plugin.h
- $(CC) -c $(CFLAGS) -o $@ $<
+antispam-storage.o: antispam-storage.c antispam-storage-*.c $(CONFIG) antispam-plugin.h dovecot-version.h
+ $(CC) -c $(CFLAGS) $(INCS) -o $@ $<
+
+%.o: %.c $(CONFIG) antispam-plugin.h dovecot-version.h
+ $(CC) -c $(CFLAGS) $(INCS) -o $@ $<
$(LIBRARY_NAME): $(objs)
- $(CC) $(CFLAGS) $(objs) -o $(LIBRARY_NAME) $(LDFLAGS)
+ $(CC) $(CFLAGS) $(INCS) $(objs) -o $(LIBRARY_NAME) $(LDFLAGS)
+
+dovecot-version: dovecot-version.c $(CONFIG)
+ $(HOSTCC) $(INCS) -o dovecot-version dovecot-version.c
+
+dovecot-version.h: dovecot-version
+ ./dovecot-version > dovecot-version.h
clean:
- rm -f *.so *.o *~
+ rm -f *.so *.o *~ dovecot-version dovecot-version.h
install: all
install -o $(USER) -g $(GROUP) -m 0660 $(LIBRARY_NAME) $(INSTALLDIR)/
diff --git a/antispam-plugin.h b/antispam-plugin.h
index d50abf5..ff1294e 100644
--- a/antispam-plugin.h
+++ b/antispam-plugin.h
@@ -1,12 +1,12 @@
#ifndef _ANTISPAM_PLUGIN_H
#define _ANTISPAM_PLUGIN_H
-#include "config.h"
#include "lib.h"
#include "str.h"
#include "client.h"
#include "ostream.h"
#include "imap-search.h"
+#include "dovecot-version.h"
#define __stringify_1(x) #x
#define stringify(x) __stringify_1(x)
@@ -79,7 +79,7 @@ extern bool need_folder_hook;
* Dovecot version compat code
*/
-#if defined(CONFIG_DOVECOT_11)
+#if DOVECOT_VERSION_CODE(1, 1) == DOVECOT_VERSION
#define __attr_unused__ ATTR_UNUSED
#define ME(err) MAIL_ERROR_ ##err,
#define PLUGIN_ID uint32_t PLUGIN_FUNCTION(id) = 0
@@ -107,7 +107,7 @@ o_stream_create_from_fd(int fd, pool_t pool ATTR_UNUSED)
{
return o_stream_create_fd(fd, 0, TRUE);
}
-#elif defined(CONFIG_DOVECOT_10)
+#elif DOVECOT_VERSION_CODE(1, 0) == DOVECOT_VERSION
#define ME(err)
#define PLUGIN_ID
#define str_array_length(x) strarray_length(x)
diff --git a/antispam-storage.c b/antispam-storage.c
new file mode 100644
index 0000000..fa0672d
--- /dev/null
+++ b/antispam-storage.c
@@ -0,0 +1,3 @@
+#include "dovecot-version.h"
+
+#include ANTISPAM_STORAGE
diff --git a/defconfig b/defconfig
index 94cdc5b..ef22e81 100644
--- a/defconfig
+++ b/defconfig
@@ -8,20 +8,6 @@
# This file is included in Makefile, so variables like CFLAGS and LIBS can also
# be modified from here. In most cases, these lines should use += in order not
# to override previous values of the variables.
-#
-# IMPORTANT NOTE: If you change the config, you need to run 'make clean'!
-
-# Dovecot build/header directory
-# Building the plugin requires configured dovecot sources or having
-# configured it with --enable-header-install in which case you can
-# point DOVECOT= to the installed headers too.
-#DOVECOT=../dovecot-1.0.5
-#DOVECOT=../dovecot-1.1
-DOVECOT=/usr/include/dovecot
-
-# Dovecot version to build against
-DOVECOT_VERSION=1.0
-#DOVECOT_VERSION=1.1 # CURRENTLY NOT REALLY TESTED
# backend (select exactly one)
# dspam-exec - direct dspam training by calling dspam executable
@@ -33,6 +19,13 @@ DOVECOT_VERSION=1.0
#BACKEND=mailtrain
#BACKEND=crm114-exec
+# Dovecot build/header directory
+# Building the plugin requires configured dovecot sources or having
+# configured it with --enable-header-install in which case you can
+# point DOVECOT= to the installed headers too.
+#DOVECOT=../dovecot-1.0.5
+#DOVECOT=../dovecot-1.1
+DOVECOT=/usr/include/dovecot
# install directory for 'make install'
# NB no need for a final '/'
diff --git a/dovecot-version.c b/dovecot-version.c
new file mode 100644
index 0000000..82772a9
--- /dev/null
+++ b/dovecot-version.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "config.h"
+
+int main(int argc, char **argv)
+{
+ char *v = PACKAGE_STRING, *e;
+ int maj = 0, min = 0;
+
+ if (strncmp(v, "dovecot ", 8))
+ return 1;
+
+ /* skip "dovecot " */
+ v += 8;
+
+ maj = strtol(v, &e, 10);
+ if (v == e)
+ return 1;
+
+ v = e + 1;
+
+ min = strtol(v, &e, 10);
+ if (v == e)
+ return 1;
+
+ printf("/* Auto-generated file, do not edit */\n\n");
+ printf("#define DOVECOT_VERSION_CODE(maj, min) ((maj)<<8 | (min))\n\n");
+
+ printf("#define DOVECOT_VERSION 0x%.2x%.2x\n", maj, min);
+ printf("#define ANTISPAM_STORAGE \"antispam-storage-%d.%d.c\"\n", maj, min);
+
+ return 0;
+}