Skip to content

Commit 718cefe

Browse files
dekkerskeszybz
authored andcommitted
build-sys: generate systemd/id128-constants.h in setup.py
Fixes #7.
1 parent b71b8b6 commit 718cefe

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ builddir := $(shell $(PYTHON) -c '$(buildscript)')
1313

1414
all: build
1515

16-
systemd/id128-constants.h: $(INCLUDE_DIR)/systemd/sd-messages.h
17-
$(SED) -n -r 's/,//g; s/#define (SD_MESSAGE_[A-Z0-9_]+)\s.*/add_id(m, "\1", \1) JOINER/p' <$< >$@
18-
19-
build: systemd/id128-constants.h
16+
build:
2017
$(PYTHON) setup.py build
2118

2219
install:

setup.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
import sys, os
22
from distutils.core import setup, Extension
3+
from distutils.command.build_ext import build_ext
34
from subprocess import Popen, PIPE, check_output
45

6+
7+
class build_ext_generate_id128_header(build_ext):
8+
def run(self):
9+
if not self.dry_run and not os.path.exists("systemd/id128-constants.h"):
10+
constants = []
11+
with open("/usr/include/systemd/sd-messages.h") as f:
12+
for line in f:
13+
if line.startswith('#define SD'):
14+
constants.append(line.split()[1])
15+
16+
with open("systemd/id128-constants.h", "w") as f:
17+
for c in constants:
18+
f.write('add_id(m, "{0}", {0}) JOINER\n'.format(c))
19+
20+
return build_ext.run(self)
21+
22+
523
def call(*cmd):
624
cmd = Popen(cmd,
725
stdout=PIPE, stderr=PIPE,
@@ -84,4 +102,5 @@ def lib(*names, **kw):
84102
_reader,
85103
_daemon,
86104
id128,
87-
login])
105+
login],
106+
cmdclass = {'build_ext': build_ext_generate_id128_header})

0 commit comments

Comments
 (0)