PageRenderTime 24ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

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