Skip to content

Instantly share code, notes, and snippets.

@atsushieno
Created October 26, 2009 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atsushieno/218836 to your computer and use it in GitHub Desktop.
Save atsushieno/218836 to your computer and use it in GitHub Desktop.
# -*- mode: python -*-
#
# Copyright (C) 2006, 2007, 2008 Imendio AB
#
# Default setup for building GTK+ on Mac OS X. Note that you should
# normally never need to edit this file. Any custom settings should be
# done in ~/.jhbuildrc-custom.
#
# Specific builds can be set up by creating files named
# ~/.jhbuildrc-<build>. When setting the environment variable JHB to
# such a name, the corresponding rc file will be read (e.g.:
# JHB=mybuild jhbuild shell).
#
# Use .jhbuildrc-custom to override the moduleset, modules to build,
# the source checkout location, installation prefix, or svn usernames
# etc.
#
# Please email richard@imendio.com if you have suggestions for
# improving this setup, or have any patches that you would like to get
# included.
import sys
import errno
# Register an extra command to get the checkout dir for a module.
#
import jhbuild
class _cmd_get_srcdir(jhbuild.commands.Command):
doc = 'Display information about one or more modules'
from jhbuild.errors import FatalError
name = 'gtk-osx-get-srcdir'
usage_args = 'module'
def run(self, config, options, args):
module_set = jhbuild.moduleset.load(config)
if args:
modname = args[0]
try:
module = module_set.get_module(modname, ignore_case = True)
except KeyError:
raise FatalError(_('unknown module %s') % modname)
print module.get_srcdir(None)
else:
raise FatalError('no module specified')
jhbuild.commands.register_command(_cmd_get_srcdir)
# Some utitily functions used here and in custom files:
#
def environ_append(key, value, separator=' '):
old_value = os.environ.get(key)
if old_value is not None:
value = old_value + separator + value
os.environ[key] = value
def environ_prepend(key, value, separator=' '):
old_value = os.environ.get(key)
if old_value is not None:
value = value + separator + old_value
os.environ[key] = value
def parse_custom_argument(key):
for i, arg in enumerate(sys.argv[:-1]):
if arg == key:
return sys.argv[i+1]
return None
def set_git_branch(module, branch):
# Keep any overriden repo name here to keep custom usernames set
# up in a custom setup.
#
branches[module] = ('', branch)
def append_autogenargs(module, args):
old_value = module_autogenargs.get(module, autogenargs)
module_autogenargs[module] = old_value + " " + args
# Set up the environment for building against 10.4 SDK.
#
def setup_sdk_10_5():
target = "10.5"
sdk = "MacOSX10.5.sdk"
sdkdir = os.path.join("/Developer/SDKs", sdk)
# To pick up cups-config from the right place. NOTE: Change this as
# soon as GTK+ is fixed, and only set CUPS_CONFIG instead (GTK+ 2.13
# is fixed).
#
prependpath("PATH", os.path.join(sdkdir, "usr/bin"))
os.environ["MACOSX_DEPLOYMENT_TARGET"] = target
# Seems like we need this since many libraries otherwise only look for
# various dependencies (e.g. libiconv) in /usr/lib, hence pulling in
# the wrong -L that doesn't have fat binaries on pre-10.5.
#
environ_prepend("LDFLAGS", "-L" + sdkdir + "/usr/lib")
environ_prepend("CPPFLAGS", "-I" + sdkdir + "/usr/include")
# It looks like -isysroot is broken on 10.4, causing link
# problems. But we don't really need to set it for 10.4 so just
# skip that.
#
if not _osx_version.startswith("8."):
environ_append("CFLAGS", "-isysroot " + sdkdir)
environ_append("CXXFLAGS", "-isysroot " + sdkdir)
environ_append("LDFLAGS", "-isysroot " + sdkdir)
environ_append("CFLAGS", "-mmacosx-version-min=" + target)
environ_append("LDFLAGS", "-mmacosx-version-min=" + target)
return sdkdir
# Set up the environment for building against 10.4 SDK.
#
def setup_sdk_10_4():
target = "10.4"
sdk = "MacOSX10.4u.sdk"
sdkdir = os.path.join("/Developer/SDKs", sdk)
# To pick up cups-config from the right place. NOTE: Change this as
# soon as GTK+ is fixed, and only set CUPS_CONFIG instead (GTK+ 2.13
# is fixed).
#
prependpath("PATH", os.path.join(sdkdir, "usr/bin"))
os.environ["MACOSX_DEPLOYMENT_TARGET"] = target
# Seems like we need this since many libraries otherwise only look for
# various dependencies (e.g. libiconv) in /usr/lib, hence pulling in
# the wrong -L that doesn't have fat binaries on pre-10.5.
#
environ_prepend("LDFLAGS", "-L" + sdkdir + "/usr/lib")
environ_prepend("CPPFLAGS", "-I" + sdkdir + "/usr/include")
# It looks like -isysroot is broken on 10.4, causing link
# problems. But we don't really need to set it for 10.4 so just
# skip that.
#
if not _osx_version.startswith("8."):
environ_append("CFLAGS", "-isysroot " + sdkdir)
environ_append("CXXFLAGS", "-isysroot " + sdkdir)
environ_append("LDFLAGS", "-isysroot " + sdkdir)
environ_append("CFLAGS", "-mmacosx-version-min=" + target)
environ_append("LDFLAGS", "-mmacosx-version-min=" + target)
return sdkdir
def autogenargs_for_arch(root, arch, original_cflags, original_cxxflags, original_ldflags):
if root is not None and not _osx_version.startswith("8."):
rootstr = " -isysroot " + root
else:
rootstr = ""
archstr = " -arch " + arch
return \
'CFLAGS="' + original_cflags + rootstr + archstr + '" ' + \
'CXXFLAGS="' + original_cxxflags + rootstr + archstr + '" ' + \
'LDFLAGS="' + original_ldflags + archstr + '"'
_osx_version = os.popen("uname -r").read().strip()
# Moduleset to use.
#
moduleset = 'http://github.com/jralls/gtk-osx-build/raw/master/modulesets-stable/gtk-osx.modules'
use_local_modulesets = True
# A list of the modules to build.
#
modules = [ 'meta-gtk-osx-bootstrap', 'meta-gtk-osx-core' ]
# A list of modules to skip.
#
skip.append('gmp')
skip.append('guile')
# Source and installation locations.
#
_root = os.path.expanduser("~/gtk")
checkoutroot = os.path.join(_root, "source")
prefix = os.path.join(_root, "inst")
# Extra arguments to pass to all autogen.sh scripts.
#
autogenargs='--disable-static'
alwaysautogen = True
# Use the included install-check program if available. It won't update
# timestamps if the header hasn't changed, which speeds up builds.
#
_path = os.path.expanduser('~/.local/bin/install-check')
if os.path.exists(_path):
os.environ['INSTALL'] = _path
# When building on intel, force build to be 486, since glib won't
# enable asm atomic operations otherwise.
#
try:
_f = os.popen("uname -p")
if _f.read().startswith("i386"):
append_autogenargs("glib", "--build=i486-apple-darwin")
except:
pass
# Prefix to use in the shell, can be overridden in the custom rc file
# or in specific setups. Can be set to None to be removed.
#
_gtk_osx_prompt_prefix = "JH"
_gtk_osx_default_build = ""
if _osx_version.startswith("7."):
print "Error: Mac OS X 10.4 or newer is required, exiting."
raise SystemExit
elif _osx_version.startswith("8."):
# Tiger, we want to use the python version from jhbuild.
_gtk_osx_use_jhbuild_python = True
_gtk_osx_use_jhbuild_bison_flex = True
else:
# Leopard or newer.
_gtk_osx_use_jhbuild_python = False
_gtk_osx_use_jhbuild_bison_flex = False
# Import optional user RC for further customization. You can override
# the prefix or default build setup for example, or CFLAGS or
# module_autogenargs, etc.
#
_userrc = os.path.join(os.environ['HOME'], '.jhbuildrc-custom')
if os.path.exists(_userrc):
execfile(_userrc)
# Allow including different variants depending on the environment
# variable JHB. This can be used to have different setups for SDK
# builds, for example.
#
_build = os.environ.get('JHB', _gtk_osx_default_build)
# Check and warn if jhbuild is started from within jhbuild, since that
# will mess up environment variables, especially if different build
# setups are used.
#
_old_prefix = os.environ.get('JHBUILD_PREFIX', "")
_old_build = os.environ.get('JHBUILD_CONFIG', "")
_ran_recursively = _old_prefix != ""
if _ran_recursively:
if _old_build != _build:
print "Error: jhbuild is already running with a different build setup, exiting."
raise SystemExit
print "Warning: jhbuild is started from within a jhbuild session."
if _build != "":
try:
execfile(os.path.join(os.environ['HOME'], '.jhbuildrc-' + _build))
except EnvironmentError, e:
print "Couldn't find the file '.jhbuildrc-" + _build + "', exiting."
raise SystemExit
tarballdir = os.path.join(checkoutroot, 'pkgs')
os.environ['PREFIX'] = prefix # Deprecated, please move to JHBUILD_PREFIX.
os.environ['JHBUILD_PREFIX'] = prefix
os.environ['JHBUILD_SOURCE'] = checkoutroot
#some packages go off and find /usr/lib/gm4, which is broken
os.environ["M4"] = prefix + "/bin/m4"
os.environ['LIBTOOLIZE'] = prefix + '/bin/libtoolize'
# By default, we want the system perl and python, not from macports or
# so.
#
os.environ["PERL"] = "/usr/bin/perl"
os.environ["INTLTOOL_PERL"] = "/usr/bin/perl"
if not _gtk_osx_use_jhbuild_python:
skip.append('python')
if os.environ.get("PYTHON", "") == "":
os.environ["PYTHON"] = "/usr/bin/python"
else:
os.environ["PYTHON"] = prefix + "/bin/python"
if not _gtk_osx_use_jhbuild_bison_flex:
skip.append('bison')
skip.append('flex')
# Use libxml/libxslt from the system. Append to the pkg-config path to
# get the system versions picked up.
#
skip.append("libxml2")
skip.append("libxslt")
addpath("PKG_CONFIG_PATH", "/usr/lib/pkgconfig")
# The option "headerpad_max_install_names" is there to leave some room for
# changing the library locations with install_name_tool. Note that GNU
# libtool seems to drop the option if we don't use -W here.
#
environ_append('LDFLAGS', '-Wl,-headerpad_max_install_names')
# Make sure we find our installed modules, and before other versions.
environ_prepend('LDFLAGS', '-L' + prefix + '/lib')
environ_prepend('CPPFLAGS', '-I' + prefix + '/include')
# Add additional Python/Perl paths so that our modules can be found.
#
_version = 'python' + str(sys.version_info[0]) + '.' + str(sys.version_info[1])
prependpath('PYTHONPATH', prefix + '/lib/' + _version + '/site-packages/gtk-2.0')
prependpath('PERL5LIB', prefix + '/lib/perl5/vendor_perl')
prependpath('PERL5LIB', prefix + '/lib/perl5/site_perl')
# Point gtk-doc and other xlstproc users to our XML catalog.
#
os.environ['XML_CATALOG_FILES'] = prefix + '/etc/xml/catalog'
# Speed up gettext build by disabling unneeded stuff.
#
append_autogenargs("gettext", "--without-emacs --disable-java --disable-native-java --disable-libasprintf --disable-csharp")
# Support prepending frameworks to the setup so they are picked up
# instead of things from the prefix or /usr.
#
_frameworks = os.environ.get("JHB_PREPEND_FRAMEWORKS", "")
for _framework in _frameworks.split(":"):
if _framework != "" and os.path.exists(_framework):
# Use prependpath to ensure our paths are added in front of
# the ones jhbuild sets up.
if os.path.exists(_framework + "/Headers"):
prependpath("C_INCLUDE_PATH", _framework + "/Headers")
prependpath("CPLUS_INCLUDE_PATH", _framework + "/Headers")
if os.path.exists(_framework + "/Resources/dev/bin"):
prependpath("PATH", _framework + "/Resources/dev/bin")
if os.path.exists(_framework + "/Resources/dev/lib/pkgconfig"):
prependpath("PKG_CONFIG_PATH", _framework + "/Resources/dev/lib/pkgconfig")
if os.path.exists(_framework + "/Resources/dev/lib"):
# FIXME: Need fix in jhbuild for this to work:
#prependpath("LDFLAGS", "-L" + _framework + "/Resources/dev/lib")
environ_prepend("LDFLAGS", "-L" + _framework + "/Resources/dev/lib", " ")
if os.path.exists(_framework + "/Resources/dev/share/aclocal"):
prependpath("ACLOCAL_FLAGS", _framework + "/Resources/dev/share/aclocal")
# We do some crude extra argument parsing just to add support for
# getting environment variables. Used in framework creation to pick up
# the jhbuild prefix.
#
_value = parse_custom_argument("getenv")
if _value:
print os.environ.get(_value, "")
raise SystemExit
if _build:
if "shell" in sys.argv:
print "Build setup: %s, prefix: %s" % (_build, prefix)
os.environ["JHBUILD_CONFIG"] = _build
else:
if "shell" in sys.argv:
print "Prefix: %s" % (prefix)
if not _ran_recursively and _gtk_osx_prompt_prefix:
os.environ["JHBUILD_PROMPT"] = "[" + _gtk_osx_prompt_prefix + "] "
# Unset this so we don't mess with the check for not starting
# recursively.
os.unsetenv("JHB")
if "shell" in sys.argv:
print "Entered jhbuild shell, type 'exit' to return."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment