summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-09-14 20:32:42 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-09-14 20:32:42 -0400
commit50a322adcfa3c1ac375e061270e73bc76c57cc47 (patch)
treea53a4e358507e16c933e9b428d9a0a00d6d4d840
parent5d99b1e24179d65e75431b8d5dfbe6e11acb0d24 (diff)
downloadfork-ledger-50a322adcfa3c1ac375e061270e73bc76c57cc47.tar.gz
fork-ledger-50a322adcfa3c1ac375e061270e73bc76c57cc47.tar.bz2
fork-ledger-50a322adcfa3c1ac375e061270e73bc76c57cc47.zip
main.py (via ledger.so) and main.cc can now use the same shared library
-rw-r--r--Makefile.am59
-rwxr-xr-xacprep11
-rw-r--r--ledger.h7
-rw-r--r--pyledger.cc39
-rw-r--r--python.cc50
-rwxr-xr-xsetup.py11
6 files changed, 55 insertions, 122 deletions
diff --git a/Makefile.am b/Makefile.am
index 7115efef..8cf0552a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,5 @@
lib_LTLIBRARIES = libledger.la
+libledger_la_CXXFLAGS =
libledger_la_SOURCES = amount.cc balance.cc value.cc autoxact.cc \
binary.cc config.cc datetime.cc format.cc journal.cc option.cc \
parser.cc qif.cc quotes.cc textual.cc valexpr.cc walk.cc
@@ -6,71 +7,41 @@ if READ_GNUCASH
libledger_la_SOURCES += gnucash.cc
endif
if HAVE_BOOST_PYTHON
-libledger_la_SOURCES += python.cc
-libledger_la_CXXFLAGS = -DUSE_BOOST_PYTHON=1
-else
-libledger_la_CXXFLAGS =
+libledger_la_CXXFLAGS += -DUSE_BOOST_PYTHON=1
+libledger_la_SOURCES += python.cc
+libledger_la_LIBADD = $(LIBOBJS) -lboost_python -lpython$(PYTHON_VERSION)
endif
if DEBUG
libledger_la_CXXFLAGS += -DDEBUG_LEVEL=4
-libledger_la_SOURCES += debug.cc
+libledger_la_SOURCES += debug.cc
endif
libledger_la_LDFLAGS = -version-info 2:0
######################################################################
bin_PROGRAMS = ledger
-if DEBUG
-ledger_CXXFLAGS = -DDEBUG_LEVEL=4
-endif
+ledger_CXXFLAGS = $(global_CXXFLAGS)
ledger_SOURCES = main.cc
+if HAVE_BOOST_PYTHON
ledger_LDADD = $(LIBOBJS) libledger.la -lboost_python -lpython$(PYTHON_VERSION)
+else
+ledger_LDADD = $(LIBOBJS) libledger.la
+endif
-nobase_include_HEADERS = \
- amount.h \
- balance.h \
- value.h \
- autoxact.h \
- binary.h \
- config.h \
- datetime.h \
- debug.h \
- error.h \
- format.h \
- gnucash.h \
- ledger.h \
- option.h \
- parser.h \
- qif.h \
- quotes.h \
- textual.h \
- valexpr.h \
- walk.h
info_TEXINFOS = ledger.texi
######################################################################
if HAVE_BOOST_PYTHON
-noinst_LIBRARIES = libledger_bpy.a
-libledger_bpy_a_SOURCES = amount.cc balance.cc value.cc autoxact.cc \
- binary.cc config.cc datetime.cc format.cc journal.cc option.cc \
- parser.cc qif.cc quotes.cc textual.cc valexpr.cc walk.cc python.cc
-libledger_bpy_a_CXXFLAGS = -DUSE_BOOST_PYTHON=1 -DPYTHON_MODULE=1
-if READ_GNUCASH
-libledger_bpy_a_SOURCES += gnucash.cc
-endif
-if DEBUG
-libledger_bpy_a_CXXFLAGS += -DDEBUG_LEVEL=4
-libledger_bpy_a_SOURCES += debug.cc
-endif
-
bin_PROGRAMS += ledger.so
-ledger.so: pyledger.cc libledger_bpy.a
- CFLAGS="$(CPPFLAGS) -L." python setup.py build --build-lib=.
+ledger.so: python.cc libledger.la
+ CFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS) -L. -L.libs" \
+ python setup.py build --build-lib=.
install-exec-hook:
- CFLAGS="$(CPPFLAGS) -L." python setup.py install --prefix=$(DESTDIR)
+ CFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS) -L. -L.libs" \
+ python setup.py install --prefix=$(DESTDIR)
endif
diff --git a/acprep b/acprep
index 2d40b341..7a05fd5c 100755
--- a/acprep
+++ b/acprep
@@ -1,6 +1,6 @@
#!/bin/sh
-libtoolize --automake -f -c
+glibtoolize --automake -f -c
aclocal
autoheader
touch AUTHORS ChangeLog
@@ -18,14 +18,13 @@ INCDIRS="$INCDIRS -Wno-long-double"
LIBDIRS="-L/sw/lib -L/sw/lib/python2.3/config"
if [ "$1" = "--debug" ]; then
- ./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" \
- CXXFLAGS="-g" --enable-debug --disable-shared
+ ./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" CXXFLAGS="-g" \
+ --enable-debug
elif [ "$1" = "--opt" ]; then
./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" \
- CXXFLAGS="-fomit-frame-pointer -fastf -mcpu=7450 -fPIC" --disable-shared
+ CXXFLAGS="-fomit-frame-pointer -fastf -mcpu=7450 -fPIC"
elif [ "$1" = "--perf" ]; then
- ./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" CXXFLAGS="-g -pg" \
- --disable-shared
+ ./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" CXXFLAGS="-g -pg"
fi
rm AUTHORS ChangeLog
diff --git a/ledger.h b/ledger.h
index c3ed47b3..1d64e4e1 100644
--- a/ledger.h
+++ b/ledger.h
@@ -62,13 +62,6 @@ class transaction_t
delete cost;
}
-#ifdef USE_BOOST_PYTHON
- entry_t& get_entry() const {
- assert(entry);
- return *entry;
- }
-#endif
-
bool valid() const;
};
diff --git a/pyledger.cc b/pyledger.cc
index 923d8a88..dc65a4a3 100644
--- a/pyledger.cc
+++ b/pyledger.cc
@@ -2,43 +2,8 @@
using namespace boost::python;
-#include "ledger.h"
-#include "acconf.h"
-
-void export_amount();
-void export_balance();
-void export_value();
-void export_journal();
-void export_parser();
-void export_textual();
-void export_binary();
-void export_qif();
-#ifdef READ_GNUCASH
-void export_gnucash();
-#endif
-void export_option();
-void export_config();
-void export_walk();
-void export_format();
-void export_valexpr();
-void export_datetime();
+void initialize_ledger_for_python();
BOOST_PYTHON_MODULE(ledger) {
- export_amount();
- export_balance();
- export_value();
- export_journal();
- export_parser();
- export_textual();
- export_binary();
- export_qif();
-#ifdef READ_GNUCASH
- export_gnucash();
-#endif
- export_option();
- export_config();
- export_walk();
- export_format();
- export_valexpr();
- export_datetime();
+ initialize_ledger_for_python();
}
diff --git a/python.cc b/python.cc
index 980df95c..b5d7d493 100644
--- a/python.cc
+++ b/python.cc
@@ -6,6 +6,11 @@
using namespace boost::python;
+namespace {
+ bool python_initialized = false;
+ bool module_initialized = false;
+}
+
void export_amount();
void export_balance();
void export_value();
@@ -18,27 +23,13 @@ void export_qif();
void export_gnucash();
#endif
void export_option();
+void export_config();
void export_walk();
void export_format();
void export_valexpr();
void export_datetime();
-namespace ledger {
-
-python_support * python_interpretor = NULL;
-
-#ifndef PYTHON_MODULE
-
-static struct cleanup_python {
- ~cleanup_python() {
- if (python_interpretor) {
- Py_Finalize();
- delete python_interpretor;
- }
- }
-} _cleanup;
-
-void init_module()
+void initialize_ledger_for_python()
{
export_amount();
export_balance();
@@ -52,22 +43,35 @@ void init_module()
export_gnucash();
#endif
export_option();
+ export_config();
export_walk();
export_format();
export_valexpr();
export_datetime();
+
+ module_initialized = true;
}
-#endif // PYTHON_MODULE
+namespace ledger {
+
+python_support * python_interpretor = NULL;
+
+static struct cleanup_python {
+ ~cleanup_python() {
+ if (python_initialized)
+ Py_Finalize();
+ if (python_interpretor)
+ delete python_interpretor;
+ }
+} _cleanup;
void init_python()
{
- assert(! python_interpretor);
-
-#ifndef PYTHON_MODULE
- Py_Initialize();
- detail::init_module("ledger", &init_module);
-#endif
+ if (! module_initialized) {
+ Py_Initialize();
+ python_initialized = true;
+ detail::init_module("ledger", &initialize_ledger_for_python);
+ }
python_interpretor = new python_support;
}
diff --git a/setup.py b/setup.py
index 2f76281d..45b4292f 100755
--- a/setup.py
+++ b/setup.py
@@ -2,6 +2,8 @@
from distutils.core import setup, Extension
+libs = ["ledger", "boost_python", "gmp", "pcre", "xmlparse", "xmltok"]
+
#setup(name = "Amounts",
# version = "2.0b",
# description = "Amounts Library",
@@ -10,8 +12,8 @@ from distutils.core import setup, Extension
# url = "http://www.newartisans.com/johnw/",
# ext_modules = [
# Extension("amounts", ["pyamounts.cc"],
-# define_macros = [('PYTHON_MODULE', None)],
-# libraries = ["ledger_bpy", "boost_python", "gmp"])])
+# define_macros = [('PYTHON_MODULE', 1)],
+# libraries = libs)])
setup(name = "Ledger",
version = "2.0b",
@@ -21,6 +23,5 @@ setup(name = "Ledger",
url = "http://www.newartisans.com/johnw/",
ext_modules = [
Extension("ledger", ["pyledger.cc"],
- define_macros = [('PYTHON_MODULE', None)],
- libraries = ["ledger_bpy", "boost_python", "gmp",
- "pcre", "xmlparse", "xmltok"])])
+ define_macros = [('PYTHON_MODULE', 1)],
+ libraries = libs)])