| 1 | == Overview == |
| 2 | |
| 3 | The flexibility of a [https://guide.macports.org/#development Portfile] allows MacPorts to support a wide variety of languages. |
| 4 | The lowest level of support is for a Portfile to call the appropriate build command. |
| 5 | The port [https://github.com/macports/macports-ports/blob/master/math/lapack/Portfile lapack-manpages] builds documentation by calling [https://en.wikipedia.org/wiki/Doxygen doxygen]. |
| 6 | Commonality among several ports can be gathered into a [https://guide.macports.org/#reference.portgroup portgroup]. |
| 7 | For example, [https://github.com/macports/macports-ports/blob/master/_resources/port1.0/group/cargo_fetch-1.0.tcl there is a portgroup] that facilitates building projects written in [https://en.wikipedia.org/wiki/Rust_(programming_language) Rust]. However, some language have direct support in the [https://guide.macports.org/#introduction MacPorts base]. |
| 8 | |
| 9 | == Minimal Base Support == |
| 10 | [https://en.wikipedia.org/wiki/Perl Perl], |
| 11 | [https://en.wikipedia.org/wiki/Python_(programming_language) Python], |
| 12 | [https://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], |
| 13 | [https://en.wikipedia.org/wiki/AWK Awk], |
| 14 | [https://en.wikipedia.org/wiki/GNU_Bison Bison], |
| 15 | and |
| 16 | [https://en.wikipedia.org/wiki/Java_(programming_language) Java] |
| 17 | have minimal support in the base through |
| 18 | {{{ |
| 19 | configure.perl |
| 20 | configure.python |
| 21 | configure.ruby |
| 22 | configure.awk |
| 23 | configure.bison |
| 24 | configure.javac |
| 25 | }}} |
| 26 | These commands do nothing more than set environmental variables during the [https://guide.macports.org/#reference.phases configure phase] if [https://guide.macports.org/#reference.phases.configure use_configure] is {{{yes}}}. |
| 27 | They do **not** add [https://guide.macports.org/#reference.dependencies dependencies]. |
| 28 | |
| 29 | == Full Base Support == |
| 30 | [https://en.wikipedia.org/wiki/C_(programming_language) C] and [https://en.wikipedia.org/wiki/C%2B%2B C++] are fully supported in the base. This means that, unless instructed otherwise, each Portfile will have access to a compiler for both of these languages. |
| 31 | * {{{configure.cc}}}, {{{configure.cxx}}}, and {{{configure.cpp}}} are set. |
| 32 | * The environmental variables {{{CC}}} and {{{CXX}}} are set during the configure phase if {{{use_configure}}} is {{{yes}}}. |
| 33 | * If MacPorts provides the compiler, the appropriate dependencies are added. |
| 34 | |
| 35 | Ideally, [https://guide.macports.org/#installing.xcode Xcode] would provide the C and C++ compilers. |
| 36 | This ideal, however, cannot always be achieved. |
| 37 | MacPorts have two alternates to provide C and C++ compilers: [https://en.wikipedia.org/wiki/Clang Clang] and [https://en.wikipedia.org/wiki/GNU_Compiler_Collection GCC]. |
| 38 | |
| 39 | === Language Standards === |
| 40 | Both C and C++ evolve. |
| 41 | A project can require a more recent [https://en.wikipedia.org/wiki/C_(programming_language)#History C standard] or [https://en.wikipedia.org/wiki/C%2B%2B#Standardization C++ standard] than is provided by the Xcode compiler. |
| 42 | |
| 43 | C Standards supported by Clang, GCC, and Xcode: |
| 44 | ||= C Standard =||= Clang =||= [https://trac.macports.org/wiki/XcodeVersionInfo Xcode Clang] =||= Xcode =||= GCC =|| |
| 45 | ||= 1989 (C89) =|| - || - || - || - || |
| 46 | ||= 1999 (C99) =|| - || 211.10.1 || 4.2 || [https://gcc.gnu.org/c99status.html 4.5] || |
| 47 | ||= 2011 (C11) =|| [https://releases.llvm.org/3.1/docs/ClangReleaseNotes.html#cchanges 3.1] || 318.0.61 || 4.3 || [https://gcc.gnu.org/wiki/C11Status 4.9] || |
| 48 | |
| 49 | [https://en.cppreference.com/w/cpp/compiler_support C++ Standards supported by Clang, GCC, and Xcode]: |
| 50 | ||= C++ Standard =||= Clang =||= Xcode Clang =||= Xcode =||= GCC =|| |
| 51 | ||= 1998 (C++98) =|| [https://clang.llvm.org/cxx_status.html#cxx98 -] =||= - =||= - =||= [https://gcc.gnu.org/projects/cxx-status.html#cxx98 -] =|| |
| 52 | ||= 2011 (C++11) =|| [https://clang.llvm.org/cxx_status.html#cxx11 3.3] || 500.2.75 || 5.0 || [https://gcc.gnu.org/projects/cxx-status.html#cxx11 4.8.1] || |
| 53 | ||= 2014 (C++14) =|| [https://clang.llvm.org/cxx_status.html#cxx14 3.4] || 600.0.54 || 6.1 || [https://gcc.gnu.org/projects/cxx-status.html#cxx14 5] || |
| 54 | ||= 2017 (C++17) =|| [https://clang.llvm.org/cxx_status.html#cxx17 5.0] || 902.0.39.1 || 9.3 || [https://gcc.gnu.org/projects/cxx-status.html#cxx17 7] || |
| 55 | |
| 56 | === Parallelism === |
| 57 | The compilers provided by Xcode do not support all of the methods of parallelism that ports may require. |
| 58 | |
| 59 | None of the compilers provided by Xcode support any version [https://en.wikipedia.org/wiki/OpenMP OpenMP]. |
| 60 | OpenMP Standards supported by Clang, GCC, and Xcode: |
| 61 | ||= OpenMP Version =||= Clang =||= Xcode Clang =||= Xcode =||= GCC =|| |
| 62 | ||= 2.5 =|| [https://openmp.llvm.org 3.8] || Future? || Future? || [https://gcc.gnu.org/wiki/openmp 4.2] || |
| 63 | ||= 3.0 =|| [https://openmp.llvm.org 3.8] || Future? || Future? || [https://gcc.gnu.org/wiki/openmp 4.4] || |
| 64 | ||= 3.1 =|| [https://openmp.llvm.org 3.8] || Future? || Future? || [https://gcc.gnu.org/wiki/openmp 4.7] || |
| 65 | ||= 4.0 =|| [https://openmp.llvm.org Partial] || Future? || Future? || [https://gcc.gnu.org/wiki/openmp 4.9] || |
| 66 | ||= 4.5 =|| [https://openmp.llvm.org Partial] || Future? || Future? || ??? || |
| 67 | |
| 68 | None of the compilers provided by Xcode implement [https://en.wikipedia.org/wiki/Message_Passing_Interface MPI]. |
| 69 | To implement it, [https://en.wikipedia.org/wiki/MPICH MPICH] and [https://en.wikipedia.org/wiki/Open_MPI Open MPI] provide wrappers for Clang, GCC, and Xcode. |
| 70 | |
| 71 | The compilers provided by Xcode only support [https://en.wikipedia.org/wiki/Thread-local_storage thread-local storage] if the OS supports it, which did not happen until [https://en.wikipedia.org/wiki/Mac_OS_X_Lion Mac OS X Lion]. |
| 72 | GCC and Clang can emulate thread-local storage even on versions of macOS that do not support it. |
| 73 | |
| 74 | === C++ Standard Library === |
| 75 | There are three possible [https://en.wikipedia.org/wiki/C%2B%2B_Standard_Library C++ standard libraries] on macOS. |
| 76 | |
| 77 | C++ standard libraries supported by Clang, GCC, and Xcode: |
| 78 | ||= C++ Standard Library =||= Supported by Clang =||= Supported by Xcode =||= Supported by GCC =||= Supports C++11 =|| |
| 79 | ||=[https://libcxx.llvm.org libc++] =|| Yes ({{{-stdlib=libc++}}}) ||Yes ({{{-stdlib=libc++}}}) || No || Yes || |
| 80 | ||=[https://gcc.gnu.org/onlinedocs/libstdc++ libstdc++ in /usr/lib/] =||Yes ({{{-stdlib=libstdc++}}}) || Yes ({{{-stdlib=libstdc++}}}) || No || No || |
| 81 | ||=[https://gcc.gnu.org/onlinedocs/libstdc++ libstdc++ provided by MacPorts] =||Yes ({{{-stdlib=macports-libstdc++}}}) || No || Yes || Yes || |
| 82 | |
| 83 | === Getting the Right Compiler in the Portfile === |
| 84 | Names of valid Compilers: |
| 85 | ||= [https://en.wikipedia.org/wiki/Regular_expression Regular Expression] =||= Description =|| |
| 86 | || {{{^apple-gcc-(4\.[02])$}}} || MacPorts Apple GCC %s || |
| 87 | || {{{^cc$}}} || System cc || |
| 88 | || {{{^clang$}}} || Xcode Clang || |
| 89 | || {{{^gcc$}}} || System GCC || |
| 90 | || {{{^gcc-(3\.3|4\.[02])$}}} || Xcode GCC %s || |
| 91 | || {{{^llvm-gcc-4\.2$}}} || Xcode LLVM-GCC 4.2 || |
| 92 | || {{{^macports-clang$}}} || MacPorts Clang (port select) || |
| 93 | || {{{^macports-clang-(\d+\.\d+)$}}} || MacPorts Clang %s || |
| 94 | || {{{^macports-dragonegg-(\d+\.\d+)$}}} || MacPorts DragonEgg %s || |
| 95 | || {{{^macports-dragonegg-(\d+\.\d+)-gcc-(\d+\.\d+)$}}} || MacPorts DragonEgg %s with GCC %s || |
| 96 | || {{{^macports-gcc$}}} || MacPorts GCC (port select) || |
| 97 | || {{{^macports-gcc-(\d+(?:\.\d+)?)$}}} || MacPorts GCC %s || |
| 98 | || {{{^macports-llvm-gcc-4\.2$}}} || MacPorts LLVM-GCC 4.2 || |
| 99 | || {{{^macports-g95$}}} || MacPorts G95 || |
| 100 | || {{{^macports-mpich-default$}}} || MacPorts MPICH Wrapper for MacPorts' Default C/C++ Compiler || |
| 101 | || {{{^macports-openmpi-default$}}} || MacPorts Open MPI Wrapper for MacPorts' Default C/C++ Compiler || |
| 102 | || {{{^macports-mpich-clang$}}} || MacPorts MPICH Wrapper for Xcode Clang || |
| 103 | || {{{^macports-openmpi-clang$}}} || MacPorts Open MPI Wrapper for Xcode Clang || |
| 104 | || {{{^macports-mpich-clang-(\d+\.\d+)$}}} || MacPorts MPICH Wrapper for Clang %s || |
| 105 | || {{{^macports-openmpi-clang-(\d+\.\d+)$}}} || MacPorts Open MPI Wrapper for Clang %s || |
| 106 | || {{{^macports-mpich-gcc-(\d+(?:\.\d+)?)$}}} || MacPorts MPICH Wrapper for GCC %s || |
| 107 | || {{{^macports-openmpi-gcc-(\d+(?:\.\d+)?)$}}} || MacPorts Open MPI Wrapper for GCC %s || |
| 108 | |
| 109 | The compiler is chosen with the following precedence: |
| 110 | 1. If {{{configure.compiler}}} is set in the Portfile, then that is the compiler that is used. |
| 111 | 1. If the user sets {{{default_compilers}}}, the compiler is chosen from that list unless the compiler is blacklisted. |
| 112 | 1. If the Portfile sets {{{compiler.whitelist}}}, the compiler is chosen from that list unless the compiler is blacklisted. |
| 113 | 1. If the Portfile sets {{{compiler.fallback}}}, the compiler is chosen from that list unless the compiler is blacklisted. |
| 114 | 1. A compiler is chosen (Xcode compilers if possible) that |
| 115 | * is not blacklisted, |
| 116 | * is known to work on the particular version of the OS, and |
| 117 | * satisfies the requirements set in the Portfile. |
| 118 | |
| 119 | The following are requirements that can be set in the Portfile: |
| 120 | ||= =||= Description =||= Possible Values =||= Default =|| |
| 121 | || {{{compiler.c_standard}}} || Standard for the C programming language || 1989, 1999, 2011, etc. || 1989 || |
| 122 | || {{{compiler.cxx_standard}}} || Standard for the C++ programming language || 1998, 2011, 2014, 2017, etc. || 1998 || |
| 123 | || {{{compiler.openmp_version}}} || Version of OpenMP required || blank, 2.5, 3.0, 3.1, 4.0, 4.5, etc. || blank || |
| 124 | || {{{compiler.mpi}}} || MacPorts port that provides MPI || blank, mpich, or openmpi || blank || |
| 125 | || {{{compiler.thread_local_storage}}} || Is thread local storage required, e.g. {{{__thread}}}, {{{_Thread_local}}}, or {{{std::thread_local}}} || yes or no || no || |
| 126 | || {{{configure.cxx_stdlib}}} || C++ Standard Library || blank, libc++, libstdc++, or macports-libstdc++ || dependent on user preference and OS version || |
| 127 | |
| 128 | == Medium Base Support == |
| 129 | [https://en.wikipedia.org/wiki/Objective-C Objective-C] and |
| 130 | [https://en.wikipedia.org/wiki/Objective-C#Objective-C++ Objective-C++] |
| 131 | are supported as well. |
| 132 | * {{{configure.objc}}} and {{{configure.objcxx}}} are set. |
| 133 | * The environmental variables {{{OBJC}}} and {{{OBJCXX}}} are set during the configure phase if {{{use_configure}}} is {{{yes}}}. |
| 134 | This is achieved, however, by assuming that the Objective-C and Objective-C++ compilers as the same as the C and C++ compilers respectively. |
| 135 | |
| 136 | [https://en.wikipedia.org/wiki/Fortran Fortran] is partially supported in the base. |
| 137 | * {{{configure.fc}}}, {{{configure.f90}}}, and {{{configure.f77}}} are set. |
| 138 | * The environmental variables {{{FC}}}, {{{F90}}}, and {{{F77}}} are set during the configure phase if {{{use_configure}}} is {{{yes}}}. |
| 139 | * If MacPorts provides the compiler, the appropriate dependencies are added. |
| 140 | Xcode does not provide any Fortran compilers. |
| 141 | Clang does not provide a Fortran compiler (although [https://github.com/flang-compiler/flang Flang] might one day be viable). |
| 142 | A Fortran compiler is available only if one is requested or is provided by a previously requested compiler. |
| 143 | 1. A Fortran compiler is requested if {{{compiler.require_fortran}}} is set to {{{yes}}}. |
| 144 | 1. A Fortran compiler is provided if GCC is being used as a compiler (since GCC provides [https://en.wikipedia.org/wiki/GNU_Fortran GFortran] anyway). |
| 145 | |
| 146 | The Fortran compiler is chosen with the following precedence: |
| 147 | 1. If a Fortran compiler is already available (e.g. from GCC), then use it. |
| 148 | 1. If the Portfile sets {{{compiler.fortran_fallback}}}, the Fortran compiler is chosen from that list unless the compiler is blacklisted. |
| 149 | 1. A Fortran compiler is chosen that |
| 150 | * is not blacklisted, |
| 151 | * is known to work on the particular version of the OS, and |
| 152 | * satisfies the requirements set in the Portfile. |
| 153 | |
| 154 | == Compiler Consideration: Runtime Libraries == |
| 155 | When a GCC compiler is used, the resulting binary links against [https://wiki.osdev.org/Libgcc libgcc], a low-level runtime library. |
| 156 | While there can be multiple versions of these runtimes in a single process, it is not possible to pass objects between different versions. |
| 157 | So while MacPorts allows multiple versions of GCC to be installed at once, they must all use the same libgcc. |
| 158 | This means that an upgrade of libgcc sometimes requires ports compiled with GCC to be rebuilt. |
| 159 | |
| 160 | Passing objects between C++ standard libraries can cause crashes that are difficult to debug. |
| 161 | The current trend is to [https://trac.macports.org/wiki/LibcxxOnOlderSystems use libc++ on all systems] except on older [https://en.wikipedia.org/wiki/Apple%27s_transition_to_Intel_processors PowerPC] systems. |
| 162 | Some notes on the C++ Standard Libraries: |
| 163 | 1. libc++ |
| 164 | * Installed by the system on Mac OS X Lion and later. |
| 165 | * Is the **default** C++ standard library on [https://en.wikipedia.org/wiki/OS_X_Mavericks OS X Mavericks] and later. |
| 166 | 1. libstdc++ in /usr/lib/ |
| 167 | * Does not support C++11. |
| 168 | * Is now deprecated. |
| 169 | * Was the default C++ standard library prior to OS X Mavericks. |
| 170 | 1. libstdc++ provided by MacPorts |
| 171 | * Is ABI incompatible with libstdc++ in /usr/lib/ unless the macro [https://gcc.gnu.org/onlinedocs/gcc-5.2.0/libstdc++/manual/manual/using_dual_abi.html _GLIBCXX_USE_CXX11_ABI] is defined. |