summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Dekkers <jeroen@dekkers.ch>2015-10-15 15:27:57 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-10-25 11:55:48 -0400
commit718cefefcdcbd916bcd24f9d2d8f0d927cbc6342 (patch)
tree5056281a9a55fc3d14c28491750d42d50192e3af
parentb71b8b64ebb28ddbf1130e9127f1e9fc5fb6117f (diff)
downloadpython-systemd-718cefefcdcbd916bcd24f9d2d8f0d927cbc6342.tar.gz
build-sys: generate systemd/id128-constants.h in setup.py
Fixes #7.
-rw-r--r--Makefile5
-rw-r--r--setup.py21
2 files changed, 21 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 4f9db96..beb4067 100644
--- a/Makefile
+++ b/Makefile
@@ -13,10 +13,7 @@ builddir := $(shell $(PYTHON) -c '$(buildscript)')
all: build
-systemd/id128-constants.h: $(INCLUDE_DIR)/systemd/sd-messages.h
- $(SED) -n -r 's/,//g; s/#define (SD_MESSAGE_[A-Z0-9_]+)\s.*/add_id(m, "\1", \1) JOINER/p' <$< >$@
-
-build: systemd/id128-constants.h
+build:
$(PYTHON) setup.py build
install:
diff --git a/setup.py b/setup.py
index 36db2ef..742deb8 100644
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,25 @@
import sys, os
from distutils.core import setup, Extension
+from distutils.command.build_ext import build_ext
from subprocess import Popen, PIPE, check_output
+
+class build_ext_generate_id128_header(build_ext):
+ def run(self):
+ if not self.dry_run and not os.path.exists("systemd/id128-constants.h"):
+ constants = []
+ with open("/usr/include/systemd/sd-messages.h") as f:
+ for line in f:
+ if line.startswith('#define SD'):
+ constants.append(line.split()[1])
+
+ with open("systemd/id128-constants.h", "w") as f:
+ for c in constants:
+ f.write('add_id(m, "{0}", {0}) JOINER\n'.format(c))
+
+ return build_ext.run(self)
+
+
def call(*cmd):
cmd = Popen(cmd,
stdout=PIPE, stderr=PIPE,
@@ -84,4 +102,5 @@ setup (name = 'python-systemd',
_reader,
_daemon,
id128,
- login])
+ login],
+ cmdclass = {'build_ext': build_ext_generate_id128_header})