--- a/lang/gcc7/Portfile	2017-05-19 13:40:32.000000000 +0200
+++ b/lang/gcc7/Portfile	2017-05-19 13:46:59.000000000 +0200
@@ -3,6 +3,7 @@
 PortSystem 1.0
 PortGroup select 1.0
 PortGroup compiler_blacklist_versions 1.0
+PortGroup active_variants 1.1
 
 name                gcc7
 subport             libgcc {}
@@ -144,7 +145,11 @@
 if {${subport} eq "libgcc"} {
     conflicts       libgcc-devel
     long_description-append \
-                    This port installs the standard runtime libraries, including libstdc++.
+                    This port installs the standard runtime libraries, including libstdc++. \
+                    Users building from source can install port:${name}+with_libgcc \
+                    and port:${subport}+stub to avoid building everything twice.
+
+    variant stub description "Use when the standard libraries are provided by the main port:${name}+with_libgcc" {}
 
     # http://trac.macports.org/ticket/35770
     # http://trac.macports.org/ticket/38814
@@ -158,7 +163,47 @@
     # version should continue to provide a subport for that and older gcc
     # versions.
 
+    if {![catch {set result [active_variants ${name} with_libgcc {}]}]} {
+        if {${result}} {
+            default_variants-append +stub
+        }
+    }
+    if {[variant_isset stub]} {
+        # reset the depspecs to just port:${name}
+        depends_lib     port:${name}
+        require_active_variants ${name} with_libgcc
+
+        use_configure   no
+        fetch           {}
+        extract         {}
+        patch           {}
+        build           {}
+        destroot {
+            # install symlinks to the set of standardLibs that have in this case been
+            # installed by the main port. In other words, use the reverse logic to the
+            # comparable foreach loop in the main port's post-destroot, minus the deleting.
+            xinstall -m 755 -d ${destroot}${prefix}/lib/libgcc
+            foreach dylib ${standardLibs} {
+                # Different OS versions (eg: Leopard) or architectures (eg: PPC) don't produce all the dylibs
+                # https://trac.macports.org/ticket/40098
+                # https://trac.macports.org/ticket/40100
+                if {[file exists ${prefix}/lib/${name}/${dylib}]} {
+                    ln -s ${prefix}/lib/${name}/${dylib} ${destroot}${prefix}/lib/libgcc/${dylib}
+                }
+
+                if {[variant_isset universal]} {
+                    foreach archdir [glob ${prefix}/lib/${name}/*/] {
+                        if {[file exists ${archdir}/${dylib}]} {
+                            ln -s ${archdir}/${dylib} ${destroot}${prefix}/lib/libgcc/${dylib}
+                        }
+                    }
+                }
+            }
+        }
+    } else {
+    ## default libgcc variant
     depends_lib-delete path:lib/libgcc/libgcc_s.1.dylib:libgcc
+    require_active_variants ${name} "" with_libgcc
 
     configure.args-delete --libdir=${prefix}/lib/${name}
     configure.args-append --libdir=${prefix}/lib/libgcc
@@ -219,10 +264,18 @@
         # For binary compatibility with binaries that linked against the old libstdcxx port
         ln -s libgcc/libstdc++.6.dylib ${destroot}${prefix}/lib/libstdc++.6.dylib
     }
+    ## end default libgcc variant
+    }
 
 } else {
 
+variant with_libgcc description "Include the standard libraries instead of getting them from port:libgcc. Speeds up building from source." {}
+
 depends_run-append         port:gcc_select
+if {[variant_isset with_libgcc]} {
+    # we install libgcc's content ourselves
+    depends_lib-delete path:lib/libgcc/libgcc_s.1.dylib:libgcc
+}
 
 post-destroot {
     file delete ${destroot}${prefix}/share/info/dir
@@ -234,6 +287,8 @@
         file rename ${file} ${newfile}
     }
 
+    if {![variant_isset with_libgcc]} {
+    ## default gcc7 variant
     foreach dylib ${standardLibs} {
         # Different OS versions (eg: Leopard) or architectures (eg: PPC) don't produce all the dylibs
         # https://trac.macports.org/ticket/40098
@@ -252,6 +307,8 @@
             }
         }
     }
+    ## end default gcc7 variant
+    }
 }
 
 select.group        gcc
