# -*- mode: python -*-
#
# Build setup for Reinteract dependencies. This depends on the the
# wrapper .jhbuildrc from gtk-osx-build.
#
# Copyright (C) 2008 Owen Taylor
#
# Portions adopted from  .jhbuildrc-cfw-10.4
# Copyright (C) 2006 - 2008 Imendio AB
#

try:
    _variant = os.environ['JHB_VARIANT']
except:
    _f = os.popen("uname -p")
    if _f.read().startswith("i386"):
        _variant = "devel-i386"
    else:
        _variant = "devel-ppc"
    _f.close()

checkoutroot = "/opt/reinteract/" + _variant + "/source"
prefix = "/opt/reinteract/" + _variant + "/install"

modules = [ 'meta-reinteract-deps' ]

if "ppc" in _variant:
    os.environ['CC'] = 'gcc -arch ppc'
    os.environ['CXX'] = 'g++ -arch ppc'
    os.environ['LDFLAGS'] = '-arch ppc'

_cflags = '-std=gnu89'
if "devel" in _variant:
    _optimize = '-gstabs+3 -O1'
else:
    _optimize = '-O2'

# Python splits CFLAGS up this way
os.environ['BASECFLAGS'] = _cflags
os.environ['OPT'] = _optimize
# For autoconf, they are unified
os.environ['CFLAGS'] = _cflags + ' ' + _optimize
os.environ['OBJCFLAGS'] = _cflags + ' ' + _optimize
os.environ['CXXFLAGS'] = _optimize

# Always build against the 10.4 SDK even in devel mode; this will help
# keep us introducing problems that show up at release time
_sdkdir = setup_sdk_10_4()
environ_append("BASECFLAGS", "-isysroot " + _sdkdir)
environ_append("OBJCFLAGS", "-isysroot " + _sdkdir)

# Needed to get the various sublibraries to find and use the same symbols.
# (Copied from jhbuildrc-cfw-10.4, not 100% sure it's needed here)
environ_append('LDFLAGS', '-Wl,-flat_namespace')

# Need to point some modules to the right place so we don't pick up
# things from /usr/lib.
append_autogenargs("gettext", "--with-libiconv-prefix=" + _sdkdir + "/usr")

# We we need to do a framework build to get a shared libpython;
# if we didn't specify a directory, it would be installed in the system
# /Library/Frameworks, which we don't want
append_autogenargs("python", "--enable-framework=" + prefix + "/Library/Frameworks")

# A workaround: if --enable-universalsdk isn't passed, the Python
# Framework creation does -arch_only i386, and things break. So, for
# ppc we build the framework universal, even though we don't need that
#if "ppc" in _variant:
#    append_autogenargs("python", "--enable-universalsdk")

# This is used by the Reinteract native app to locate the Python framework to use
os.environ['PYTHON_FRAMEWORK_DIR'] = prefix + "/Library/Frameworks/Python.framework"

# For unknown reasons, iconv is not picked up correctly without this
# (possibly due to using -flat_namespace....).
append_autogenargs('glib', ' --with-libiconv=gnu')

_reinteract_basedir = os.path.expanduser("~/Source/reinteract/tools/build_deps_osx")

# We need to explicitly force the endianness to GLib's configure, which gets
# confused by a universal setup
if "i386" in _variant:
    _cache_file = "i386.cache"
else:
    _cache_file = "ppc.cache"

append_autogenargs('glib', ' --cache-file=' + os.path.join(_reinteract_basedir, _cache_file))

# The standard gtk-osx-build .jhbuildrc adds a --build for glib, fix it up
# if necessary
if "ppc" in _variant:
    module_autogenargs['glib'] = module_autogenargs['glib'].replace("--build=i486-apple-darwin", "powerpc-apple-darwin")

moduleset = _reinteract_basedir + "/reinteract.modules"

# Not quite true ... we want to JHBuild Python, but we JHBuild our own
# version of it.
_gtk_osx_use_jhbuild_python = True
