]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/tools/headerstyle.sh
Cleanup #includes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / tools / headerstyle.sh
index b638927bf4a50441d0adef391b4f48101337cef6..e40fb392a86265091052077549fcc7e61d3cb122 100755 (executable)
@@ -1,6 +1,6 @@
-#!/bin/bash
+#!/usr/bin/env bash
 set -eu
-cd "$(dirname "$0")"
+cd ${0%/*}
 cd ..
 
 function startswith() {
@@ -28,8 +28,23 @@ function check() {
         echo "$file"
         startswith "$file" "#pragma once"
     done
+    find "$base" -type f -name '_mod.inc' -print0 | sort -z | while read -r -d '' file; do
+        echo "$file"
+        declare -l file_inc="${file%_mod.inc}_all.inc"
+        if [ ! -f "$file_inc" ]; then
+            echo '#include "_all.qh"' > "$file_inc"
+            echo '#include "_mod.inc"' >> "$file_inc"
+        fi
+        declare -l file_qh="${file%_mod.inc}_all.qh"
+        if [ ! -f "$file_qh" ]; then
+            echo '#pragma once' > "$file_qh"
+            echo '#include "_mod.qh"' >> "$file_qh"
+        fi
+    done
 }
 
 check client
 check server
 check menu
+
+# TODO: check that "_mod.(qc|inc)" is not included except by "_all.(qc|inc)"