summaryrefslogtreecommitdiff
path: root/Cython/Utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'Cython/Utils.py')
-rw-r--r--Cython/Utils.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Cython/Utils.py b/Cython/Utils.py
index d59d67d78..69563794c 100644
--- a/Cython/Utils.py
+++ b/Cython/Utils.py
@@ -447,3 +447,24 @@ def build_hex_version(version_string):
hexversion = (hexversion << 8) + digit
return '0x%08X' % hexversion
+
+
+def write_depfile(target, source, dependencies):
+ src_base_dir = os.path.dirname(source)
+ cwd = os.getcwd()
+ if not src_base_dir.endswith(os.sep):
+ src_base_dir += os.sep
+ # paths below the base_dir are relative, otherwise absolute
+ paths = []
+ for fname in dependencies:
+ fname = os.path.abspath(fname)
+ if fname.startswith(src_base_dir):
+ paths.append(os.path.relpath(fname, cwd))
+ else:
+ paths.append(fname)
+
+ depline = os.path.relpath(target, cwd) + ": \\\n "
+ depline += " \\\n ".join(paths) + "\n"
+
+ with open(target+'.dep', 'w') as outfile:
+ outfile.write(depline)