| 1 | == Command Line Options == |
| 2 | |
| 3 | The behavior of compilers are primarily controlled with [https://en.wikipedia.org/wiki/Command-line_interface#Command-line_option switches]. For example, `-I${prefix}/include` and `-L${prefix}/lib` tell the [https://en.wikipedia.org/wiki/C_(programming_language) C] [https://en.wikipedia.org/wiki/Preprocessor preprocessor] and [https://en.wikipedia.org/wiki/Linker_(computing) linker] to look in the [https://guide.macports.org/chunked/reference.variables.html MacPorts prefix] for header files and libraries respectively. However, changing compiler behavior with switches can cause problems. |
| 4 | * Order matters. |
| 5 | * `-I${prefix}/include -I${worksrcpath}/include` and `-I${worksrcpath}/include -I${prefix}/include` produce different results if different header files with the same name are in both location. |
| 6 | * Such errors can be subtle and difficult to track down, especially when the header files are from different versions of the same packages (e.g. during the upgrade process). |
| 7 | * The MacPorts construct `conflicts_build` can be used to prevent the conflicting header files from being simultaneously installed, but this not ideal. |
| 8 | * Using `-isystem` instead of `-I` can more [https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html precisely control] search order, but this also [https://trac.macports.org/ticket/40656 causes problems]. |
| 9 | * The search order for libraries has similar problems, but it is more difficult to precisely control library search order (there is just `-L` or using the full library path name). |
| 10 | * The MacPorts [https://guide.macports.org/chunked/development.buildbot.html buildbot] is careful to build a port only with the minimal set of dependencies active, which prevents most search order issues. |
| 11 | * Switches can be “baked in” the installed files. |
| 12 | * [https://trac.macports.org/ticket/49801 Some packages] record the history of the switches they were built with. |
| 13 | * Some packages use the same switches they were built with to build other packages. |
| 14 | * At best, this is unnecessary noise. At worst, it causes build problems that can be difficult to diagnose. |
| 15 | * The switches `-isysroot` and ` -Wl,-syslibroot` are particularly problematic. |
| 16 | * Major upgrades of Xcode usually remove old [https://en.wikipedia.org/wiki/Software_development_kit SDKs]. |
| 17 | * After a user upgrades Xcode, ports can [https://trac.macports.org/ticket/56458 mysteriously stop building correctly]. |
| 18 | * If the Xcode versions of the user and buildbot are different, ports can [https://trac.macports.org/ticket/59078 fail to build correctly]. |
| 19 | |
| 20 | |
| 21 | == Environmental Variables == |
| 22 | |
| 23 | To a limited extent, the behavior of compilers can also be controlled with [https://en.wikipedia.org/wiki/Environment_variable environmental variables] instead of switches. |
| 24 | ||= Switch =||= Variable =||= Affect =||= Notes =|| |
| 25 | || `-I`, `-isystem` || CPATH || treated as a delimited list of paths to be added to the default system include path list || || |
| 26 | || `-L` || LIBRARY_PATH || tries the directories specified when searching for special linker files || || |
| 27 | || `-mmacosx-version-min` || MACOSX_DEPLOYMENT_TARGET || the default deployment target || || |
| 28 | || `-isysroot`, `-Wl,-syslibroot` || SDKROOT || specifies the SDK || || |
| 29 | || || DEVELOPER_DIR || tells `xcrun` where to search for development tools and properties || || |
| 30 | || || CC_PRINT_OPTIONS || like `-v` but logs the commands || [https://github.com/macports/macports-base/pull/163 interferes] with`-v` || |
| 31 | || || CC_PRINT_OPTIONS_FILE || the file to log CC_PRINT_OPTIONS output to || || |
| 32 | |
| 33 | Using environmental variables can alleviate some of the problems with switches.\\ |
| 34 | * They are less likely to be “baked in” the installed files. |
| 35 | * Directories in CPATH and LIBRARY_PATH are searched **after** those specified by the command line options. |
| 36 | However, an environmental variable is no panacea. |
| 37 | * Not all build systems [https://github.com/macports/macports-ports/pull/5385 respect environmental variables]. |
| 38 | * Not all environmental variables are supported on all compilers. |
| 39 | * Setting CC_PRINT_OPTIONS causes `-v` to behave differently. For example, it breaks FindOpenMP in CMake. |
| 40 | |
| 41 | ||= Variable =||= Minimum Xcode Support =||= Minimun Clang Support =||= Minimum GCC Support =|| |
| 42 | || CPATH || ??? || ??? || ??? || |
| 43 | || LIBRARY_PATH || ??? || ??? || ??? || |
| 44 | || MACOSX_DEPLOYMENT_TARGET || ??? || ??? || ??? || |
| 45 | || SDKROOT || ??? || ??? || [https://github.com/macports/macports-ports/commit/1850136d289019f3b29a5b24d3ec8ef9b23913ee version 9] || |
| 46 | || DEVELOPER_DIR || ??? || ??? || - || |
| 47 | || CC_PRINT_OPTIONS || ??? || ??? || ??? || |
| 48 | || CC_PRINT_OPTIONS_FILE || ??? || ??? || ??? || |