diff --git a/.gitignore b/.gitignore
index e2786a55998f59126afc5db2c79bb15ec857323b..b02b2a0026c3627541166df1b295c0b3ab369e4e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,6 +11,7 @@
 /src/latex-make.pdf
 /src/texdepends.pdf
 /examples/example.pdf
+/examples/lualatex-example.pdf
 /examples/bin/
 /examples/*.sty
 /examples/LaTeX.mk
diff --git a/examples/Makefile b/examples/Makefile
index 6d83836b03c4cbef21b38b543f16e8959916550a..6579892edd9027f8e6c0244bebfd904eebf28013 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -1,7 +1,10 @@
 
 #COMPATIBILITY=true
 
-all: example.pdf
+# example-luatex must be compiled with lualatex
+LU_lualatex-example_FLAVORS=LUALATEX
+
+all: pdf
 
 example.pdf:
 
diff --git a/examples/lualatex-example.tex b/examples/lualatex-example.tex
new file mode 100644
index 0000000000000000000000000000000000000000..ef7a2c6d2ac0e8340dd47acde4af38797f463fec
--- /dev/null
+++ b/examples/lualatex-example.tex
@@ -0,0 +1,8 @@
+\documentclass{article}
+\usepackage{luacode}
+\begin{document}
+A random number:
+\begin{luacode}
+tex.print(math.random())
+\end{luacode}
+\end{document}
diff --git a/src/latex-make.dtx b/src/latex-make.dtx
index 73c0b5da8adbb3c056930588c6fd8314f363f5e4..bb177420ac835cd12183cf73f405d0041eb4f6fe 100644
--- a/src/latex-make.dtx
+++ b/src/latex-make.dtx
@@ -101,7 +101,7 @@
 % documents with the help of a Makefile. Dependencies are
 % automatically tracked with the help of the |texdepends.sty| package.
 % \end{abstract}
-% \CheckSum{323}
+% \CheckSum{332}
 %
 % \changes{v2.0.0}{2006/03/09}{First autocommented version}
 % \changes{v2.1.0}{2008/01/28}{That's the question}
@@ -289,6 +289,8 @@
 %     \hline
 %     PDF & & PDFLATEX & |.tex| $\Rightarrow$ |.pdf| \\
 %     \hline
+%     LUALATEX & & LUALATEX & |.tex| $\Rightarrow$ |.pdf| \\
+%     \hline
 %     DVIPDF & DVI & DVIPDFM & |.dvi| $\Rightarrow$ |.pdf| \\
 %     \hline
 %   \end{tabular}
@@ -422,6 +424,14 @@
 % endef
 % \end{source}
 % 
+% \paragraph{LuaLaTeX flavor}
+% \begin{source}[0.9\linewidth]
+% define lu-define-flavor-LUALATEX\\
+% \hspace*{2ex}\$\$(eval \$\$(call lu-create-flavor,LUALATEX,tex,LUALATEX,.pdf,pdf,\textbackslash\\
+% \hspace*{4ex}.pdftex\_t .\$\$(\_LU\_PDFTEX\_EXT)))\\
+% endef
+% \end{source}
+% 
 % \paragraph{PS flavor}
 % \begin{source}[0.9\linewidth]
 % define lu-define-flavor-PS\\
@@ -1094,6 +1104,7 @@ endef
 # Globals variables
 $(eval $(call lu-setvar-global,LATEX,latex))
 $(eval $(call lu-setvar-global,PDFLATEX,pdflatex))
+$(eval $(call lu-setvar-global,LUALATEX,lualatex))
 $(eval $(call lu-setvar-global,DVIPS,dvips))
 $(eval $(call lu-setvar-global,DVIPDFM,dvipdfm))
 $(eval $(call lu-setvar-global,BIBTEX,bibtex))
@@ -1198,6 +1209,11 @@ define lu-define-flavor-PDF #
 	.pdftex_t .$$(_LU_PDFTEX_EXT)))
 endef
 
+define lu-define-flavor-LUALATEX #
+  $$(eval $$(call lu-create-flavor,LUALATEX,tex,LUALATEX,.pdf,pdf,\
+	.pdftex_t .$$(_LU_PDFTEX_EXT)))
+endef
+
 define lu-define-flavor-PS #
   $$(eval $$(call lu-create-flavor,PS,dvi,DVIPS,.ps,ps,DVI))
 endef
@@ -1248,7 +1264,7 @@ define _lu-do-latex # 1:master 2:flavor 3:source.tex 4:ext(.dvi/.pdf)
 	if [ ! -f "$(1)$(4).mk" ]; then \
 		NO_TEXDEPENDS_FILE=1 ;\
 	fi ;\
-	sed -e 's,\\openout[0-9]* = `\(.*\)'"'.,TD_$(1)$(4)_OUTPUTS += \1,p;d" \
+	sed -e 's,\\openout[0-9]* = \([^`].*\),TD_$(1)$(4)_OUTPUTS += \1,p;s,\\openout[0-9]* = `\(.*\)'"'.,TD_$(1)$(4)_OUTPUTS += \1,p;d" \
 		"$(1).log" >> "$(1)$(4).mk" ;\
 	if [ -f "$(1)$(4)_FAILED" ]; then \
 		echo "*************************************" ;\