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-2022 Free Software Foundation, Inc.
7 cnt =
split(subdirs
, all
) + 1
11 # Let input files have comments.
12 { sub(/[ ]*#.*$/, "") }
16 subdir = type =
FILENAME;
17 sub(/^.
*\
//, "", type
);
18 sub(/\
/[^
/]+$
/, "", subdir
);
19 sub(/^.
*\
//, "", subdir
);
23 type ==
"Depend" && NF ==
1 {
30 type ==
"Subdirs" && NF ==
1 { thisdir = $
1 }
32 type ==
"Subdirs" && NF ==
2 && $
1 ==
"first" {
34 # Make the first dir in the list depend on this one.
40 type ==
"Subdirs" && NF ==
2 && $
1 ==
"inhibit" {
45 type ==
"Subdirs" && thisdir
{
48 this_srcdir = srcpfx thisdir
49 if (system("test -d " this_srcdir
) != 0) {
50 print FILENAME ":" FNR ":", "cannot find", this_srcdir
> "/dev/stderr";
53 file = this_srcdir
"/Depend";
54 if (system("test -f " file
) ==
0) {
56 # Emit a dependency on the implicitly-read file.
58 sub(/^\.\.\
//, "", file
);
61 print "$(common-objpfx)sysd-sorted:", "$(wildcard", file
")";
67 print FILENAME ":" FNR ":", "what type of file is this?" > "/dev/stderr";
74 for (i =
0; i
< dnt
; ++i
) {
75 for (j =
1; j
< cnt
; ++j
) {
76 if (all
[j
] == from
[i
]) {
77 for (k = j
+ 1; k
< cnt
; ++k
) {
78 if (all
[k
] == to
[i
]) {
83 for (l = k
- 1; l
>= j
; --l
) {
98 # Make sure we list "elf" last.
100 printf "sorted-subdirs :=";
101 for (i =
1; i
< cnt
; ++i
) {
102 if (all
[i
] in inhibit
)
107 printf " %s", all
[i
];
109 printf "%s\n", saw_elf ?
" elf" : "";
111 print "sysd-sorted-done := t"