| 1 | Variants are a powerful feature of the MacPorts port system that allow users to install ports in other than the default manner, optionally enabling or disabling a feature or building a port with or without a dependency. |
| 2 | |
| 3 | == default_variants == |
| 4 | In a portfile, you may use the line: |
| 5 | {{{default_variants variant1 variant2...}}} |
| 6 | to indicate that the port should, by default, build with those variants. |
| 7 | |
| 8 | Breaking variants out of the main port into conflicting variants where one variant is the default variant has the benifit of installing the port with the default variant embedded in the version. Consider the following ports: |
| 9 | |
| 10 | === port Foo === |
| 11 | {{{ |
| 12 | version 1 |
| 13 | configure.args --enable-this --enable-that |
| 14 | variant disable_this { |
| 15 | configure.args_delete --enable-this |
| 16 | configure.args_append --disable-this |
| 17 | } |
| 18 | }}} |
| 19 | === port Bar === |
| 20 | {{{ |
| 21 | version 1 |
| 22 | configure.args --enable-that |
| 23 | default_variants enable_this |
| 24 | variant enable_this conflicts disable_this { |
| 25 | configure.args_append --enable-this |
| 26 | } |
| 27 | variant disable_this conflicts enable_this { |
| 28 | configure.args_append --disable-this |
| 29 | } |
| 30 | }}} |
| 31 | When a user installs port Foo, port Foo installs as version @1_0 while port Bar installs as version @1_0+enable_this. Due to the way port Bar was written, the user knows what variants were applied when the port was installed. |