waf

FORK: waf with some random patches
git clone https://git.neptards.moe/neptards/waf.git
Log | Files | Refs | README

wscript (4045B)


      1 #! /usr/bin/env python
      2 # encoding: UTF-8
      3 # Peter Forai
      4 # Thomas Nagy, 2008
      5 
      6 """
      7 Demonstrates how to create a c++ app that runs python scripts
      8 
      9 Useful for apps providing script extensions
     10 """
     11 
     12 VERSION='0.0.1'
     13 APPNAME='swig_test'
     14 top = '.'
     15 out = 'build'
     16 
     17 def options(opt):
     18 	opt.load('g++ python')
     19 
     20 def configure(conf):
     21 	conf.load('g++ python')
     22 	conf.check_python_version((2,4,2))
     23 	conf.check_python_headers()
     24 
     25 	conf.load('swig')
     26 	if conf.check_swig_version() < (1, 2, 27):
     27 		conf.fatal('this swig version is too old')
     28 
     29 	try:
     30 		conf.load('java')
     31 		# on mandriva, at least, libjvm.so is difficult to find
     32 		#conf.env.LIBPATH_JAVA = "/usr/lib/jvm/java-1.6.0-sun-1.6.0.13/jre/lib/amd64/server/"
     33 		conf.check_jni_headers()
     34 		conf.env.HAVE_JAVA = True
     35 	except conf.errors.ConfigurationError:
     36 		conf.env.HAVE_JAVA = False
     37 
     38 def build(bld):
     39 
     40 	# embedding
     41 	#
     42 	# use swig_flags = '-c++ -python -debug-classes' for debugging
     43 
     44 	obj = bld(
     45 		features = 'cxx cxxprogram pyembed',
     46 		source = 'embed/src1.cpp embed/bind.swig',
     47 		target = 'embed/embed_demo',
     48 		swig_flags = '-c++ -python -Wall',
     49 		includes = '. embed')
     50 
     51 
     52 	# extending
     53 	#
     54 	# be careful that the .py produced by swig is mandatory for using the library
     55 	#
     56 	# it is possible to disable 'mylib', and to add extend/a.cpp
     57 	# to the source of extend/python/_test_swig_waf and remove use
     58 
     59 	bld(
     60 		features = 'cxx cxxshlib',
     61 		source = 'extend/a.cpp',
     62 		target = 'extend/mylib',
     63 		includes = 'extend',
     64 		export_includes = 'extend',
     65 		vnum = '1.2.3',
     66 		name = 'mylib')
     67 
     68 	bld(
     69 		features = 'cxx cxxshlib pyext',
     70 		source = 'extend/python/test_swig_waf.i',
     71 		target = 'extend/python/_test_swig_waf',
     72 		swig_flags = '-c++ -python -Wall',
     73 		includes = 'extend',
     74 		vnum = '1.2.3',
     75 		use  = 'mylib')
     76 
     77 	bld.add_group()
     78 
     79 	python_site_package = '${PREFIX}/lib/python%s/site-packages' % bld.env.PYTHON_VERSION
     80 	generated_py = bld.path.find_or_declare('extend/python/test_swig_waf.py')
     81 	bld(features='py', source=generated_py, install_path=python_site_package, install_from=bld.path.get_bld())
     82 
     83 
     84 	bld.add_post_fun(exec_test_python)
     85 
     86 	# some java stuff
     87 	if not bld.env.HAVE_JAVA:
     88 		return
     89 
     90 	swigsrcdir = bld.path.get_bld().make_node('extend/java') # destination for generated java source from swig
     91 	swigoutdir = bld.path.get_bld().make_node('extend/jar') # destination for generated class files
     92 
     93 	# Will generate code via swig and also the JNI library in C++
     94 	jniswig = bld(
     95 		features   = 'cxx cxxshlib',
     96 		source     = 'extend/java/test_swig_waf.i',
     97 		target     = 'extend/java/_test_swig_waf',
     98 		swig_flags = '-c++ -java -package foo.bar.pouet -outdir extend/java/foo/bar/pouet',
     99 		includes   = 'extend',
    100 		vnum       = '1.2.3',
    101 		uselib     = 'JAVA',
    102 		use        = 'mylib')
    103 
    104 	# Java will contain the generated code from swigsrcdir plus the local sources
    105 	jswig = bld(features   = 'javac jar',
    106 		srcdir     = [ swigsrcdir , 'extend/java'] ,
    107 		sourcepath = [],
    108 		outdir     = swigoutdir,
    109 		basedir    = swigoutdir,
    110 		destfile   = 'maha.jar',
    111 		)
    112 
    113 	# Post JNI library and Java generators so we have tasks created
    114 	jniswig.post()
    115 	jswig.post()
    116 	# Now make sure javac task is executed after swig generation
    117 	for x in jniswig.tasks:
    118 		if x.__class__.__name__ == 'swig':
    119 			jswig.javac_task.set_run_after(x)
    120 
    121 	# Launch the test after build
    122 	bld.add_post_fun(exec_test_java)
    123 
    124 
    125 def exec_test_java(bld):
    126 	try:
    127 		bld.cmd_and_log('LD_LIBRARY_PATH=$LD_LIBRARY_PATH:build/extend/java:build/extend java -classpath "build/maha.jar:." foo.bar.pouet.Foo')
    128 	except:
    129 		pass
    130 
    131 def exec_test_python(bld):
    132 	import os, stat
    133 	try:
    134 		import subprocess
    135 		proc = subprocess.Popen('''
    136 PYTHONPATH=$PYTHONPATH:build/extend/python
    137 LD_LIBRARY_PATH=$LD_LIBRARY_PATH:build/extend/python:build/extend
    138 python -c "import test_swig_waf; a=test_swig_waf.A(); print('Testing: a.add(2, 3) -> %r' % a.add(2, 3))"
    139 '''.replace('\n', ' '), shell=True)
    140 		proc.wait()
    141 	except:
    142 		pass
    143 
    144 	# why does this fail now on mandriva???
    145 	try:
    146 		os.stat('build/embed/embed_demo')
    147 		bld.cmd_and_log('PYTHONPATH=$PYTHONPATH:build/embed/ build/embed/embed_demo')
    148 	except:
    149 		pass
    150