~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to build/get-py-info.py

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:26:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205012614-qom4xfypgtsqc2xq
Tags: 1.2.3dfsg1-3ubuntu1
Merge with the final Debian release of 1.2.3dfsg1-3, bringing in
fixes to the clean target, better documentation of the libdb4.3
upgrade and build fixes to work with swig1.3_1.3.27.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# get-py-info.py: get various Python info (for building)
 
3
#
 
4
# This should be loaded/run by the appropriate Python, rather than executed
 
5
# directly as a program. In other words, you should:
 
6
#
 
7
#    $ python2 get-py-info.py --includes
 
8
#
 
9
 
 
10
import sys
 
11
import os
 
12
import string
 
13
from distutils import sysconfig
 
14
 
 
15
def usage():
 
16
  print 'USAGE: %s WHAT' % sys.argv[0]
 
17
  print '  Returns information about how to build Python extensions.'
 
18
  print '  WHAT may be one of:'
 
19
  print "    --includes : return -I include flags"
 
20
  print "    --compile  : return a compile command"
 
21
  print "    --link     : return a link command"
 
22
  print "    --libs     : return just the library options for linking"
 
23
  sys.exit(1)
 
24
 
 
25
if len(sys.argv) != 2:
 
26
  usage()
 
27
 
 
28
if sys.argv[1] == '--includes':
 
29
  inc = sysconfig.get_python_inc()
 
30
  plat = sysconfig.get_python_inc(plat_specific=1)
 
31
  if inc == plat:
 
32
    print "-I" + inc
 
33
  else:
 
34
    print "-I%s -I%s" % (inc, plat)
 
35
  sys.exit(0)
 
36
 
 
37
if sys.argv[1] == '--compile':
 
38
  cc, basecflags, opt, ccshared = \
 
39
      sysconfig.get_config_vars('CC', 'BASECFLAGS', 'OPT', 'CCSHARED')
 
40
  if basecflags:
 
41
    opt = basecflags + ' ' + opt
 
42
  print cc, opt, ccshared
 
43
  sys.exit(0)
 
44
 
 
45
def ldshared_process(just_libs = None):
 
46
  ldshared = sysconfig.get_config_var('LDSHARED')
 
47
  ldshared_elems = string.split(ldshared, " ")
 
48
  libs_elems = []
 
49
  for i in range(len(ldshared_elems)):
 
50
    if ldshared_elems[i] == '-framework':
 
51
      ldshared_elems[i] = '-Wl,' + ldshared_elems[i]
 
52
      ldshared_elems[i+1] = '-Wl,' + ldshared_elems[i+1]
 
53
      libs_elems.append(ldshared_elems[i])
 
54
      libs_elems.append(ldshared_elems[i+1])
 
55
    elif ldshared_elems[i][:2] == '-L':
 
56
      if ldshared_elems[i][:3] != '-L:':
 
57
        libs_elems.append(ldshared_elems[i])
 
58
    elif ldshared_elems[i][:2] == '-l':
 
59
      libs_elems.append(ldshared_elems[i])
 
60
  if sys.platform[:6] == 'cygwin':
 
61
    py_Lopt = "-L" + os.path.join(sys.prefix, "lib", "python" +
 
62
        sysconfig.get_python_version(), "config")
 
63
    py_lopt = "-lpython" + sysconfig.get_python_version()
 
64
    libs_elems.append(py_Lopt)
 
65
    libs_elems.append(py_lopt)
 
66
    ldshared_elems.append(py_Lopt)
 
67
    ldshared_elems.append(py_lopt)
 
68
  if just_libs:
 
69
    return string.join(libs_elems, " ")
 
70
  else:
 
71
    return string.join(ldshared_elems, " ")
 
72
 
 
73
if sys.argv[1] == '--link':
 
74
  print ldshared_process()
 
75
  sys.exit(0)
 
76
 
 
77
if sys.argv[1] == '--libs':
 
78
  print ldshared_process(just_libs = 1)
 
79
  sys.exit(0)
 
80
 
 
81
usage()