mktime fix for Gnulib + coreutils
[glibc.git] / scripts / gen-sorted.awk
blobf338807e8e485ef1351933524f728756cab05576
1 #!/usr/bin/awk -f
2 # Generate sorted list of directories. The sorting is stable but with
3 # dependencies between directories resolved by moving dependees in front.
4 # Copyright (C) 1998-2018 Free Software Foundation, Inc.
5 # Written by Ulrich Drepper <drepper@cygnus.com>, 1998.
7 BEGIN {
8 cnt = split(subdirs, all) + 1
9 dnt = 0
12 # Let input files have comments.
13 { sub(/[ ]*#.*$/, "") }
14 NF == 0 { next }
17 subdir = type = FILENAME;
18 sub(/^.*\//, "", type);
19 sub(/\/[^/]+$/, "", subdir);
20 sub(/^.*\//, "", subdir);
21 thisdir = "";
24 type == "Depend" && NF == 1 {
25 from[dnt] = subdir;
26 to[dnt] = $1;
27 ++dnt;
28 next
31 type == "Subdirs" && NF == 1 { thisdir = $1 }
33 type == "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;
41 type == "Subdirs" && NF == 2 && $1 == "inhibit" {
42 inhibit[$2] = subdir;
43 next
46 type == "Subdirs" && thisdir {
47 all[cnt++] = thisdir;
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
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 ")";
64 next
68 print FILENAME ":" FNR ":", "what type of file is this?" > "/dev/stderr";
69 exit 2
72 END {
73 do {
74 moved = 0
75 for (i = 0; i < dnt; ++i) {
76 for (j = 1; j < cnt; ++j) {
77 if (all[j] == from[i]) {
78 for (k = j + 1; k < cnt; ++k) {
79 if (all[k] == to[i]) {
80 break;
83 if (k < cnt) {
84 for (l = k - 1; l >= j; --l) {
85 all[l + 1] = all[l]
87 all[j] = to[i]
88 break;
92 if (j < cnt) {
93 moved = 1
94 break
97 } while (moved);
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];
110 printf "%s\n", saw_elf ? " elf" : "";
112 print "sysd-sorted-done := t"