1. Introduction
2. Installing MacPorts
2.1. Install Xcode
2.2. Install MacPorts
2.3. Upgrade MacPorts
2.4. Uninstall MacPorts
2.5. MacPorts and the Shell
3. Using MacPorts
3.1. The port Command
3.2. Port Variants
3.3. Common Tasks
3.4. Port Binaries
4. Portfile Development
4.1. Portfile Introduction
4.2. Creating a Portfile
4.3. Example Portfiles
4.4. Port Variants
4.5. Subports
4.6. Patch Files
4.7. Local Portfile Repositories
4.8. Portfile Best Practices
4.9. MacPorts' buildbot
5. Portfile Reference
5.1. Global Keywords
5.2. Global Variables
5.3. Port Phases
5.4. Dependencies
5.5. Variants
5.6. Subports
5.7. Tcl Extensions & Useful Tcl Commands
5.8. StartupItems
5.9. Livecheck / Distcheck
5.10. PortGroups
6. MacPorts Internals
6.1. File Hierarchy
6.2. Configuration Files
6.3. Port Images
6.4. APIs and Libs
6.5. The MacPorts Registry
6.6. Tests
7. MacPorts Project
7.1. Using Trac for Tickets
7.2. Using Git and GitHub
7.3. Contributing to MacPorts
7.4. Port Update Policies
7.5. Updating Documentation
7.6. MacPorts Membership
7.7. The PortMgr Team
8. MacPorts Guide Glossary
Glossary

4.5. Subports

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.

4.5.1. Subport Declarations

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.

4.5.2. Subport Examples

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

4.5.3. Subport Tips

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.