Skip to content
Snippets Groups Projects
Commit e423697c authored by Fons Rademakers's avatar Fons Rademakers
Browse files

from Pere:

fixes in the configure script, Makefile and make Module.mk for the
PyROOT module.

Also class TPython now adheres to ROOT naming conventions.


git-svn-id: http://root.cern.ch/svn/root/trunk@8714 27541ba8-7e3a-0410-8455-c3a389f83636
parent 0e7d14b3
No related branches found
No related tags found
No related merge requests found
......@@ -122,13 +122,13 @@ endif
ifneq ($(FVENUSLIB),)
MODULES += venus
endif
ifneq ($(TABLE),)
MODULES += table
endif
ifneq ($(PYTHONINCDIR),)
#ifneq ($(PYTHONLIB),)
ifneq ($(PYTHONLIB),)
MODULES += pyroot
#endif
endif
endif
ifneq ($(TABLE),)
MODULES += table
endif
ifneq ($(SRPUTILLIB),)
MODULES += srputils
......@@ -695,7 +695,6 @@ showbuild:
@echo "CINTCFLAGS = $(CINTCFLAGS)"
@echo "EXTRA_CFLAGS = $(EXTRA_CFLAGS)"
@echo "F77FLAGS = $(F77FLAGS)"
@echo "FPYTHONLIBDIR = $(FPYTHONLIBDIR)"
@echo "LDFLAGS = $(LDFLAGS)"
@echo "F77LDFLAGS = $(F77LDFLAGS)"
@echo "EXTRA_LDFLAGS = $(EXTRA_LDFLAGS)"
......@@ -727,6 +726,9 @@ showbuild:
@echo "DCAPLIB = $(DCAPLIB)"
@echo "MYSQLINCDIR = $(MYSQLINCDIR)"
@echo "PGSQLINCDIR = $(PGSQLINCDIR)"
@echo "PYTHONLIBDIR = $(PYTHONLIBDIR)"
@echo "PYTHONLIB = $(PYTHONLIB)"
@echo "PYTHONINCDIR = $(PYTHONINCDIR)"
@echo "SAPDBINCDIR = $(SAPDBINCDIR)"
@echo "SRPLIBDIR = $(SRPLIBDIR)"
@echo "SRPINCDIR = $(SRPINCDIR)"
......
......@@ -29,6 +29,7 @@ R__SONAME=$5
R__LIB=$6
R__OBJS=$7
R__EXTRA=$8
R__LEXTRA=$9
lastsyslib=comctl32.lib
extralibs=$lastsyslib
......@@ -48,9 +49,9 @@ if [ "$R__PLATFORM" = "win32" ]; then
echo "$bindexp $name $R__OBJS > lib/${name}.def"
$bindexp $name $R__OBJS > lib/${name}.def
echo lib -nologo -MACHINE:IX86 -out:lib/${name}.lib $R__OBJS \
-def:lib/${name}.def
-def:lib/${name}.def $R__LEXTRA
lib -nologo -MACHINE:IX86 -out:lib/${name}.lib $R__OBJS \
-def:lib/${name}.def
-def:lib/${name}.def $R__LEXTRA
if [ "$R__LIB" = "lib/libCint.dll" ]; then
echo $R__LD $R__SOFLAGS $R__LDFLAGS -o bin/${name}.dll $R__OBJS \
lib/${name}.exp $syslibs
......
......@@ -105,12 +105,13 @@ FPYTHIALIB := @pythialib@
FPYTHIA6LIBDIR := @pythia6libdir@
FPYTHIA6LIB := @pythia6lib@
FVENUSLIBDIR := @venuslibdir@
FVENUSLIB := @venuslib@
PYTHONLIBDIR := @pythonlibdir@
PYTHONLIB := @pythonlib@
PYTHONINCDIR := @pythonincdir@
FVENUSLIBDIR := @venuslibdir@
FVENUSLIB := @venuslib@
PYTHONLIBFLAGS := @pythonlibflags@
SRPLIBDIR := @srplibdir@
SRPLIB := @srplib@
......
......@@ -557,8 +557,8 @@ enable/disable options, prefix with either --enable- or --disable-
ldap LDAP support, requires (Open)LDAP libs
mysql MySQL support, requires libmysqlclient
opengl OpenGL support, requires libGL and libGLU
python PyROOT Python bindings, requires python >= 2.3
openiv OpenInventor support, requires libInventor and libInventorXt
python PyROOT python bindings, requires python >= 2.1
pgsql PostgreSQL support, requires libpq
pythia Pythia5 EG support, requires libPythia
pythia6 Pythia6 EG support, requires libPythia6
......@@ -1507,6 +1507,50 @@ if test ! "x$enable_ldap" = "xno"; then
fi
fi
######################################################################
#
### echo %%% Python - Optional alternative interpreter
#
# (See http://www.python.org)
#
if test ! "x$enable_python" = "xno" ; then
# Check for Python include and library
if test "x$platform" = "xwin32"; then
check_header "Python.h" "$pythonincdir" \
$PYTHONDIR/include C:/Python23/include C:/Python22/include
pythoninc=$found_hdr
pythonincdir=$found_dir
check_library "python23" "$enable_shared" "$pythonlibdir" \
$PYTHONDIR/libs C:/Python23/libs C:/Python22/libs
pythonlib=$found_lib
pythonlibdir=$found_dir
pythonlibflags="-nodefaultlib:python23"
else
check_header "Python.h" "$pythonincdir" \
$PYTHONDIR/include/python2.3 $PYTHONDIR/include/python2.2 \
$PYTHONDIR/include /usr/include/python2.3 /usr/include/python2.2 \
/usr/local/include/python2.3 /usr/local/include/python2.2
pythoninc=$found_hdr
pythonincdir=$found_dir
check_library "libpython2.3 libpython2.2" "$enable_shared" \
"$pythonlibdir" $PYTHONDIR/lib/python2.3/config \
$PYTHONDIR/lib/python2.2/config $PYTHONDIR/lib \
/usr/lib/python2.3/config /usr/lib/python2.2/config \
/usr/local/lib/python2.3/config /usr/local/lib/python2.2/config
pythonlib=$found_lib
pythonlibdir=$found_dir
fi
if test "x$pythonincdir" = "x" || test "x$pythonlib" = "x"; then
enable_python="no"
fi
fi
######################################################################
#
### echo %%% Globus Support - Third party libraries
......@@ -2107,41 +2151,6 @@ fi
echo $enable_shadowpw
######################################################################
#
### echo %%% PyRoot - Python Optional alternative interpreter
#
# (See http://www.python.org)
#
if test ! "x$enable_python" = "xno" ; then
# Check for Python include and library
if test "x$platform" = "xwin32"; then
check_header "Python.h" "$pythonincdir" \
$PYTHONDIR/include C:/Python23/include C:/Python22/include
pythoninc=$found_hdr
pythonincdir=$found_dir
check_library "python23" "$enable_shared" "$pythonlibdir" \
$PYTHONDIR/libs C:/Python23/libs C:/Python22/libs
pythonlib=$found_lib
pythonlibdir=$found_dir
else
check_header "Python.h" "$pythonincdir" \
$PYTHONDIR/include/python2.3 $PYTHONDIR/include/python2.2 \
$PYTHONDIR/include $PYTHONDIR/include \
/usr/include/python2.3 /usr/include/python2.2 \
/usr/local/include/python2.3 /usr/local/include/python2.2
pythoninc=$found_hdr
pythonincdir=$found_dir
fi
if test "x$pythonincdir" = "x" ; then
enable_python=no
fi
fi
######################################################################
#
### echo %%% Table Library - Contributed library
......@@ -2427,14 +2436,15 @@ sed -e "s|@ldflags@||" \
-e "s|@pgsqlincdir@|$pgsqlincdir|" \
-e "s|@pgsqllib@|$pgsqllib|" \
-e "s|@pgsqllibdir@|$pgsqllibdir|" \
-e "s|@pythonlib@|$pythonlib|" \
-e "s|@pythonlibdir@|$pythonlibdir|" \
-e "s|@pythonincdir@|$pythonincdir|" \
-e "s|@proofdir@|$proofdir|" \
-e "s|@pythia6lib@|$pythia6lib|" \
-e "s|@pythia6libdir@|$pythia6libdir|" \
-e "s|@pythialib@|$pythialib|" \
-e "s|@pythialibdir@|$pythialibdir|" \
-e "s|@pythonlib@|$pythonlib|" \
-e "s|@pythonlibdir@|$pythonlibdir|" \
-e "s|@pythonincdir@|$pythonincdir|" \
-e "s|@pythonlibflags@|$pythonlibflags|" \
-e "s|@qtincdir@|$qtincdir|" \
-e "s|@qtlib@|$qtlib|" \
-e "s|@qtlibdir@|$qtlibdir|" \
......
# Module.mk for pyroot module
#
# Authors: Pere Mato, Wim Lavrijsen, 22/4/2004
MODDIR := pyroot
MODDIRS := $(MODDIR)/src
MODDIRI := $(MODDIR)/inc
PYROOTDIR := $(MODDIR)
PYROOTDIRS := $(PYROOTDIR)/src
PYROOTDIRI := $(PYROOTDIR)/inc
PYROOTL := $(MODDIRI)/LinkDef.h
PYROOTDS := $(MODDIRS)/G__PyROOT.cxx
PYROOTDO := $(PYROOTDS:.cxx=.o)
PYROOTDH := $(PYROOTDS:.cxx=.h)
PYROOTH := $(filter-out $(MODDIRI)/LinkDef%,$(wildcard $(MODDIRI)/*.h))
PYROOTS := $(filter-out $(MODDIRS)/G__%,$(wildcard $(MODDIRS)/*.cxx))
PYROOTO := $(PYROOTS:.cxx=.o)
PYROOTDEP := $(PYROOTO:.o=.d) $(PYROOTDO:.o=.d)
PYROOTLIB := $(LPATH)/PyROOT.$(SOEXT)
# used in the main Makefile
ALLHDRS += $(patsubst $(MODDIRI)/%.h,include/%.h,$(PYROOTH))
ALLLIBS += $(PYROOTLIB)
# include all dependency files
INCLUDEFILES += $(PYROOTDEP)
##### local rules #####
include/%.h: $(PYROOTDIRI)/%.h
cp $< $@
$(PYROOTLIB): $(PYROOTO) $(PYROOTDO) $(MAINLIBS)
@$(MAKELIB) $(PLATFORM) $(LD) "$(LDFLAGS)" \
"$(SOFLAGS)" PyROOT.$(SOEXT) $@ \
"$(PYROOTO) $(PYROOTDO)" "$(PYTHONLIB)"
$(PYROOTDS): $(PYROOTH) $(PYROOTL) $(ROOTCINTTMP)
@echo "Generating dictionary $@..."
$(ROOTCINTTMP) -f $@ -c $(PYROOTH) $(PYROOTL)
$(PYROOTDO): $(PYROOTDS)
$(CXX) $(NOOPT) $(CXXFLAGS) -I. -o $@ -c $<
all-pyroot: $(PYROOTLIB)
clean-pyroot:
@rm -f $(PYROOTO) $(PYROOTDO)
clean:: clean-pyroot
distclean-pyroot: clean-pyroot
@rm -f $(PYROOTDEP) $(PYROOTDS) $(PYROOTDH) $(PYROOTLIB)
distclean:: distclean-pyroot
##### extra rules ######
$(PYROOTO): %.o: %.cxx
$(CXX) $(OPT) $(CXXFLAGS) -I$(PYTHONINCDIR) -o $@ -c $<
# Module.mk for pyroot module
#
# Authors: Pere Mato, Wim Lavrijsen, 22/4/2004
MODDIR := pyroot
MODDIRS := $(MODDIR)/src
MODDIRI := $(MODDIR)/inc
PYROOTDIR := $(MODDIR)
PYROOTDIRS := $(PYROOTDIR)/src
PYROOTDIRI := $(PYROOTDIR)/inc
PYROOTL := $(MODDIRI)/LinkDef.h
PYROOTDS := $(MODDIRS)/G__PyROOT.cxx
PYROOTDO := $(PYROOTDS:.cxx=.o)
PYROOTDH := $(PYROOTDS:.cxx=.h)
PYROOTH := $(filter-out $(MODDIRI)/LinkDef%,$(wildcard $(MODDIRI)/*.h))
PYROOTS := $(filter-out $(MODDIRS)/G__%,$(wildcard $(MODDIRS)/*.cxx))
PYROOTO := $(PYROOTS:.cxx=.o)
PYROOTDEP := $(PYROOTO:.o=.d) $(PYROOTDO:.o=.d)
PYROOTLIB := $(LPATH)/PyROOT.$(SOEXT)
# used in the main Makefile
ALLHDRS += $(patsubst $(MODDIRI)/%.h,include/%.h,$(PYROOTH))
ALLLIBS += $(PYROOTLIB)
# include all dependency files
INCLUDEFILES += $(PYROOTDEP)
##### local rules #####
include/%.h: $(PYROOTDIRI)/%.h
cp $< $@
$(PYROOTLIB): $(PYROOTO) $(PYROOTDO) $(MAINLIBS)
@$(MAKELIB) $(PLATFORM) $(LD) "$(LDFLAGS)" \
"$(SOFLAGS)" PyROOT.$(SOEXT) $@ \
"$(PYROOTO) $(PYROOTDO)" "$(PYTHONLIBDIR) $(PYTHONLIB)" \
"$(PYTHONLIBFLAGS)"
$(PYROOTDS): $(PYROOTH) $(PYROOTL) $(ROOTCINTTMP)
@echo "Generating dictionary $@..."
$(ROOTCINTTMP) -f $@ -c $(PYROOTH) $(PYROOTL)
$(PYROOTDO): $(PYROOTDS)
$(CXX) $(NOOPT) $(CXXFLAGS) -I. -o $@ -c $<
all-pyroot: $(PYROOTLIB)
clean-pyroot:
@rm -f $(PYROOTO) $(PYROOTDO)
clean:: clean-pyroot
distclean-pyroot: clean-pyroot
@rm -f $(PYROOTDEP) $(PYROOTDS) $(PYROOTDH) $(PYROOTLIB)
distclean:: distclean-pyroot
##### extra rules ######
$(PYROOTO): %.o: %.cxx
$(CXX) $(OPT) $(CXXFLAGS) -I$(PYTHONINCDIR) -o $@ -c $<
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ function Python::exec;
#pragma link C++ function Python::eval;
#pragma link C++ function Python::bind;
#pragma link C++ function Python::prompt;
#endif
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ function TPython::exec;
#pragma link C++ function TPython::eval;
#pragma link C++ function TPython::bind;
#pragma link C++ function TPython::prompt;
#endif
// @(#)root/pyroot:$Name$:$Id$
// Author: Wim Lavrijsen April 2004
#ifndef ROOT_TPython
#define ROOT_TPython
// ROOT
class TObject;
class Python {
public:
// execute a python statement (eg. "import ROOT" )
static void exec( char* cmd );
// evaluate a python expression (eg. "1+1")
static TObject* eval( char* expr );
// bind a ROOT object with at the python side with name "label"
static bool bind( TObject*, char* label );
// enter an interactive python session (exit with ^D)
static void prompt();
private:
static bool initialize_();
};
#endif
// @(#)root/pyroot:$Name: $:$Id: TPython.h,v 1.2 2004/04/27 09:20:34 rdm Exp $
// Author: Wim Lavrijsen April 2004
#ifndef ROOT_TPython
#define ROOT_TPython
// ROOT
#ifndef ROOT_TObject
#include "TObject.h"
#endif
class TPython {
private:
static bool Initialize();
public:
// execute a python statement (e.g. "import ROOT" )
static void Exec(const char *cmd);
// evaluate a python expression (e.g. "1+1")
static TObject *Eval(const char *expr);
// bind a ROOT object with, at the python side, the name "label"
static bool Bind(TObject *obj, const char *label);
// enter an interactive python session (exit with ^D)
static void Prompt();
ClassDef(TPython,0)
};
#endif
// @(#)root/pyroot:$Name: $:$Id: $
// Author: Wim Lavrijsen, Apr 2004
// Bindings
#include "PyROOT.h"
#include "RootWrapper.h"
#include "ObjectHolder.h"
#include "Utility.h"
#include "TPython.h"
// ROOT
#include "TROOT.h"
#include "TObject.h"
// Standard
#include <stdio.h>
#include <iostream>
//- data ________________________________________________________________________
namespace {
PyObject* g_maindict = 0;
} // unnamed namespace
//- private helpers -------------------------------------------------------------
bool Python::initialize_() {
if ( ! Py_IsInitialized() ) {
// this happens if CINT comes in first
PyEval_InitThreads();
Py_Initialize();
// try again
if ( ! Py_IsInitialized() ) {
// give up ...
std::cout << "Error: python has not been intialized; returning." << std::endl;
return false;
}
// set argv
char* argv[] = { const_cast< char* >( "root" ) };
PySys_SetArgv( sizeof(argv)/sizeof(argv[0]), argv );
// force loading of ROOT
PyRun_SimpleString( const_cast< char* >( "import ROOT" ) );
}
if ( g_maindict == 0 ) {
// retrieve the main dictionary
g_maindict = PyModule_GetDict(
PyImport_AddModule( const_cast< char* >( "__main__" ) ) );
Py_INCREF( g_maindict );
}
// declare success ...
return true;
}
//- CINT entry points -----------------------------------------------------------
void Python::exec( char* cmd ) {
// setup
if ( ! initialize_() )
return;
// execute the command
PyObject* result = PyRun_String( cmd, Py_file_input, g_maindict, g_maindict );
// test for error
if ( result )
Py_DECREF( result );
else
PyErr_Print();
}
TObject* Python::eval( char* expr ) {
// setup
if ( ! initialize_() )
return 0;
// evaluate the expression
PyObject* result = PyRun_String( expr, Py_eval_input, g_maindict, g_maindict );
// test for error
if ( ! result ) {
PyErr_Print();
return 0;
}
// test for a usuable result
if ( result == Py_None ) {
Py_DECREF( result );
return 0;
}
// the result is a new handle, for testing use a borrowed, since ROOT will have to take
// care of the clean up (need to figure out how)
PyROOT::ObjectHolder* holder = PyROOT::Utility::getObjectHolder( result );
if ( holder != 0 )
return reinterpret_cast< TObject* >( holder->getObject() );
Py_DECREF( result );
return 0;
}
bool Python::bind( TObject* obj, char* label ) {
// check given address and setup
if ( ! ( obj && initialize_() ) )
return false;
// bind object in the main namespace
TClass* cls = obj->IsA();
if ( cls != 0 ) {
PyObject* bound =
PyROOT::bindRootObject( new PyROOT::ObjectHolder( (void*)obj, cls, false ) );
if ( bound ) {
bool bOk = PyDict_SetItemString( g_maindict, label, bound ) == 0;
Py_DECREF( bound );
return bOk;
}
}
return false;
}
void Python::prompt() {
// setup
if ( ! initialize_() ) {
return;
}
// enter i/o interactive mode
PyRun_InteractiveLoop( stdin, const_cast< char* >( "\0" ) );
}
// @(#)root/pyroot:$Name: $:$Id: TPython.cxx,v 1.1 2004/04/27 06:28:48 brun Exp $
// Author: Wim Lavrijsen, Apr 2004
// Bindings
#include "PyROOT.h"
#include "RootWrapper.h"
#include "ObjectHolder.h"
#include "Utility.h"
#include "TPython.h"
// ROOT
#include "TROOT.h"
#include "TObject.h"
// Standard
#include <stdio.h>
#include <Riostream.h>
namespace {
PyObject* g_maindict = 0;
} // unnamed namespace
//______________________________________________________________________________
bool TPython::Initialize()
{
// Private initialization method.
if ( ! Py_IsInitialized() ) {
// this happens if CINT comes in first
PyEval_InitThreads();
Py_Initialize();
// try again
if ( ! Py_IsInitialized() ) {
// give up ...
std::cout << "Error: python has not been intialized; returning." << std::endl;
return false;
}
// set argv
char* argv[] = { const_cast< char* >( "root" ) };
PySys_SetArgv( sizeof(argv)/sizeof(argv[0]), argv );
// force loading of ROOT
PyRun_SimpleString( const_cast< char* >( "import ROOT" ) );
}
if ( g_maindict == 0 ) {
// retrieve the main dictionary
g_maindict = PyModule_GetDict(
PyImport_AddModule( const_cast< char* >( "__main__" ) ) );
Py_INCREF( g_maindict );
}
// declare success ...
return true;
}
//______________________________________________________________________________
void TPython::Exec(const char *cmd)
{
// Execute a python statement (e.g. "import ROOT").
// setup
if ( ! Initialize() )
return;
// execute the command
PyObject* result = PyRun_String( const_cast< char * >(cmd), Py_file_input, g_maindict, g_maindict );
// test for error
if ( result )
Py_DECREF( result );
else
PyErr_Print();
}
//______________________________________________________________________________
TObject *TPython::Eval(const char* expr)
{
// Evaluate a python expression (e.g. "1+1").
// setup
if ( ! Initialize() )
return 0;
// evaluate the expression
PyObject* result = PyRun_String( const_cast< char * >(expr), Py_eval_input, g_maindict, g_maindict );
// test for error
if ( ! result ) {
PyErr_Print();
return 0;
}
// test for a usuable result
if ( result == Py_None ) {
Py_DECREF( result );
return 0;
}
// the result is a new handle, for testing use a borrowed, since ROOT
// will have to take care of the clean up (need to figure out how)
PyROOT::ObjectHolder* holder = PyROOT::Utility::getObjectHolder( result );
if ( holder != 0 )
return reinterpret_cast< TObject* >( holder->getObject() );
Py_DECREF( result );
return 0;
}
//______________________________________________________________________________
bool TPython::Bind(TObject *obj, const char *label)
{
// Bind a ROOT object with, at the python side, the name "label".
// check given address and setup
if ( ! ( obj && Initialize() ) )
return false;
// bind object in the main namespace
TClass* cls = obj->IsA();
if ( cls != 0 ) {
PyObject* bound =
PyROOT::bindRootObject( new PyROOT::ObjectHolder( (void*)obj, cls, false ) );
if ( bound ) {
bool bOk = PyDict_SetItemString( g_maindict, const_cast< char * >(label), bound ) == 0;
Py_DECREF( bound );
return bOk;
}
}
return false;
}
//______________________________________________________________________________
void TPython::Prompt()
{
// Enter an interactive python session (exit with ^D).
// setup
if ( ! Initialize() ) {
return;
}
// enter i/o interactive mode
PyRun_InteractiveLoop( stdin, const_cast< char* >( "\0" ) );
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment