MacPorts subports are a way of declaring multiple related ports in a single Portfile. It is especially helpful to use subports when the related ports share variables or keywords, because they can be declared in the shared part of the Portfile and used by each subport.
subport name body
The subport declaration causes MacPorts to define an additional port, with the name given by the declaration. The keywords for the subport are those in the global section of the Portfile, and those in the brace-enclosed body.
For example, if a Portfile contains:
Portfile 1.0 name example depends_lib aaa configure.args --bbb subport example-sub1 { depends_lib-append ccc configure.args --ddd } subport example-sub2 { depends_lib-append eee configure.args-append --fff }
MacPorts will produce the same results as if there were three Portfiles:
Portfile 1.0 name example # Note: For the parent port, 'subport' has the same value as 'name'. # Also, one cannot override the subport name; it's shown here merely # to illustrate what the value is set to, for the given context. #subport example depends_lib aaa configure.args --bbb
Portfile 1.0 name example # Value for 'subport' shown here for illustration purposes only; see note above. #subport example-sub1 depends_lib aaa depends_lib-append ccc configure.args --ddd
Portfile 1.0 name example # Value for 'subport' shown here for illustration purposes only; see note above. #subport example-sub2 depends_lib aaa depends_lib-append eee configure.args --bbb configure.args-append --fff
Because MacPorts treats each subport as a separate port declaration, each subport will have its own, independent phases: fetch, configure, build, destroot, install, activate, etc. However, because the subports share the global declaration part, all the subports will by default share the same dist_subdir. This means that MacPorts only needs to fetch the distfiles once, and the remaining subports can reuse the distfiles.