]>
Commit | Line | Data |
---|---|---|
bb41a976 UD |
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. | |
d4697bc9 | 4 | # Copyright (C) 1998-2014 Free Software Foundation, Inc. |
bb41a976 UD |
5 | # Written by Ulrich Drepper <drepper@cygnus.com>, 1998. |
6 | ||
7 | BEGIN { | |
e0a3ed4f | 8 | cnt = split(subdirs, all) + 1 |
bb41a976 UD |
9 | dnt = 0 |
10 | } | |
e0a3ed4f RM |
11 | |
12 | # Let input files have comments. | |
13 | { sub(/[ ]*#.*$/, "") } | |
14 | NF == 0 { next } | |
15 | ||
bb41a976 | 16 | { |
e0a3ed4f RM |
17 | subdir = type = FILENAME; |
18 | sub(/^.*\//, "", type); | |
19 | sub(/\/[^/]+$/, "", subdir); | |
20 | sub(/^.*\//, "", subdir); | |
21 | thisdir = ""; | |
22 | } | |
23 | ||
24 | type == "Depend" && NF == 1 { | |
25 | from[dnt] = subdir; | |
26 | to[dnt] = $1; | |
27 | ++dnt; | |
28 | next | |
29 | } | |
30 | ||
31 | type == "Subdirs" && NF == 1 { thisdir = $1 } | |
32 | ||
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; | |
39 | } | |
40 | ||
41 | type == "Subdirs" && NF == 2 && $1 == "inhibit" { | |
42 | inhibit[$2] = subdir; | |
43 | next | |
44 | } | |
45 | ||
46 | type == "Subdirs" && thisdir { | |
47 | all[cnt++] = thisdir; | |
48 | ||
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 | |
54 | } | |
55 | else { | |
56 | # The Subdirs file comes from an add-on that should have the subdirectory. | |
57 | dir = FILENAME; | |
58 | do | |
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 | |
71 | } | |
72 | } | |
73 | file = dir "/Depend"; | |
74 | if (srcpfx) | |
75 | sub(/^\.\.\//, "", dir); | |
76 | if (dir !~ /^\/.*$/) | |
77 | dir = "$(..)" dir; | |
78 | print thisdir "-srcdir", ":=", dir; | |
79 | } | |
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 ")"; | |
bb41a976 | 89 | } |
e0a3ed4f | 90 | next |
bb41a976 | 91 | } |
e0a3ed4f RM |
92 | |
93 | { | |
94 | print FILENAME ":" FNR ":", "what type of file is this?" > "/dev/stderr"; | |
95 | exit 2 | |
96 | } | |
97 | ||
bb41a976 UD |
98 | END { |
99 | do { | |
100 | moved = 0 | |
101 | for (i = 0; i < dnt; ++i) { | |
e0a3ed4f | 102 | for (j = 1; j < cnt; ++j) { |
bb41a976 UD |
103 | if (all[j] == from[i]) { |
104 | for (k = j + 1; k < cnt; ++k) { | |
105 | if (all[k] == to[i]) { | |
106 | break; | |
107 | } | |
108 | } | |
109 | if (k < cnt) { | |
110 | for (l = k - 1; l >= j; --l) { | |
111 | all[l + 1] = all[l] | |
112 | } | |
113 | all[j] = to[i] | |
114 | break; | |
115 | } | |
116 | } | |
117 | } | |
118 | if (j < cnt) { | |
119 | moved = 1 | |
120 | break | |
121 | } | |
122 | } | |
e0a3ed4f | 123 | } while (moved); |
bb41a976 | 124 | |
e0a3ed4f RM |
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]; | |
bb41a976 | 135 | } |
e0a3ed4f RM |
136 | printf "%s\n", saw_elf ? " elf" : ""; |
137 | ||
138 | print "sysd-sorted-done := t" | |
bb41a976 | 139 | } |