about summary refs log tree commit diff
path: root/make/lib/find-includes.sh
diff options
context:
space:
mode:
Diffstat (limited to 'make/lib/find-includes.sh')
-rw-r--r--make/lib/find-includes.sh20
1 files changed, 20 insertions, 0 deletions
diff --git a/make/lib/find-includes.sh b/make/lib/find-includes.sh
new file mode 100644
index 000000000000..4824207c2917
--- /dev/null
+++ b/make/lib/find-includes.sh
@@ -0,0 +1,20 @@
+. $stdenv/setup
+
+echo "finding includes of \`$(basename $main)'..."
+
+makefile=$NIX_BUILD_TOP/makefile
+
+mainDir=$(dirname $main)
+(cd $mainDir && gcc $cFlags -MM $(basename $main) -MF $makefile) || false
+
+echo "[" >$out
+
+while read line; do
+    line=$(echo "$line" | sed 's/.*://')
+    for i in $line; do
+        fullPath=$(readlink -f $mainDir/$i)
+        echo "  [ $fullPath \"$i\" ]" >>$out
+    done
+done < $makefile
+
+echo "]" >>$out