--- ./Makefile.am.orig	2011-09-25 16:53:42.000000000 +0000
+++ ./Makefile.am	2012-05-12 08:11:36.000000000 +0000
@@ -34,6 +34,8 @@
 	path.c imacs.c sysintf.c parse.c getinp.c quit.c state.c\
 	dmdump.c macparse.c rulparse.c percent.c function.c
 
+BUILT_SOURCES = dmakeroot.h
+
 # set the include path found by configure
 INCLUDES = -I$(top_srcdir) -I$(top_builddir) \
            -I$(top_srcdir)/@OS_TYPE@/@OS_VERSION@ -I$(top_srcdir)/@OS_TYPE@
@@ -59,6 +61,10 @@
 INCLUDES += -I$(top_srcdir)/@OS_TYPE@/@OS_VERSION@ -I$(top_srcdir)/@OS_TYPE@
 endif
 
-SUBDIRS = startup tests
+SUBDIRS = startup man tests
 
 EXTRA_DIST = NEWS ChangeLog
+
+dmakeroot.h: dmakeroot.h.in
+	$(SED) -e 's%@DMAKEROOT_H_LINE1\@%"DMAKEROOT := ${dmakerootprefix}/startup",%' $< > $@
+
--- ./configure.in.orig	2011-09-25 16:53:42.000000000 +0000
+++ ./configure.in	2012-05-12 08:10:34.000000000 +0000
@@ -21,19 +21,24 @@
 
 dnl Extra parameters
 AC_ARG_ENABLE(dbug,
-[  --enable-dbug:          Enable build with dbug macros.
-],,)
+[AS_HELP_STRING([--enable-dbug],[Enable build with dbug macros.])],,
+)
 
 AC_ARG_ENABLE(spawn,
-[  --enable-spawn:         Enables the use of spawn instead of fork/exec
-                          if it is supported.
-],,)
+[AS_HELP_STRING([--enable-spawn],[Enables the use of spawn instead of fork/exec, if it is supported.])],,
+)
+
+AC_ARG_WITH(dmakeroot,
+[AS_HELP_STRING([--with-dmakeroot],[Use DIR as dataroot prefix @<:@default=\${pkgdatadir}@:>@])],,
+)
+
 dnl Checks for programs.
 AC_PROG_CPP
 AC_PROG_INSTALL
 AC_PROG_LN_S
 AC_PROG_MAKE_SET
 AC_PROG_RANLIB
+AC_PROG_SED
 
 dnl Checks for utilities.
 AC_PROG_AWK
@@ -160,26 +165,36 @@
    AC_MSG_RESULT([no])
 fi
 
-dnl Predefine the DMAKEROOT macro for unix targets.
-eval dmakerootprefix="$datarootdir"
-# $datadir is ${prefix}/share if not overridden
-test "x$dmakerootprefix" != "x${dmakerootprefix##NONE}" && dmakerootprefix=${ac_default_prefix}/share
-
+dnl Define the DMAKEROOT macro differently for unix targets.
 if test x$OS_TYPE = xunix; then
-DMAKEROOT_H_LINE1='"DMAKEROOT := '${dmakerootprefix}'/startup",'
+    dmakerootprefix='${pkgdatadir}'
+else
+    dmakerootprefix='${datadir}'
 fi
-AC_SUBST(DMAKEROOT_H_LINE1)
+case X$with_dmakeroot in
+X|Xyes|Xno) ;;
+*) dmakerootprefix=$with_dmakeroot
+esac
+AC_SUBST(dmakerootprefix)
 
 dnl List (all possible) *.in files
-AC_CONFIG_FILES(dmakeroot.h Makefile startup/config.mk \
-		startup/Makefile startup/unix/Makefile \
-		startup/unix/linux/Makefile startup/unix/solaris/Makefile \
-		startup/unix/macosx/Makefile startup/unix/sysvr4/Makefile \
-		startup/unix/cygwin/Makefile \
-		startup/unix/os2/Makefile \
-		startup/winnt/Makefile startup/winnt/mingw/Makefile \
-		startup/winnt/msvc6/Makefile \
-		tests/Makefile)
+AC_CONFIG_FILES([
+	startup/config.mk
+	Makefile
+	man/Makefile
+	startup/Makefile
+	startup/unix/Makefile
+	startup/unix/cygwin/Makefile
+	startup/unix/linux/Makefile
+	startup/unix/macosx/Makefile
+	startup/unix/os2/Makefile
+	startup/unix/solaris/Makefile
+	startup/unix/sysvr4/Makefile
+	startup/winnt/Makefile
+	startup/winnt/mingw/Makefile
+	startup/winnt/msvc6/Makefile
+	tests/Makefile
+])
 
 dnl Checks for libraries.
 
--- ./man/Makefile.am.orig	2012-05-12 08:10:11.000000000 +0000
+++ ./man/Makefile.am	2012-05-12 08:10:11.000000000 +0000
@@ -0,0 +1,7 @@
+man1_MANS = dmake.1
+
+dmake.1: dmake.tf
+	$(LN_S) $< $@
+
+EXTRA_DIST = dmake.nc dmake.tf readme
+
--- ./startup/Makefile.am.orig	2011-09-25 16:53:38.000000000 +0000
+++ ./startup/Makefile.am	2012-05-12 08:10:11.000000000 +0000
@@ -1,5 +1,5 @@
 
-startupdir = $(datadir)/startup
+startupdir = $(pkgdatadir)/startup
 
 startup_DATA = startup.mk config.mk
 
--- ./startup/unix/Makefile.am.orig	2011-09-25 16:53:38.000000000 +0000
+++ ./startup/unix/Makefile.am	2012-05-12 08:10:11.000000000 +0000
@@ -1,5 +1,5 @@
 
-startupdir = $(datadir)/startup/unix
+startupdir = $(pkgdatadir)/startup/unix
 
 startup_DATA = macros.mk recipes.mk
 
--- ./startup/unix/cygwin/Makefile.am.orig	2011-09-25 16:53:38.000000000 +0000
+++ ./startup/unix/cygwin/Makefile.am	2012-05-12 08:10:11.000000000 +0000
@@ -1,4 +1,4 @@
-startupdir = $(datadir)/startup/unix/cygwin
+startupdir = $(pkgdatadir)/startup/unix/cygwin
 
 startup_DATA = macros.mk 
 
--- ./startup/unix/linux/Makefile.am.orig	2011-09-25 16:53:38.000000000 +0000
+++ ./startup/unix/linux/Makefile.am	2012-05-12 08:10:11.000000000 +0000
@@ -1,5 +1,5 @@
 
-startupdir = $(datadir)/startup/unix/linux
+startupdir = $(pkgdatadir)/startup/unix/linux
 
 startup_DATA = macros.mk 
 
--- ./startup/unix/macosx/Makefile.am.orig	2011-09-25 16:53:38.000000000 +0000
+++ ./startup/unix/macosx/Makefile.am	2012-05-12 08:10:11.000000000 +0000
@@ -1,5 +1,5 @@
 
-startupdir = $(datadir)/startup/unix/macosx
+startupdir = $(pkgdatadir)/startup/unix/macosx
 
 startup_DATA = macros.mk 
 
--- ./startup/unix/os2/Makefile.am.orig	2011-09-25 16:53:38.000000000 +0000
+++ ./startup/unix/os2/Makefile.am	2012-05-12 08:10:11.000000000 +0000
@@ -1,5 +1,5 @@
 
-startupdir = $(datadir)/startup/unix/os2
+startupdir = $(pkgdatadir)/startup/unix/os2
 
 startup_DATA = macros.mk 
 
--- ./startup/unix/solaris/Makefile.am.orig	2011-09-25 16:53:38.000000000 +0000
+++ ./startup/unix/solaris/Makefile.am	2012-05-12 08:10:11.000000000 +0000
@@ -1,5 +1,5 @@
 
-startupdir = $(datadir)/startup/unix/solaris
+startupdir = $(pkgdatadir)/startup/unix/solaris
 
 startup_DATA = macros.mk 
 
--- ./startup/unix/sysvr4/Makefile.am.orig	2011-09-25 16:53:38.000000000 +0000
+++ ./startup/unix/sysvr4/Makefile.am	2012-05-12 08:10:11.000000000 +0000
@@ -1,5 +1,5 @@
 
-startupdir = $(datadir)/startup/unix/sysvr4
+startupdir = $(pkgdatadir)/startup/unix/sysvr4
 
 startup_DATA = macros.mk 
 
