Docs GODI Archive
Projects Blog Link DB

Search GODI:


More options
File build/mk/bsd.pkg.mk GODI Package godi-tools
 
   bsd.pkg.mk  
# This file is in the public domain.
#
# --
#
# This file is derived from the bsd.pkg.mk of NetBSD, and came with this
# CVS ID:
#	$NetBSD: bsd.pkg.mk,v 1.1223 2003/07/24 22:27:16 dmcmahill Exp $
# Many features have been removed, because they are not needed for
# GODI.
#
# --
#
# This file is derived from bsd.port.mk - 940820 Jordan K. Hubbard.
#
# Please see the NetBSD packages(7) manual page for details on the
# that variables used in this make file template.
# ----------------------------------------------------------------------

# Default sequence for "all" is:  fetch checksum extract patch configure build
#
# Please read the comments in the targets section below, you
# should be able to use the pre-* or post-* targets/scripts
# (which are available for every stage except checksum) or
# override the do-* targets to do pretty much anything you want.
#
# NEVER override the "regular" targets unless you want to open
# a major can of worms.

##### Include any preferences, if not already included, and common definitions
.include "${.PARSEDIR}/bsd.prefs.mk"

##### Pass information about desired toolchain to package build.
# .if defined(USETOOLS)
# MAKE_ENV+=	USETOOLS="${USETOOLS}"
# .endif

PKGBASE?=		${PKGNAME:C/-[^-]*$//}
PKGVERSION?=		${PKGNAME:C/^.*-//}
PKGWILDCARD?=		${PKGBASE}-*

_DISTDIR?=		${DISTDIR}/${DIST_SUBDIR}

# INTERACTIVE_STAGE?=	none

PREFIX=			${LOCALBASE}

.if defined(USE_GMAKE)

# GODI: We currently do not have gmake in the "base" category, but if we
# had it, the following addition would make sense:
#
#.  if ${_OPSYS_HAS_GMAKE} == "no"
#BUILD_DEPENDS+=		gmake>=3.78:../../devel/gmake
#.  endif

MAKE_PROGRAM=		${GMAKE}
.else
.if defined(USE_OMAKE)
MAKE_PROGRAM=		${LOCALBASE}/bin/omake
BUILD_DEPENDS+=	        godi-omake>=0:../../godi/godi-omake
.else
.if defined(CONF_SCRIPT)
MAKE_PROGRAM=		${TRUE}
.else

MAKE_PROGRAM=		${MAKE}
.endif
.endif
.endif
CONFIGURE_ENV+=		MAKE=${MAKE_PROGRAM:Q}

# Automatically increase process limit where necessary for building.
_ULIMIT_CMD=
.if defined(UNLIMIT_RESOURCES)
.  for __tmp__ in ${UNLIMIT_RESOURCES}
.    if defined(ULIMIT_CMD_${__tmp__})
_ULIMIT_CMD+=	${ULIMIT_CMD_${__tmp__}} ;
.    endif
.  endfor
.endif

.if !empty(CPP_PRECOMP_FLAGS)
CPPFLAGS+=	${CPP_PRECOMP_FLAGS}
.endif

EXTRACT_COOKIE=		${WRKDIR}/.extract_done
BUILDLINK_COOKIE=	${WRKDIR}/.buildlink_done
CONFIGURE_COOKIE=	${WRKDIR}/.configure_done
INSTALL_COOKIE=		${WRKDIR}/.install_done
TEST_COOKIE=		${WRKDIR}/.test_done
BUILD_COOKIE=		${WRKDIR}/.build_done
PATCH_COOKIE=		${WRKDIR}/.patch_done
PACKAGE_COOKIE=		${WRKDIR}/.package_done
INTERACTIVE_COOKIE=	.interactive_stage
NULL_COOKIE=		${WRKDIR}/.null

# New message digest defs
DIGEST_ALGORITHM?=	SHA1

# Miscellaneous overridable commands:
SHCOMMENT?=		${ECHO_MSG} >/dev/null '***'

DISTINFO_FILE?=		${.CURDIR}/distinfo

.if ${ELF_RPATH} == "yes"
LDFLAGS+=		-Wl,${ELF_RPATH_FLAG}${LOCALBASE}/lib
.endif
LDFLAGS+=		-L${LOCALBASE}/lib

# Environment for essential programs:
ESSENTIAL_ENV=		HAVE_ESSENTIALS=yes
.for _var in ${ESSENTIAL_PROGRAMS}
_value:=		${${_var}}
ESSENTIAL_ENV:=		${ESSENTIAL_ENV} ${_var}=${_value:Q}
.endfor

# How to invoke "make" in wrkdir to build and install the software:
MAKE_ENV+=		OPSYS=${OPSYS:Q}
.if defined(W32PORT)
MAKE_ENV+=		W32PORT=${W32PORT:Q}
.endif
MAKE_ENV+=		LDFLAGS=${LDFLAGS:Q}
MAKE_ENV+=		CREATE_SHLIBS=${CREATE_SHLIBS:Q}
MAKE_ENV+=		SHLIB_TYPE=${SHLIB_TYPE:Q}
MAKE_ENV+=		ELF_RPATH=${ELF_RPATH:Q}
.if ${ELF_RPATH} == "yes"
MAKE_ENV+=		ELF_RPATH_FLAG=${ELF_RPATH_FLAG:Q}
MAKE_ENV+=		RPATH_FLAG=${RPATH_FLAG:Q}
.endif
MAKE_ENV+=		WHOLE_ARCHIVE_FLAG=${WHOLE_ARCHIVE_FLAG:Q}
MAKE_ENV+=		NO_WHOLE_ARCHIVE_FLAG=${NO_WHOLE_ARCHIVE_FLAG:Q}
MAKE_ENV+=		LINK_ALL_LIBGCC_HACK=${LINK_ALL_LIBGCC_HACK:Q}
MAKE_ENV+=		PATH=${LOCALBASE:Q}/bin:${PATH:Q}
MAKE_ENV+=		PREFIX=${PREFIX:Q}
MAKE_ENV+= 		LOCALBASE=${LOCALBASE:Q}
MAKE_ENV+= 		LOCALBASE_NATIVE=${LOCALBASE_NATIVE:Q}
MAKE_ENV+=		CFLAGS=${CFLAGS:Q}
MAKE_ENV+=		CPPFLAGS=${CPPFLAGS:Q}
.if defined(CC)
MAKE_ENV+=		CC=${CC:Q}
.endif
.if defined(CPP)
MAKE_ENV+=		CPP=${CPP:Q}
.endif
# export the flags needed to compile and link pthreaded code.
# GODI: Probably not needed.
MAKE_ENV+=		PTHREAD_CFLAGS=${PTHREAD_CFLAGS:Q}
MAKE_ENV+=		PTHREAD_LDFLAGS=${PTHREAD_LDFLAGS:Q}
# Add essentials if requested:
.if defined(MAKE_GETS_ESSENTIALS) && ${MAKE_GETS_ESSENTIALS} == "yes"
MAKE_ENV+=		${ESSENTIAL_ENV}
.endif


MAKE_FLAGS?=
MAKEFILE?=		Makefile

# How to invoke "configure" in wrkdir to configure the software:
CONFIGURE_ENV+=		OPSYS=${OPSYS:Q}
.if defined(W32PORT)
CONFIGURE_ENV+=		W32PORT=${W32PORT:Q}
.endif
CONFIGURE_ENV+=		LDFLAGS=${LDFLAGS:Q}
CONFIGURE_ENV+=		CREATE_SHLIBS=${CREATE_SHLIBS:Q}
CONFIGURE_ENV+=		SHLIB_TYPE=${SHLIB_TYPE:Q}
CONFIGURE_ENV+=		ELF_RPATH=${ELF_RPATH:Q}
.if ${ELF_RPATH} == "yes"
CONFIGURE_ENV+=		ELF_RPATH_FLAG=${ELF_RPATH_FLAG:Q}
CONFIGURE_ENV+=		RPATH_FLAG=${RPATH_FLAG:Q}
.endif
CONFIGURE_ENV+=		PATH=${LOCALBASE:Q}/bin:${PATH:Q}
CONFIGURE_ENV+=		PREFIX=${PREFIX:Q}
CONFIGURE_ENV+= 	LOCALBASE=${LOCALBASE:Q}
CONFIGURE_ENV+= 	LOCALBASE_NATIVE=${LOCALBASE_NATIVE:Q}
CONFIGURE_ENV+=		CFLAGS=${CFLAGS:Q}
CONFIGURE_ENV+=		CPPFLAGS=${CPPFLAGS:Q}
CONFIGURE_ENV+=		INSTALL=${INSTALL:Q}\ -c
CONFIGURE_ENV+=		ac_given_INSTALL=${INSTALL:Q}\ -c
CONFIGURE_ENV+=		INSTALL_DATA=${INSTALL_DATA:Q}
CONFIGURE_ENV+=		INSTALL_PROGRAM=${INSTALL_PROGRAM:Q}
CONFIGURE_ENV+=		INSTALL_SCRIPT=${INSTALL_SCRIPT:Q}
CONFIGURE_ENV+=		M4=${M4:Q}
CONFIGURE_ENV+=		AWK=${AWK:Q}
.if defined(CC)
CONFIGURE_ENV+=		CC=${CC:Q}
.endif
.if defined(CPP)
CONFIGURE_ENV+=		CPP=${CPP:Q}
.endif
CONFIGURE_DIRS?=	${WRKSRC}
CONFIGURE_SCRIPT?=	./configure

.if defined(GNU_CONFIGURE)
#
# CONFIGURE_PREFIX is the argument to the --prefix option passed to the
# GNU configure script.
#
GNU_CONFIGURE_PREFIX?=	${PREFIX}
.if defined(SET_GNU_HOST) && ${SET_GNU_HOST} == "yes"
CONFIGURE_ARGS+=	--host=${MACHINE_GNU_PLATFORM:Q}
.endif
CONFIGURE_ARGS+=	--prefix=${GNU_CONFIGURE_PREFIX:Q}
HAS_CONFIGURE=		yes
# If GNU_CONFIGURE is defined, then pass LIBS to the GNU configure script.
# also pass in a CONFIG_SHELL to avoid picking up bash
#CONFIGURE_ENV+=	LIBS="${LIBS}"
#CONFIG_SHELL?=		${SH}
#CONFIGURE_ENV+=	CONFIG_SHELL=${CONFIG_SHELL}
.endif

# GODI's flavor of configure scripts:
.if defined(CONF_SCRIPT)
HAS_CONFIGURE=yes
CONFIGURE_GETS_ESSENTIALS=yes
CONFIGURE_ENV+=	SEARCH_LIBS=${SEARCH_LIBS:Q}

.if ${CONF_SCRIPT:M*.gcs} != ""
CONFIGURE_SCRIPT:=${LOCALBASE}/bin/godi_script ${.CURDIR}/${CONF_SCRIPT}
.else
CONFIGURE_SCRIPT:=${.CURDIR}/${CONF_SCRIPT}
.endif

CONFIGURE_ARGS:=${CONF_SCRIPT_ARGS}

.endif


# Add essentials if requested:
.if defined(CONFIGURE_GETS_ESSENTIALS) && ${CONFIGURE_GETS_ESSENTIALS} == "yes"
CONFIGURE_ENV+=		${ESSENTIAL_ENV}
.endif

# Setup for ${PATCH}:
# _PATCH_RMEMPTY, _PATCH_IGNREV, _PATCH_QUIET come from defs.cmd.mk
PATCH_STRIP=		-p0
PATCH_DIST_STRIP=	-p0
.if defined(PATCH_DEBUG) || defined(PKG_VERBOSE)
PATCH_DEBUG_TMP=	yes
PATCH_ARGS=		-d ${WRKSRC:Q} ${_PATCH_RMEMPTY} ${PATCH_STRIP}
PATCH_DIST_ARGS=	-d ${WRKSRC:Q} ${_PATCH_RMEMPTY} ${PATCH_DIST_STRIP}
.else
PATCH_DEBUG_TMP=	no
PATCH_ARGS=		-d ${WRKSRC:Q} ${_PATCH_IGNREV} ${_PATCH_QUIET} ${PATCH_RMEMPTY} ${PATCH_STRIP}
PATCH_DIST_ARGS=	-d ${WRKSRC:Q} ${_PATCH_IGNREV} ${_PATCH_QUIET} ${PATCH_RMEMPTY} ${PATCH_DIST_STRIP}
.endif
.if defined(_PATCH_CAN_BACKUP) && ${_PATCH_CAN_BACKUP} == "yes"
PATCH_ARGS+=		${_PATCH_BACKUP_ARG} .orig
PATCH_DIST_ARGS+=	${_PATCH_BACKUP_ARG} .orig_dist
.endif
PATCH_ARGS+=		${_PATCH_BINARY}
PATCH_FUZZ_FACTOR?=	-F0			# Default to zero fuzz

EXTRACT_SUFX?=		.tar.gz

# Debugging levels for this file, dependent on PKG_DEBUG_LEVEL definition
# 0 == normal, default, quiet operation
# 1 == all shell commands echoed before invocation
# 2 == shell "set -x" operation
PKG_DEBUG_LEVEL=	0
_PKG_SILENT=		@
_PKG_DEBUG=		# empty
_PKG_DEBUG_SCRIPT=	# empty

.if ${PKG_DEBUG_LEVEL} > 0
_PKG_SILENT=		# empty
.endif

.if ${PKG_DEBUG_LEVEL} > 1
_PKG_DEBUG=		set -x;
_PKG_DEBUG_SCRIPT=	${SH} -x
.endif

WRKSRC?=		${WRKDIR}/${DISTNAME}


# A few aliases for *-install targets
INSTALL_PROGRAM= \
	${INSTALL} ${COPY} -m ${BINMODE}
INSTALL_SCRIPT= \
	${INSTALL} ${COPY} -m ${BINMODE}
INSTALL_DATA= \
	${INSTALL} ${COPY} -m ${SHAREMODE}
INSTALL_MAN= \
	${INSTALL} ${COPY} -m ${MANMODE}
INSTALL_PROGRAM_DIR= \
	${INSTALL} -d -m ${PKGDIRMODE}
INSTALL_SCRIPT_DIR= \
	${INSTALL_PROGRAM_DIR}
INSTALL_DATA_DIR= \
	${INSTALL} -d -m ${PKGDIRMODE}
INSTALL_MAN_DIR= \
	${INSTALL} -d -m ${PKGDIRMODE}

INSTALL_MACROS=	BSD_INSTALL_PROGRAM=${INSTALL_PROGRAM:Q}		\
		BSD_INSTALL_SCRIPT=${INSTALL_SCRIPT:Q}			\
		BSD_INSTALL_DATA=${INSTALL_DATA:Q}			\
		BSD_INSTALL_MAN=${INSTALL_MAN:Q}			\
		BSD_INSTALL=${INSTALL:Q}				\
		BSD_INSTALL_PROGRAM_DIR=${INSTALL_PROGRAM_DIR:Q}	\
		BSD_INSTALL_SCRIPT_DIR=${INSTALL_SCRIPT_DIR:Q}		\
		BSD_INSTALL_DATA_DIR=${INSTALL_DATA_DIR:Q}		\
		BSD_INSTALL_MAN_DIR=${INSTALL_MAN_DIR:Q}
MAKE_ENV+=	${INSTALL_MACROS}
SCRIPTS_ENV+=	${INSTALL_MACROS}

.if !defined(COMMENT)
COMMENT!=	(${CAT} ${PKGDIR:Q}/COMMENT || ${ECHO} -n "(no description)") 2>/dev/null
.endif

DESCR=			${WRKDIR}/.DESCR
DESCR_SRC?=		${PKGDIR}/DESCR
PLIST=			${WRKDIR}/.PLIST
PLIST_SRC?=		${PKGDIR}/PLIST


# Set PLIST_SUBST to substitute "${variable}" to "value" in PLIST
# Known BUG: Quoting does not work within PLIST_SUBST due to the way
# this variable is processed.
PLIST_SUBST+=	OPSYS=${OPSYS}						\
		OS_VERSION=${OS_VERSION}				\
		MACHINE_ARCH=${MACHINE_ARCH}				\
		MACHINE_GNU_ARCH=${MACHINE_GNU_ARCH}			\
		MACHINE_GNU_PLATFORM=${MACHINE_GNU_PLATFORM}		\
		LN=${LN}						\
		LOWER_VENDOR=${LOWER_VENDOR}				\
		LOWER_OPSYS=${LOWER_OPSYS}				\
		LOWER_OS_VERSION=${LOWER_OS_VERSION}			\
		PKGBASE=${PKGBASE}					\
		PKGNAME=${PKGNAME_NOREV}				\
		PKGLOCALEDIR=${PKGLOCALEDIR}				\
		PKGVERSION=${PKGVERSION:C/nb[0-9]*$//}			\
		LOCALBASE=${LOCALBASE}					\
		SVR4_PKGNAME=${SVR4_PKGNAME}				\
		CHMOD=${CHMOD}						\
		MKDIR=${MKDIR_EXE}					\
		RMDIR=${RMDIR}						\
		RM=${RM}						\
		TRUE=${TRUE}

# By setting GODI_PLIST, the file PLIST.godi is processed instead of
# PLIST. This is now documented in project_doc/plist.ref.txt.

.if defined(GODI_PLIST)
PLIST_GODI_FILE?=PLIST.godi
.if ${PLIST_GODI_FILE:M/*} == ""
PLIST_SRC=${PKGDIR}/${PLIST_GODI_FILE}
.else
PLIST_SRC=${PLIST_GODI_FILE}
.endif
.endif

# Set INSTALL_FILE to be the name of any INSTALL file
.if !defined(INSTALL_FILE) && exists(${PKGDIR}/INSTALL)
INSTALL_FILE=		${PKGDIR}/INSTALL
.endif

# Set DEINSTALL_FILE to be the name of any DEINSTALL file
.if !defined(DEINSTALL_FILE) && exists(${PKGDIR}/DEINSTALL)
DEINSTALL_FILE=		${PKGDIR}/DEINSTALL
.endif

# If MESSAGE hasn't been defined, then set MESSAGE_SRC to be a space-separated
# list of files to be concatenated together to generate the MESSAGE file.
#
.if !defined(MESSAGE_SRC) && !defined(MESSAGE)
.  if exists(${PKGDIR}/MESSAGE)
MESSAGE_SRC=		${PKGDIR}/MESSAGE
.  endif
.endif

.if defined(MESSAGE_SRC)
MESSAGE=		${WRKDIR}/.MESSAGE

# Set MESSAGE_SUBST to substitute "${variable}" to "value" in MESSAGE
# Known BUG: Same quoting issues as for PLIST_SUBST.
MESSAGE_SUBST+=	PKGNAME=${PKGNAME}					\
		PREFIX=${PREFIX}					\
		LOCALBASE=${LOCALBASE}					\
		PKG_SYSCONFDIR=${PKG_SYSCONFDIR}

MESSAGE_SUBST_SED=	${MESSAGE_SUBST:S/=/}!/:S/$/!g/:S/^/ -e s!\\\${/}
.endif

PKGCONFIG_OVERRIDE_SED=	\
		'-e s|^\(Libs:.*[ 	]\)-L\([ 	]*[^ 	]*\)\(.*\)$$|\1-Wl,${ELF_RPATH_FLAG}\2 -L\2\3|'

# Files to create for versioning and build information
BUILD_VERSION_FILE=	${WRKDIR}/.build_version
BUILD_INFO_FILE=	${WRKDIR}/.build_info

# File to denote "no deletion of a package"
PRESERVE_FILE=		${WRKDIR}/.PRESERVE

# Args for ptool:
PTOOL_ARGS=		-set-name ${PKGNAME:Q} \
			-set-comment ${COMMENT:Q} \
			-set-description-file ${DESCR:Q} \
			-set-maintainer ${MAINTAINER:Q} \
			${DEPENDS:D-set-dependencies ${DEPENDS:QQ}} \
			${BUILD_DEPENDS:D-set-build-dependencies ${BUILD_DEPENDS:QQ}} \
			${CONFLICTS:D-set-conflicts ${CONFLICTS:QQ}} \
			${INSTALL_FILE:D-set-install-message-file ${INSTALL_FILE:QQ}} \
			-set-build-version-file ${BUILD_INFO_FILE:Q} \
			-set-build-info-file ${BUILD_INFO_FILE:Q} \
			${PKG_PRESERVE:D-set-preserve true} \
			${INSTALL_FILE:D-set-install-script ${INSTALL_FILE:QQ}} \
			${DEINSTALL_FILE:D-set-deinstall-script ${DEINSTALL_FILE:QQ}}


PKG_SUFX?=		.tgz

_PKGSRC_IN=		===

# How to do nothing.  Override if you, for some strange reason, would rather
# do something.
DO_NADA=		${TRUE}

# Filter that removes the last line:
FILTER_BUTLAST=		${AWK} '{ if (have_line) print line; line=$$0; have_line=1 }'

ALL_TARGET?=		all
INSTALL_TARGET?=	install

.if defined(DIST_SUBDIR)
_MASTER_SITE_BACKUP:=	${MASTER_SITE_BACKUP:=${DIST_SUBDIR}/}
.  if defined(MASTER_SITE_OVERRIDE)
_MASTER_SITE_OVERRIDE:=	${MASTER_SITE_OVERRIDE:=${DIST_SUBDIR}/}
.  endif # MASTER_SITE_OVERRIDE
.else  # !DIST_SUBDIR
_MASTER_SITE_BACKUP:=	${MASTER_SITE_BACKUP}
.  if defined(MASTER_SITE_OVERRIDE)
_MASTER_SITE_OVERRIDE:= ${MASTER_SITE_OVERRIDE}
.  endif # MASTER_SITE_OVERRIDE
.endif # DIST_SUBDIR


# Derived names so that they're easily overridable.
DISTFILES?=		${DISTNAME}${EXTRACT_SUFX}
.if defined(PKGREVISION) && ${PKGREVISION} != "" && ${PKGREVISION} != "0"
.  if defined(PKGNAME)
PKGNAME_NOREV:=		${PKGNAME}
PKGNAME:=		${PKGNAME}godi${PKGREVISION}
.  else
PKGNAME?=		${DISTNAME}godi${PKGREVISION}
PKGNAME_NOREV=		${DISTNAME}
.  endif
.else
PKGNAME?=		${DISTNAME}
PKGNAME_NOREV=		${PKGNAME}
.endif
SVR4_PKGNAME?=		${PKGNAME}

MAINTAINER?=		nobody

ALLFILES?=	${DISTFILES} ${PATCHFILES}
CKSUMFILES?=	${ALLFILES}
.for __tmp__ in ${IGNOREFILES}
CKSUMFILES:=	${CKSUMFILES:N${__tmp__}}
.endfor

# List of all files, with ${DIST_SUBDIR} in front.  Used for fetch and checksum.
.if defined(DIST_SUBDIR)
.  if ${CKSUMFILES} != ""
_CKSUMFILES=	${CKSUMFILES:S/^/${DIST_SUBDIR}\//}
.  endif
_DISTFILES=	${DISTFILES:S/^/${DIST_SUBDIR}\//}
_IGNOREFILES=	${IGNOREFILES:S/^/${DIST_SUBDIR}\//}
_PATCHFILES=	${PATCHFILES:S/^/${DIST_SUBDIR}\//}
.else
_CKSUMFILES=	${CKSUMFILES}
_DISTFILES=	${DISTFILES}
_IGNOREFILES=	${IGNOREFILES}
_PATCHFILES=	${PATCHFILES}
.endif
_ALLFILES=	${_DISTFILES} ${_PATCHFILES}

# This is what is actually going to be extracted, and is overridable
#  by user.
EXTRACT_ONLY?=	${DISTFILES}

.if !defined(CATEGORIES) || !defined(DISTNAME)
PKG_FAIL_REASON+='CATEGORIES and DISTNAME are mandatory.'
.endif

.if defined(GODI_PATH)
PKG_FAIL_REASON+='Please unset GODI_PATH before doing pkgsrc work!'
.endif

PKGREPOSITORYSUBDIR?=	All
PKGREPOSITORY=		${PACKAGES}/${PKGREPOSITORYSUBDIR}
PKGFILE=		${PKGREPOSITORY}/${PKGNAME}${PKG_SUFX}

#
# Config file related settings - see Packages.txt
#
PKG_SYSCONFVAR?=	${PKGBASE}
PKG_SYSCONFBASE?=	${PREFIX}/etc
#.if defined(PKG_SYSCONFDIR.${PKG_SYSCONFVAR})
#PKG_SYSCONFDIR=		${PKG_SYSCONFDIR.${PKG_SYSCONFVAR}}
#.else
PKG_SYSCONFSUBDIR?=	# empty
.  if empty(PKG_SYSCONFSUBDIR)
PKG_SYSCONFDIR=		${PKG_SYSCONFBASE}
.  else
PKG_SYSCONFDIR=		${PKG_SYSCONFBASE}/${PKG_SYSCONFSUBDIR}
.  endif
#.endif

CONFIGURE_ENV+=		PKG_SYSCONFDIR=${PKG_SYSCONFDIR:Q}
MAKE_ENV+=		PKG_SYSCONFDIR=${PKG_SYSCONFDIR:Q}
BUILD_DEFS+=		PKG_SYSCONFDIR

# Passed to most of script invocations
SCRIPTS_ENV+= CURDIR=${.CURDIR:Q} DISTDIR=${DISTDIR:Q} \
	PATH=${LOCALBASE:Q}/bin:${PATH:Q} \
	WRKDIR=${WRKDIR:Q} WRKSRC=${WRKSRC:Q} PATCHDIR=${PATCHDIR:Q} \
	SCRIPTDIR=${SCRIPTDIR:Q} FILESDIR=${FILESDIR:Q} \
	_PKGSRCDIR=${_PKGSRCDIR:Q} DEPENDS=${DEPENDS:Q} \
	PREFIX=${PREFIX:Q} LOCALBASE=${LOCALBASE:Q}

.MAIN: all

#
# Now print some error messages that we know we should ignore the pkg
#
.  if defined(PKG_FAIL_REASON)
fetch checksum extract patch configure all build install package:
	@for str in ${PKG_FAIL_REASON} ; \
	do \
	     ${ECHO} "${_PKGSRC_IN}> $$str" ; \
	done
.    if defined(PKG_FAIL_REASON)
	@${FALSE}
.    endif
.endif

# Add these defs to the ones dumped into +BUILD_DEFS
BUILD_DEFS+=	PKGPATH
BUILD_DEFS+=	OPSYS W32PORT OS_VERSION MACHINE_ARCH MACHINE_GNU_ARCH
BUILD_DEFS+=	CPPFLAGS CFLAGS LDFLAGS
BUILD_DEFS+=	CONFIGURE_ENV CONFIGURE_ARGS

.PHONY: all
.if !target(all)
.  if ${PKGSRC_RUN_TEST} == "YES" || ${PKGSRC_RUN_TEST} == "yes"
all: test
.  else
all: build
.  endif
.endif

################################################################
# The following are used to create easy dummy targets for
# disabling some bit of default target behavior you don't want.
# They still check to see if the target exists, and if so don't
# do anything, since you might want to set this globally for a
# group of packages in a Makefile.inc, but still be able to
# override from an individual Makefile.
################################################################

# Disable checksum
.PHONY: checksum
.if ((defined(NO_CHECKSUM) || exists(${EXTRACT_COOKIE})) && !target(checksum))
checksum: fetch
	@${DO_NADA}
.endif

# Disable configure
.PHONY: configure
.if defined(NO_CONFIGURE) && !target(configure)
configure: buildlink
	${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_FLAGS} ${CONFIGURE_COOKIE:Q}
.endif

# Disable build
.PHONY: build
.if defined(NO_BUILD) && !target(build)
build: configure
	${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_FLAGS} ${BUILD_COOKIE:Q}
.endif

# Disable install
.PHONY: install
.if defined(NO_INSTALL) && !target(install)
install: build
	${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_FLAGS} ${INSTALL_COOKIE:Q}
.endif

# Disable package
.PHONY: package
.if defined(NO_PACKAGE) && !target(package)
package:
.  if defined(SKIP_SILENT)
	@${DO_NADA}
.  else
	@${ECHO_MSG} "${_PKGSRC_IN}> ${PKGNAME} may not be packaged: ${NO_PACKAGE}."
.  endif
.endif

################################################################
# More standard targets start here.
#
# These are the body of the build/install framework.  If you are
# not happy with the default actions, and you can't solve it by
# adding pre-* or post-* targets/scripts, override these.
################################################################

## GODI: "fetch" could be moved to godi_console, so
## user interaction becomes possible.

#
# Define the elementary fetch macros.
#
# Quoting BUG: "for site in $$sites"
# Quoting BUG: The way $bfile etc. are inserted into awk scripts
_FETCH_FILE=								\
	if [ ! -f "$$file" -a ! -f "$$bfile" -a ! -h "$$bfile" ]; then	\
		${ECHO_MSG} "=> $$bfile doesn't seem to exist on this system."; \
		if [ ! -w ${_DISTDIR:Q}/. ]; then 			\
			${ERROR_MSG} "=> Can't download to ${_DISTDIR} (permission denied?)."; \
			exit 1; 					\
		fi; 							\
		for site in $$sites; do					\
			${ECHO_MSG} "=> Attempting to fetch $$bfile from $${site}."; \
			if [ -f ${DISTINFO_FILE:Q} ]; then		\
				${AWK} 'NF == 5 && $$1 == "Size" && $$2 == "('"$$bfile"')" { printf("=> [%s %s]\n", $$4, $$5) }' ${DISTINFO_FILE:Q}; \
			fi;						\
			if ${FETCH_CMD} ${FETCH_BEFORE_ARGS} "$${site}$${bfile}" ${FETCH_AFTER_ARGS}; then \
				if [ -n "${FAILOVER_FETCH}" -a -f ${DISTINFO_FILE:Q} -a -f ${_DISTDIR:Q}/"$$bfile" ]; then \
					alg=`${AWK} 'NF == 4 && $$2 == "('"$$file"')" && $$3 == "=" {print $$1;}' ${DISTINFO_FILE:Q}`; \
					if [ -z "$$alg" ]; then		\
						alg=${DIGEST_ALGORITHM};\
					fi;				\
					CKSUM=`${DIGEST} $$alg < ${_DISTDIR:Q}/"$$bfile"`; \
					CKSUM2=`${AWK} '$$1 == "'$$alg'" && $$2 == "('"$$file"')" {print $$4;}' <${DISTINFO_FILE:Q}`; \
					if [ "$$CKSUM" = "$$CKSUM2" -o "$$CKSUM2" = "IGNORE" ]; then \
						break;			\
					else				\
						${ECHO_MSG} "=> Checksum failure - trying next site."; \
					fi;				\
				elif [ ! -f ${_DISTDIR:Q}/"$$bfile" ]; then \
					${ECHO_MSG} "=> FTP didn't fetch expected file, trying next site." ; \
				else					\
					break;				\
				fi;					\
			fi						\
		done;							\
		if [ ! -f ${_DISTDIR:Q}/"$$bfile" ]; then \
			${ERROR_MSG} "=> Couldn't fetch $$bfile - please try to retrieve this";\
			${ERROR_MSG} "=> file manually into ${_DISTDIR} and try again."; \
			exit 1;						\
		fi;							\
	fi

_CHECK_DIST_PATH=							\
	if [ "X${DIST_PATH}" != "X" ]; then				\
		for d in "" ${DIST_PATH:Q:S/:/ /g}; do	\
			if [ "X$$d" = "X" -o "X$$d" = "X${DISTDIR}" ]; then continue; fi; \
			if [ -f "$$d"/${DIST_SUBDIR:Q}/"$$bfile" ]; then     \
				${ECHO} "Using $$d/${DIST_SUBDIR}/$$bfile";  \
				${RM} -f "$$bfile";	 		     \
				${LN} -s "$$d"/${DIST_SUBDIR:Q}/"$$bfile" "$$bfile"; \
				break;					\
			fi;						\
		done;							\
	fi

#
# Set up ORDERED_SITES to work out the exact list of sites for every file,
# using the dynamic sites script, or sorting according to the master site
# list or the patterns in MASTER_SORT or MASTER_SORT_REGEX as appropriate.
# No actual sorting is done until ORDERED_SITES is expanded.
#
.if defined(MASTER_SORT) || defined(MASTER_SORT_REGEX)
MASTER_SORT?=
MASTER_SORT_REGEX?=
MASTER_SORT_REGEX+= ${MASTER_SORT:S/./\\./g:C/.*/:\/\/[^\/]*&\//}

MASTER_SORT_AWK= BEGIN { RS = " "; ORS = " "; IGNORECASE = 1 ; gl = "${MASTER_SORT_REGEX}"; }
.  for srt in ${MASTER_SORT_REGEX}
MASTER_SORT_AWK+= /${srt:C/\//\\\//g}/ { good["${srt}"] = good["${srt}"] " " $$0 ; next; }
.  endfor
MASTER_SORT_AWK+= { rest = rest " " $$0; } END { n=split(gl, gla); for(i=1;i<=n;i++) { print good[gla[i]]; } print rest; }

# Quoting BUG: $$unsorted_sites
SORT_SITES_CMD= ${ECHO} $$unsorted_sites | ${AWK} '${MASTER_SORT_AWK}'
ORDERED_SITES= ${_MASTER_SITE_OVERRIDE} `${SORT_SITES_CMD:C/"/\"/g}`
.else
ORDERED_SITES= ${_MASTER_SITE_OVERRIDE} $$unsorted_sites
.endif

#
# Associate each file to fetch with the correct site(s).
#
#.if defined(DYNAMIC_MASTER_SITES)
#.  for fetchfile in ${_ALLFILES}
#SITES_${fetchfile:T:S/=/--/}?= `${SH} ${FILESDIR}/getsite.sh ${fetchfile:T}`
#.  endfor
#.endif
.if !empty(_DISTFILES)
.  for fetchfile in ${_DISTFILES}
SITES_${fetchfile:T:S/=/--/}= ${MASTER_SITES}
.  endfor
.endif
.if !empty(_PATCHFILES)
.  for fetchfile in ${_PATCHFILES}
SITES_${fetchfile:T:S/=/--/}= ${PATCH_SITES}
.  endfor
.endif

.PHONY: do-fetch
.if !target(do-fetch)
do-fetch:
.  if !empty(_ALLFILES)
	${_PKG_SILENT}${_PKG_DEBUG}					\
	${TEST} -d ${_DISTDIR:Q} || ${MKDIR} ${_DISTDIR:Q}
# .    if ${INTERACTIVE_STAGE:Mfetch} == "fetch" && defined(BATCH)
# 	${_PKG_SILENT}${_PKG_DEBUG}					\
# 	${MAKE} ${MAKEFLAGS} batch-check-distfiles
# .    else
.      for fetchfile in ${_ALLFILES}
.        if defined(_FETCH_MESSAGE)
	${_PKG_SILENT}${_PKG_DEBUG}					\
	file="${fetchfile}";						\
	if [ ! -f ${DISTDIR:Q}/"$$file" ]; then				\
		${_FETCH_MESSAGE};					\
	fi
.        else
	${_PKG_SILENT}${_PKG_DEBUG}					\
	cd ${_DISTDIR:Q};						\
	file="${fetchfile}";						\
	bfile="${fetchfile:T}";						\
	unsorted_sites="${SITES_${fetchfile:T:S/=/--/}} ${_MASTER_SITE_BACKUP}"; \
	sites="${ORDERED_SITES}";					\
	${_CHECK_DIST_PATH};						\
	${_FETCH_FILE};
.        endif # defined(_FETCH_MESSAGE)
.      endfor
# .    endif # INTERACTIVE_STAGE == fetch
.  endif # !empty(_ALLFILES)
.endif


.PHONY: show-distfiles
.if !target(show-distfiles)
show-distfiles:
.  if defined(PKG_FAIL_REASON)
	${_PKG_SILENT}${_PKG_DEBUG}${DO_NADA}
.  else
	${_PKG_SILENT}${_PKG_DEBUG}					\
	for file in "" ${_CKSUMFILES}; do				\
		if [ "X$$file" = "X" ]; then continue; fi;		\
		${ECHO} "$$file";					\
	done
.  endif
.endif

# Extract

# pkgsrc coarse-grained locking definitions and targets

${WRKDIR}:
	${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${WRKDIR:Q}
.ifdef WRKOBJDIR
	${_PKG_SILENT}${_PKG_DEBUG}					\
	if ${LN} -s ${WRKDIR:Q} ${WRKDIR_BASENAME:Q} 2>/dev/null; then	\
		${ECHO} "${WRKDIR_BASENAME} -> ${WRKDIR}";		\
	fi
.endif # WRKOBJDIR

_EXTRACT_SUFFICES=	.tar.gz .tgz .tar.bz2 .tbz .tar.Z .tar
_EXTRACT_SUFFICES+=	.shar.gz .shar.bz2 .shar.Z .shar
_EXTRACT_SUFFICES+=	.Z .bz2 .gz

## GODI: We do not support zip, lha, zoo

DECOMPRESS_CMD.tar.gz=		${GZCAT}
DECOMPRESS_CMD.tgz=		${DECOMPRESS_CMD.tar.gz}
DECOMPRESS_CMD.tar.bz2=	 	${BZCAT}
DECOMPRESS_CMD.tbz=		${DECOMPRESS_CMD.tar.bz2}
DECOMPRESS_CMD.tar.Z=		${GZCAT}
DECOMPRESS_CMD.tar=		${CAT}

DECOMPRESS_CMD.shar.gz=		${GZCAT}
DECOMPRESS_CMD.shar.bz2=	${BZCAT}
DECOMPRESS_CMD.shar.Z=		${GZCAT}
DECOMPRESS_CMD.shar=		${CAT}

DECOMPRESS_CMD.Z=		${GZCAT}
DECOMPRESS_CMD.bz2=		${BZCAT}
DECOMPRESS_CMD.gz=		${GZCAT}

.undef EXTRACT_CMD.tar.gz
.undef EXTRACT_CMD.tgz
.undef EXTRACT_CMD.tar.bz2
.undef EXTRACT_CMD.tbz
.undef EXTRACT_CMD.tar.Z
.undef EXTRACT_CMD.tar

.undef EXTRACT_CMD.shar.gz
.undef EXTRACT_CMD.shar.bz2
.undef EXTRACT_CMD.shar.Z
.undef EXTRACT_CMD.shar

.undef EXTRACT_CMD.Z
.undef EXTRACT_CMD.bz2
.undef EXTRACT_CMD.gz

# If this is empty, then everything gets extracted.
EXTRACT_ELEMENTS?=	# empty

DOWNLOADED_DISTFILE=	$${extract_file}

.for __suffix__ in .gz .bz2 .Z
EXTRACT_CMD${__suffix__}=	${DECOMPRESS_CMD${__suffix__}} "$${extract_file}" > `${BASENAME} "$${extract_file}" ${__suffix__}`
.endfor

.for __suffix__ in .shar.gz .shar.bz2 .shar.Z .shar
EXTRACT_CMD${__suffix__}=	${DECOMPRESS_CMD${__suffix__}} "$${extract_file}" | ${SH}
.endfor

# Use pax in preference to (GNU) tar.
#
# Quoting BUG: ${EXTRACT_ELEMENTS}
_DFLT_EXTRACT_CMD=	${DECOMPRESS_CMD} "$${extract_file}" | ${PAX} -r -x tar ${EXTRACT_ELEMENTS}

.for __suffix__ in ${_EXTRACT_SUFFICES}
.  if !defined(EXTRACT_CMD${__suffix__})
EXTRACT_CMD${__suffix__}=	${DECOMPRESS_CMD${__suffix__}} "$${extract_file}" | ${PAX} -r -x tar ${EXTRACT_ELEMENTS}
.  endif
.endfor

# _SHELL_EXTRACT is a "subroutine" for extracting an archive.  It extracts
# the contents of archive named by the shell variable "extract_file" based
# on the file extension of the archive.
#
_SHELL_EXTRACT=		case "$${extract_file}" in
.for __suffix__ in ${_EXTRACT_SUFFICES}
_SHELL_EXTRACT+=	*${__suffix__})	${EXTRACT_CMD${__suffix__}} ;;
.endfor
_SHELL_EXTRACT+=	*)		${_DFLT_EXTRACT_CMD} ;;
_SHELL_EXTRACT+=	esac

EXTRACT_CMD?=		${_SHELL_EXTRACT}

.PHONY: do-extract
.if !target(do-extract)
do-extract: ${WRKDIR}
.  for __file__ in ${EXTRACT_ONLY}
	${_PKG_SILENT}${_PKG_DEBUG}					\
	extract_file=${_DISTDIR:Q}/${__file__:Q}; export extract_file;	\
	cd ${WRKDIR:Q}; ${EXTRACT_CMD}
.  endfor
.  if defined(DISTNAME) && !empty(DISTNAME)
	${MKDIR} ${WRKSRC}
.  endif
	${_PKG_SILENT}${_PKG_DEBUG} ${ECHO} "Distinfo:" >${BUILD_VERSION_FILE:Q}
	${_PKG_SILENT}${_PKG_DEBUG} ${TEST} '!' -f ${DISTINFO_FILE:Q} || ${CAT} ${DISTINFO_FILE:Q} >>${BUILD_VERSION_FILE:Q}
.endif

# Patch

# LOCALPATCHES contains the location of local patches to packages
#	that are maintained in a directory tree reflecting the same
#	hierarchy as the pkgsrc tree, i.e. local patches for www/apache
#	would be found as ${LOCALPATCHES}/www/apache/*.
#
.if defined(LOCALPATCHES)
_DFLT_LOCALPATCHFILES=	${LOCALPATCHES}/${PKGPATH}
_LOCALPATCHFILES=	${_DFLT_LOCALPATCHFILES}
.endif

# Quoting BUG: for in in ${PATCHFILES}
# Quoting BUF: for in in $$patchlist

.PHONY: do-patch
.if !target(do-patch)
do-patch:
.  if defined(PATCHFILES)
	@${ECHO_MSG} "${_PKGSRC_IN}> Applying distribution patches for ${PKGNAME}"
	${_PKG_SILENT}${_PKG_DEBUG}cd ${_DISTDIR:Q};			\
	  for i in ${PATCHFILES}; do					\
		if [ ${PATCH_DEBUG_TMP} = yes ]; then			\
			${ECHO_MSG} "${_PKGSRC_IN}> Applying distribution patch $$i" ; \
		fi;							\
		case "$$i" in						\
			*.Z|*.gz)					\
				${GZCAT} "$$i" | ${PATCH} ${PATCH_DIST_ARGS} \
				|| { ${ERROR_MSG} Patch "$$i" failed ; exit 1; } ; \
				${ECHO} "Patch $$i" >>${BUILD_VERSION_FILE}; \
				;;					\
			*.bz2)						\
				${BZCAT} "$$i" | ${PATCH} ${PATCH_DIST_ARGS} \
				|| { ${ERROR_MSG} Patch "$$i" failed ; exit 1; } ; \
				${ECHO} "Patch $$i" >>${BUILD_VERSION_FILE}; \
				;;					\
			*)						\
				${PATCH} ${PATCH_DIST_ARGS} < "$$i"	\
				|| { ${ERROR_MSG} Patch "$$i" failed ; exit 1; } ; \
				${ECHO} "Patch $$i" >>${BUILD_VERSION_FILE}; \
				;;					\
		esac;							\
	  done
.  endif
	${_PKG_SILENT}${_PKG_DEBUG}					\
	patchlist="";							\
	if [ -d ${PATCHDIR:Q} ]; then					\
		if [ "`${ECHO} ${PATCHDIR:Q}/patch-*`" = "${PATCHDIR:Q}/patch-*" ]; then \
			${ECHO_MSG} "${_PKGSRC_IN}> Ignoring empty patch directory"; \
			if [ -d ${PATCHDIR:Q}/CVS ]; then			\
				${ECHO_MSG} "${_PKGSRC_IN}> Perhaps you forgot the -P flag to 'cvs checkout' or 'cvs update'?"; \
			fi;						\
		else							\
			patchlist=`${ECHO} ${PATCHDIR:Q}/patch-*`;	\
		fi;							\
	fi;								\
         if [ -n "${_LOCALPATCHFILES}" ]; then                                    \
	    if [ "X${_LOCALPATCHFILES}" = "X${_DFLT_LOCALPATCHFILES}" ]; then \
		    localpatchfiles="`${ECHO} ${_LOCALPATCHFILES:Q}/*`";	\
		    if [ "$${localpatchfiles}" != "${_LOCALPATCHFILES}/*" ]; then \
			    patchlist="$${patchlist} $${localpatchfiles}";	\
		    fi;							\
	    else								\
		    patchlist=`${ECHO} "$${patchlist}" ${_LOCALPATCHFILES:Q}/*`; \
	    fi;								\
         fi;                                                                      \
	if [ -n "$${patchlist}" ]; then					\
		${ECHO_MSG} "${_PKGSRC_IN}> Applying pkgsrc patches for ${PKGNAME}" ; \
		fail="";						\
		for i in $${patchlist}; do				\
			if [ ! -f "$$i" ]; then				\
				${ECHO_MSG} "${_PKGSRC_IN}> $$i is not a valid patch file - skipping"; \
				continue; 				\
			fi;						\
			case "$$i" in					\
			*.orig|*.rej|*~)				\
				${ECHO_MSG} "${_PKGSRC_IN}> Ignoring patchfile $$i"; \
				continue;				\
				;;					\
			${PATCHDIR:Q}/patch-local-*) 			\
				;;					\
			${PATCHDIR:Q}/patch-*)	 			\
				if [ -f ${DISTINFO_FILE:Q} ]; then	\
					filename=`expr $$i : '.*/\(.*\)'`; \
					algsum=`${AWK} 'NF == 4 && $$2 == "('$$filename')" && $$3 == "=" {print $$1 " " $$4}' ${DISTINFO_FILE:Q} || ${TRUE}`; \
					if [ "X$$algsum" != "X" ]; then	\
						alg=`${ECHO} $$algsum | ${AWK} '{ print $$1 }'`; \
						recorded=`${ECHO} $$algsum | ${AWK} '{ print $$2 }'`; \
						calcsum=`${CAT} $$i | ${DIGEST} $$alg`; \
						if [ ${PATCH_DEBUG_TMP} = yes ]; then \
							${ECHO_MSG} "=> Verifying $$filename (using digest algorithm $$alg)"; \
						fi;			\
					fi;				\
					if [ "X$$algsum" = "X" -o "X$$recorded" = "X" ]; then \
						${ECHO_MSG} "**************************************"; \
						${ECHO_MSG} "Ignoring unknown patch file: $$i"; \
						${ECHO_MSG} "**************************************"; \
						continue;		\
					fi;				\
					if [ "X$$calcsum" != "X$$recorded" ]; then \
						${ECHO_MSG} "**************************************"; \
						${ECHO_MSG} "Patch file $$i has been modified"; \
						${ECHO_MSG} "**************************************"; \
						fail="$$fail $$filename"; \
						continue;		\
					fi;				\
				fi;					\
				;;					\
			esac;						\
			if [ ${PATCH_DEBUG_TMP} = yes ]; then		\
				${ECHO_MSG} "${_PKGSRC_IN}> Applying pkgsrc patch $$i" ; \
			fi;						\
			fuzz="";					\
			${PATCH} -v > /dev/null 2>&1 && fuzz="${PATCH_FUZZ_FACTOR}"; \
			${PATCH} $$fuzz ${PATCH_ARGS} < "$$i" ||	\
				{ ${ECHO} Patch "$$i" failed ; exit 1; };	\
			${ECHO} "Patch $$i" >>${BUILD_VERSION_FILE}; \
		done;							\
		if [ "X$$fail" != "X" ]; then				\
			${ERROR_MSG} "Patching failed due to modified patch file(s): $$fail"; \
			exit 1;						\
		fi;							\
	fi
.endif

# Configure

# _CONFIGURE_PREREQ is a list of targets to run after pre-configure but before
#	do-configure.  These targets typically edit the files used by the
#	do-configure target.  The targets are run as dependencies of
#	pre-configure-override.
#
# _CONFIGURE_POSTREQ is a list of targets to run after do-configure but before
#	post-configure.  These targets typically edit the files generated by
#	the do-configure target that are used during the build phase.

.if defined(PKGCONFIG_OVERRIDE) && ${ELF_RPATH} == "yes"
_CONFIGURE_PREREQ+=	do-pkgconfig-override
.PHONY: do-pkgconfig-override
do-pkgconfig-override:
.  for pkgconfig in ${PKGCONFIG_OVERRIDE}
	${_PKG_SILENT}${_PKG_DEBUG}					\
	if [ -f ${pkgconfig:Q} ]; then					\
		${MV} ${pkgconfig:Q} ${pkgconfig:Q}.norpath ;		\
		${SED} ${PKGCONFIG_OVERRIDE_SED}			\
			< ${pkgconfig:Q}.norpath > ${pkgconfig:Q} ;	\
	fi
.  endfor
.endif


# By adding this target, it makes sure the the above PREREQ's work.
.PHONY: pre-configure-override
pre-configure-override: ${_CONFIGURE_PREREQ}
	@${DO_NADA}

.PHONY: do-configure
.if !target(do-configure)
do-configure:
.  if defined(HAS_CONFIGURE)
.    for DIR in ${CONFIGURE_DIRS}
	${_PKG_SILENT}${_PKG_DEBUG}${_ULIMIT_CMD}cd ${DIR:Q} && ${SETENV} \
	    ${CONFIGURE_ENV} ${CONFIGURE_SCRIPT} ${CONFIGURE_ARGS}
.    endfor
.  endif
.endif

.PHONY: post-configure
post-configure: ${_CONFIGURE_POSTREQ}

# Build

BUILD_DIRS?=	${WRKSRC}

.PHONY: do-build
.if !target(do-build)
do-build:
.  for DIR in ${BUILD_DIRS}
	${_PKG_SILENT}${_PKG_DEBUG}${_ULIMIT_CMD}cd ${DIR:Q} && ${SETENV} ${MAKE_ENV} ${MAKE_PROGRAM} ${MAKE_FLAGS} -f ${MAKEFILE:Q} ${ALL_TARGET}
.  endfor
.endif

#Test

TEST_DIRS?=	${BUILD_DIRS}

.PHONY: do-test
.if !target(do-test)
do-test:
.  if defined(TEST_TARGET)
.    for DIR in ${TEST_DIRS}
	${_PKG_SILENT}${_PKG_DEBUG}${_ULIMIT_CMD}cd ${DIR:Q} && ${SETENV} ${MAKE_ENV} ${MAKE_PROGRAM} ${MAKE_FLAGS} -f ${MAKEFILE:Q} ${TEST_TARGET}
.    endfor
.  else
	@${DO_NADA}
.  endif
.endif

# Install

INSTALL_DIRS?=	${BUILD_DIRS}

.PHONY: do-install
.if !target(do-install)
do-install:
.  for DIR in ${INSTALL_DIRS}
	${_PKG_SILENT}${_PKG_DEBUG}${_ULIMIT_CMD}cd ${DIR:Q} && ${SETENV} ${MAKE_ENV} ${MAKE_PROGRAM} ${MAKE_FLAGS} -f ${MAKEFILE:Q} ${INSTALL_TARGET}
.  endfor
.endif

# Package

.PHONY: real-su-package
.if !target(real-su-package)
real-su-package:
	${_PKG_SILENT}${_PKG_DEBUG}					\
	${ECHO_MSG} "${_PKGSRC_IN}> Building binary package for ${PKGNAME}"; \
	if [ ! -d ${PKGREPOSITORY:Q} ]; then				\
		${MKDIR} ${PKGREPOSITORY:Q};				\
		if [ $$? -ne 0 ]; then					\
			${ERROR_MSG} "=> Can't create directory ${PKGREPOSITORY}."; \
			exit 1;						\
		fi;							\
	fi;								\
	if ${PKG_PTOOL} -in-installed ${PKGNAME} -out-binary ${PKGREPOSITORY:Q}; then \
		${MAKE} ${MAKEFLAGS} package-links;			\
	else								\
		${MAKE} ${MAKEFLAGS} delete-package;			\
		exit 1;							\
	fi
	${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_FLAGS} ${PACKAGE_COOKIE:Q}
.endif

# Some support rules for real-su-package

# Quoting BUG: for cat in ${CATEGORIES}

.PHONY: package-links
.if !target(package-links)
package-links:
	${_PKG_SILENT}${_PKG_DEBUG}${MAKE} ${MAKEFLAGS} delete-package-links
	${_PKG_SILENT}${_PKG_DEBUG}for cat in ${CATEGORIES}; do		\
		if [ ! -d ${PACKAGES:Q}/"$$cat" ]; then			\
			${MKDIR} ${PACKAGES:Q}/"$$cat";			\
			if [ $$? -ne 0 ]; then				\
				${ERROR_MSG} "=> Can't create directory ${PACKAGES}/$$cat."; \
				exit 1;					\
			fi;						\
		fi;							\
		${RM} -f ${PACKAGES:Q}/"$$cat"/${PKGNAME:Q}${PKG_SUFX:Q};	\
		${LN} -s ../${PKGREPOSITORYSUBDIR:Q}/${PKGNAME:Q}${PKG_SUFX:Q} ${PACKAGES:Q}/"$$cat"; \
	done;
.endif

.PHONY: delete-package-links
.if !target(delete-package-links)
delete-package-links:
	${_PKG_SILENT}${_PKG_DEBUG}\
	${FIND} ${PACKAGES} -type l -name ${PKGNAME:Q}${PKG_SUFX:Q} | ${XARGS} ${RM} -f
.endif

.PHONY: delete-package
.if !target(delete-package)
delete-package:
	${_PKG_SILENT}${_PKG_DEBUG}${MAKE} ${MAKEFLAGS} delete-package-links
	${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${PKGFILE:Q}
.endif

# Note about conflicts: The rule real-su-install only checks whether this
# package lists a conflict with another package, but not whether a foreign
# package lists a conflict with this package. The latter is hard to to here.
# Godi_console performs the checks in both directions.

.PHONY: real-su-install
real-su-install: ${MESSAGE}
.if !defined(NO_PKG_REGISTER) && !defined(FORCE_PKG_REGISTER)
.  if defined(CONFLICTS)
	${_PKG_SILENT}${_PKG_DEBUG}					\
	${RM} -f ${WRKDIR:Q}/.CONFLICTS
.    for conflict in ${CONFLICTS}
	${_PKG_SILENT}${_PKG_DEBUG}					\
	found="`${PKG_DEP} \"${conflict}\" 2>/dev/null || ${TRUE}`";	\
	if [ X"$$found" != X"" ]; then					\
		${ECHO} "$$found" >> ${WRKDIR:Q}/.CONFLICTS;		\
	fi
.     endfor
	${_PKG_SILENT}${_PKG_DEBUG}					\
	if [ -s ${WRKDIR:Q}/.CONFLICTS ]; then				\
		found=`${SED} -e s'|${GODI_DBDIR}/||g' ${WRKDIR:Q}/.CONFLICTS | tr '\012' ' '`; \
		${ERRRO_MSG} "${_PKGSRC_IN}> ${PKGNAME} conflicts with installed package(s): $$found found."; \
		${ERROR_MSG} "*** They install the same files into the same place."; \
		${ERROR_MSG} "*** Please remove $$found first with godi_delete(1)."; \
		${RM} -f ${WRKDIR:Q}/.CONFLICTS;			\
		exit 1;							\
	fi
.  endif	# CONFLICTS
	${_PKG_SILENT}${_PKG_DEBUG}					\
	found="`${PKG_DEP} \"${PKGWILDCARD}\" 2>/dev/null || ${TRUE}`";	\
	if [ "$$found" != "" ]; then					\
		${ERROR_MSG} "${_PKGSRC_IN}>  $$found is already installed - perhaps an older version?"; \
		${ERROR_MSG} "*** If so, you may use either of:"; \
		${ERROR_MSG} "***  - \"godi_delete $$found\" and \"${MAKE} reinstall\" to upgrade properly"; \
		${ERROR_MSG} "***  - \"${MAKE} update\" to rebuild the package and all of its dependencies"; \
		${ERROR_MSG} "***  - \"${MAKE} replace\" to replace only the package without re-linking"; \
		${ERROR_MSG} "***    dependencies, risking various problems."; \
		exit 1;							\
	fi
.endif # !NO_PKG_REGISTER && !NO_FORCE_REGISTER
	${_PKG_SILENT}${_PKG_DEBUG}if [ `${SH} -c umask` -ne ${DEF_UMASK} ]; then \
		${ECHO_MSG} "${_PKGSRC_IN}>  Warning: your umask is \"`${SH} -c umask`"\".; \
		${ECHO_MSG} "If this is not desired, set it to an appropriate value (${DEF_UMASK})"; \
		${ECHO_MSG} "and install this package again by \`\`${MAKE} deinstall reinstall''."; \
	fi
# PLIST AUTOGENERATION -- turned on by the AUTOGENERATE_PLIST variable
.  if !defined(AUTOGENERATE_PLIST)
# The old way -- no autogeneration going on.
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && ${MAKE} ${MAKEFLAGS} pre-install-script
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && ${MAKE} ${MAKEFLAGS} pre-install
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && ${MAKE} ${MAKEFLAGS} do-install
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && ${MAKE} ${MAKEFLAGS} post-install
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && ${MAKE} ${MAKEFLAGS} post-install-script
	@# PLIST must be generated at this late point (instead of
	@# depending on it somewhere earlier), as the
	@# pre/do/post-install aren't run then yet:
	@${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && ${MAKE} ${MAKEFLAGS} ${PLIST:Q}
.    if !defined(NO_PKG_REGISTER)
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && ${MAKE} ${MAKEFLAGS} register-pkg
.    endif # !NO_PKG_REGISTER
.  else
	${_PKG_SILENT}${_PKG_DEBUG}${ECHO_MSG} "${_PKGSRC_IN}> Installing to image dir"
# Install to the sandbox directory (${WRKDIR}/image)
	${MKDIR} ${WRKDIR:Q}/image
# Make all the main godi structure in the image dir:
	${MKDIR} ${WRKDIR:Q}/image/lib/ocaml/pkg-lib
	${MKDIR} ${WRKDIR:Q}/image/lib/ocaml/pkg-lib/stublibs
	${MKDIR} ${WRKDIR:Q}/image/bin
	${MKDIR} ${WRKDIR:Q}/image/doc
	${MKDIR} ${WRKDIR:Q}/image/share
	${MKDIR} ${WRKDIR:Q}/image/man
	${MKDIR} ${WRKDIR:Q}/image/etc
	${MKDIR} ${WRKDIR:Q}/image/sbin
	${MKDIR} ${WRKDIR:Q}/image/include
	${MKDIR} ${WRKDIR:Q}/image/man/man1
	${MKDIR} ${WRKDIR:Q}/image/man/man2
	${MKDIR} ${WRKDIR:Q}/image/man/man3
	${MKDIR} ${WRKDIR:Q}/image/man/man4
	${MKDIR} ${WRKDIR:Q}/image/man/man5
	${MKDIR} ${WRKDIR:Q}/image/man/man6
	${MKDIR} ${WRKDIR:Q}/image/man/man7
	${MKDIR} ${WRKDIR:Q}/image/man/man8
	${MKDIR} ${WRKDIR:Q}/image/man/man9
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && OCAMLFIND_DESTDIR=${WRKDIR:Q:n}/image/lib/ocaml/pkg-lib ${MAKE} ${MAKEFLAGS} PREFIX=${WRKDIR:Q}/image pre-install-script
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && OCAMLFIND_DESTDIR=${WRKDIR:Q:n}/image/lib/ocaml/pkg-lib ${MAKE} ${MAKEFLAGS} PREFIX=${WRKDIR:Q}/image pre-install
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && OCAMLFIND_DESTDIR=${WRKDIR:Q:n}/image/lib/ocaml/pkg-lib ${MAKE} ${MAKEFLAGS} PREFIX=${WRKDIR:Q}/image do-install
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && OCAMLFIND_DESTDIR=${WRKDIR:Q:n}/image/lib/ocaml/pkg-lib ${MAKE} ${MAKEFLAGS} PREFIX=${WRKDIR:Q}/image post-install
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && OCAMLFIND_DESTDIR=${WRKDIR:Q:n}/image/lib/ocaml/pkg-lib ${MAKE} ${MAKEFLAGS} PREFIX=${WRKDIR:Q}/image post-install-script
.    if !defined(NO_PKG_REGISTER)
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && ${MAKE} ${MAKEFLAGS} godiva-register-pkg
.    endif # !NO_PKG_REGISTER
.  endif
.ifdef MESSAGE
	@${ECHO_MSG} "${_PKGSRC_IN}> Please note the following:"
	@${ECHO_MSG} ""
	@${CAT} ${MESSAGE:Q}
	@${ECHO_MSG} ""
.endif
	${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_FLAGS} ${INSTALL_COOKIE:Q}


# Fake installation of package so that user can pkg_delete it later.
# Also, make sure that an installed package is recognized correctly in
# accordance to the @pkgdep directive in the packing lists

.PHONY: register-pkg
.if !target(register-pkg)
register-pkg: ${PLIST} ${DESCR} ${MESSAGE} prepare-registration
	${_PKG_SILENT}${_PKG_DEBUG}					\
	if [ ! -f ${PLIST:Q} -o ! -f ${DESCR:Q} ]; then			\
		${ERROR_MSG} "** Missing package files for ${PKGNAME} - installation not recorded."; \
		exit 1;							\
	fi
	${_PKG_SILENT}${_PKG_DEBUG}					\
		${ECHO_MSG} "${_PKGSRC_IN}> Registering installation for ${PKGNAME}"; \
		${PKG_PTOOL} \
			-in-dispersed -fixup-symlinks -out-register \
			-set-prefix ${PREFIX:Q} \
			-set-plist ${PLIST:Q} \
			${PTOOL_ARGS}
.endif

.PHONY: godiva-register-pkg
.if !target(godiva-register-pkg)
godiva-register-pkg: ${DESCR} ${MESSAGE} prepare-registration
	${_PKG_SILENT}${_PKG_DEBUG}${ECHO_MSG} "${_PKGSRC_IN}> Installing and registering"
	${_PKG_SILENT}${_PKG_DEBUG}\
	${PKG_PTOOL} -in-dispersed -fixup-symlinks -out-install \
		-set-prefix ${WRKDIR:Q}/image \
		-set-auto-plist \
		${PTOOL_ARGS}
.endif


.PHONY: prepare-registration
prepare-registration:
.  if defined(FORCE_PKG_REGISTER)
	${_PKG_SILENT}${_PKG_DEBUG}${RM} -rf ${GODI_DBDIR:Q}/${PKGNAME:Q}
.  endif
	${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${BUILD_VERSION_FILE:Q} ${BUILD_INFO_FILE:Q}
	@${ECHO} "Build version n/a" > ${BUILD_VERSION_FILE:Q}
.  for def in ${BUILD_DEFS}
	@${ECHO} ${def}=${${def}:Q} | ${SED} -e 's|^PATH=[^ 	]*|PATH=...|' >> ${BUILD_INFO_FILE:Q}
.  endfor
	@${ECHO} "CC=${CC}" >> ${BUILD_INFO_FILE:Q}
	@if ${CC} -v 2>&1 | ${GREP} -q '^gcc'; then \
	  ${ECHO} "CC_VERSION=`${CC} -v 2>&1 | ${GREP} '^gcc'`" >> ${BUILD_INFO_FILE:Q}; \
	elif ${CC} -V 2>&1 | ${GREP} -q '^cc'; then \
	  ${ECHO} "CC_VERSION=`${CC} -V 2>&1 | ${GREP} '^cc'`" >> ${BUILD_INFO_FILE:Q}; \
	fi
.  ifdef USE_GMAKE
	@${ECHO} "GMAKE=`${GMAKE} --version | ${GREP} Make`" >> ${BUILD_INFO_FILE:Q}
.  endif


.if !target(show-shlib-type)
# Show the shared lib type being built: one of ELF, a.out, dylib, or none
# GODI: This piece of code is kept inside this file because it is unclear
# whether it is still needed.
.PHONY: show-shlib-type
show-shlib-type:
.  if exists(/usr/lib/libc.dylib)
	${_PKG_SILENT}${_PKG_DEBUG}					\
	${ECHO} "dylib"
.  else
	${_PKG_SILENT}${_PKG_DEBUG}					\
	cd ${WRKDIR} &&							\
	sotype=none;							\
	if [ "X${MKPIC}" != "Xno" -a "X${NOPIC}" = "X" ]; then		\
		${ECHO} "int main() { exit(0); }" > a.$$$$.c;		\
		${CC} ${CFLAGS} a.$$$$.c -o a.$$$$.out;			\
		case `${FILE_CMD} a.$$$$.out` in			\
		*ELF*dynamically*)					\
			sotype=ELF ;;					\
		*shared*library*)					\
			sotype="a.out" ;;				\
		*dynamically*)						\
			sotype="a.out" ;;				\
		esac;							\
	fi;								\
	${ECHO} "$$sotype";						\
	${RM} -f a.$$$$.c a.$$$$.out
.  endif # libc.dylib
.endif

################################################################
# Skeleton targets start here
#
# You shouldn't have to change these.  Either add the pre-* or
# post-* targets/scripts or redefine the do-* targets.  These
# targets don't do anything other than checking for cookies and
# call the necessary targets/scripts.
################################################################

.PHONY: fetch
.if !target(fetch)
fetch:
	@cd ${.CURDIR:Q} && ${MAKE} ${MAKEFLAGS} real-fetch
.endif

.PHONY: extract
.if !target(extract)
extract: checksum ${WRKDIR} ${EXTRACT_COOKIE}
.endif

.PHONY: patch
.if !target(patch)
patch: extract ${PATCH_COOKIE}
.endif

.PHONY: configure
.if !target(configure)
configure: patch ${CONFIGURE_COOKIE}
.endif

.PHONY: build
.if !target(build)
build: configure ${BUILD_COOKIE}
.endif

.PHONY: test
.if !target(test)
test: build ${TEST_COOKIE}
.endif

.PHONY: install
.if !target(install)
.  if ${PKGSRC_RUN_TEST} == "YES" || ${PKGSRC_RUN_TEST} == "yes"
install: build test ${INSTALL_COOKIE}
.  else
install: build ${INSTALL_COOKIE}
.  endif
.endif

.PHONY: package
.if !target(package)
package: install ${PACKAGE_COOKIE}
.endif

${EXTRACT_COOKIE}:
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && ${MAKE} ${MAKEFLAGS} real-extract DEPENDS_TARGET=${DEPENDS_TARGET}

${PATCH_COOKIE}:
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && ${MAKE} ${MAKEFLAGS} real-patch

${CONFIGURE_COOKIE}:
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && ${MAKE} ${MAKEFLAGS} real-configure

${BUILD_COOKIE}:
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && ${MAKE} ${MAKEFLAGS} real-build

${TEST_COOKIE}:
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && ${MAKE} ${MAKEFLAGS} real-test

${INSTALL_COOKIE}:
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && ${MAKE} ${MAKEFLAGS} real-install

${PACKAGE_COOKIE}:
	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR:Q} && ${MAKE} ${MAKEFLAGS} real-package

.PHONY: extract-message patch-message configure-message
.PHONY: build-message test-message
extract-message:
	@${ECHO_MSG} "${_PKGSRC_IN}> Extracting for ${PKGNAME}"
patch-message:
	@${ECHO_MSG} "${_PKGSRC_IN}> Patching for ${PKGNAME}"
configure-message:
	@${ECHO_MSG} "${_PKGSRC_IN}> Configuring for ${PKGNAME}"
build-message:
	@${ECHO_MSG} "${_PKGSRC_IN}> Building for ${PKGNAME}"
test-message:
	@${ECHO_MSG} "${_PKGSRC_IN}> Testing for ${PKGNAME}"

.PHONY: extract-cookie patch-cookie configure-cookie
.PHONY: build-cookie test-cookie
extract-cookie:
	${_PKG_SILENT}${_PKG_DEBUG}${ECHO} ${PKGNAME:Q} >> ${EXTRACT_COOKIE:Q}
patch-cookie:
	${_PKG_SILENT}${_PKG_DEBUG} ${TOUCH} ${TOUCH_FLAGS} ${PATCH_COOKIE:Q}
configure-cookie:
	${_PKG_SILENT}${_PKG_DEBUG} ${TOUCH} ${TOUCH_FLAGS} ${CONFIGURE_COOKIE:Q}
build-cookie:
	${_PKG_SILENT}${_PKG_DEBUG} ${TOUCH} ${TOUCH_FLAGS} ${BUILD_COOKIE:Q}
test-cookie:
	${_PKG_SILENT}${_PKG_DEBUG} ${TOUCH} ${TOUCH_FLAGS} ${TEST_COOKIE:Q}

.ORDER: pre-fetch do-fetch post-fetch
.ORDER: extract-message pre-extract do-extract post-extract extract-cookie
.ORDER: patch-message pre-patch do-patch post-patch patch-cookie
.ORDER: configure-message pre-configure pre-configure-override do-configure post-configure configure-cookie
.ORDER: build-message pre-build do-build post-build build-cookie
.ORDER: test-message pre-test do-test post-test test-cookie

# Please note that the order of the following targets is important, and
# should not be modified (.ORDER is not recognised by make(1) in a serial
# make i.e. without -j n)
.PHONY: real-fetch real-extract real-patch real-configure
.PHONY: real-build real-test real-install real-package
real-fetch: pre-fetch do-fetch post-fetch
real-extract: extract-message pre-extract do-extract post-extract extract-cookie
real-patch: patch-message pre-patch do-patch post-patch patch-cookie
real-configure: configure-message pre-configure pre-configure-override do-configure post-configure configure-cookie
real-build: build-message pre-build do-build post-build build-cookie
real-test: test-message pre-test do-test post-test test-cookie
real-install: do-su-install
real-package: do-su-package

## GODI does not need superuser privileges for installation. So _SU_TARGET
## simply starts the selected action.
## (In NetBSD, _SU_TARGET runs 'su', and executes the $$realtarget with
## superuser privileges.)

_SU_TARGET=                                                             \
		args="";						\
		if [ "X${FORCE_PKG_REGISTER}" != X"" ]; then		\
			args="FORCE_PKG_REGISTER=1";			\
		fi;							\
		if [ "X${PKG_DEBUG_LEVEL}" != X"" ]; then		\
			args="$$args PKG_DEBUG_LEVEL=${PKG_DEBUG_LEVEL}"; \
		fi;							\
		${SETENV} PATH=${PATH:Q}:${SU_CMD_PATH_APPEND:Q} ${MAKE} $$args ${MAKEFLAGS} $$realtarget $$realflags



.PHONY: do-su-install
do-su-install:
	@${ECHO_MSG} "${_PKGSRC_IN}> Installing for ${PKGNAME}"
	${_PKG_SILENT}${_PKG_DEBUG}					\
	realtarget="real-su-install";					\
	action="install";						\
	${_SU_TARGET}

.PHONY: do-su-package
do-su-package:
	@${ECHO_MSG} "${_PKGSRC_IN}> Packaging ${PKGNAME}"
	${_PKG_SILENT}${_PKG_DEBUG}					\
	realtarget="real-su-package";					\
	action="package";						\
	${_SU_TARGET}


# Empty pre-* and post-* targets

.for name in fetch extract patch configure build test install-script install package

.  if !target(pre-${name})
pre-${name}:
	@${DO_NADA}
.  endif

.  if !target(post-${name})
post-${name}:
	@${DO_NADA}
.  endif

.endfor

# Reinstall
#
# Special target to re-run install

.PHONY: reinstall
.if !target(reinstall)
reinstall:
	${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${INSTALL_COOKIE:Q} ${PACKAGE_COOKIE:Q} ${PLIST:Q}
	${_PKG_SILENT}${_PKG_DEBUG} ${MAKE} ${MAKEFLAGS} install
.endif

# Deinstall
#
# Special target to remove installation

.PHONY: deinstall do-su-deinstall
.if !target(deinstall)
deinstall: do-su-deinstall

do-su-deinstall:
	@${ECHO_