From 718cefefcdcbd916bcd24f9d2d8f0d927cbc6342 Mon Sep 17 00:00:00 2001 From: Jeroen Dekkers Date: Thu, 15 Oct 2015 15:27:57 +0200 Subject: build-sys: generate systemd/id128-constants.h in setup.py Fixes #7. --- Makefile | 5 +---- setup.py | 21 ++++++++++++++++++++- 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}) -- cgit v1.2.1