1PYBINDING_DEPS  = tools/python-yasm/bytecode.pxi
2PYBINDING_DEPS += tools/python-yasm/errwarn.pxi
3PYBINDING_DEPS += tools/python-yasm/expr.pxi
4PYBINDING_DEPS += tools/python-yasm/floatnum.pxi
5PYBINDING_DEPS += tools/python-yasm/intnum.pxi
6PYBINDING_DEPS += tools/python-yasm/symrec.pxi
7PYBINDING_DEPS += tools/python-yasm/value.pxi
8
9EXTRA_DIST += tools/python-yasm/pyxelator/cparse.py
10EXTRA_DIST += tools/python-yasm/pyxelator/genpyx.py
11EXTRA_DIST += tools/python-yasm/pyxelator/ir.py
12EXTRA_DIST += tools/python-yasm/pyxelator/lexer.py
13EXTRA_DIST += tools/python-yasm/pyxelator/node.py
14EXTRA_DIST += tools/python-yasm/pyxelator/parse_core.py
15EXTRA_DIST += tools/python-yasm/pyxelator/work_unit.py
16EXTRA_DIST += tools/python-yasm/pyxelator/wrap_yasm.py
17EXTRA_DIST += tools/python-yasm/setup.py
18EXTRA_DIST += tools/python-yasm/yasm.pyx
19EXTRA_DIST += $(PYBINDING_DEPS)
20
21if HAVE_PYTHON_BINDINGS
22
23# Use Pyxelator to generate Pyrex function headers.
24_yasm.pxi: ${HEADERS}
25	@rm -rf .tmp
26	@mkdir .tmp
27	$(PYTHON) $(srcdir)/tools/python-yasm/pyxelator/wrap_yasm.py \
28		"YASM_DIR=${srcdir}" "CPP=${CPP}" "CPPFLAGS=${CPPFLAGS}"
29	@rm -rf .tmp
30
31CLEANFILES += _yasm.pxi
32
33# Need to build a local copy of the main Pyrex input file to include _yasm.pxi
34# from the build directory.  Also need to fixup the other .pxi include paths.
35yasm.pyx: $(srcdir)/tools/python-yasm/yasm.pyx
36	sed -e 's,^include "\([^_]\),include "${srcdir}/tools/python-yasm/\1,' \
37		$(srcdir)/tools/python-yasm/yasm.pyx > $@
38
39CLEANFILES += yasm.pyx
40
41# Actually run Cython
42yasm_python.c: yasm.pyx _yasm.pxi $(PYBINDING_DEPS)
43	$(PYTHON) -c "from Cython.Compiler.Main import main; main(command_line=1)" \
44		-o $@ yasm.pyx
45
46CLEANFILES += yasm_python.c
47
48# Now the Python build magic...
49python-setup.txt: Makefile
50	echo "includes=${DEFS} ${DEFAULT_INCLUDES} ${INCLUDES} ${AM_CPPFLAGS} ${CPPFLAGS}" > python-setup.txt
51	echo "sources=${libyasm_a_SOURCES} ${nodist_libyasm_a_SOURCES}" >> python-setup.txt
52	echo "srcdir=${srcdir}" >> python-setup.txt
53	echo "gcc=${GCC}" >> python-setup.txt
54
55CLEANFILES += python-setup.txt
56
57.python-build: python-setup.txt yasm_python.c ${libyasm_a_SOURCES} ${nodist_libyasm_a_SOURCES}
58	$(PYTHON) `test -f tools/python-yasm/setup.py || echo '$(srcdir)/'`tools/python-yasm/setup.py build
59	touch .python-build
60python-build: .python-build
61
62CLEANFILES += .python-build
63
64python-install: .python-build
65	$(PYTHON) `test -f tools/python-yasm/setup.py || echo '$(srcdir)/'`tools/python-yasm/setup.py install "--install-lib=$(DESTDIR)$(pythondir)"
66
67python-uninstall:
68	rm -f `$(PYTHON) -c "import sys;sys.path.insert(0, '${DESTDIR}${pythondir}'); import yasm; print yasm.__file__"`
69
70else
71
72python-build:
73python-install:
74python-uninstall:
75
76endif
77
78EXTRA_DIST += tools/python-yasm/tests/Makefile.inc
79include tools/python-yasm/tests/Makefile.inc
80