scons: Make LLVM a black-white dependency.

Now that draw depends on llvm it is very difficult to correctly handle
broken llvm installations. Either the user requests LLVM and it needs to
supply a working installation. Or it doesn't, and it gets no LLVM
accelerate pipe drivers.
This commit is contained in:
José Fonseca
2010-04-10 02:41:39 +01:00
parent 9fc93b8041
commit ea532f0e72
19 changed files with 51 additions and 65 deletions

View File

@@ -81,15 +81,6 @@ debug = env['debug']
dri = env['dri']
machine = env['machine']
platform = env['platform']
drawllvm = 'llvmpipe' in env['drivers']
# LLVM support in the Draw module
if drawllvm:
env.Tool('llvm')
if not env.has_key('LLVM_VERSION'):
drawllvm = False
if drawllvm:
env.Append(CFLAGS = ['-DDRAW_LLVM=1'])
# derived options
x86 = machine == 'x86'
@@ -102,7 +93,6 @@ Export([
'x86',
'ppc',
'dri',
'drawllvm',
'platform',
'gcc',
'msvc',
@@ -167,10 +157,6 @@ if platform in ('posix', 'linux', 'freebsd', 'darwin'):
'dl',
])
# LLVM support in the Draw module
if drawllvm:
env.Append(CPPDEFINES = ['DRAW_LLVM'])
# for debugging
#print env.Dump()

View File

@@ -3,6 +3,7 @@
import os
import os.path
import subprocess
import sys
import platform as _platform
@@ -33,6 +34,11 @@ else:
default_machine = _platform.machine()
default_machine = _machine_map.get(default_machine, 'generic')
if 'LLVM' in os.environ or subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
default_llvm = 'yes'
else:
default_llvm = 'no'
if default_platform in ('linux', 'freebsd'):
default_dri = 'yes'
elif default_platform in ('winddk', 'windows', 'wince', 'darwin'):
@@ -61,5 +67,5 @@ def AddOptions(opts):
opts.Add(EnumOption('platform', 'target platform', default_platform,
allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded')))
opts.Add('toolchain', 'compiler toolchain', 'default')
opts.Add(BoolOption('llvm', 'use LLVM', 'no'))
opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
opts.Add(BoolOption('dri', 'build DRI drivers', default_dri))

View File

@@ -12,7 +12,7 @@ GALLIUM_DRIVERS_DIRS += llvmpipe
OPT_FLAGS = -O3 -ansi -pedantic
ARCH_FLAGS = -mmmx -msse -msse2 -mstackrealign
DEFINES += -DNDEBUG -DGALLIUM_LLVMPIPE -DDRAW_LLVM -DHAVE_UDIS86
DEFINES += -DNDEBUG -DGALLIUM_LLVMPIPE -DHAVE_UDIS86
# override -std=c99
CFLAGS += -std=gnu99

View File

@@ -142,8 +142,6 @@ def generate(env):
# configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
build_topdir = 'build'
build_subdir = env['platform']
if env['llvm']:
build_subdir += "-llvm"
if env['machine'] != 'generic':
build_subdir += '-' + env['machine']
if env['debug']:
@@ -471,6 +469,10 @@ def generate(env):
# Default libs
env.Append(LIBS = [])
# Load LLVM
if env['llvm']:
env.Tool('llvm')
# Custom builders and methods
env.Tool('custom')
createInstallMethods(env)

View File

@@ -63,13 +63,14 @@ def generate(env):
if env['platform'] == 'windows':
# XXX: There is no llvm-config on Windows, so assume a standard layout
if llvm_dir is None:
return
print 'scons: LLVM environment variable must be specified when building for windows'
env.Exit(1)
# Try to determine the LLVM version from llvm/Config/config.h
llvm_config = os.path.join(llvm_dir, 'include/llvm/Config/config.h')
if not os.path.exists(llvm_config):
print 'scons: could not find %s' % llvm_config
return
env.Exit(1)
llvm_version_re = re.compile(r'^#define PACKAGE_VERSION "([^"]*)"')
llvm_version = None
for line in open(llvm_config, 'rt'):
@@ -80,7 +81,7 @@ def generate(env):
break
if llvm_version is None:
print 'scons: could not determine the LLVM version from %s' % llvm_config
return
env.Exit(1)
env.Prepend(CPPPATH = [os.path.join(llvm_dir, 'include')])
env.AppendUnique(CPPDEFINES = [
@@ -129,7 +130,11 @@ def generate(env):
# debug build we'll be linking against LIBCMTD, so disable
# that.
env.Append(LINKFLAGS = ['/nodefaultlib:LIBCMT'])
elif env.Detect('llvm-config'):
else:
if not env.Detect('llvm-config'):
print 'scons: llvm-config script not found' % llvm_version
env.Exit(1)
llvm_version = env.backtick('llvm-config --version').rstrip()
llvm_version = distutils.version.LooseVersion(llvm_version)
@@ -138,11 +143,10 @@ def generate(env):
env.ParseConfig('llvm-config --libs jit interpreter nativecodegen bitwriter')
env.ParseConfig('llvm-config --ldflags')
except OSError:
print 'llvm-config version %s failed' % llvm_version
print 'scons: llvm-config version %s failed' % llvm_version
env.Exit(1)
else:
env['LINK'] = env['CXX']
else:
return
assert llvm_version is not None

View File

@@ -191,7 +191,7 @@ source = [
'target-helpers/wrap_screen.c',
]
if drawllvm:
if env['llvm']:
source += [
'gallivm/lp_bld_alpha.c',
'gallivm/lp_bld_arit.c',

View File

@@ -196,7 +196,7 @@ boolean draw_need_pipeline(const struct draw_context *draw,
const struct pipe_rasterizer_state *rasterizer,
unsigned prim );
#ifdef DRAW_LLVM
#ifdef HAVE_LLVM
/*******************************************************************************
* LLVM integration
*/

View File

@@ -1,5 +1,5 @@
#ifndef DRAW_LLVM_H
#define DRAW_LLVM_H
#ifndef HAVE_LLVM_H
#define HAVE_LLVM_H
#include "draw/draw_private.h"

View File

@@ -46,7 +46,7 @@
#include "tgsi/tgsi_scan.h"
#ifdef DRAW_LLVM
#ifdef HAVE_LLVM
#include <llvm-c/ExecutionEngine.h>
#endif
@@ -241,7 +241,7 @@ struct draw_context
unsigned instance_id;
#ifdef DRAW_LLVM
#ifdef HAVE_LLVM
LLVMExecutionEngineRef engine;
#endif
void *driver_private;

View File

@@ -140,7 +140,7 @@ boolean draw_pt_init( struct draw_context *draw )
if (!draw->pt.middle.fetch_shade_emit)
return FALSE;
#if DRAW_LLVM
#if HAVE_LLVM
draw->pt.middle.general = draw_pt_fetch_pipeline_or_emit_llvm( draw );
#else
draw->pt.middle.general = NULL;

View File

@@ -40,7 +40,7 @@
#include "tgsi/tgsi_parse.h"
#ifdef DRAW_LLVM
#ifdef HAVE_LLVM
struct draw_llvm_vertex_shader {
struct draw_vertex_shader base;

View File

@@ -38,9 +38,9 @@
#include <llvm-c/Core.h>
/** Set version to 0 if missing to avoid #ifdef HAVE_LLVM everywhere */
/** Ensure HAVE_LLVM is set to avoid #ifdef HAVE_LLVM everywhere */
#ifndef HAVE_LLVM
#define HAVE_LLVM 0x0207
#error "HAVE_LLVM should be set with LLVM's version number, e.g. (0x0207 for 2.7)"
#endif

View File

@@ -1,12 +1,11 @@
Import('*')
env = env.Clone()
env.Tool('llvm')
if not env.has_key('LLVM_VERSION'):
print 'warning: LLVM not found: not building llvmpipe'
if not env['llvm']:
print 'warning: LLVM disabled: not building llvmpipe'
Return()
env = env.Clone()
env.Tool('udis86')
env.Append(CPPPATH = ['.'])

View File

@@ -23,11 +23,9 @@ if 'softpipe' in env['drivers']:
env.Prepend(LIBS = [softpipe])
if 'llvmpipe' in env['drivers']:
env.Tool('llvm')
if 'LLVM_VERSION' in env:
env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE')
env.Tool('udis86')
env.Prepend(LIBS = [llvmpipe])
env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE')
env.Tool('udis86')
env.Prepend(LIBS = [llvmpipe])
if 'cell' in env['drivers']:
env.Append(CPPDEFINES = 'GALLIUM_CELL')

View File

@@ -46,7 +46,6 @@ if 'python' in env['statetrackers']:
if 'llvmpipe' in env['drivers']:
env.Append(CPPDEFINES = ['HAVE_LLVMPIPE'])
env.Tool('llvm')
env.Prepend(LIBS = [llvmpipe])
if 'softpipe' in env['drivers']:
env.Append(CPPDEFINES = ['HAVE_SOFTPIPE'])

View File

@@ -25,11 +25,9 @@ if 'softpipe' in env['drivers']:
env.Prepend(LIBS = [softpipe])
if 'llvmpipe' in env['drivers']:
env.Tool('llvm')
if 'LLVM_VERSION' in env:
env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE')
env.Tool('udis86')
env.Prepend(LIBS = [llvmpipe])
env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE')
env.Tool('udis86')
env.Prepend(LIBS = [llvmpipe])
swrastg_sources = [
'swrast_drm_api.c'

View File

@@ -33,11 +33,9 @@ if 'softpipe' in env['drivers']:
env.Prepend(LIBS = [softpipe])
if 'llvmpipe' in env['drivers']:
env.Tool('llvm')
if 'LLVM_VERSION' in env:
env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE')
env.Tool('udis86')
env.Prepend(LIBS = [llvmpipe])
env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE')
env.Tool('udis86')
env.Prepend(LIBS = [llvmpipe])
# Need this for trace, identity drivers referenced by
# gallium_wrap_screen().

View File

@@ -27,10 +27,8 @@ if env['platform'] == 'windows':
drivers = [softpipe]
if 'llvmpipe' in env['drivers']:
env.Tool('llvm')
if 'LLVM_VERSION' in env:
sources = ['gdi_llvmpipe_winsys.c']
drivers = [llvmpipe]
sources = ['gdi_llvmpipe_winsys.c']
drivers = [llvmpipe]
if not sources or not drivers:
print 'warning: softpipe or llvmpipe not selected, gdi winsys disabled'

View File

@@ -50,11 +50,9 @@ if 'softpipe' in env['drivers']:
env.Prepend(LIBS = [softpipe])
if 'llvmpipe' in env['drivers']:
env.Tool('llvm')
if 'LLVM_VERSION' in env:
env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE')
env.Tool('udis86')
env.Prepend(LIBS = [llvmpipe])
env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE')
env.Tool('udis86')
env.Prepend(LIBS = [llvmpipe])
if 'cell' in env['drivers']:
env.Append(CPPDEFINES = 'GALLIUM_CELL')