Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Aug 2006 15:16:33 -0600
From:      John E Hein <jhein@timing.com>
To:        =?ISO-8859-1?Q?G=E1bor_K=F6vesd=E1n?= <gabor@FreeBSD.org>
Cc:        babak@farrokhi.net, amdmi3@mail.ru, Erwin Lansing <erwin@FreeBSD.org>, freebsd-ports@FreeBSD.org, Kris Kennaway <kris@obsecurity.org>
Subject:   Re: DESTDIR implementation [Was:: ATTENTION: is the way DESTDIR was introduced completely wrong?]
Message-ID:  <17644.50609.673610.67525@gromit.timing.com>
In-Reply-To: <44ECB023.708@FreeBSD.org>
References:  <20060814234414.GA57035@hades.panopticon> <44E194BA.2020507@FreeBSD.org> <17634.5246.887894.836856@gromit.timing.com> <20060816173628.GA14848@xor.obsecurity.org> <44ECB023.708@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
G=E1bor K=F6vesd=E1n wrote at 21:44 +0200 on Aug 23, 2006:
 > Kris Kennaway wrote:
 > > mount_nullfs ${PORTSDIR} ${DESTDIR}${PORTSDIR}
 > > mount_nullfs ${WRKDIR} ${DESTDIR}${WRKDIR}
 > > mount_devfs foo ${DESTDIR}/dev
 > > chroot ${DESTDIR} cd ${.CURDIR} && make install
 > >
 > > A suitable version of the above should allow all ports to be install=
ed
 > > into a jail-ready filesystem hierarchy, while requiring 0 port
 > > changes.
 >
 > Ok, I think it's time to follow this way, but have to make some parts =

 > clearer. For your last line, it should be
 > =

 > chroot ${DESTDIR} cd ${.CURDIR} && make ${.TARGETDIR}

I assume you mean .TARGET


 > since we want to run all targets chrooted. We could put this part into=
 =

 > an .if defined(DESTDIR) block before the targets, but I don't know how=
 =

 > to prevent running the further code, since we don't want to reach =

 > do-install in the host environment, but only in the chroot. I think of=
 =

 > exit 0, if that's correct, or what else is better.
 > So, what I mean:
 > =

 > .if defined(DESTDIR)
 > .BEGIN   # We need this if not in a target
 >     ${MOUNT_NULLFS} ${PORTSDIR} ${DESTDIR}${PORTSDIR}
 >     ${MOUNT_NULLFS} ${WRKDIR} ${DESTDIR}${WRKDIR}
 >     ${MOUNT_DEVFS} foo ${DESTDIR}/dev
 >     ${CHROOT} ${DESTDIR} cd ${.CURDIR} && ${MAKE} ${.TARGETDIR}
 >     exit 0
 > .endif

Each line with a command in a makefile is it's own shell.
So 'exit 0' will start a shell and exit that shell.
It will not prevent make from continuing.

'exit 1' (or anything that returns a non-zero code, like false) will
stop make (unless -k or -i or similar is specified), but that's not
what you want.


make(1) is not a very good tool for this kind of thing (a script would
probably be better), but here is one way to do this kind of two stage
make (untested, but illustrates the point):

bsd.port.mk would have something like this:

STAGE?=3D     1
=2Eif ${STAGE} =3D=3D 1 && defined(DESTDIR) && !empty(DESTDIR)

=2EMAKEFLAGS: STAGE=3D2

=2EBEGIN:
	${MOUNT_NULLFS} ${PORTSDIR} ${DESTDIR}${PORTSDIR}
	${MOUNT_NULLFS} ${WRKDIR} ${DESTDIR}${WRKDIR}
	${MOUNT_DEVFS} foo ${DESTDIR}/dev
	${CHROOT} ${DESTDIR} cd ${.CURDIR} && ${MAKE} ${.TARGET}

=2Eelse
 .
 .
 rest of bsd.port.mk
 .
 .
=2Eendif

You could put the first part into a bsd.destdir.mk and .include it
to make it look cleaner.

Note there are other complications like unmounting the nullfs and
devfs.


 > The another issue I find is how we can pass variables to the chrooted =

 > make. E.g. if we want to set WITH_FOO in command line or in make.conf.=
 =

 > And note, that we can't just pass everything, since DESTDIR should be =

 > unset in the chroot, otherwise we would run into infinite loop and it =

 > would fail due to the non-existent directories.

Really, for these and other reasons, a script would be better.  It
could be done with make(1) and bsd.port.mk, but it's probably not
worth it.

Again, if we do decide to go this route, we should remove all mention
of DESTDIR from Mk/*.mk (rather than pretend to support it, but
incorrectly).

Others have mentioned cross building.  Neither proper DESTDIR support
in bsd.port.mk nor a scripted mount_nullfs & a chroot is going to be
the one thing to solve that problem.  Some ports will build okay if
you give them access to cross tools (like ppc-gcc) and tell them what
target architecture to produce.  Other ports will need to be taught.
Some ports might need to run intermediate native architecture tools
produced at build time in order to produce the final cross arch
product.  It's not as simple as just being able to install to an
alternate location.  And I don't think it matters much how ports/Mk
handles DESTDIR.  There are bigger issues.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?17644.50609.673610.67525>