* stdio-common/tfformat.c (sprint_doubles): Add 12 new tests.
[glibc.git] / scripts / gen-sorted.awk
blob0092fe61d1b1bfa66333f125e1f7751b1eeeda8c
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 # (C) Copyright 1998 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 if (FILENAME ~ (srcpfx ? /^\.\.\/sysdeps\// : /^sysdeps\//) \
50 || system("test -d " srcpfx thisdir) == 0) {
51 # This Subdirs file is in the main source tree,
52 # or this subdirectory exists in the main source tree.
53 this_srcdir = srcpfx thisdir
55 else {
56 # The Subdirs file comes from an add-on that should have the subdirectory.
57 dir = FILENAME;
59 sub(/\/[^/]+$/, "", dir);
60 while (dir !~ /\/sysdeps$/);
61 sub(/\/sysdeps$/, "", dir);
62 if (system("test -d " dir "/" thisdir) == 0)
63 dir = dir "/" thisdir;
64 else {
65 sub(/\/[^/]+$/, "", dir);
66 if (system("test -d " dir "/" thisdir) == 0)
67 dir = dir "/" thisdir;
68 else {
69 print FILENAME ":" FNR ":", "cannot find", thisdir > "/dev/stderr";
70 exit 2
73 file = dir "/Depend";
74 if (srcpfx)
75 sub(/^\.\.\//, "", dir);
76 if (dir !~ /^\/.*$/)
77 dir = "$(..)" dir;
78 print thisdir "-srcdir", ":=", dir;
80 file = this_srcdir "/Depend";
81 if (system("test -f " file) == 0) {
82 ARGV[ARGC++] = file;
83 # Emit a dependency on the implicitly-read file.
84 if (srcpfx)
85 sub(/^\.\.\//, "", file);
86 if (file !~ /^\/.*$/)
87 file = "$(..)" file;
88 print "$(common-objpfx)sysd-sorted:", "$(wildcard", file ")";
90 next
94 print FILENAME ":" FNR ":", "what type of file is this?" > "/dev/stderr";
95 exit 2
98 END {
99 do {
100 moved = 0
101 for (i = 0; i < dnt; ++i) {
102 for (j = 1; j < cnt; ++j) {
103 if (all[j] == from[i]) {
104 for (k = j + 1; k < cnt; ++k) {
105 if (all[k] == to[i]) {
106 break;
109 if (k < cnt) {
110 for (l = k - 1; l >= j; --l) {
111 all[l + 1] = all[l]
113 all[j] = to[i]
114 break;
118 if (j < cnt) {
119 moved = 1
120 break
123 } while (moved);
125 # Make sure we list "elf" last.
126 saw_elf = 0;
127 printf "sorted-subdirs :=";
128 for (i = 1; i < cnt; ++i) {
129 if (all[i] in inhibit)
130 continue;
131 if (all[i] == "elf")
132 saw_elf = 1;
133 else
134 printf " %s", all[i];
136 printf "%s\n", saw_elf ? " elf" : "";
138 print "sysd-sorted-done := t"