diff options
author | Jeroen Dekkers <jeroen@dekkers.ch> | 2015-10-15 15:27:57 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-10-25 11:55:48 -0400 |
commit | 718cefefcdcbd916bcd24f9d2d8f0d927cbc6342 (patch) | |
tree | 5056281a9a55fc3d14c28491750d42d50192e3af | |
parent | b71b8b64ebb28ddbf1130e9127f1e9fc5fb6117f (diff) | |
download | python-systemd-718cefefcdcbd916bcd24f9d2d8f0d927cbc6342.tar.gz |
build-sys: generate systemd/id128-constants.h in setup.py
Fixes #7.
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | setup.py | 21 |
2 files changed, 21 insertions, 5 deletions
@@ -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: @@ -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}) |