8fb72194b19f386dfc9ef97b034d9c8c875253c9
[aubio.git] / Makefile
1 WAFCMD=python waf
2 WAFURL=https://waf.io/waf-1.8.22
3
4 #WAFOPTS:=
5 # turn on verbose mode
6 WAFOPTS += --verbose
7 # build wafopts
8 WAFOPTS += --destdir $(DESTDIR)
9 # multiple jobs
10 WAFOPTS += --jobs 4
11 # if HAVE_AUBIO_DOUBLE is defined, pass --enable-double to waf
12 # python/lib/moresetuptools.py also checks for HAVE_AUBIO_DOUBLE
13 WAFOPTS += $(shell [ -z $(HAVE_AUBIO_DOUBLE) ] || echo --enable-double )
14
15 DESTDIR:=$(PWD)/build/dist
16 PYDESTDIR:=$(PWD)/build/pydist
17
18 # default install locations
19 PREFIX?=/usr/local
20 EXEC_PREFIX?=$(PREFIX)
21 LIBDIR?=$(PREFIX)/lib
22 INCLUDEDIR?=$(PREFIX)/include
23 DATAROOTDIR?=$(PREFIX)/share
24 MANDIR?=$(DATAROOTDIR)/man
25
26 SOX=sox
27
28 TESTSOUNDS := python/tests/sounds
29
30 all: build
31
32 checkwaf:
33         @[ -f waf ] || make getwaf
34
35 getwaf:
36         ./scripts/get_waf.sh
37
38 expandwaf: getwaf
39         [ -d wafilb ] || rm -fr waflib
40         $(WAFCMD) --help > /dev/null
41         mv .waf*/waflib . && rm -fr .waf*
42         sed '/^#==>$$/,$$d' waf > waf2 && mv waf2 waf
43         chmod +x waf
44
45 cleanwaf:
46         rm -rf waf waflib .waf*
47
48 configure: checkwaf
49         $(WAFCMD) configure $(WAFOPTS)
50
51 build: configure
52         $(WAFCMD) build $(WAFOPTS)
53
54 install:
55         # install
56         $(WAFCMD) install $(WAFOPTS)
57
58 list_installed:
59         find $(DESTDIR) -ls | \
60                 sed 's|$(DESTDIR)|/«destdir»|'
61
62 list_installed_python:
63         ( find $(PYDESTDIR) -ls || make list_installed_python_package ) | \
64                 sed 's|$(PYDESTDIR)|/«pydestdir»|'
65
66 list_installed_python_package:
67         pip show -f aubio
68         PACKAGE_LOCATION=$(shell pip show -f aubio | grep ^Location | cut -d \  -f 2) \
69                 make list_installed_python_package_content
70
71 list_installed_python_package_content:
72         ( [ -d $(PACKAGE_LOCATION) ] && find $(PACKAGE_LOCATION) -ls ) || \
73                 unzip -l $(PACKAGE_LOCATION)
74
75 list_all_installed: list_installed list_installed_python
76
77 uninstall:
78         # uninstall
79         $(WAFCMD) uninstall $(WAFOPTS)
80
81 delete_install:
82         rm -rf $(PWD)/dist/test
83
84 build_python:
85         # build python-aubio, using locally built libaubio if found
86         python ./setup.py build
87
88 build_python_extlib:
89         # build python-aubio using (locally) installed libaubio
90         [ -f $(DESTDIR)/$(INCLUDEDIR)/aubio/aubio.h ]
91         [ -d $(DESTDIR)/$(LIBDIR) ]
92         [ -f $(DESTDIR)/$(LIBDIR)/pkgconfig/aubio.pc ]
93         PKG_CONFIG_PATH=$(DESTDIR)/$(LIBDIR)/pkgconfig \
94         CFLAGS="-I$(DESTDIR)/$(INCLUDEDIR)" \
95         LDFLAGS="-L$(DESTDIR)/$(LIBDIR)" \
96                 make build_python
97
98 deps_python:
99         # install or upgrade python requirements
100         pip install --verbose --requirement requirements.txt
101
102 # use pip or distutils?
103 #install_python: install_python_with_pip
104 uninstall_python: uninstall_python_with_pip
105 install_python: install_python_with_distutils
106 #uninstall_python: uninstall_python_with_distutils
107
108 install_python_with_pip:
109         # install package
110         pip install --verbose .
111
112 uninstall_python_with_pip:
113         # uninstall package
114         pip uninstall -y -v aubio || make uninstall_python_with_distutils
115
116 install_python_with_distutils:
117         ./setup.py install $(DISTUTILSOPTS)
118
119 uninstall_python_with_distutils:
120         #./setup.py uninstall
121         [ -d $(PYDESTDIR)/$(LIBDIR) ] && echo Warning: did not clean $(PYDESTDIR)/$(LIBDIR) || true
122
123 force_uninstall_python:
124         # ignore failure if not installed
125         -make uninstall_python
126
127 local_dylib:
128         # DYLD_LIBRARY_PATH is no more on mac os
129         # create links from ~/lib/lib* to build/src/lib*
130         [ -f $(PWD)/build/src/libaubio.[0-9].dylib ] && ( mkdir -p ~/lib && cp -prv build/src/libaubio.[0-9].dylib ~/lib ) || true
131
132 test_python: export LD_LIBRARY_PATH=$(DESTDIR)/$(LIBDIR)
133 test_python: export PYTHONPATH=$(PYDESTDIR)/$(LIBDIR)
134 test_python: local_dylib
135         # run test with installed package
136         ./python/tests/run_all_tests --verbose
137         # also run with nose, multiple processes
138         nose2 -N 4
139
140 clean_python:
141         ./setup.py clean
142
143 check_clean_python:
144         # check cleaning a second time works
145         make clean_python
146         make clean_python
147
148 clean: checkwaf
149         # optionnaly clean before build
150         -$(WAFCMD) clean
151         # remove possible left overs
152         -rm -rf doc/_build
153
154 check_clean:
155         # check cleaning after build works
156         $(WAFCMD) clean
157         # check cleaning a second time works
158         $(WAFCMD) clean
159
160 distclean:
161         $(WAFCMD) distclean
162
163 check_distclean:
164         make distclean
165
166 distcheck: checkwaf
167         $(WAFCMD) distcheck $(WAFOPTS)
168
169 help:
170         $(WAFCMD) --help
171
172 create_test_sounds:
173         -[ -z `which $(SOX)` ] && ( echo $(SOX) could not be found) || true
174         -mkdir -p $(TESTSOUNDS)
175         -$(SOX) -r 44100 -b 16 -n "$(TESTSOUNDS)/44100Hz_1f_silence.wav"          synth 1s   silence 0        dcshift .01
176         -$(SOX) -r 22050 -b 16 -n "$(TESTSOUNDS)/22050Hz_5s_brownnoise.wav"   synth 5    brownnoise      vol 0.9
177         -$(SOX) -r 32000 -b 16 -n "$(TESTSOUNDS)/32000Hz_127f_sine440.wav"    synth 127s sine 440        vol 0.9
178         -$(SOX) -r  8000 -b 16 -n "$(TESTSOUNDS)/8000Hz_30s_silence.wav"      synth 30   silence 0       vol 0.9
179         -$(SOX) -r 48000 -b 32 -n "$(TESTSOUNDS)/48000Hz_60s_sweep.wav"       synth 60   sine 100-20000  vol 0.9
180         -$(SOX) -r 44100 -b 16 -n "$(TESTSOUNDS)/44100Hz_44100f_sine441.wav"  synth 44100s   sine 441   vol 0.9
181         -$(SOX) -r 44100 -b 16 -n "$(TESTSOUNDS)/44100Hz_100f_sine441.wav"    synth 100s sine 441       vol 0.9
182
183 # build only libaubio, no python-aubio
184 test_lib_only: clean distclean configure build install list_installed
185 # additionally, clean after a fresh build
186 test_lib_only_clean: test_lib_only uninstall check_clean check_distclean
187
188 # build libaubio, build and test python-aubio against it
189 test_lib_python: force_uninstall_python deps_python \
190         clean_python clean distclean \
191         configure build build_python \
192         install install_python \
193         test_python \
194         list_all_installed
195
196 test_lib_python_clean: test_lib_python \
197         uninstall_python uninstall \
198         check_clean_python \
199         check_clean \
200         check_distclean
201
202 # build libaubio, install it, build python-aubio against it
203 test_lib_install_python: force_uninstall_python deps_python \
204         clean_python distclean \
205         configure build \
206         install \
207         build_python_extlib \
208         install_python \
209         test_python \
210         list_all_installed
211
212 test_lib_install_python_clean: test_lib_install_python \
213         uninstall_python \
214         delete_install \
215         check_clean_python \
216         check_distclean
217
218 # build a python-aubio that includes libaubio
219 test_python_only: force_uninstall_python deps_python \
220         clean_python clean distclean \
221         build_python \
222         install_python \
223         test_python \
224         list_installed_python
225
226 test_python_only_clean: test_python_only \
227         uninstall_python \
228         check_clean_python
229
230
231 html:
232         cd doc && make html
233
234 dist: distclean expandwaf
235         $(WAFCMD) dist