Subject: RFC addendum: Subpackage dependencies
To: None <tech-pkg@NetBSD.org>
From: Johnny C. Lam <jlam@NetBSD.org>
List: tech-pkg
Date: 05/31/2004 22:18:54
Since both Eric and Julio want the ability to specify dependencies
separately for each subpackage, I'll outline a way to do this that
will be succinct and hopefully be easy for package maintainers to
understand.

The technical difficulty with listing dependencies for each subpackage
is that most packages pull in dependencies via buildlink3.mk files,
and that including some buildlink3.mk files don't add any dependencies,
e.g. if you include libiconv/buildlink3.mk on a NetBSD-2.0 machine.
To work around this problem, I think we can make the following
modification to bsd.pkg.mk:

	real-su-install:
	.for _subpkg_ in ${SUBPACKAGES}
		${SETENV} ${BUILD_ENV} ${MAKE} ${MAKEFLAGS} \
			real-su-install-subpkg SUBPACKAGE=${_subpkg_}
	.endfor

and rename the current real-su-install to "real-su-install-subpkg" with
the appropriate modifications.  Then in the package Makefile, do:

	SUBDEPENDS.client=	lib

	.include "../../mk/bsd.prefs.mk"

	.if empty(SUBPACKAGE) || (${SUBPACKAGE} == "lib")
	.  include "../../graphics/imlib/buildlink3.mk"
	.endif
	.if empty(SUBPACKAGE) || (${SUBPACKAGE} == "client")
	.  include "../../x11/gtk/buildlink3.mk"
	.endif

	.include "../../mk/bsd.pkg.mk"

The idea is that SUBPACKAGE is empty during every phase except during
the "install" and "package" phases.  This lets the usual dependency
machinery see only the relevant dependencies in the buildlink3.mk files
for each subpackage.  It's possible to make it look nicer by doing
something like:

	SUBDEPENDS.client=	lib
	DEPENDS.lib=		imlib
	DEPENDS.client=		gtk

	.include "../../graphics/imlib/buildlink3.mk"
	.include "../../x11/gtk/buildlink3.mk"
	.include "../../mk/bsd.pkg.mk"

Here, SUBDEPENDS.* describes the internal dependency structure of the
subpackages, and DEPENDS.* describes the external dependencies of each
subpackage.  We would add some logic to bsd.buildlink3.mk to add the
correct dependencies to each subpackage.  The main package would still
depend on everything, but the subpackages would have individual lists
of dependencies.

The problem here is that this scheme only works with packages that use
buildlink3.  We could extend it by having DEPENDS.* also list dependencies
of the usual form "foo>=1.0:../../devel/foo", and for those elements listed
in DEPENDS.* that match "*:*", we just add them directly to the dependencies
for that subpackage.  So for non-buildlink3 packages, we have:

	SUBDEPENDS.client=	lib
	DEPENDS.lib=		imlib>=1.9.14nb5:../../graphics/imlib
	DEPENDS.client=		gtk+>=1.2.10:../../x11/gtk

	.include "../../mk/bsd.pkg.mk"

Can anyone see any problems or suggest refinements to doing it this way?
Again, please cc: me on all replies.

	Thanks,

	-- Johnny Lam <jlam@NetBSD.org>