From ccb9881319276e94fdede79c46c4f0d4c981dc41 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Wed, 8 May 2019 22:01:55 +1200 Subject: Refactor build process, use setup.py --- Makefile | 7 +++++++ TODO | 1 + alarm-tools/Makefile | 5 +++++ alarmd/Makefile | 3 +++ config.mk | 3 +++ lib/Makefile | 19 +++++++++++++------ lib/python/Makefile | 16 ++++++---------- lib/python/setup.py | 17 +++++++++++++++++ 8 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 config.mk create mode 100644 lib/python/setup.py diff --git a/Makefile b/Makefile index b18d07e..58db3ae 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +include config.mk + export CFLAGS += -Wall all: @@ -5,6 +7,11 @@ all: make -C alarmd make -C alarm-tools +install: + make -C lib install + make -C alarmd install + make -C alarm-tools install + clean: make -C lib clean make -C alarmd clean diff --git a/TODO b/TODO index ad7ccd8..0767b5f 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,4 @@ - Watch /proc/ and destroy alarms last owned by processes when they die - Allow ownership change command so long as uuid can be given - Add alarm querying to libalarmd +- Build: synchronise version between makefile for .so, python, header files diff --git a/alarm-tools/Makefile b/alarm-tools/Makefile index f181e5f..c5097f4 100644 --- a/alarm-tools/Makefile +++ b/alarm-tools/Makefile @@ -1,3 +1,5 @@ +include ../config.mk + LDFLAGS += -L../lib -lalarm CFLAGS += -I../inc @@ -6,5 +8,8 @@ all: alarms-show alarms-show: alarms-show.o $(CC) -o $@ $^ $(LDFLAGS) +install: + install -Dm755 alarms-show "$(DESTDIR)/$(PREFIX)/bin/alarms-show" + clean: rm alarms-show diff --git a/alarmd/Makefile b/alarmd/Makefile index 30e0317..bb187ad 100644 --- a/alarmd/Makefile +++ b/alarmd/Makefile @@ -6,5 +6,8 @@ all: alarmd alarmd: alarmd.o alarmd_lock.o $(CC) -o $@ $^ $(LDFLAGS) +install: + install -Dm755 alarmd "$(DESTDIR)/$(PREFIX)/bin/alarmd" + clean: rm alarmd alarmd.o alarmd_lock.o diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..3f1bc83 --- /dev/null +++ b/config.mk @@ -0,0 +1,3 @@ +PREFIX = +DESTDIR = /usr +PYTHON = python diff --git a/lib/Makefile b/lib/Makefile index 4961c4e..ade9772 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,18 +1,25 @@ +include ../config.mk + CFLAGS += -I../inc/ -all: python +all: libalarm.so -python: libalarm.so - make -C python +libalarm.so.1: libalarm.o + $(CC) -shared -o $@ $< $(LDFLAGS) -Wl,-soname,libalarm.so.1 -%.so: %.o - $(CC) -shared -o $@ $< $(LDFLAGS) +libalarm.so: libalarm.so.1 + ln -sf $^ $@ %.o: %.c $(CC) -c -o $@ $< $(LDFLAGS) $(CFLAGS) +install: + install -Dm755 libalarm.so.1 "$(DESTDIR)/$(PREFIX)/lib/libalarm.so.1" + ln -sf libalarm.so.1 "$(DESTDIR)/$(PREFIX)/lib/libalarm.so" + make -C python install + clean: - rm -f libalarm.{s,}o + rm -f libalarm.o libalarm.so.1 make -C python clean .PHONY: python diff --git a/lib/python/Makefile b/lib/python/Makefile index e260e64..e23cc9d 100644 --- a/lib/python/Makefile +++ b/lib/python/Makefile @@ -1,16 +1,12 @@ -CFLAGS += -fPIC \ - -I../../inc/ \ - $(shell pkg-config --cflags python3) +include ../../config.mk -all: alarms.so +all: + $(PYTHON) setup.py build -%.so: %.o - $(CC) -shared -o $@ $< $(LDFLAGS) - -%.o: %.c - $(CC) -c -o $@ $< $(CFLAGS) +install: + $(PYTHON) setup.py install --root="$(DESTDIR)/$(PREFIX)" .PHONY: clean clean: - - rm -f alarms.{s,}o + - rm -rf build *.egg-info diff --git a/lib/python/setup.py b/lib/python/setup.py new file mode 100644 index 0000000..5e3c673 --- /dev/null +++ b/lib/python/setup.py @@ -0,0 +1,17 @@ +from setuptools import setup, Extension + +if __name__ == "__main__": + setup( + name="alarms", + version="0.1", + ext_modules=[ + Extension( + "alarms", + language = "C", + sources = [ "alarms.c" ], + extra_compile_args = [ "-I../../inc" ], + libraries = [ "alarm", "uuid" ], + library_dirs = [ "../" ] + ) + ] + ) -- cgit v1.1