rnhmjoj
ad7852d9c2
- unify the three makefiles into a single generic one - automatically generate link targets (via the `depend` script) and object dependencies (via a make rule) - move all build artifacts under the build/ directory - replace svn with git for the version information - add a `static` variable to toggle between static/shared builds - add a target to build the dependency graph of GRAY modules
29 lines
814 B
Bash
Executable File
29 lines
814 B
Bash
Executable File
#!/bin/sh
|
|
|
|
# Compute the dependencies (direct and transitive) of an object
|
|
# This is used to collect all objects needed to link a program.
|
|
|
|
# Bail out when .d files are missing
|
|
test -f "${1%.o}.d" || exit 1
|
|
|
|
# Check whether $1 contains substring $2
|
|
contains(){ test "${1#*$2}" != "$1"; }
|
|
|
|
# Walk the dependency graph (consinting of the set of all .d files)
|
|
# and output the visited nodes (objects).
|
|
walk_dag(){
|
|
while read -r line; do
|
|
# skip the first line (file own name)
|
|
contains "$line" ': ' && continue
|
|
line="${line% \\}"
|
|
contains "$visited" "$line" && continue
|
|
visited="$line:$visited"
|
|
printf '%s ' "$line"
|
|
# whether the node is a leaf
|
|
test "$(wc -l < "${line%.o}.d")" -gt 1 && walk_dag < "${line%.o}.d"
|
|
done
|
|
}
|
|
|
|
printf '%s ' "$1" # the object itself
|
|
walk_dag < "${1%.o}.d"
|