Makefile: factorise pip options
[aubio.git] / Makefile
index 62cf0af..63a5bee 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,35 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+
 WAFCMD=python waf
 WAFURL=https://waf.io/waf-1.8.22
 
+#WAFOPTS:=
+# turn on verbose mode
+WAFOPTS += --verbose
+# build wafopts
+WAFOPTS += --destdir $(DESTDIR)
+# multiple jobs
+WAFOPTS += --jobs 4
+# if HAVE_AUBIO_DOUBLE is defined, pass --enable-double to waf
+# python/lib/moresetuptools.py also checks for HAVE_AUBIO_DOUBLE
+WAFOPTS += $(shell [ -z $(HAVE_AUBIO_DOUBLE) ] || echo --enable-double )
+
+PIPOPTS += --verbose
+
+DESTDIR:=$(PWD)/build/dist
+PYDESTDIR:=$(PWD)/build/pydist
+
+# default install locations
+PREFIX?=/usr/local
+EXEC_PREFIX?=$(PREFIX)
+LIBDIR?=$(PREFIX)/lib
+INCLUDEDIR?=$(PREFIX)/include
+DATAROOTDIR?=$(PREFIX)/share
+MANDIR?=$(DATAROOTDIR)/man
+
 SOX=sox
 
-ENABLE_DOUBLE := $(shell [ -z $(HAVE_DOUBLE) ] || echo --enable-double )
 TESTSOUNDS := python/tests/sounds
 
 all: build
@@ -25,89 +51,125 @@ cleanwaf:
        rm -rf waf waflib .waf*
 
 configure: checkwaf
-       $(WAFCMD) configure $(WAFOPTS) $(ENABLE_DOUBLE)
+       $(WAFCMD) configure $(WAFOPTS)
 
 build: configure
        $(WAFCMD) build $(WAFOPTS)
 
-build_python:
-       python ./setup.py build_ext $(ENABLE_DOUBLE)
+install:
+       # install
+       $(WAFCMD) install $(WAFOPTS)
 
-test_python: export LD_LIBRARY_PATH=$(PWD)/build/src
-test_python: local_dylib
-       # clean
-       -pip uninstall -v -y aubio
-       ./setup.py clean
-       $(WAFCMD) distclean
-       # build library
-       $(WAFCMD) configure build
-       # install python requirements
-       pip install -v -r requirements.txt
+list_installed:
+       find $(DESTDIR) -ls | \
+               sed 's|$(DESTDIR)|/«destdir»|'
+
+list_installed_python:
+       ( find $(PYDESTDIR) -ls || make list_installed_python_package ) | \
+               sed 's|$(PYDESTDIR)|/«pydestdir»|'
+
+list_installed_python_package:
+       pip show -f aubio
+       PACKAGE_LOCATION=$(shell pip show -f aubio | grep ^Location | cut -d \  -f 2) \
+               make list_installed_python_package_content
+
+list_installed_python_package_content:
+       ( [ -d $(PACKAGE_LOCATION) ] && find $(PACKAGE_LOCATION) -ls ) || \
+               unzip -l $(PACKAGE_LOCATION)
+
+list_all_installed: list_installed list_installed_python
+
+uninstall:
+       # uninstall
+       $(WAFCMD) uninstall $(WAFOPTS)
+
+delete_install:
+       rm -rf $(PWD)/dist/test
+
+build_python:
+       # build python-aubio, using locally built libaubio if found
+       python ./setup.py build
+
+build_python_extlib:
+       # build python-aubio using (locally) installed libaubio
+       [ -f $(DESTDIR)/$(INCLUDEDIR)/aubio/aubio.h ]
+       [ -d $(DESTDIR)/$(LIBDIR) ]
+       [ -f $(DESTDIR)/$(LIBDIR)/pkgconfig/aubio.pc ]
+       PKG_CONFIG_PATH=$(DESTDIR)/$(LIBDIR)/pkgconfig \
+       CFLAGS="-I$(DESTDIR)/$(INCLUDEDIR)" \
+       LDFLAGS="-L$(DESTDIR)/$(LIBDIR)" \
+               make build_python
+
+deps_python:
+       # install or upgrade python requirements
+       pip install $(PIPOPTS) --requirement requirements.txt
+
+# use pip or distutils?
+#install_python: install_python_with_pip
+uninstall_python: uninstall_python_with_pip
+install_python: install_python_with_distutils
+#uninstall_python: uninstall_python_with_distutils
+
+install_python_with_pip:
        # install package
-       pip install -v .
-       # can clean twice
-       ./setup.py clean
-       ./setup.py clean
-       # run test with installed package
-       ./python/tests/run_all_tests --verbose
-       nose2 -N 4 #--verbose
+       pip install $(PIPOPTS) .
+
+uninstall_python_with_pip:
        # uninstall package
-       pip uninstall -y -v aubio
+       pip uninstall -y -v aubio || make uninstall_python_with_distutils
+
+install_python_with_distutils:
+       ./setup.py install $(PIPOPTS) $(DISTUTILSOPTS)
+
+uninstall_python_with_distutils:
+       #./setup.py uninstall
+       [ -d $(PYDESTDIR)/$(LIBDIR) ] && echo Warning: did not clean $(PYDESTDIR)/$(LIBDIR) || true
+
+force_uninstall_python:
+       # ignore failure if not installed
+       -make uninstall_python
 
 local_dylib:
+       # DYLD_LIBRARY_PATH is no more on mac os
        # create links from ~/lib/lib* to build/src/lib*
-       [ -f build/src/libaubio.[0-9].dylib ] && ( mkdir -p ~/lib && cp -prv build/src/libaubio.[0-9].dylib ~/lib ) || true
-
-clean_python:
-       ./setup.py clean
+       [ -f $(PWD)/build/src/libaubio.[0-9].dylib ] && ( mkdir -p ~/lib && cp -prv build/src/libaubio.[0-9].dylib ~/lib ) || true
 
-test_pure_python:
-       # clean
-       -pip uninstall -v -y aubio
-       -$(WAFCMD) distclean
-       ./setup.py clean
-       # install python requirements
-       pip install --verbose --requirement requirements.txt
-       # compile
-       CFLAGS=-Os python setup.py build $(ENABLE_DOUBLE)
-       # needs recompile, disabled
-       #./setup.py test
-       # install package
-       pip install --verbose .
-       # can clean twice
-       ./setup.py clean
-       ./setup.py clean
+test_python: export LD_LIBRARY_PATH=$(DESTDIR)/$(LIBDIR)
+test_python: export PYTHONPATH=$(PYDESTDIR)/$(LIBDIR)
+test_python: local_dylib
        # run test with installed package
        ./python/tests/run_all_tests --verbose
-       nose2 -N 4 #--verbose
-       # uninstall
-       pip uninstall -v -y aubio
-
-test_pure_python_wheel:
-       -pip uninstall -v -y aubio
-       -rm -rf build/ python/gen/
-       -rm -f dist/*.whl
-       -pip install -v -r requirements.txt
-       -pip install -v wheel
-       CFLAGS=-Os python setup.py build_ext $(ENABLE_DOUBLE) bdist_wheel --universal
-       wheel install dist/*.whl
+       # also run with nose, multiple processes
        nose2 -N 4
-       pip uninstall -v -y aubio
 
-build_python3:
-       python3 ./setup.py build_ext $(ENABLE_DOUBLE)
+clean_python:
+       ./setup.py clean
+
+check_clean_python:
+       # check cleaning a second time works
+       make clean_python
+       make clean_python
 
-clean_python3:
-       python3 ./setup.py clean
+clean: checkwaf
+       # optionnaly clean before build
+       -$(WAFCMD) clean
+       # remove possible left overs
+       -rm -rf doc/_build
 
-clean:
+check_clean:
+       # check cleaning after build works
+       $(WAFCMD) clean
+       # check cleaning a second time works
        $(WAFCMD) clean
 
 distclean:
        $(WAFCMD) distclean
 
+check_distclean:
+       make distclean
+
 distcheck: checkwaf
-       $(WAFCMD) distcheck $(WAFOPTS) $(ENABLE_DOUBLE)
+       $(WAFCMD) distcheck $(WAFOPTS)
 
 help:
        $(WAFCMD) --help
@@ -123,6 +185,54 @@ create_test_sounds:
        -$(SOX) -r 44100 -b 16 -n "$(TESTSOUNDS)/44100Hz_44100f_sine441.wav"  synth 44100s   sine 441   vol 0.9
        -$(SOX) -r 44100 -b 16 -n "$(TESTSOUNDS)/44100Hz_100f_sine441.wav"    synth 100s sine 441       vol 0.9
 
+# build only libaubio, no python-aubio
+test_lib_only: clean distclean configure build install list_installed
+# additionally, clean after a fresh build
+test_lib_only_clean: test_lib_only uninstall check_clean check_distclean
+
+# build libaubio, build and test python-aubio against it
+test_lib_python: force_uninstall_python deps_python \
+       clean_python clean distclean \
+       configure build build_python \
+       install install_python \
+       test_python \
+       list_all_installed
+
+test_lib_python_clean: test_lib_python \
+       uninstall_python uninstall \
+       check_clean_python \
+       check_clean \
+       check_distclean
+
+# build libaubio, install it, build python-aubio against it
+test_lib_install_python: force_uninstall_python deps_python \
+       clean_python distclean \
+       configure build \
+       install \
+       build_python_extlib \
+       install_python \
+       test_python \
+       list_all_installed
+
+test_lib_install_python_clean: test_lib_install_python \
+       uninstall_python \
+       delete_install \
+       check_clean_python \
+       check_distclean
+
+# build a python-aubio that includes libaubio
+test_python_only: force_uninstall_python deps_python \
+       clean_python clean distclean \
+       build_python \
+       install_python \
+       test_python \
+       list_installed_python
+
+test_python_only_clean: test_python_only \
+       uninstall_python \
+       check_clean_python
+
+
 html:
        cd doc && make html