diff options
author | Richard Braun <rbraun@sceen.net> | 2017-07-26 01:19:01 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2017-07-26 01:30:05 +0200 |
commit | 22b1aecea7a3d1e8f5388e8f8bd69046a4c7ff88 (patch) | |
tree | 4acd27afb3675197d5b02178cb034b41d18856de | |
parent | 0fb916cd84b40c3b3df7b01788ae03ed52fc03cb (diff) |
tools/tsort_init_ops.sh: new script
This script retrieves all initialization operation dependencies, taking
all build options into account, and attempts a topological sort, failing
in case loops are detected.
It's automatically run by the build system as a dependency of the kernel
binary.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.am | 7 | ||||
-rw-r--r-- | Makefrag.am | 4 | ||||
-rwxr-xr-x | tools/tsort_init_ops.sh | 51 |
4 files changed, 60 insertions, 3 deletions
@@ -14,5 +14,6 @@ x15.lds /configure /stamp-h1 /x15 +/x15.sorted_init_ops /doc/*\.[1-9] /doc/*\.[1-9]\.html diff --git a/Makefile.am b/Makefile.am index 50baae96..413ac6db 100644 --- a/Makefile.am +++ b/Makefile.am @@ -57,10 +57,13 @@ SUFFIXES += .9 .9.html .9.xml .9.txt $(AM_V_GEN)$(A2X) $(A2X_FLAGS) -f manpage --xsltproc-opts="-o $(abs_top_builddir)/$@" $< bin_PROGRAMS = x15 -x15_DEPENDENCIES = arch/$(arch)/x15.lds -MOSTLYCLEANFILES += arch/$(arch)/x15.lds +x15_DEPENDENCIES = arch/$(arch)/x15.lds x15.sorted_init_ops +MOSTLYCLEANFILES += $(x15_DEPENDENCIES) x15_SOURCES = x15_LDFLAGS = -nostdlib -Xlinker -T arch/$(arch)/x15.lds x15_LDADD = -lgcc include Makefrag.am + +x15.sorted_init_ops: $(filter %.c,$(x15_SOURCES)) + $(AM_V_GEN)$(top_srcdir)/tools/tsort_init_ops.sh "$(COMPILE)" "$@" $^ diff --git a/Makefrag.am b/Makefrag.am index 8c2e35e7..1b39b724 100644 --- a/Makefrag.am +++ b/Makefrag.am @@ -1,7 +1,9 @@ include arch/x86/Makefrag.am include doc/Makefrag.am -EXTRA_DIST += tools/qemu.sh +EXTRA_DIST += \ + tools/qemu.sh \ + tools/tsort_init_ops.sh x15_SOURCES += \ include/assert.h \ diff --git a/tools/tsort_init_ops.sh b/tools/tsort_init_ops.sh new file mode 100755 index 00000000..a367ef27 --- /dev/null +++ b/tools/tsort_init_ops.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +set -e + +compile="$1" +output_file="$2" + +shift 2 + +tmpfile1=$(mktemp) +tmpfile2=$(mktemp) + +cleanup() +{ + rm -f $tmpfile1 $tmpfile2 +} + +trap cleanup EXIT + +process() +{ + target=$1 + + shift + + for dep in $@; do + echo $target $dep + done +} + +# Define _KERN_INIT_H so that the INIT_XXX macros aren't expanded. +$compile -E -D_KERN_INIT_H "$@" \ + | sed -e 's/#.*$//' \ + | tr '\n' ' ' \ + | tr -s ' ' \ + | sed -E -e 's/INIT_OP_DEP\(([a-zA-Z0-9_]*), 1 \)/\1/g' \ + | grep -P -o 'INIT_OP_DEFINE\(.*?\)' \ + | sed -e 's/^INIT_OP_DEFINE(//' \ + | sed -e 's/).*$//' \ + | tr -d , \ +| while read line; do + process $line +done > $tmpfile1 + +if [ -z "$(cat $tmpfile1)" ]; then + return 1 +fi + +# XXX Avoid using pipes because of the lack of a standard -o pipefail variant. +tsort < $tmpfile1 > $tmpfile2 +tac < $tmpfile2 > "$output_file" |