Skip to content

Commit

Permalink
Improve python bindings Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
infinisil committed Feb 8, 2023
1 parent f1eba79 commit 7c4b513
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ makefiles = \
misc/upstart/local.mk \
doc/manual/local.mk \
tests/local.mk \
tests/plugins/local.mk \
python/local.mk
tests/plugins/local.mk

-include Makefile.config

Expand Down
54 changes: 47 additions & 7 deletions python/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,49 @@
build:
$(MAKE) -C .. python/build
meson compile -C build
# This Makefile is only used for development of the Python bindings, it is not
# used in the Nix build.
# The reason this exists is to make it easier to develop the Python bindings in
# tandem with the main Nix.
# The default `make` (defaults to `make build`) calls the main Nix projects
# `make install` before calling the Python bindings' `meson compile`, therefore
# ensuring that the needed Nix dynamic libraries are up-to-date

test:
$(MAKE) -C .. python/build
meson test -C build -v
builddir=build

.PHONY: build test
.PHONY: build
build: nix-install setup-done
meson compile -C $(builddir)

.PHONY: test
test: nix-install setup-done
meson test -C $(builddir) -v

.PHONY: clean
clean:
rm -rf $(builddir)

# We include the main Nix projects Makefile.config file to know the $(libdir)
# variable, which is where Nix is installed in, which we can then use to setup
# the meson build
include ../Makefile.config

# We need the file to exist though
../Makefile.config:
@# Throw a good error message in case ./configure hasn't been run yet
@[[ -e ../config.status ]] || ( echo "The main Nix project needs to be configured first, see https://nixos.org/manual/nix/stable/contributing/hacking.html" && exit 1 )
@# If ./configure is done, we can create the file ourselves
$(MAKE) -C .. Makefile.config

.PHONY: setup
setup: nix-install
@# Make meson be able to find the locally-installed Nix
PKG_CONFIG_PATH=$(libdir)/pkgconfig:$$PKG_CONFIG_PATH meson setup $(builddir)

.PHONY: setup-done
setup-done:
@# A better error message in case the build directory doesn't exist yet
@[[ -e $(builddir) ]] || ( echo "Run 'make setup' once to configure the project build directory" && exit 1 )

.PHONY: nix-install
nix-install:
@# The python bindings don't technically need an _entire_ Nix installation,
@# but it seems non-trivial to pick out only exactly the files it actually needs
$(MAKE) -C .. install
7 changes: 0 additions & 7 deletions python/local.mk

This file was deleted.

0 comments on commit 7c4b513

Please sign in to comment.