Changes between Version 12 and Version 13 of PortfileRecipes


Ignore:
Timestamp:
Oct 24, 2009, 8:02:04 AM (14 years ago)
Author:
ryandesign (Ryan Carsten Schmidt)
Comment:

Add "Providing compiler variants" section

Legend:

Unmodified
Added
Removed
Modified
  • PortfileRecipes

    v12 v13  
    160160
    161161Note: Ensure you use the correct capitalization for each filename. For example, many projects typically use all-caps for most of the documentation files, except for ChangeLog, which is often written in camel-case. If you fail to use the correct capitalization, the port may still install on your system, but will fail for users with case-sensitive filesystems.
     162
     163== Providing compiler variants == #gcc
     164
     165By default, a port will compile using Apple's gcc compiler.
     166For most ports this is fine, but some require a newer version of gcc, or are for some reason incompatible with Apple's version.
     167In these cases you can use `configure.compiler` to specify an alternate compiler, for example one provided by a MacPorts gcc port.
     168More commonly, a port specifies such a compiler because it needs gcj or gfortran, which Apple does not provide any version of at all.
     169
     170On the one hand, such ports should prefer to use the newest suitable stable version of gcc they can.
     171On the other hand, a user may already have an older gcc port installed and may not want to spend the time to compile a newer one right now, or may have other reasons for preferring a particular version of gcc.
     172Therefore, ports that need to use a gcc port, but aren't picky about exactly which one, are encouraged to offer variants:
     173
     174{{{
     175variant gcc42 conflicts gcc43 gcc44 description {Compile with gcc42} {
     176    configure.compiler macports-gcc-4.2
     177    depends_lib-append port:gcc42
     178}
     179
     180variant gcc43 conflicts gcc42 gcc44 description {Compile with gcc43} {
     181    configure.compiler macports-gcc-4.3
     182    depends_lib-append port:gcc43
     183}
     184
     185variant gcc44 conflicts gcc42 gcc43 description {Compile with gcc44} {
     186    configure.compiler macports-gcc-4.4
     187    depends_lib-append port:gcc44
     188}
     189
     190if {![variant_isset gcc42] && ![variant_isset gcc43] && ![variant_isset gcc44]} {
     191    default_variants +gcc44
     192}
     193}}}
     194
     195Note that the variants are all marked as conflicting with one another, and that the newest one is chosen by default if the user has not picked one.
     196Note also that the compiler dependencies are library dependencies because programs compiled using these compilers will generally end up linked to at least one of the compiler's libraries (i.e. libgcc_s.dylib, libgfortran.dylib, etc.).
     197
     198Setting `configure.compiler` changes the values MacPorts puts in variables like ${configure.cc}, ${configure.cxx}, ${configure.f77}, etc., which MacPorts automatically sets as environment variables during the configure phase.
     199If the software in question doesn't use the configure phase, and you therefore need to pass these variables to the build phase, you must do so in a pre-build block;
     200if you try to do so directly in the portfile body, you'll pick up the original values, before the variant changed them.
     201
     202{{{
     203pre-build {
     204    build.args      CC=${configure.cc} \
     205                    CXX=${configure.cxx}
     206}
     207}}}
     208
     209Another reason to want compiler variants is if the software installs a library, or uses a library built with a different gcc.
     210Subtle and difficult-to-find errors can occur if a library and the program using it are not both compiled with the same compiler.