  PKGREQ?=		${PKGDIR}/pkg-req
  PKGMESSAGE?=	${PKGDIR}/pkg-message
  
-@@ -2493,6 +2500,42 @@
+@@ -2492,6 +2500,48 @@
  
  .if !defined(PKG_ARGS)
  PKG_ARGS=		-v -c -${COMMENT:Q} -d ${DESCR} -f ${TMPPLIST} -p ${PREFIX} -P "`cd ${.CURDIR} && ${MAKE} actual-package-depends | ${GREP} -v -E ${PKG_IGNORE_DEPENDS} | ${SORT} -u -t : -k 2`" ${EXTRA_PKG_ARGS} $${_LATE_PKG_ARGS}
 +.if defined(PKGNG)
 +PKG_ARGS+= -n ${PKGNAME}
++.if defined(MAINTAINER)
++PKG_ARGS+= -r ${MAINTAINER}
++.endif
++.if defined(WWW)
++PKG_ARGS+= -w ${WWW}
++.endif
 +.if exists(${PKGMESSAGE})
 +PKG_ARGS+= -M ${PKGMESSAGE}
 +.endif

 	@${DO_NADA}
 .endif
 .endif

 .if !defined(NO_MTREE)
 PKG_ARGS+=		-m ${MTREE_FILE}
 .endif
@@ -2501,6 +2551,9 @@
 .if defined(CONFLICTS) && !defined(DISABLE_CONFLICTS)
 PKG_ARGS+=		-C "${CONFLICTS}"
 .endif
+.if defined(CONFLICTS_INSTALL) && !defined(DISABLE_CONFLICTS)
+PKG_ARGS+=		-C "${CONFLICTS_INSTALL}"
+.endif
 .endif
 .if defined(PKG_NOCOMPRESS)
 PKG_SUFX?=		.tar
@@ -3077,12 +3130,8 @@
 	@${FALSE}
 .endif
 _MLINKS=	${_MLINKS_PREPEND}
-# XXX 20040119 This next line should read:
-# .for lang in ${MANLANG:S%^%man/%:S%^man/""$%man%}
-# but there is currently a bug in make(1) that prevents the double-quote
-# substitution from working correctly.  Once that problem is addressed,
-# and has had a enough time to mature, this hack should be removed.
-.for lang in ${MANLANG:S%^%man/%:S%^man/""$%man%:S%^man/"$%man%}
+
+.for lang in ${MANLANG:S%^%man/%:S%^man/""$%man%}
 .for ___pmlinks in ${__pmlinks}
 .for __lang in ${lang}
 _MLINKS+=	${___pmlinks:S// /g}
@@ -3100,12 +3149,7 @@
 .endif
 .endfor
 
-# XXX 20040119 This next line should read:
-# .for manlang in ${MANLANG:S%^%man/%:S%^man/""$%man%}
-# but there is currently a bug in make(1) that prevents the double-quote
-# substitution from working correctly.  Once that problem is addressed,
-# and has had a enough time to mature, this hack should be removed.
-.for manlang in ${MANLANG:S%^%man/%:S%^man/""$%man%:S%^man/"$%man%}
+.for manlang in ${MANLANG:S%^%man/%:S%^man/""$%man%}
 
 .for sect in 1 2 3 4 5 6 7 8 9 L N
 # MAN${sect} is for man pages installed for all languages in MANLANG for a given
@@ -3411,9 +3455,9 @@
 .endif
 
 # Disable install
-.if defined(NO_INSTALL) && !target(install)
-install: build
-	@${TOUCH} ${TOUCH_FLAGS} ${INSTALL_COOKIE}
+.if defined(NO_INSTALL) && !target(do-install)
+do-install:
+	@${DO_NADA}
 .endif
 
 # Disable package
@@ -3442,8 +3486,6 @@
 
 # Pre-everything
 
-# XXX MCL suggests deprecating this in favor of something
-# less likely to be abused by overloading
 pre-everything::
 	@${DO_NADA}
 
@@ -3464,9 +3506,6 @@
 .endif
 .if defined(_OPTIONS_READ)
 	@${ECHO_MSG} "===>  Found saved configuration for ${_OPTIONS_READ}"
-.if ${OPTIONSFILE} != ${OPTIONSFILE}
-	@${ECHO_MSG} "===>  *** CAUTION *** Using wrong configuration file ${OPTIONSFILE}"
-.endif
 .endif
 
 
@@ -3756,6 +3795,11 @@
 	fi
 .endif
 
+.if !target(configure-autotools)
+configure-autotools:
+	@${DO_NADA}
+.endif
+
 .if !target(run-autotools)
 run-autotools:
 	@${DO_NADA}
@@ -3826,9 +3870,41 @@
 # Check conflicts
 
 .if !target(check-conflicts)
-check-conflicts:
-.if defined(CONFLICTS) && !defined(DISABLE_CONFLICTS)
-	@found=`${PKG_INFO} -I ${CONFLICTS:C/.+/'&'/} 2>/dev/null | ${AWK} '{print $$1}'`; \
+check-conflicts: check-build-conflicts check-install-conflicts
+.endif
+
+.if !target(check-build-conflicts)
+check-build-conflicts:
+.if ( defined(CONFLICTS) || defined(CONFLICTS_BUILD) ) && !defined(DISABLE_CONFLICTS) && !defined(DEFER_CONFLICTS_CHECK)
+	@found=`${PKG_INFO} -I ${CONFLICTS:C/.+/'&'/} ${CONFLICTS_BUILD:C/.+/'&'/} 2>/dev/null | ${AWK} '{print $$1}'`; \
+	conflicts_with=; \
+	for entry in $${found}; do \
+		if ${PKG_INFO} -e $${entry} ; then \
+			prfx=`${PKG_INFO} -q -p "$${entry}" 2> /dev/null | ${SED} -ne '1s/^@cwd //p'`; \
+			orgn=`${PKG_INFO} -q -o "$${entry}" 2> /dev/null`; \
+			if [ "/${PREFIX}" = "/$${prfx}" -a "/${PKGORIGIN}" != "/$${orgn}" ]; then \
+				conflicts_with="$${conflicts_with} $${entry}"; \
+			fi; \
+		fi; \
+	done; \
+	if [ -n "$${conflicts_with}" ]; then \
+		${ECHO_MSG}; \
+		${ECHO_MSG} "===>  ${PKGNAME} conflicts with installed package(s): "; \
+		for entry in $${conflicts_with}; do \
+			${ECHO_MSG} "      $${entry}"; \
+		done; \
+		${ECHO_MSG}; \
+		${ECHO_MSG} "      They will not build together."; \
+		${ECHO_MSG} "      Please remove them first with pkg_delete(1)."; \
+		exit 1; \
+	fi
+.endif
+.endif
+
+.if !target(identify-install-conflicts)
+identify-install-conflicts:
+.if ( defined(CONFLICTS) || defined(CONFLICTS_INSTALL) ) && !defined(DISABLE_CONFLICTS)
+	@found=`${PKG_INFO} -I ${CONFLICTS:C/.+/'&'/} ${CONFLICTS_INSTALL:C/.+/'&'/} 2>/dev/null | ${AWK} '{print $$1}'`; \
 	conflicts_with=; \
 	for entry in $${found}; do \
 		if ${PKG_INFO} -e $${entry} ; then \
@@ -3847,10 +3923,62 @@
 		done; \
 		${ECHO_MSG}; \
 		${ECHO_MSG} "      They install files into the same place."; \
+		${ECHO_MSG} "      You may want to stop build with Ctrl + C."; \
+		sleep 10; \
+	fi
+.endif
+.endif
+
+.if !target(check-install-conflicts)
+check-install-conflicts:
+.if ( defined(CONFLICTS) || defined(CONFLICTS_INSTALL) || ( defined(CONFLICTS_BUILD) && defined(DEFER_CONFLICTS_CHECK) ) ) && !defined(DISABLE_CONFLICTS) 
+.if defined(DEFER_CONFLICTS_CHECK)
+	@found=`${PKG_INFO} -I ${CONFLICTS:C/.+/'&'/} ${CONFLICTS_BUILD:C/.+/'&'/} ${CONFLICTS_INSTALL:C/.+/'&'/} 2>/dev/null | ${AWK} '{print $$1}'`; \
+	conflicts_with=; \
+	for entry in $${found}; do \
+		if ${PKG_INFO} -e $${entry} ; then \
+			prfx=`${PKG_INFO} -q -p "$${entry}" 2> /dev/null | ${SED} -ne '1s/^@cwd //p'`; \
+			orgn=`${PKG_INFO} -q -o "$${entry}" 2> /dev/null`; \
+			if [ "/${PREFIX}" = "/$${prfx}" -a "/${PKGORIGIN}" != "/$${orgn}" ]; then \
+				conflicts_with="$${conflicts_with} $${entry}"; \
+			fi; \
+		fi; \
+	done; \
+	if [ -n "$${conflicts_with}" ]; then \
+		${ECHO_MSG}; \
+		${ECHO_MSG} "===>  ${PKGNAME} conflicts with installed package(s): "; \
+		for entry in $${conflicts_with}; do \
+			${ECHO_MSG} "      $${entry}"; \
+		done; \
+		${ECHO_MSG}; \
 		${ECHO_MSG} "      Please remove them first with pkg_delete(1)."; \
 		exit 1; \
 	fi
-.endif  # CONFLICTS
+.else
+	@found=`${PKG_INFO} -I ${CONFLICTS:C/.+/'&'/} ${CONFLICTS_INSTALL:C/.+/'&'/} 2>/dev/null | ${AWK} '{print $$1}'`; \
+	conflicts_with=; \
+	for entry in $${found}; do \
+		if ${PKG_INFO} -e $${entry} ; then \
+			prfx=`${PKG_INFO} -q -p "$${entry}" 2> /dev/null | ${SED} -ne '1s/^@cwd //p'`; \
+			orgn=`${PKG_INFO} -q -o "$${entry}" 2> /dev/null`; \
+			if [ "/${PREFIX}" = "/$${prfx}" -a "/${PKGORIGIN}" != "/$${orgn}" ]; then \
+				conflicts_with="$${conflicts_with} $${entry}"; \
+			fi; \
+		fi; \
+	done; \
+	if [ -n "$${conflicts_with}" ]; then \
+		${ECHO_MSG}; \
+		${ECHO_MSG} "===>  ${PKGNAME} conflicts with installed package(s): "; \
+		for entry in $${conflicts_with}; do \
+			${ECHO_MSG} "      $${entry}"; \
+		done; \
+		${ECHO_MSG}; \
+		${ECHO_MSG} "      They install files into the same place."; \
+		${ECHO_MSG} "      Please remove them first with pkg_delete(1)."; \
+		exit 1; \
+	fi
+.endif # defined(DEFER_CONFLICTS_CHECK)
+.endif
 .endif
 
 # Install
@@ -3883,20 +4011,7 @@
 		fi; \
 	fi
 	@__softMAKEFLAGS='${__softMAKEFLAGS:S/'/'\''/g}'; \
-	_LATE_PKG_ARGS=""; \
-	if [ -f ${PKGINSTALL} ]; then \
-		_LATE_PKG_ARGS="$${_LATE_PKG_ARGS} -i ${PKGINSTALL}"; \
-	fi; \
-	if [ -f ${PKGDEINSTALL} ]; then \
-		_LATE_PKG_ARGS="$${_LATE_PKG_ARGS} -k ${PKGDEINSTALL}"; \
-	fi; \
-	if [ -f ${PKGREQ} ]; then \
-		_LATE_PKG_ARGS="$${_LATE_PKG_ARGS} -r ${PKGREQ}"; \
-	fi; \
-	if [ -f ${PKGMESSAGE} ]; then \
-		_LATE_PKG_ARGS="$${_LATE_PKG_ARGS} -D ${PKGMESSAGE}"; \
-	fi; \
-	if ${PKG_CMD} ${PKG_ARGS} ${PKGFILE}; then \
+	if ${PKG_CMD} -b ${PKGNAME} ${PKGFILE}; then \
 		if [ -d ${PACKAGES} ]; then \
 			cd ${.CURDIR} && eval ${MAKE} $${__softMAKEFLAGS} package-links; \
 		fi; \
@@ -4337,28 +4452,28 @@
 .endif
 _SANITY_SEQ=	${_CHROOT_SEQ} pre-everything check-makefile \
 				check-categories check-makevars check-desktop-entries \
-				check-conflicts check-depends check-deprecated \
+				check-depends identify-install-conflicts check-deprecated \
 				check-vulnerable check-license buildanyway-message \
 				options-message
 _FETCH_DEP=		check-sanity
 _FETCH_SEQ=		fetch-depends pre-fetch pre-fetch-script \
 				do-fetch post-fetch post-fetch-script
 _EXTRACT_DEP=	fetch
-_EXTRACT_SEQ=	extract-message checksum extract-depends pre-extract \
-				pre-extract-script do-extract \
+_EXTRACT_SEQ=	check-build-conflicts extract-message checksum extract-depends \
+				pre-extract pre-extract-script do-extract \
 				post-extract post-extract-script
 _PATCH_DEP=		extract
 _PATCH_SEQ=		ask-license patch-message patch-depends patch-dos2unix pre-patch \
 				pre-patch-script do-patch post-patch post-patch-script
 _CONFIGURE_DEP=	patch
 _CONFIGURE_SEQ=	build-depends lib-depends configure-message \
-				pre-configure pre-configure-script \
+				configure-autotools pre-configure pre-configure-script \
 				run-autotools do-configure post-configure post-configure-script
 _BUILD_DEP=		configure
 _BUILD_SEQ=		build-message pre-build pre-build-script do-build \
 				post-build post-build-script
 _INSTALL_DEP=	build
-_INSTALL_SEQ=	install-message run-depends lib-depends apply-slist pre-install \
+_INSTALL_SEQ=	install-message check-install-conflicts run-depends lib-depends apply-slist pre-install \
 				pre-install-script generate-plist check-already-installed
 _INSTALL_SUSEQ= check-umask install-mtree pre-su-install \
 				pre-su-install-script create-users-groups do-install \
@@ -5486,6 +5601,7 @@
 		fi; \
 	done
 
