Solved Download distfile for architecture?

Is it possible to conditionally download a distfile based on architecture? ARCH isn't available since it isn't possible to put .include <bsd.port.pre.mk> before DISTFILES. So currently I'm resorting to downloading the artifact for every architecture and then picking the right one later when ARCH is available like:
Makefile:
DISTFILES=  some-artifact_amd64.tar.gz \
            some-artifact_i386.tar.gz

...
.include <bsd.port.pre.mk>
.if ${ARCH} == amd64
    ${DO_SOMETHING} some-artifact_amd64.tar.gz
.elif ${ARCH} == i386
    ${DO_SOMETHING} some-artifact_i386.tar.gz
.else
    ...
But that's messy/inefficient...
 
So, why not simply
Makefile:
DISTFILES=  some-artifact_${ARCH}.tar.gz

I don't see why this shouldn't work, variables in Makefiles are evaluated lazily, and by the time DISTFILES is evaluated, ARCH should be defined.

Of course, you still need both files in your distinfo
 
Oh and if your package can be built for many architectures, and only some of them need extra distfiles, you could either come up with something like (untested)
Makefile:
DISTFILES=    foo.tar.gz \
              bar.tar.gz \
              ${ARCH_DISTFILES}

[...]

.include <bsd.port.pre.mk>
.if ${ARCH} == amd64
        ARCH_DISTFILES=   some-artifact_amd64.tar.gz
.elif ${ARCH} == i386
        ARCH_DISTFILES=   some-artifact_i386.tar.gz
.else
        ARCH_DISTFILES=
.endif
or apply some expansion magic in DISTFILES directly, e.g. using the :?true_string:false_string expansion, see make(1), which could avoid inclusion of bsd.port.pre.mk, but gets unreadable quickly ;)
 
Even better. It ends up looking a lot like my original version but doesn't force everyone to download every version and doesn't fail if someone builds on an architecture for which the artifact doesn't exist.
 
Back
Top