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-2017 Free Software Foundation, Inc.
5 # Written by Ulrich Drepper <drepper@cygnus.com>, 1998.
8 cnt =
split(subdirs
, all
) + 1
12 # Let input files have comments.
13 { sub(/[ ]*#.*$/, "") }
17 subdir = type =
FILENAME;
18 sub(/^.
*\
//, "", type
);
19 sub(/\
/[^
/]+$
/, "", subdir
);
20 sub(/^.
*\
//, "", subdir
);
24 type ==
"Depend" && NF ==
1 {
31 type ==
"Subdirs" && NF ==
1 { thisdir = $
1 }
33 type ==
"Subdirs" && NF ==
2 && $
1 ==
"first" {
35 # Make the first dir in the list depend on this one.
41 type ==
"Subdirs" && NF ==
2 && $
1 ==
"inhibit" {
46 type ==
"Subdirs" && 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
56 # The Subdirs file comes from an add-on that should have the subdirectory.
59 sub(/\
/[^
/]+$
/, "", dir
);
60 while (dir !~
/\
/sysdeps$
/);
61 sub(/\
/sysdeps$
/, "", dir
);
62 if (system("test -d " dir
"/" thisdir
) ==
0)
63 dir = dir
"/" thisdir
;
65 sub(/\
/[^
/]+$
/, "", dir
);
66 if (system("test -d " dir
"/" thisdir
) ==
0)
67 dir = dir
"/" thisdir
;
69 print FILENAME ":" FNR ":", "cannot find", thisdir
> "/dev/stderr";
75 sub(/^\.\.\
//, "", dir
);
78 print thisdir
"-srcdir", ":=", dir
;
80 file = this_srcdir
"/Depend";
81 if (system("test -f " file
) ==
0) {
83 # Emit a dependency on the implicitly-read file.
85 sub(/^\.\.\
//, "", file
);
88 print "$(common-objpfx)sysd-sorted:", "$(wildcard", file
")";
94 print FILENAME ":" FNR ":", "what type of file is this?" > "/dev/stderr";
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
]) {
110 for (l = k
- 1; l
>= j
; --l
) {
125 # Make sure we list "elf" last.
127 printf "sorted-subdirs :=";
128 for (i =
1; i
< cnt
; ++i
) {
129 if (all
[i
] in inhibit
)
134 printf " %s", all
[i
];
136 printf "%s\n", saw_elf ?
" elf" : "";
138 print "sysd-sorted-done := t"