Fix off-by-one memory error
[warzone2100:mainline.git] / fixbrokendependencies
1 #!/bin/bash
2
3 # HACK Don't give make errors when switching between trunk and branches.
4 # Works by finding the .deps/*.Po files which refer to source files that don't exist, and replacing them with a single dependency on the correct source file.
5 # Now with PD-ksh support.
6
7 if ! rootdir="`git rev-parse --show-cdup 2> /dev/null`"
8 then
9         echo "Not in a git repository."
10         exit 0
11 fi
12
13 for path in src/ lib/*/ lib/*/*/
14 do
15         srcpath="${rootdir}${path}"
16         deppath="${path}.deps/"
17         if [ -d "${srcpath}" -a -d "${deppath}" ]
18         then
19                 for ext in c cpp
20                 do
21                         # Iterate over all files that might have broken dependencies.
22                         for fname in `cd ${srcpath} ; echo *.${ext}`
23                         do
24                                 fpref="`echo "${fname}" | sed "s/\.${ext}//"`"
25                                 srcfile="${srcpath}${fname}"
26                                 depfile="${deppath}${fpref}.Po"
27
28                                 # Check if the dependency file ${depfile} exists and is broken. (The ${srcfile} check prevents looking for files literally called "*.cpp".)
29                                 if [ -f "${srcfile}" -a -f "${depfile}" ] && ! grep -q "\b${fname}\b" "${depfile}" 2> /dev/null
30                                 then
31                                         relpath="`echo "${path}" | sed "s/[^./]*\//..\//g"`"
32                                         echo "${fpref}.o: ${relpath}${srcfile}" | tee "${depfile}"
33                                 fi
34                         done
35                 done
36         fi
37 done
38
39 exit 0