diff --git a/lib/Makefile.am b/lib/Makefile.am
index 067034540381707b8eb01e37f7463dcbee62925a..b0f83b2c39a17b63969fba7687b8dbf039d0c00f 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -5,6 +5,7 @@ pkgpython_PYTHON = __init__.py backend.py cli.py cmdlib.py config.py \
 	objects.py errors.py logger.py ssh.py utils.py rpc.py \
 	bdev.py hypervisor.py opcodes.py mcpu.py constants.py \
 	ssconf.py locking.py luxi.py jqueue.py serializer.py
+python_files = $(pkgpython_PYTHON)
 
 all-local: _autoconf.py
 
@@ -28,7 +29,4 @@ _autoconf.py: Makefile
 	  echo "IALLOCATOR_SEARCH_PATH = [$(IALLOCATOR_SEARCH_PATH)]"; \
 	} > $@
 
-pre-check: all
-	for i in $(pkgpython_PYTHON); do \
-		if test ! -f $$i; then $(LN_S) $(srcdir)/$$i $$i; fi; \
-	done
+include $(srcdir)/Makefile.libcommon
diff --git a/lib/Makefile.libcommon b/lib/Makefile.libcommon
new file mode 100644
index 0000000000000000000000000000000000000000..73b48f3fa6883f9bf2d0fbf2ef48585c6a945251
--- /dev/null
+++ b/lib/Makefile.libcommon
@@ -0,0 +1,8 @@
+# We need to create symlinks because "make distcheck" will not install Python
+# files for building.
+pre-check: all
+	for i in $(python_files); do \
+		if test ! -f $$i; then \
+			$(LN_S) $(srcdir)/$$i $$i; \
+		fi; \
+	done