diff --git a/.ldoc/build_versioned_docs.sh b/.ldoc/build_versioned_docs.sh
new file mode 100755
index 0000000..728103f
--- /dev/null
+++ b/.ldoc/build_versioned_docs.sh
@@ -0,0 +1,98 @@
+#!/usr/bin/env bash
+
+# place this file in mod ".ldoc" directory
+
+
+d_config="$(dirname $(readlink -f $0))"
+
+cd "${d_config}/.."
+
+d_root="$(pwd)"
+d_export="${d_export:-${d_root}/docs/reference}"
+
+cmd_ldoc="${d_root}/../ldoc/ldoc.lua"
+if test -f "${cmd_ldoc}"; then
+ if test ! -x "${cmd_ldoc}"; then
+ chmod +x "${cmd_ldoc}"
+ fi
+else
+ cmd_ldoc="ldoc"
+fi
+
+# clean old files
+rm -rf "${d_export}"
+
+# store current branch
+main_branch="$(git branch --show-current)"
+
+html_out="\n
\n\n\n\n\n"
+
+# generate new doc files
+mkdir -p "${d_export}"
+for vinfo in $(git tag -l --sort=-v:refname | grep "^v[0-9]"); do
+ echo -e "\nbuilding ${vinfo} docs ..."
+ git checkout ${vinfo}
+ d_temp="${d_config}/temp"
+ mkdir -p "${d_temp}"
+
+ # backward compat
+ f_config="${d_root}/docs/config.ld"
+ if test ! -f "${f_config}"; then
+ f_config="${d_config}/config.ld"
+ fi
+
+ if test ! -f "${f_config}"; then
+ echo -e "\nLDoc config not available for ${vinfo}, skipping build ..."
+ continue
+ fi
+
+ "${cmd_ldoc}" --UNSAFE_NO_SANDBOX --multimodule -c "${f_config}" -d "${d_temp}" "${d_root}"; retval=$?
+ if test ${retval} -ne 0; then
+ echo -e "\nERROR: doc build for ${vinfo} failed!"
+ rm -rf "${d_temp}"
+ continue
+ fi
+
+ # show version info
+ for html in $(find "${d_temp}" -type f -name "*.html"); do
+ sed -i -e "s|^[cC]leaner
$|Cleaner (${vinfo})
|" \
+ "${html}"
+ done
+
+ if test -d "${d_root}/textures"; then
+ # copy textures to data directory
+ echo -e "\ncopying textures ..."
+ d_data="${d_temp}/data"
+ mkdir -p "${d_data}"
+ texture_count=0
+ for png in $(find "${d_root}/textures" -maxdepth 1 -type f -name "*.png"); do
+ t_png="${d_data}/$(basename ${png})"
+ if test -f "${t_png}"; then
+ echo "WARNING: not overwriting existing file: ${t_png}"
+ else
+ cp "${png}" "${d_data}"
+ texture_count=$((texture_count + 1))
+ printf "\rcopied ${texture_count} textures"
+ fi
+ done
+ fi
+
+ mv "${d_temp}" "${d_export}/${vinfo}"
+ if test -z ${vcur+x}; then
+ vcur="${vinfo}"
+ ln -s "${d_export}/${vinfo}" "${d_export}/current"
+ ln -s "${d_export}/${vinfo}" "${d_export}/latest"
+ html_out="${html_out} - current
\n"
+ html_out="${html_out} - latest
\n"
+ fi
+ html_out="${html_out} - ${vinfo}
\n"
+done
+
+html_out="${html_out}
\n\n"
+
+cd "${d_root}"
+git checkout ${main_branch}
+
+echo -e "${html_out}" > "${d_export}/index.html"
+
+echo -e "\nDone!"