Description: Add --with-system-dotlock configure option.
 Original --with-dotlock patch on 2002-07-29 by Vincent Lefèvre
 <https://marc.info/?l=mutt-dev&m=102795315208049&w=2>.
 New --with-system-dotlock patch on 2005-02-03 by Tamotsu Takahashi.
Author: Tamotsu Takahashi, Vincent Lefevre <vincent@vinc17.net>
Last-Update: 2022-06-09

diff --git a/Makefile.am b/Makefile.am
index b62c3343..cf8b77bd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -54,7 +54,7 @@ mutt_DEPENDENCIES = $(MUTT_LIB_OBJECTS) $(LIBOBJS) $(LIBIMAPDEPS) \
 	$(INTLDEPS) $(LIBAUTOCRYPTDEPS)
 
 DEFS=-DPKGDATADIR=\"$(pkgdatadir)\" -DSYSCONFDIR=\"$(sysconfdir)\" \
-	-DBINDIR=\"$(bindir)\" -DMUTTLOCALEDIR=\"$(datadir)/locale\" \
+	-DDOTLOCK_PATH=\"@DOTLOCK_PATH@\" -DMUTTLOCALEDIR=\"$(datadir)/locale\" \
 	-DHAVE_CONFIG_H=1
 
 AM_CPPFLAGS=-I. -I$(top_srcdir) $(IMAP_INCLUDES) $(AUTOCRYPT_INCLUDES) $(GPGME_CFLAGS)
diff --git a/PATCHES b/PATCHES
index e69de29b..ea832bdc 100644
--- a/PATCHES
+++ b/PATCHES
@@ -0,0 +1,1 @@
+patch-20220609.tamovl.sysdotlock.1
diff --git a/configure.ac b/configure.ac
index c12bce88..7d32b22a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -578,8 +578,6 @@ else
         MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS dotlock.o"
 fi
 
-AC_SUBST(DOTLOCK_TARGET)
-
 dnl autoconf <2.60 compatibility
 if test -z "$datarootdir"; then
   datarootdir='${prefix}/share'
@@ -604,8 +602,18 @@ else
         DOTLOCK_GROUP=''
         DOTLOCK_PERMISSION=755
 fi
+
+AC_ARG_WITH(system-dotlock, AS_HELP_STRING([--with-system-dotlock=PATH],[Specify where mutt_dotlock already exists]),
+        [DOTLOCK_TARGET=''
+         DOTLOCK_GROUP=''
+         DOTLOCK_PERMISSION=755
+         DOTLOCK_PATH=$withval],
+        [DOTLOCK_PATH=$bindir/mutt_dotlock])
+
+AC_SUBST(DOTLOCK_TARGET)
 AC_SUBST(DOTLOCK_GROUP)
 AC_SUBST(DOTLOCK_PERMISSION)
+AC_SUBST(DOTLOCK_PATH)
 
 AC_ARG_WITH(domain, AS_HELP_STRING([--with-domain=DOMAIN],[Specify your DNS domain name]),
         [if test $withval != yes; then
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 0d68693b..df727a20 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -12,7 +12,7 @@ if BUILD_DOC
 BUILD_DOC_TARGETS = stamp-doc-chunked manual.html manual.txt $(INFO_DOCFILES)
 endif
 
-DEFS = -DSYSCONFDIR=\"$(sysconfdir)\" -DBINDIR=\"$(bindir)\" -DHAVE_CONFIG_H=1
+DEFS = -DSYSCONFDIR=\"$(sysconfdir)\" -DBINDIR=\"$(bindir)\" -DDOTLOCK_PATH=\"@DOTLOCK_PATH@\" -DHAVE_CONFIG_H=1
 AM_CPPFLAGS = -I. -I.. -I$(includedir) -I$(top_srcdir)
 
 MAKEDOC_CPP = $(CPP) $(AM_CPPFLAGS) $(DEFS) $(CPPFLAGS) -D_MAKEDOC -C
diff --git a/init.h b/init.h
index e3d43851..77486318 100644
--- a/init.h
+++ b/init.h
@@ -1053,7 +1053,7 @@ struct option_t MuttVars[] = {
   ** filtered message is read from the standard output.
   */
 #if defined(DL_STANDALONE) && defined(USE_DOTLOCK)
-  { "dotlock_program",  DT_CMD_PATH, R_NONE, {.p=&MuttDotlock}, {.p=BINDIR "/mutt_dotlock"} },
+  { "dotlock_program",  DT_CMD_PATH, R_NONE, {.p=&MuttDotlock}, {.p=DOTLOCK_PATH} },
   /*
   ** .pp
   ** Contains the path of the \fCmutt_dotlock(1)\fP binary to be used by
