PageRenderTime 28ms CodeModel.GetById 15ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts/scramble/scripts/psycopg2-macosx.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 85 lines | 67 code | 11 blank | 7 comment | 5 complexity | c3dd424c6b790c82e0ac359bc8f5994a MD5 | raw file
 1import os, sys, shutil
 2from distutils.sysconfig import get_config_var
 3
 4def prep_postgres( prepped, args ):
 5
 6    pg_version = args['version']
 7    pg_srcdir = os.path.join( os.getcwd(), "postgresql-%s" % pg_version )
 8
 9    # set up environment
10    os.environ['CC'] = get_config_var('CC')
11    os.environ['CFLAGS'] = get_config_var('CFLAGS')
12    os.environ['LDFLAGS'] = get_config_var('LDFLAGS')
13
14    if '-fPIC' not in os.environ['CFLAGS']:
15        os.environ['CFLAGS'] += ' -fPIC'
16
17    # run configure
18    run( "./configure --prefix=%s/postgres --disable-dependency-tracking --enable-static --disable-shared --without-readline --with-thread-safety" % os.getcwd(),
19        os.path.join( os.getcwd(), "postgresql-%s" % pg_version ),
20        "Configuring postgres (./configure)" )
21
22    # compile
23    run( "make ../../src/include/utils/fmgroids.h", os.path.join( pg_srcdir, 'src', 'backend' ), "Compiling fmgroids.h (cd src/backend; make ../../src/include/utils/fmgroids.h)" )
24    run( "make all-static-lib", os.path.join( pg_srcdir, 'src', 'interfaces', 'libpq' ), "Compiling libpq (cd src/interfaces/libpq; make)" )
25    run( "make", os.path.join( pg_srcdir, 'src', 'bin', 'pg_config' ), "Compiling pg_config (cd src/bin/pg_config; make)" )
26
27    # install
28    run( "make install-lib-static", os.path.join( pg_srcdir, 'src', 'interfaces', 'libpq' ), "Compiling libpq (cd src/interfaces/libpq; make install)" )
29    run( "make install", os.path.join( pg_srcdir, 'src', 'bin', 'pg_config' ), "Compiling pg_config (cd src/bin/pg_config; make install)" )
30    run( "make install", os.path.join( pg_srcdir, 'src', 'include' ), "Compiling pg_config (cd src/include; make install)" )
31
32    # manually install some headers
33    run( "cp libpq-fe.h %s" % os.path.join( os.getcwd(), 'postgres', 'include' ), os.path.join( pg_srcdir, 'src', 'interfaces', 'libpq' ), "Installing libpq-fe.h" )
34    run( "cp libpq-events.h %s" % os.path.join( os.getcwd(), 'postgres', 'include' ), os.path.join( pg_srcdir, 'src', 'interfaces', 'libpq' ), "Installing libpq-fe.h" )
35    run( "cp libpq-int.h %s" % os.path.join( os.getcwd(), 'postgres', 'include', 'internal' ), os.path.join( pg_srcdir, 'src', 'interfaces', 'libpq' ), "Installing libpq-fe.h" )
36    run( "cp pqexpbuffer.h %s" % os.path.join( os.getcwd(), 'postgres', 'include', 'internal' ), os.path.join( pg_srcdir, 'src', 'interfaces', 'libpq' ), "Installing libpq-fe.h" )
37
38    # create prepped archive
39    print "%s(): Creating prepped archive for future builds at:" % sys._getframe().f_code.co_name
40    print " ", prepped
41    compress( prepped,
42           'postgres/bin',
43           'postgres/include',
44           'postgres/lib' )
45
46if __name__ == '__main__':
47
48    # change back to the build dir
49    if os.path.dirname( sys.argv[0] ) != "":
50        os.chdir( os.path.dirname( sys.argv[0] ) )
51
52    # find setuptools
53    sys.path.append( os.path.abspath( os.path.join( '..', '..', '..', 'lib' ) ) )
54    from scramble_lib import *
55
56    tag = get_tag()
57
58    pg_version = ( tag.split( "_" ) )[1]
59    pg_archive_base = os.path.join( archives, "postgresql-%s" % pg_version )
60    pg_archive = get_archive( pg_archive_base )
61    pg_archive_prepped = os.path.join( archives, "postgresql-%s-%s.tar.gz" % ( pg_version, platform_noucs ) )
62
63    # clean up any existing stuff (could happen if you run scramble.py by hand)
64    clean( [ 'postgresql-%s' % pg_version ] )
65
66    # unpack postgres
67    unpack_dep( pg_archive, pg_archive_prepped, prep_postgres, dict( version=pg_version ) )
68
69    # localize setup.cfg
70    if not os.path.exists( 'setup.cfg.orig' ):
71        shutil.copy( 'setup.cfg', 'setup.cfg.orig' )
72        f = open( 'setup.cfg', 'a' )
73        f.write( '\npg_config=postgres/bin/pg_config\n' )
74        f.close()
75
76    # tag
77    me = sys.argv[0]
78    sys.argv = [ me ]
79    if tag is not None:
80        sys.argv.append( "egg_info" )
81        sys.argv.append( "--tag-build=%s" %tag )
82    sys.argv.append( "bdist_egg" )
83
84    # go
85    execfile( "setup.py", globals(), locals() )