Home | History | Annotate | Line # | Download | only in mk
bsd.syspkg.mk revision 1.2
      1 #	$NetBSD: bsd.syspkg.mk,v 1.2 2002/03/29 20:56:28 jwise Exp $
      2 #
      3 #	This file is derived from:
      4 #
      5 #	NetBSD: bsd.pkg.mk,v 1.636 2001/01/05 18:03:14 jlam Exp
      6 #
      7 #	Plus many fixes and improvements from later revisions.
      8 #	
      9 #	However, it has been pared down to a minimum of targets, and
     10 #	adapted to the standard bsd.*.mk world order.
     11 #
     12 #	Portions of this code are copyright (c) 2000-2002 Jim Wise
     13 #
     14 
     15 .if !target(__initialized__)
     16 __initialized__:
     17 .if exists(${.CURDIR}/../Makefile.inc)
     18 .include "${.CURDIR}/../Makefile.inc"
     19 .endif
     20 .include <bsd.own.mk>
     21 .include <bsd.obj.mk>
     22 .MAIN:		all
     23 .endif
     24 
     25 PREFIX:=		${DESTDIR}/${PREFIX}
     26 
     27 OPSYS=			NetBSD
     28 OS_VERSION!=		sh ${.PARSEDIR}/../../../sys/conf/osrelease.sh
     29 
     30 # keep bsd.own.mk from generating an install: target.
     31 NEED_OWN_INSTALL_TARGET=no
     32 
     33 ##### Some overrides of defaults below on a per-OS basis.
     34 
     35 DEINSTALLDEPENDS?=	NO	# add -R to pkg_delete
     36 
     37 PKGSRCDIR?=		${.CURDIR:C|/[^/]*/[^/]*$||}
     38 PKGVERSION?=		${OS_VERSION}.${TINY_VERSION}
     39 PKGWILDCARD?=		${PKGBASE}-[0-9]*
     40 
     41 # For system packages, we set this here, as the version is auto-generated.
     42 PKGNAME?=		${PKGBASE}-${PKGVERSION}
     43 
     44 PACKAGES?=		${PKGSRCDIR}/../packages
     45 PKGDIR?=		${.CURDIR}
     46 
     47 # Don't change these!!!  These names are built into the _TARGET_USE macro,
     48 # there is no way to refer to them cleanly from within the macro AFAIK.
     49 PACKAGE_COOKIE=		${WRKDIR}/.package_done
     50 
     51 # Miscellaneous overridable commands:
     52 SHCOMMENT?=		${ECHO_MSG} >/dev/null '***'
     53 
     54 MAKE_ENV+=		PREFIX=${PREFIX}
     55 
     56 TOUCH_FLAGS?=		-f
     57 
     58 # Debugging levels for this file, dependent on PKG_DEBUG_LEVEL definition
     59 # 0 == normal, default, quiet operation
     60 # 1 == all shell commands echoed before invocation
     61 # 2 == shell "set -x" operation
     62 PKG_DEBUG_LEVEL?=	0
     63 _PKG_SILENT=		@
     64 _PKG_DEBUG=		
     65 
     66 .if ${PKG_DEBUG_LEVEL} > 0
     67 _PKG_SILENT=	
     68 .endif
     69 
     70 .if ${PKG_DEBUG_LEVEL} > 1
     71 _PKG_DEBUG=		set -x;
     72 .endif
     73 
     74 # In point of fact, this will often be ./obj, as per bsd.obj.mk
     75 WRKDIR?=		.
     76 
     77 COMMENT?=		${PKGDIR}/COMMENT
     78 DESCR=			${PKGDIR}/DESCR
     79 PLIST=			${WRKDIR}/PLIST
     80 PLIST_SRC?=		${PKGDIR}/PLIST
     81 
     82 
     83 # Set PKG_INSTALL_FILE to be the name of any INSTALL file
     84 .if !defined(PKG_INSTALL_FILE) && exists(${PKGDIR}/INSTALL)
     85 PKG_INSTALL_FILE=		${PKGDIR}/INSTALL
     86 .endif
     87 
     88 # Set PKG_DEINSTALL_FILE to be the name of any DEINSTALL file
     89 .if !defined(PKG_DEINSTALL_FILE) && exists(${PKGDIR}/DEINSTALL)
     90 PKG_DEINSTALL_FILE=		${PKGDIR}/DEINSTALL
     91 .endif
     92 
     93 # Set MESSAGE_FILE to be the name of any MESSAGE file
     94 .if !defined(MESSAGE_FILE) && exists(${PKGDIR}/MESSAGE)
     95 MESSAGE_FILE=		${PKGDIR}/MESSAGE
     96 .endif
     97 
     98 AWK?=		/usr/bin/awk
     99 CAT?=		/bin/cat
    100 CP?=		/bin/cp
    101 DC?=		/usr/bin/dc
    102 ECHO?=		echo				# Shell builtin
    103 FALSE?=		false				# Shell builtin
    104 FIND?=		/usr/bin/find
    105 GREP?=		/usr/bin/grep
    106 IDENT?=		/usr/bin/ident
    107 LN?=		/bin/ln
    108 LS?=		/bin/ls
    109 MKDIR?=		/bin/mkdir -p
    110 MV?=		/bin/mv
    111 PKG_TOOLS_BIN?= /usr/sbin
    112 RM?=		/bin/rm
    113 SED?=		/usr/bin/sed
    114 SETENV?=	/usr/bin/env
    115 SH?=		/bin/sh
    116 TEST?=		test				# Shell builtin
    117 TOUCH?=		/usr/bin/touch
    118 TRUE?=		true				# Shell builtin
    119 
    120 PKG_ADD?=	PKG_DBDIR=${PKG_DBDIR} ${PKG_TOOLS_BIN}/pkg_add
    121 PKG_ADMIN?=	PKG_DBDIR=${PKG_DBDIR} ${PKG_TOOLS_BIN}/pkg_admin
    122 PKG_CREATE?=	PKG_DBDIR=${PKG_DBDIR} ${PKG_TOOLS_BIN}/pkg_create
    123 PKG_DELETE?=	PKG_DBDIR=${PKG_DBDIR} ${PKG_TOOLS_BIN}/pkg_delete
    124 PKG_INFO?=	PKG_DBDIR=${PKG_DBDIR} ${PKG_TOOLS_BIN}/pkg_info
    125 
    126 .if !defined(PKGTOOLS_VERSION)
    127 .if !exists(${IDENT})
    128 PKGTOOLS_VERSION=${PKGTOOLS_REQD}
    129 .else
    130 PKGTOOLS_VERSION!=${IDENT} ${PKG_TOOLS_BIN}/pkg_add ${PKG_TOOLS_BIN}/pkg_admin ${PKG_TOOLS_BIN}/pkg_create ${PKG_TOOLS_BIN}/pkg_delete ${PKG_TOOLS_BIN}/pkg_info | ${AWK} 'BEGIN {n = 0;}; $$1 ~ /\$$NetBSD/ && $$2 !~ /^crt0/ {gsub("/", "", $$4); if ($$4 > n) {n = $$4;}}; END {print n;}'
    131 .endif
    132 .endif
    133 MAKEFLAGS+=	PKGTOOLS_VERSION="${PKGTOOLS_VERSION}"
    134 
    135 # Latest version of pkgtools required for this file.
    136 PKGTOOLS_REQD=		20000202
    137 
    138 # Check that we're using up-to-date pkg_* tools with this file.
    139 uptodate-pkgtools:
    140 	${_PKG_SILENT}${_PKG_DEBUG}					\
    141 	if [ ${PKGTOOLS_VERSION} -lt ${PKGTOOLS_REQD} ]; then		\
    142 		case ${PKGNAME} in					\
    143 		pkg_install-*)						\
    144 			;;						\
    145 		*)							\
    146 			${ECHO} "Your package tools need to be updated to ${PKGTOOLS_REQD:C|(....)(..)(..)|\1/\2/\3|} versions."; \
    147 			${ECHO} "The installed package tools were last updated on ${PKGTOOLS_VERSION:C|(....)(..)(..)|\1/\2/\3|}."; \
    148 			${FALSE} ;;					\
    149 		esac							\
    150 	fi
    151 
    152 # Files to create for versioning and build information
    153 BUILD_VERSION_FILE=	${WRKDIR}/.build_version
    154 BUILD_INFO_FILE=	${WRKDIR}/.build_info
    155 
    156 # Files containing size of pkg w/o and w/ all required pkgs
    157 SIZE_PKG_FILE=		${WRKDIR}/.SizePkg
    158 SIZE_ALL_FILE=		${WRKDIR}/.SizeAll
    159 
    160 .ifndef PKG_ARGS_COMMON
    161 PKG_ARGS_COMMON=	-v -c ${COMMENT} -d ${DESCR} -f ${PLIST} -l
    162 PKG_ARGS_COMMON+=	-b ${BUILD_VERSION_FILE} -B ${BUILD_INFO_FILE}
    163 PKG_ARGS_COMMON+=	-s ${SIZE_PKG_FILE} -S ${SIZE_ALL_FILE}
    164 PKG_ARGS_COMMON+=	-P "`${MAKE} ${MAKEFLAGS} run-depends-list PACKAGE_DEPENDS_QUICK=true|sort -u`"
    165 .ifdef CONFLICTS
    166 PKG_ARGS_COMMON+=	-C "${CONFLICTS}"
    167 .endif
    168 .ifdef PKG_INSTALL_FILE
    169 PKG_ARGS_COMMON+=	-i ${PKG_INSTALL_FILE}
    170 .endif
    171 .ifdef PKG_DEINSTALL_FILE
    172 PKG_ARGS_COMMON+=	-k ${PKG_DEINSTALL_FILE}
    173 .endif
    174 .ifdef MESSAGE_FILE
    175 PKG_ARGS_COMMON+=	-D ${MESSAGE_FILE}
    176 .endif
    177 
    178 PKG_ARGS_INSTALL=	-p ${PREFIX} ${PKG_ARGS_COMMON}
    179 PKG_ARGS_BINPKG=	-p ${PREFIX:C/^${DESTDIR}//} -L ${PREFIX} ${PKG_ARGS_COMMON}
    180 .endif # !PKG_ARGS_COMMON
    181 
    182 PKG_SUFX?=		.tgz
    183 #PKG_SUFX?=		.tbz		# bzip2(1) pkgs
    184 # where pkg_add records its dirty deeds.
    185 PKG_DBDIR?=		${DESTDIR}/var/db/syspkg
    186 
    187 # Define SMART_MESSAGES in /etc/mk.conf for messages giving the tree
    188 # of depencies for building, and the current target.
    189 .ifdef SMART_MESSAGES
    190 _PKGSRC_IN?=		===> ${.TARGET} [${PKGNAME}${_PKGSRC_DEPS}] ===
    191 .else
    192 _PKGSRC_IN?=		===
    193 .endif
    194 
    195 # Used to print all the '===>' style prompts - override this to turn them off.
    196 ECHO_MSG?=		${ECHO}
    197 
    198 # How to do nothing.  Override if you, for some strange reason, would rather
    199 # do something.
    200 DO_NADA?=		${TRUE}
    201 
    202 .if !defined(PKGBASE) || !defined(SETNAME)
    203 .BEGIN:
    204 	@${ECHO_MSG} "PKGBASE and SETNAME are mandatory."
    205 	@${FALSE}
    206 .endif
    207 
    208 PKGREPOSITORY?=		${PACKAGES}
    209 PKGFILE?=		${PKGREPOSITORY}/${PKGNAME}${PKG_SUFX}
    210 
    211 .MAIN: all
    212 
    213 # Add these defs to the ones dumped into +BUILD_DEFS
    214 BUILD_DEFS+=	OPSYS OS_VERSION MACHINE_ARCH OBJECT_FMT
    215 
    216 .if !target(all)
    217 # We don't build here
    218 all:
    219 .endif
    220 
    221 ################################################################
    222 # More standard targets start here.
    223 #
    224 # These are the body of the build/install framework.  If you are
    225 # not happy with the default actions, and you can't solve it by
    226 # adding pre-* or post-* targets/scripts, override these.
    227 ################################################################
    228 
    229 .if !target(show-downlevel)
    230 show-downlevel:
    231 	${_PKG_SILENT}${_PKG_DEBUG}					\
    232 	found="`${PKG_INFO} -e \"${PKGBASE}<${PKGVERSION}\" || ${TRUE}`";\
    233 	if [ "X$$found" != "X" -a "X$$found" != "X${PKGNAME}" ]; then	\
    234 		${ECHO} "${PKGBASE} package: $$found installed, pkgsrc version ${PKGNAME}"; \
    235 	fi
    236 .endif
    237 
    238 # Package
    239 
    240 .if !target(do-package)
    241 do-package: ${PLIST}
    242 	${_PKG_SILENT}${_PKG_DEBUG}\
    243 	${ECHO_MSG} "${_PKGSRC_IN}> Building binary package for ${PKGNAME}"; \
    244 	if [ ! -d ${PKGREPOSITORY} ]; then			\
    245 		${MKDIR} ${PKGREPOSITORY};			\
    246 		if [ $$? -ne 0 ]; then				\
    247 			${ECHO_MSG} "=> Can't create directory ${PKGREPOSITORY}."; \
    248 			exit 1;					\
    249 		fi;						\
    250 	fi;							\
    251 	if ${PKG_CREATE} ${PKG_ARGS_BINPKG} ${PKGFILE}; then		\
    252 		(cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} package-links);		\
    253 	else							\
    254 		(cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} delete-package);		\
    255 		exit 1;						\
    256 	fi
    257 .endif
    258 
    259 # Some support rules for do-package
    260 
    261 .if !target(package-links)
    262 package-links:
    263 	${_PKG_SILENT}${_PKG_DEBUG}(cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} delete-package-links)
    264 	${_PKG_SILENT}${_PKG_DEBUG}for cat in ${CATEGORIES}; do		\
    265 		if [ ! -d ${PACKAGES}/$$cat ]; then			\
    266 			${MKDIR} ${PACKAGES}/$$cat;			\
    267 			if [ $$? -ne 0 ]; then				\
    268 				${ECHO_MSG} "=> Can't create directory ${PACKAGES}/$$cat."; \
    269 				exit 1;					\
    270 			fi;						\
    271 		fi;							\
    272 		${RM} -f ${PACKAGES}/$$cat/${PKGNAME}${PKG_SUFX};	\
    273 		${LN} -s ../${PKGREPOSITORYSUBDIR}/${PKGNAME}${PKG_SUFX} ${PACKAGES}/$$cat; \
    274 	done;
    275 .endif
    276 
    277 .if !target(delete-package-links)
    278 delete-package-links:
    279 	${_PKG_SILENT}${_PKG_DEBUG}\
    280 	${FIND} ${PACKAGES} -type l -name ${PKGNAME}${PKG_SUFX} | xargs ${RM} -f
    281 .endif
    282 
    283 .if !target(delete-package)
    284 delete-package:
    285 	${_PKG_SILENT}${_PKG_DEBUG}(cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} delete-package-links)
    286 	${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${PKGFILE}
    287 .endif
    288 
    289 ################################################################
    290 # This is the "generic" package target, actually a macro used from the
    291 # six main targets.  See below for more.
    292 ################################################################
    293 
    294 real-package:
    295 	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR} && ${SETENV} ${MAKE_ENV} ${MAKE} ${MAKEFLAGS} ${.TARGET:S/^real-/pre-/}
    296 	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR} && ${SETENV} ${MAKE_ENV} ${MAKE} ${MAKEFLAGS} ${.TARGET:S/^real-/do-/}
    297 	${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR} && ${SETENV} ${MAKE_ENV} ${MAKE} ${MAKEFLAGS} ${.TARGET:S/^real-/post-/}
    298 
    299 ################################################################
    300 # Skeleton targets start here
    301 # 
    302 # You shouldn't have to change these.  Either add the pre-* or
    303 # post-* targets/scripts or redefine the do-* targets.  These
    304 # targets don't do anything other than checking for cookies and
    305 # call the necessary targets/scripts.
    306 ################################################################
    307 
    308 .if !target(package)
    309 package: uptodate-pkgtools ${PACKAGE_COOKIE}
    310 .endif
    311 
    312 ${PACKAGE_COOKIE}:
    313 	${_PKG_SILENT}${_PKG_DEBUG}(cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} real-package)
    314 
    315 # Empty pre-* and post-* targets, note we can't use .if !target()
    316 # in the _PORT_USE macro
    317 
    318 .for name in package
    319 
    320 .if !target(pre-${name})
    321 pre-${name}:
    322 	@${DO_NADA}
    323 .endif
    324 
    325 .if !target(post-${name})
    326 post-${name}:
    327 	@${DO_NADA}
    328 .endif
    329 
    330 .endfor
    331 
    332 # Deinstall
    333 #
    334 # Special target to remove installation
    335 
    336 .if !target(deinstall)
    337 deinstall: real-deinstall
    338 
    339 .if (${DEINSTALLDEPENDS} != "NO")
    340 .if (${DEINSTALLDEPENDS} != "ALL")
    341 # used for removing stuff in bulk builds
    342 real-su-deinstall-flags+=	-r -R
    343 # used for "update" target
    344 .else
    345 real-su-deinstall-flags+=	-r
    346 .endif
    347 .endif
    348 .ifdef PKG_VERBOSE
    349 real-su-deinstall-flags+=	-v
    350 .endif
    351 
    352 real-deinstall:
    353 	${_PKG_SILENT}${_PKG_DEBUG} \
    354 	found="`${PKG_INFO} -e \"${PKGWILDCARD}\" || ${TRUE}`"; \
    355 	if [ "$$found" != "" ]; then \
    356 		${ECHO} Running ${PKG_DELETE} ${real-su-deinstall-flags} $$found ; \
    357 		${PKG_DELETE} ${real-su-deinstall-flags} $$found || ${TRUE} ; \
    358 	fi
    359 .for pkg in ${BUILD_DEPENDS:C/:.*$//}
    360 	${_PKG_SILENT}${_PKG_DEBUG} \
    361 	found="`${PKG_INFO} -e \"${pkg}\" || ${TRUE}`"; \
    362 	if [ "$$found" != "" ]; then \
    363 		${ECHO} Running ${PKG_DELETE} $$found ; \
    364 		${PKG_DELETE} ${real-su-deinstall-flags} $$found || ${TRUE} ; \
    365 	fi
    366 .endfor
    367 .endif						# target(deinstall)
    368 
    369 
    370 ################################################################
    371 # Some more targets supplied for users' convenience
    372 ################################################################
    373 
    374 # The 'info' target can be used to display information about a package.
    375 info: uptodate-pkgtools
    376 	${_PKG_SILENT}${_PKG_DEBUG}${PKG_INFO} ${PKGWILDCARD}
    377 
    378 # The 'check' target can be used to check an installed package.
    379 check: uptodate-pkgtools
    380 	${_PKG_SILENT}${_PKG_DEBUG}${PKG_ADMIN} check ${PKGWILDCARD}
    381 
    382 # Cleaning up
    383 
    384 .if !target(pre-clean)
    385 pre-clean:
    386 	@${DO_NADA}
    387 .endif
    388 
    389 .if !target(clean)
    390 clean: pre-clean
    391 	${RM} -f ${PLIST} ${BUILD_VERSION_FILE} ${BUILD_INFO_FILE} ${SIZE_PKG_FILE} ${SIZE_ALL_FILE}
    392 .endif
    393 
    394 .if !target(cleandir)
    395 cleandir: clean
    396 .endif
    397 
    398 # Install binary pkg, without strict uptodate-check first
    399 # (XXX should be able to snarf via FTP. Later...)
    400 bin-install:
    401 	@if [ -f ${PKGFILE} ] ; then 					\
    402 		${ECHO_MSG} "Installing from binary pkg ${PKGFILE}" ;	\
    403 		${PKG_ADD} ${PKGFILE} ; 				\
    404 	else 				 				\
    405 		${SHCOMMENT} Cycle through some FTP server here ;\
    406 		${ECHO_MSG} "Installing from source" ;			\
    407 		(cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} package &&				\
    408 		${MAKE} ${MAKEFLAGS} clean) ;				\
    409 	fi
    410 
    411 
    412 ################################################################
    413 # The special package-building targets
    414 # You probably won't need to touch these
    415 ################################################################
    416 
    417 # Nobody should want to override this unless PKGNAME is simply bogus.
    418 
    419 .if !target(package-name)
    420 package-name:
    421 	@${ECHO} ${PKGNAME}
    422 .endif # !target(package-name)
    423 
    424 # Show (recursively) all the packages this package depends on.
    425 # If PACKAGE_DEPENDS_WITH_PATTERNS is set, print as pattern (if possible)
    426 PACKAGE_DEPENDS_WITH_PATTERNS?=true
    427 # To be used (-> true) ONLY if the pkg in question is known to be installed
    428 # (i.e. when calling for pkg_create args, and for fake-pkg)
    429 # Will probably not work with PACKAGE_DEPENDS_WITH_PATTERNS=false ...
    430 PACKAGE_DEPENDS_QUICK?=false
    431 .if !target(run-depends-list)
    432 run-depends-list:
    433 .for dep in ${DEPENDS}
    434 	${_PKG_SILENT}${_PKG_DEBUG}					\
    435 	pkg="${dep:C/:.*//}";						\
    436 	dir="${dep:C/[^:]*://}";					\
    437 	cd ${.CURDIR};							\
    438 	if ${PACKAGE_DEPENDS_WITH_PATTERNS}; then			\
    439 		${ECHO} "$$pkg";					\
    440 	else								\
    441 		if cd $$dir 2>/dev/null; then				\
    442 			(cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} package-name; \
    443 		else 							\
    444 			${ECHO_MSG} "Warning: \"$$dir\" non-existent -- @pkgdep registration incomplete" >&2; \
    445 		fi;							\
    446 	fi;								\
    447 	if ${PACKAGE_DEPENDS_QUICK} ; then 			\
    448 		${PKG_INFO} -qf "$$pkg" | ${AWK} '/^@pkgdep/ {print $$2}'; \
    449 	else 							\
    450 		if cd $$dir 2>/dev/null; then				\
    451 			(cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} run-depends-list; \
    452 		else 							\
    453 			${ECHO_MSG} "Warning: \"$$dir\" non-existent -- @pkgdep registration incomplete" >&2; \
    454 		fi;							\
    455 	fi
    456 .endfor
    457 .endif # target(run-depends-list)
    458 
    459 # Build a package but don't check the package cookie
    460 
    461 .if !target(repackage)
    462 repackage: pre-repackage package
    463 
    464 pre-repackage:
    465 	${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${PACKAGE_COOKIE}
    466 .endif
    467 
    468 # Build a package but don't check the cookie for installation, also don't
    469 # install package cookie
    470 
    471 .if !target(package-noinstall)
    472 package-noinstall:
    473 	${_PKG_SILENT}${_PKG_DEBUG}(cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} PACKAGE_NOINSTALL=yes real-package)
    474 .endif
    475 
    476 ################################################################
    477 # Dependency checking
    478 ################################################################
    479 
    480 .if !target(install-depends)
    481 install-depends:
    482 .endif
    483 
    484 ################################################################
    485 # Everything after here are internal targets and really
    486 # shouldn't be touched by anybody but the release engineers.
    487 ################################################################
    488 
    489 .if !target(show-pkgtools-version)
    490 show-pkgtools-version:
    491 	@${ECHO} ${PKGTOOLS_VERSION}
    492 .endif
    493 
    494 # convenience target, to display make variables from command line
    495 # i.e. "make show-var VARNAME=var", will print var's value
    496 show-var:
    497 	@${ECHO} "${${VARNAME}}"
    498 
    499 # Stat all the files of one pkg and sum the sizes up. 
    500 # 
    501 # XXX This is intended to be run before pkg_create is called, so the
    502 # existence of ${PLIST} can be assumed.
    503 print-pkg-size-this:
    504 	@${SHCOMMENT} "This pkg's files" ;				\
    505 	${AWK} 'BEGIN { base = "${PREFIX}/" }				\
    506 		/^@cwd/ { base = $$2 "/" }				\
    507 		/^@ignore/ { next }					\
    508 		NF == 1 { print base $$1 }'				\
    509 		<${PLIST} 						\
    510 	| sort -u							\
    511 	| ${SED} -e 's, ,\\ ,g'						\
    512 	| xargs ${LS} -ld						\
    513 	| ${AWK} 'BEGIN { print("0 "); }				\
    514 		  { print($$5, " + "); }				\
    515 		  END { print("p"); }'					\
    516 	| ${DC}
    517 
    518 # Sizes of required pkgs (only)
    519 # 
    520 # XXX This is intended to be run before pkg_create is called, so the
    521 # dependencies are all installed. 
    522 print-pkg-size-depends:
    523 	@(cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} run-depends-list PACKAGE_DEPENDS_QUICK=true) \
    524 	| xargs -n 1 ${SETENV} ${PKG_INFO} -e				\
    525 	| sort -u							\
    526 	| xargs ${SETENV} ${PKG_INFO} -qs				\
    527 	| ${AWK} -- 'BEGIN { print("0 "); }				\
    528 		/^[0-9]+$$/ { print($$1, " + "); }			\
    529 		END { print("p"); }'					\
    530 	| ${DC}
    531 
    532 
    533 # Fake installation of package so that user can pkg_delete it later.
    534 # Also, make sure that an installed package is recognized correctly in
    535 # accordance to the @pkgdep directive in the packing lists
    536 
    537 .if !target(register)
    538 register: fake-pkg
    539 .endif
    540 
    541 .if !target(fake-pkg)
    542 fake-pkg: ${PLIST}
    543 	${_PKG_SILENT}${_PKG_DEBUG}\
    544 	if [ ! -f ${PLIST} -o ! -f ${COMMENT} -o ! -f ${DESCR} ]; then \
    545 		${ECHO} "** Missing package files for ${PKGNAME} - installation not recorded."; \
    546 		exit 1;							\
    547 	fi
    548 	${_PKG_SILENT}${_PKG_DEBUG}\
    549 	if [ ! -d ${PKG_DBDIR} ]; then	\
    550 		${RM} -f ${PKG_DBDIR};					\
    551 		${MKDIR} ${PKG_DBDIR};					\
    552 	fi
    553 .if defined(FORCE_PKG_REGISTER)
    554 	${_PKG_SILENT}${_PKG_DEBUG}${PKG_DELETE} -O ${PKGNAME}
    555 	${_PKG_SILENT}${_PKG_DEBUG}${RM} -rf ${PKG_DBDIR}/${PKGNAME}
    556 .endif
    557 	${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${BUILD_VERSION_FILE} ${BUILD_INFO_FILE}
    558 	${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${SIZE_PKG_FILE} ${SIZE_ALL_FILE}
    559 	${_PKG_SILENT}${_PKG_DEBUG}\
    560 	files="";				\
    561 	for f in ${.CURDIR}/Makefile ${FILESDIR}/* ${PKGDIR}/*; do	\
    562 		if [ -f $$f ]; then					\
    563 			files="$$files $$f";				\
    564 		fi;							\
    565 	done;								\
    566 	${GREP} '\$$NetBSD' $$files | ${SED} -e 's|^${PKGSRCDIR}/||' > ${BUILD_VERSION_FILE};
    567 .for def in ${BUILD_DEFS}
    568 	@${ECHO} ${def}=	${${def}:Q} | ${SED} -e 's|^PATH=[^ 	]*|PATH=...|' >> ${BUILD_INFO_FILE}
    569 .endfor
    570 	@${ECHO} "CC=	${CC}-`${CC} --version`" >> ${BUILD_INFO_FILE}
    571 	${_PKG_SILENT}${_PKG_DEBUG}					\
    572 	${ECHO} "_PKGTOOLS_VER=${PKGTOOLS_VERSION}" >> ${BUILD_INFO_FILE}
    573 	${_PKG_SILENT}${_PKG_DEBUG}					\
    574 	size_this=`(cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} print-pkg-size-this)`;		\
    575 	size_depends=`(cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} print-pkg-size-depends)`;	\
    576 	${ECHO} $$size_this >${SIZE_PKG_FILE};				\
    577 	${ECHO} $$size_this $$size_depends + p | ${DC} >${SIZE_ALL_FILE}
    578 	${_PKG_SILENT}${_PKG_DEBUG}					\
    579 	if [ ! -d ${PKG_DBDIR}/${PKGNAME} ]; then			\
    580 		${ECHO_MSG} "${_PKGSRC_IN}> Registering installation for ${PKGNAME}"; \
    581 		${MKDIR} ${PKG_DBDIR}/${PKGNAME};			\
    582 		${PKG_CREATE} ${PKG_ARGS_INSTALL} -O ${PKGFILE} > ${PKG_DBDIR}/${PKGNAME}/+CONTENTS; \
    583 		${CP} ${DESCR} ${PKG_DBDIR}/${PKGNAME}/+DESC;		\
    584 		${CP} ${COMMENT} ${PKG_DBDIR}/${PKGNAME}/+COMMENT;	\
    585 		${CP} ${BUILD_VERSION_FILE} ${PKG_DBDIR}/${PKGNAME}/+BUILD_VERSION; \
    586 		${CP} ${BUILD_INFO_FILE} ${PKG_DBDIR}/${PKGNAME}/+BUILD_INFO; \
    587 		if ${TEST} -e ${SIZE_PKG_FILE}; then 			\
    588 			${CP} ${SIZE_PKG_FILE} ${PKG_DBDIR}/${PKGNAME}/+SIZE_PKG; \
    589 		fi ; 							\
    590 		if ${TEST} -e ${SIZE_ALL_FILE}; then 			\
    591 			${CP} ${SIZE_ALL_FILE} ${PKG_DBDIR}/${PKGNAME}/+SIZE_ALL; \
    592 		fi ; 							\
    593 		if [ -n "${PKG_INSTALL_FILE}" ]; then			\
    594 			if ${TEST} -e ${PKG_INSTALL_FILE}; then		\
    595 				${CP} ${PKG_INSTALL_FILE} ${PKG_DBDIR}/${PKGNAME}/+INSTALL; \
    596 			fi;						\
    597 		fi;							\
    598 		if [ -n "${PKG_DEINSTALL_FILE}" ]; then			\
    599 			if ${TEST} -e ${PKG_DEINSTALL_FILE}; then		\
    600 				${CP} ${PKG_DEINSTALL_FILE} ${PKG_DBDIR}/${PKGNAME}/+DEINSTALL; \
    601 			fi;						\
    602 		fi;							\
    603 		if [ -n "${MESSAGE_FILE}" ]; then			\
    604 			if ${TEST} -e ${MESSAGE_FILE}; then		\
    605 				${CP} ${MESSAGE_FILE} ${PKG_DBDIR}/${PKGNAME}/+DISPLAY; \
    606 			fi;						\
    607 		fi;							\
    608 		list="`(cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} run-depends-list PACKAGE_DEPENDS_QUICK=true ECHO_MSG=${TRUE} | sort -u)`" ; \
    609 		for dep in $$list; do \
    610 			realdep="`${PKG_INFO} -e \"$$dep\" || ${TRUE}`" ; \
    611 			if [ `${ECHO} $$realdep | wc -w` -gt 1 ]; then 				\
    612 				${ECHO} '***' "WARNING: '$$dep' expands to several installed packages " ; \
    613 				${ECHO} "    (" `${ECHO} $$realdep` ")." ; \
    614 				${ECHO} "    Please check if this is really intended!" ; \
    615 				continue ; 				\
    616 			fi ; 						\
    617 		done ; 						\
    618 		for realdep in `echo $$list | xargs -n 1 ${SETENV} ${PKG_INFO} -e | sort -u`; do \
    619 			if ${TEST} -z "$$realdep"; then			\
    620 				${ECHO} "$$dep not installed - dependency NOT registered" ; \
    621 			elif [ -d ${PKG_DBDIR}/$$realdep ]; then	\
    622 				if ${TEST} ! -e ${PKG_DBDIR}/$$realdep/+REQUIRED_BY; then \
    623 					${TOUCH} ${PKG_DBDIR}/$$realdep/+REQUIRED_BY; \
    624 				fi; 					\
    625 				${AWK} 'BEGIN { found = 0; } 		\
    626 					$$0 == "${PKGNAME}" { found = 1; } \
    627 					{ print $$0; } 			\
    628 					END { if (!found) { printf("%s\n", "${PKGNAME}"); }}' \
    629 					< ${PKG_DBDIR}/$$realdep/+REQUIRED_BY > ${PKG_DBDIR}/$$realdep/reqby.$$$$; \
    630 				${MV} ${PKG_DBDIR}/$$realdep/reqby.$$$$ ${PKG_DBDIR}/$$realdep/+REQUIRED_BY; \
    631 				${ECHO} "${PKGNAME} requires installed package $$realdep"; \
    632 			fi;						\
    633 		done;							\
    634 	fi
    635 .endif
    636 
    637 # Depend is generally meaningless for arbitrary packages, but if someone wants
    638 # one they can override this.  This is just to catch people who've gotten into
    639 # the habit of typing `${MAKE} depend all install' as a matter of course.
    640 #
    641 .if !target(depend)
    642 depend:
    643 .endif
    644 
    645 # Same goes for tags
    646 .if !target(tags)
    647 tags:
    648 .endif
    649 
    650 ${PLIST}:
    651 	sh ${.CURDIR}/../../../../sets/makeplist ${SETNAME} ${PKGBASE} > ${PLIST}
    652