python: Add a flag identifying in-tree builds.
authorJustus Winter <justus@g10code.com>
Tue, 2 Aug 2016 16:45:10 +0000 (18:45 +0200)
committerJustus Winter <justus@g10code.com>
Tue, 2 Aug 2016 16:45:10 +0000 (18:45 +0200)
* lang/python/helpers.c (pyme_in_tree_build): New variable.
* lang/python/helpers.h (pyme_in_tree_build): New declaration.
* lang/python/pyme/version.py.in (in_tree_build): New variable.
* lang/python/setup.py.in: Rework macro handling, set 'IN_TREE_BUILD'
as appropriate.

Signed-off-by: Justus Winter <justus@g10code.com>
lang/python/helpers.c
lang/python/helpers.h
lang/python/pyme/version.py.in
lang/python/setup.py.in

index 0406f9f..0b4a773 100644 (file)
 #include "helpers.h"
 #include "private.h"
 
+/* Flag specifying whether this is an in-tree build.  */
+int pyme_in_tree_build =
+#if IN_TREE_BUILD
+  1
+#else
+  0
+#endif
+  ;
+
 static PyObject *GPGMEError = NULL;
 
 void _pyme_exception_init(void) {
index 16a9b9f..9200f93 100644 (file)
@@ -26,6 +26,9 @@
 #define write(fd, str, sz) {DWORD written; WriteFile((HANDLE) fd, str, sz, &written, 0);}
 #endif
 
+/* Flag specifying whether this is an in-tree build.  */
+extern int pyme_in_tree_build;
+
 PyObject *pyme_raise_callback_exception(PyObject *self);
 
 PyObject *pyme_set_passphrase_cb(PyObject *self, PyObject *cb);
index a40e02d..e4a5a27 100644 (file)
@@ -21,6 +21,7 @@ from . import gpgme
 productname = 'pyme'
 versionstr = "@VERSION@"
 gpgme_versionstr = gpgme.GPGME_VERSION
+in_tree_build = bool(gpgme.cvar.pyme_in_tree_build)
 
 versionlist = versionstr.split(".")
 major = versionlist[0]
index 45b56a3..a524c95 100755 (executable)
@@ -28,7 +28,9 @@ gpg_error_config = "gpg-error-config"
 gpgme_config = "gpgme-config"
 gpgme_h = ""
 library_dirs = []
+in_tree = False
 extra_swig_opts = []
+extra_macros = dict()
 
 if os.path.exists("../../src/gpgme-config"):
     # In-tree build.
@@ -36,7 +38,10 @@ if os.path.exists("../../src/gpgme-config"):
     gpgme_config = "../../src/gpgme-config"
     gpgme_h = "../../src/gpgme.h"
     library_dirs = ["../../src/.libs"] # XXX uses libtool internals
-    extra_swig_opts = ["-DHAVE_DATA_H=1"]
+    extra_macros.update(
+        HAVE_DATA_H=1,
+        IN_TREE_BUILD=1,
+    )
 
 try:
     subprocess.check_call([gpg_error_config, '--version'],
@@ -87,6 +92,11 @@ include_dirs = [os.getcwd()]
 define_macros = []
 libs = getconfig('libs')
 
+# Define extra_macros for both the SWIG and C code
+for k, v in extra_macros.items():
+    extra_swig_opts.append("-D{0}={1}".format(k, v))
+    define_macros.append((k, str(v)))
+
 for item in getconfig('cflags'):
     if item.startswith("-I"):
         include_dirs.append(item[2:])