--- a/gdb/python/python-config.py	2014-06-20 20:54:06.654113224 -0400
+++ b/gdb/python/python-config.py	2014-06-20 20:49:50.534737216 -0400
@@ -59,11 +59,11 @@
 
     elif opt in ('--libs', '--ldflags'):
         libs = []
+        libs.append('-lpython'+pyver + abiflags)
         if getvar('LIBS') is not None:
             libs.extend(getvar('LIBS').split())
         if getvar('SYSLIBS') is not None:
             libs.extend(getvar('SYSLIBS').split())
-        libs.append('-lpython'+pyver + abiflags)
         # add the prefix/lib/pythonX.Y/config dir, but only if there is no
         # shared library in prefix/lib/.
         if opt == '--ldflags':
@@ -72,7 +72,7 @@
                     libs.insert(0, '-L' + getvar('LIBPL'))
                 elif os.name == 'nt':
                     libs.insert(0, '-L' + sysconfig.PREFIX + '/libs')
-            if getvar('LINKFORSHARED') is not None:
+            elif getvar('LINKFORSHARED') is not None:
                 libs.extend(getvar('LINKFORSHARED').split())
         print (to_unix_path(' '.join(libs)))
 
