]> git.ipfire.org Git - thirdparty/glibc.git/blame - scripts/gen-sorted.awk
nptl/tst-cancel25 needs to be an internal test
[thirdparty/glibc.git] / scripts / gen-sorted.awk
CommitLineData
48d0341c 1#!/usr/bin/awk -f
bb41a976
UD
2# Generate sorted list of directories. The sorting is stable but with
3# dependencies between directories resolved by moving dependees in front.
04277e02 4# Copyright (C) 1998-2019 Free Software Foundation, Inc.
bb41a976
UD
5# Written by Ulrich Drepper <drepper@cygnus.com>, 1998.
6
7BEGIN {
e0a3ed4f 8 cnt = split(subdirs, all) + 1
bb41a976
UD
9 dnt = 0
10}
e0a3ed4f
RM
11
12# Let input files have comments.
13{ sub(/[ ]*#.*$/, "") }
14NF == 0 { next }
15
bb41a976 16{
e0a3ed4f
RM
17 subdir = type = FILENAME;
18 sub(/^.*\//, "", type);
19 sub(/\/[^/]+$/, "", subdir);
20 sub(/^.*\//, "", subdir);
21 thisdir = "";
22}
23
24type == "Depend" && NF == 1 {
25 from[dnt] = subdir;
26 to[dnt] = $1;
27 ++dnt;
28 next
29}
30
31type == "Subdirs" && NF == 1 { thisdir = $1 }
32
33type == "Subdirs" && NF == 2 && $1 == "first" {
34 thisdir = $2;
35 # Make the first dir in the list depend on this one.
36 from[dnt] = all[1];
37 to[dnt] = thisdir;
38 ++dnt;
39}
40
41type == "Subdirs" && NF == 2 && $1 == "inhibit" {
42 inhibit[$2] = subdir;
43 next
44}
45
46type == "Subdirs" && thisdir {
47 all[cnt++] = thisdir;
48
644d3857
JM
49 this_srcdir = srcpfx thisdir
50 if (system("test -d " this_srcdir) != 0) {
51 print FILENAME ":" FNR ":", "cannot find", this_srcdir > "/dev/stderr";
52 exit 2
e0a3ed4f
RM
53 }
54 file = this_srcdir "/Depend";
55 if (system("test -f " file) == 0) {
56 ARGV[ARGC++] = file;
57 # Emit a dependency on the implicitly-read file.
58 if (srcpfx)
59 sub(/^\.\.\//, "", file);
60 if (file !~ /^\/.*$/)
61 file = "$(..)" file;
62 print "$(common-objpfx)sysd-sorted:", "$(wildcard", file ")";
bb41a976 63 }
e0a3ed4f 64 next
bb41a976 65}
e0a3ed4f
RM
66
67{
68 print FILENAME ":" FNR ":", "what type of file is this?" > "/dev/stderr";
69 exit 2
70}
71
bb41a976
UD
72END {
73 do {
74 moved = 0
75 for (i = 0; i < dnt; ++i) {
e0a3ed4f 76 for (j = 1; j < cnt; ++j) {
bb41a976
UD
77 if (all[j] == from[i]) {
78 for (k = j + 1; k < cnt; ++k) {
79 if (all[k] == to[i]) {
80 break;
81 }
82 }
83 if (k < cnt) {
84 for (l = k - 1; l >= j; --l) {
85 all[l + 1] = all[l]
86 }
87 all[j] = to[i]
88 break;
89 }
90 }
91 }
92 if (j < cnt) {
93 moved = 1
94 break
95 }
96 }
e0a3ed4f 97 } while (moved);
bb41a976 98
e0a3ed4f
RM
99 # Make sure we list "elf" last.
100 saw_elf = 0;
101 printf "sorted-subdirs :=";
102 for (i = 1; i < cnt; ++i) {
103 if (all[i] in inhibit)
104 continue;
105 if (all[i] == "elf")
106 saw_elf = 1;
107 else
108 printf " %s", all[i];
bb41a976 109 }
e0a3ed4f
RM
110 printf "%s\n", saw_elf ? " elf" : "";
111
112 print "sysd-sorted-done := t"
bb41a976 113}