waf-tools/python.py
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Mon, 26 Sep 2011 15:31:06 +0100
changeset 7545 ac0569e8cb7d
permissions -rw-r--r--
Avoid installation of ns3modulegen-modular.py as a python module
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7545
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     1
#!/usr/bin/env python
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     2
# encoding: utf-8
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     3
# Thomas Nagy, 2007-2010 (ita)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     4
# Gustavo Carneiro (gjc), 2007
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     5
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     6
#
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     7
# NS-3 Note: this python tool was added only for including a bug fix:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     8
#   http://code.google.com/p/waf/issues/detail?id=1045
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     9
# Once waf 1.6.8 comes out and ns-3 upgrades to it, this copy of the python tool can be removed
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    10
#
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    11
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    12
"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    13
Support for Python, detect the headers and libraries and provide
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    14
*use* variables to link C/C++ programs against them::
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    15
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    16
	def options(opt):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    17
		opt.load('compiler_c python')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    18
	def configure(conf):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    19
		conf.load('compiler_c python')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    20
		conf.check_python_version((2,4,2))
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    21
		conf.check_python_headers()
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    22
	def build(bld):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    23
		bld.program(features='pyembed', source='a.c', target='myprog')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    24
		bld.shlib(features='pyext', source='b.c', target='mylib')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    25
"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    26
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    27
import os, sys
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    28
from waflib import Utils, Options, Errors
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    29
from waflib.Logs import debug, warn, info, error
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    30
from waflib.TaskGen import extension, before_method, after_method, feature
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    31
from waflib.Configure import conf
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    32
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    33
FRAG = '''
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    34
#include <Python.h>
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    35
#ifdef __cplusplus
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    36
extern "C" {
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    37
#endif
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    38
	void Py_Initialize(void);
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    39
	void Py_Finalize(void);
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    40
#ifdef __cplusplus
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    41
}
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    42
#endif
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    43
int main()
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    44
{
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    45
   Py_Initialize();
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    46
   Py_Finalize();
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    47
   return 0;
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    48
}
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    49
'''
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    50
"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    51
Piece of C/C++ code used in :py:func:`waflib.Tools.python.check_python_headers`
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    52
"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    53
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    54
INST = '''
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    55
import sys, py_compile
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    56
py_compile.compile(sys.argv[1], sys.argv[2], sys.argv[3])
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    57
'''
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    58
"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    59
Piece of Python code used in :py:func:`waflib.Tools.python.install_pyfile` for installing python files
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    60
"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    61
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    62
@extension('.py')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    63
def process_py(self, node):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    64
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    65
	Add a callback using :py:func:`waflib.Tools.python.install_pyfile` to install a python file
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    66
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    67
	try:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    68
		if not self.bld.is_install:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    69
			return
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    70
	except:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    71
		return
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    72
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    73
	try:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    74
		if not self.install_path:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    75
			return
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    76
	except AttributeError:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    77
		self.install_path = '${PYTHONDIR}'
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    78
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    79
	# i wonder now why we wanted to do this after the build is over
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    80
	# issue #901: people want to preserve the structure of installed files
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    81
	def inst_py(ctx):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    82
		install_from = getattr(self, 'install_from', None)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    83
		if install_from:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    84
			install_from = self.path.find_dir(install_from)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    85
		install_pyfile(self, node, install_from)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    86
	self.bld.add_post_fun(inst_py)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    87
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    88
def install_pyfile(self, node, install_from=None):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    89
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    90
	Execute the installation of a python file
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    91
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    92
	:param node: python file
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    93
	:type node: :py:class:`waflib.Node.Node`
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    94
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    95
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    96
	from_node = install_from or node.parent
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    97
	tsk = self.bld.install_as(self.install_path + '/' + node.path_from(from_node), node, postpone=False)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    98
	path = tsk.get_install_path()
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    99
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   100
	if self.bld.is_install < 0:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   101
		info("+ removing byte compiled python files")
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   102
		for x in 'co':
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   103
			try:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   104
				os.remove(path + x)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   105
			except OSError:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   106
				pass
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   107
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   108
	if self.bld.is_install > 0:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   109
		try:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   110
			st1 = os.stat(path)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   111
		except:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   112
			error('The python file is missing, this should not happen')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   113
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   114
		for x in ['c', 'o']:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   115
			do_inst = self.env['PY' + x.upper()]
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   116
			try:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   117
				st2 = os.stat(path + x)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   118
			except OSError:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   119
				pass
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   120
			else:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   121
				if st1.st_mtime <= st2.st_mtime:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   122
					do_inst = False
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   123
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   124
			if do_inst:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   125
				lst = (x == 'o') and [self.env['PYFLAGS_OPT']] or []
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   126
				(a, b, c) = (path, path + x, tsk.get_install_path(destdir=False) + x)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   127
				argv = self.env['PYTHON'] + lst + ['-c', INST, a, b, c]
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   128
				info('+ byte compiling %r' % (path + x))
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   129
				ret = Utils.subprocess.Popen(argv).wait()
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   130
				if ret:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   131
					raise Errors.WafError('py%s compilation failed %r' % (x, path))
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   132
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   133
@feature('py')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   134
def feature_py(self):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   135
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   136
	Dummy feature which does nothing
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   137
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   138
	pass
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   139
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   140
@feature('pyext')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   141
@before_method('propagate_uselib_vars', 'apply_link')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   142
@after_method('apply_bundle')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   143
def init_pyext(self):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   144
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   145
	Change the values of *cshlib_PATTERN* and *cxxshlib_PATTERN* to remove the
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   146
	*lib* prefix from library names.
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   147
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   148
	try:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   149
		if not self.install_path:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   150
			return
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   151
	except AttributeError:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   152
		self.install_path = '${PYTHONARCHDIR}'
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   153
	self.uselib = self.to_list(getattr(self, 'uselib', []))
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   154
	if not 'PYEXT' in self.uselib:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   155
		self.uselib.append('PYEXT')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   156
	# override shlib_PATTERN set by the osx module
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   157
	self.env['cshlib_PATTERN'] = self.env['cxxshlib_PATTERN'] = self.env['macbundle_PATTERN'] = self.env['pyext_PATTERN']
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   158
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   159
@feature('pyext')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   160
@before_method('apply_link', 'apply_bundle')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   161
def set_bundle(self):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   162
	if sys.platform.startswith('darwin'):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   163
		self.mac_bundle = True
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   164
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   165
@before_method('propagate_uselib_vars')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   166
@feature('pyembed')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   167
def init_pyembed(self):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   168
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   169
	Add the PYEMBED variable.
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   170
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   171
	self.uselib = self.to_list(getattr(self, 'uselib', []))
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   172
	if not 'PYEMBED' in self.uselib:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   173
		self.uselib.append('PYEMBED')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   174
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   175
@conf
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   176
def get_python_variables(conf, variables, imports=['import sys']):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   177
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   178
	Execute a python interpreter to dump configuration variables
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   179
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   180
	:param variables: variables to print
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   181
	:type variables: list of string
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   182
	:param imports: one import by element
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   183
	:type imports: list of string
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   184
	:return: the variable values
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   185
	:rtype: list of string
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   186
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   187
	program = list(imports)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   188
	program.append('')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   189
	for v in variables:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   190
		program.append("print(repr(%s))" % v)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   191
	os_env = dict(os.environ)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   192
	try:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   193
		del os_env['MACOSX_DEPLOYMENT_TARGET'] # see comments in the OSX tool
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   194
	except KeyError:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   195
		pass
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   196
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   197
	try:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   198
		out = conf.cmd_and_log(conf.env.PYTHON + ['-c', '\n'.join(program)], env=os_env)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   199
	except Errors.WafError:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   200
		conf.fatal('The distutils module is unusable: install "python-devel"?')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   201
	return_values = []
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   202
	for s in out.split('\n'):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   203
		s = s.strip()
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   204
		if not s:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   205
			continue
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   206
		if s == 'None':
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   207
			return_values.append(None)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   208
		elif s[0] == "'" and s[-1] == "'":
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   209
			return_values.append(s[1:-1])
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   210
		elif s[0].isdigit():
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   211
			return_values.append(int(s))
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   212
		else: break
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   213
	return return_values
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   214
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   215
@conf
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   216
def check_python_headers(conf):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   217
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   218
	Check for headers and libraries necessary to extend or embed python by using the module *distutils*.
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   219
	On success the environment variables xxx_PYEXT and xxx_PYEMBED are added:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   220
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   221
	* PYEXT: for compiling python extensions
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   222
	* PYEMBED: for embedding a python interpreter
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   223
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   224
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   225
	# FIXME rewrite
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   226
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   227
	if not conf.env['CC_NAME'] and not conf.env['CXX_NAME']:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   228
		conf.fatal('load a compiler first (gcc, g++, ..)')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   229
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   230
	if not conf.env['PYTHON_VERSION']:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   231
		conf.check_python_version()
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   232
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   233
	env = conf.env
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   234
	pybin = conf.env.PYTHON
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   235
	if not pybin:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   236
		conf.fatal('could not find the python executable')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   237
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   238
	v = 'prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS'.split()
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   239
	try:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   240
		lst = conf.get_python_variables(["get_config_var('%s') or ''" % x for x in v],
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   241
			['from distutils.sysconfig import get_config_var'])
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   242
	except RuntimeError:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   243
		conf.fatal("Python development headers not found (-v for details).")
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   244
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   245
	vals = ['%s = %r' % (x, y) for (x, y) in zip(v, lst)]
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   246
	conf.to_log("Configuration returned from %r:\n%r\n" % (pybin, '\n'.join(vals)))
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   247
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   248
	dct = dict(zip(v, lst))
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   249
	x = 'MACOSX_DEPLOYMENT_TARGET'
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   250
	if dct[x]:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   251
		conf.env[x] = conf.environ[x] = dct[x]
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   252
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   253
	env['pyext_PATTERN'] = '%s' + dct['SO'] # not a mistake
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   254
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   255
	# Check for python libraries for embedding
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   256
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   257
	all_flags = dct['LDFLAGS'] + ' ' + dct['CFLAGS']
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   258
	conf.parse_flags(all_flags, 'PYEMBED')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   259
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   260
	all_flags = dct['LDFLAGS'] + ' ' + dct['LDSHARED'] + ' ' + dct['CFLAGS']
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   261
	conf.parse_flags(all_flags, 'PYEXT')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   262
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   263
	result = None
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   264
	#name = 'python' + env['PYTHON_VERSION']
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   265
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   266
	# TODO simplify this
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   267
	for name in ('python' + env['PYTHON_VERSION'], 'python' + env['PYTHON_VERSION'].replace('.', '')):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   268
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   269
		# LIBPATH_PYEMBED is already set; see if it works.
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   270
		if not result and env['LIBPATH_PYEMBED']:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   271
			path = env['LIBPATH_PYEMBED']
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   272
			conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n" % path)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   273
			result = conf.check(lib=name, uselib='PYEMBED', libpath=path, mandatory=False, msg='Checking for library %s in LIBPATH_PYEMBED' % name)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   274
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   275
		if not result and dct['LIBDIR']:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   276
			path = [dct['LIBDIR']]
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   277
			conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n" % path)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   278
			result = conf.check(lib=name, uselib='PYEMBED', libpath=path, mandatory=False, msg='Checking for library %s in LIBDIR' % name)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   279
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   280
		if not result and dct['LIBPL']:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   281
			path = [dct['LIBPL']]
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   282
			conf.to_log("\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n")
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   283
			result = conf.check(lib=name, uselib='PYEMBED', libpath=path, mandatory=False, msg='Checking for library %s in python_LIBPL' % name)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   284
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   285
		if not result:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   286
			path = [os.path.join(dct['prefix'], "libs")]
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   287
			conf.to_log("\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n")
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   288
			result = conf.check(lib=name, uselib='PYEMBED', libpath=path, mandatory=False, msg='Checking for library %s in $prefix/libs' % name)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   289
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   290
		if result:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   291
			break # do not forget to set LIBPATH_PYEMBED
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   292
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   293
	if result:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   294
		env['LIBPATH_PYEMBED'] = path
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   295
		env.append_value('LIB_PYEMBED', [name])
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   296
	else:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   297
		conf.to_log("\n\n### LIB NOT FOUND\n")
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   298
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   299
	# under certain conditions, python extensions must link to
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   300
	# python libraries, not just python embedding programs.
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   301
	if (Utils.is_win32 or sys.platform.startswith('os2')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   302
		or dct['Py_ENABLE_SHARED']):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   303
		env['LIBPATH_PYEXT'] = env['LIBPATH_PYEMBED']
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   304
		env['LIB_PYEXT'] = env['LIB_PYEMBED']
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   305
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   306
	# We check that pythonX.Y-config exists, and if it exists we
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   307
	# use it to get only the includes, else fall back to distutils.
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   308
	num = '.'.join(env['PYTHON_VERSION'].split('.')[:2])
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   309
	conf.find_program(['python%s-config' % num, 'python-config-%s' % num, 'python%sm-config' % num], var='PYTHON_CONFIG', mandatory=False)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   310
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   311
	includes = []
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   312
	if conf.env.PYTHON_CONFIG:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   313
		for incstr in conf.cmd_and_log([ conf.env.PYTHON_CONFIG, '--includes']).strip().split():
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   314
			# strip the -I or /I
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   315
			if (incstr.startswith('-I') or incstr.startswith('/I')):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   316
				incstr = incstr[2:]
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   317
			# append include path, unless already given
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   318
			if incstr not in includes:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   319
				includes.append(incstr)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   320
		conf.to_log("Include path for Python extensions "
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   321
			       "(found via python-config --includes): %r\n" % (includes,))
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   322
		env['INCLUDES_PYEXT'] = includes
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   323
		env['INCLUDES_PYEMBED'] = includes
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   324
	else:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   325
		conf.to_log("Include path for Python extensions "
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   326
			       "(found via distutils module): %r\n" % (dct['INCLUDEPY'],))
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   327
		env['INCLUDES_PYEXT'] = [dct['INCLUDEPY']]
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   328
		env['INCLUDES_PYEMBED'] = [dct['INCLUDEPY']]
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   329
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   330
	# Code using the Python API needs to be compiled with -fno-strict-aliasing
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   331
	if env['CC_NAME'] == 'gcc':
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   332
		env.append_value('CFLAGS_PYEMBED', ['-fno-strict-aliasing'])
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   333
		env.append_value('CFLAGS_PYEXT', ['-fno-strict-aliasing'])
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   334
	if env['CXX_NAME'] == 'gcc':
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   335
		env.append_value('CXXFLAGS_PYEMBED', ['-fno-strict-aliasing'])
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   336
		env.append_value('CXXFLAGS_PYEXT', ['-fno-strict-aliasing'])
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   337
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   338
	if env.CC_NAME == "msvc":
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   339
		from distutils.msvccompiler import MSVCCompiler
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   340
		dist_compiler = MSVCCompiler()
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   341
		dist_compiler.initialize()
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   342
		env.append_value('CFLAGS_PYEXT', dist_compiler.compile_options)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   343
		env.append_value('CXXFLAGS_PYEXT', dist_compiler.compile_options)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   344
		env.append_value('LINKFLAGS_PYEXT', dist_compiler.ldflags_shared)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   345
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   346
	# See if it compiles
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   347
	try:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   348
		conf.check(header_name='Python.h', define_name='HAVE_PYTHON_H',
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   349
		   uselib='PYEMBED', fragment=FRAG,
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   350
		   errmsg='Could not find the python development headers')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   351
	except conf.errors.ConfigurationError:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   352
		# python3.2, oh yeah
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   353
		conf.check_cfg(path=conf.env.PYTHON_CONFIG, package='', uselib_store='PYEMBED', args=['--cflags', '--libs'])
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   354
		conf.check(header_name='Python.h', define_name='HAVE_PYTHON_H', msg='Getting the python flags from python-config',
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   355
			uselib='PYEMBED', fragment=FRAG,
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   356
				errmsg='Could not find the python development headers elsewhere')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   357
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   358
@conf
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   359
def check_python_version(conf, minver=None):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   360
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   361
	Check if the python interpreter is found matching a given minimum version.
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   362
	minver should be a tuple, eg. to check for python >= 2.4.2 pass (2,4,2) as minver.
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   363
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   364
	If successful, PYTHON_VERSION is defined as 'MAJOR.MINOR'
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   365
	(eg. '2.4') of the actual python version found, and PYTHONDIR is
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   366
	defined, pointing to the site-packages directory appropriate for
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   367
	this python version, where modules/packages/extensions should be
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   368
	installed.
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   369
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   370
	:param minver: minimum version
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   371
	:type minver: tuple of int
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   372
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   373
	assert minver is None or isinstance(minver, tuple)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   374
	pybin = conf.env['PYTHON']
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   375
	if not pybin:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   376
		conf.fatal('could not find the python executable')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   377
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   378
	# Get python version string
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   379
	cmd = pybin + ['-c', 'import sys\nfor x in sys.version_info: print(str(x))']
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   380
	debug('python: Running python command %r' % cmd)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   381
	lines = conf.cmd_and_log(cmd).split()
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   382
	assert len(lines) == 5, "found %i lines, expected 5: %r" % (len(lines), lines)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   383
	pyver_tuple = (int(lines[0]), int(lines[1]), int(lines[2]), lines[3], int(lines[4]))
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   384
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   385
	# compare python version with the minimum required
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   386
	result = (minver is None) or (pyver_tuple >= minver)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   387
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   388
	if result:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   389
		# define useful environment variables
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   390
		pyver = '.'.join([str(x) for x in pyver_tuple[:2]])
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   391
		conf.env['PYTHON_VERSION'] = pyver
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   392
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   393
		if 'PYTHONDIR' in conf.environ:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   394
			pydir = conf.environ['PYTHONDIR']
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   395
		else:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   396
			if Utils.is_win32:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   397
				(python_LIBDEST, pydir) = \
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   398
						conf.get_python_variables(
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   399
											  ["get_config_var('LIBDEST') or ''",
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   400
											   "get_python_lib(standard_lib=0, prefix=%r) or ''" % conf.env['PREFIX']],
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   401
											  ['from distutils.sysconfig import get_config_var, get_python_lib'])
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   402
			else:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   403
				python_LIBDEST = None
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   404
				(pydir,) = \
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   405
						conf.get_python_variables(
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   406
											  ["get_python_lib(standard_lib=0, prefix=%r) or ''" % conf.env['PREFIX']],
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   407
											  ['from distutils.sysconfig import get_python_lib'])
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   408
			if python_LIBDEST is None:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   409
				if conf.env['LIBDIR']:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   410
					python_LIBDEST = os.path.join(conf.env['LIBDIR'], "python" + pyver)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   411
				else:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   412
					python_LIBDEST = os.path.join(conf.env['PREFIX'], "lib", "python" + pyver)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   413
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   414
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   415
		if 'PYTHONARCHDIR' in conf.environ:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   416
			pyarchdir = conf.environ['PYTHONARCHDIR']
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   417
		else:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   418
			(pyarchdir, ) = conf.get_python_variables(
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   419
											["get_python_lib(plat_specific=1, standard_lib=0, prefix=%r) or ''" % conf.env['PREFIX']],
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   420
											['from distutils.sysconfig import get_python_lib'])
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   421
			if not pyarchdir:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   422
				pyarchdir = pydir
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   423
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   424
		if hasattr(conf, 'define'): # conf.define is added by the C tool, so may not exist
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   425
			conf.define('PYTHONDIR', pydir)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   426
			conf.define('PYTHONARCHDIR', pyarchdir)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   427
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   428
		conf.env['PYTHONDIR'] = pydir
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   429
		conf.env['PYTHONARCHDIR'] = pyarchdir
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   430
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   431
	# Feedback
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   432
	pyver_full = '.'.join(map(str, pyver_tuple[:3]))
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   433
	if minver is None:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   434
		conf.msg('Checking for python version', pyver_full)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   435
	else:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   436
		minver_str = '.'.join(map(str, minver))
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   437
		conf.msg('Checking for python version', pyver_tuple, ">= %s" % (minver_str,) and 'GREEN' or 'YELLOW')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   438
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   439
	if not result:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   440
		conf.fatal('The python version is too old, expecting %r' % (minver,))
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   441
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   442
PYTHON_MODULE_TEMPLATE = '''
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   443
import %s
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   444
print(1)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   445
'''
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   446
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   447
@conf
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   448
def check_python_module(conf, module_name):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   449
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   450
	Check if the selected python interpreter can import the given python module::
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   451
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   452
		def configure(conf):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   453
			conf.check_python_module('pygccxml')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   454
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   455
	:param module_name: module
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   456
	:type module_name: string
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   457
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   458
	conf.start_msg('Python module %s' % module_name)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   459
	try:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   460
		conf.cmd_and_log(conf.env['PYTHON'] + ['-c', PYTHON_MODULE_TEMPLATE % module_name])
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   461
	except:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   462
		conf.end_msg(False)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   463
		conf.fatal('Could not find the python module %r' % module_name)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   464
	conf.end_msg(True)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   465
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   466
def configure(conf):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   467
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   468
	Detect the python interpreter
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   469
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   470
	try:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   471
		conf.find_program('python', var='PYTHON')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   472
	except conf.errors.ConfigurationError:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   473
		warn("could not find a python executable, setting to sys.executable '%s'" % sys.executable)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   474
		conf.env.PYTHON = sys.executable
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   475
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   476
	if conf.env.PYTHON != sys.executable:
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   477
		warn("python executable '%s' different from sys.executable '%s'" % (conf.env.PYTHON, sys.executable))
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   478
	conf.env.PYTHON = conf.cmd_to_list(conf.env.PYTHON)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   479
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   480
	v = conf.env
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   481
	v['PYCMD'] = '"import sys, py_compile;py_compile.compile(sys.argv[1], sys.argv[2])"'
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   482
	v['PYFLAGS'] = ''
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   483
	v['PYFLAGS_OPT'] = '-O'
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   484
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   485
	v['PYC'] = getattr(Options.options, 'pyc', 1)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   486
	v['PYO'] = getattr(Options.options, 'pyo', 1)
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   487
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   488
def options(opt):
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   489
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   490
	Add the options ``--nopyc`` and ``--nopyo``
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   491
	"""
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   492
	opt.add_option('--nopyc',
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   493
			action='store_false',
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   494
			default=1,
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   495
			help = 'Do not install bytecode compiled .pyc files (configuration) [Default:install]',
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   496
			dest = 'pyc')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   497
	opt.add_option('--nopyo',
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   498
			action='store_false',
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   499
			default=1,
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   500
			help='Do not install optimised compiled .pyo files (configuration) [Default:install]',
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   501
			dest='pyo')
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   502