6 from distutils import sysconfig
9 host_prefix = sysconfig.PREFIX
11 target_bin_dir = os.path.dirname(os.path.abspath(__file__))
12 target_prefix = os.path.normpath(os.path.join(target_bin_dir, '..'))
14 target_data_dir = os.path.join(target_prefix, 'lib', 'python' + sysconfig.get_config_var('VERSION') + '-openwrt')
15 sys.path.append(target_data_dir)
18 from _sysconfigdatatarget import build_time_vars
19 sysconfig._config_vars = {}
20 sysconfig._config_vars.update(build_time_vars)
22 print >>sys.stderr, "Could not import target data from %s" % (target_data_dir)
25 # plus .replace(host_prefix, target_prefix) below
27 valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
30 def exit_with_usage(code=1):
31 print >>sys.stderr, "Usage: %s [%s]" % (sys.argv[0],
32 '|'.join('--'+opt for opt in valid_opts))
36 opts, args = getopt.getopt(sys.argv[1:], '', valid_opts)
43 pyver = sysconfig.get_config_var('VERSION')
44 getvar = sysconfig.get_config_var
46 opt_flags = [flag for (flag, val) in opts]
48 if '--help' in opt_flags:
49 exit_with_usage(code=0)
53 #print sysconfig.PREFIX
56 elif opt == '--exec-prefix':
57 #print sysconfig.EXEC_PREFIX
60 elif opt in ('--includes', '--cflags'):
61 flags = ['-I' + sysconfig.get_python_inc(),
62 '-I' + sysconfig.get_python_inc(plat_specific=True)]
64 flags.extend(getvar('CFLAGS').split())
65 #print ' '.join(flags)
66 print ' '.join(flags).replace(host_prefix, target_prefix)
68 elif opt in ('--libs', '--ldflags'):
69 libs = ['-lpython' + pyver]
70 libs += getvar('LIBS').split()
71 libs += getvar('SYSLIBS').split()
72 # add the prefix/lib/pythonX.Y/config dir, but only if there is no
73 # shared library in prefix/lib/.
74 if opt == '--ldflags':
75 if not getvar('Py_ENABLE_SHARED'):
76 libs.insert(0, '-L' + getvar('LIBPL'))
77 if not getvar('PYTHONFRAMEWORK'):
78 libs.extend(getvar('LINKFORSHARED').split())
80 print ' '.join(libs).replace(host_prefix, target_prefix)