Update.
[glibc.git] / scripts / gen-sorted.awk
bloba943df6d2fa4493c1023cbfe36af103b43a5bba7
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 = 0
9 dnt = 0
12 if ($1 ~ /depend/) {
13 from[dnt] = $2
14 to[dnt] = $3
15 ++dnt
16 } else {
17 all[cnt++] = $1
20 END {
21 do {
22 moved = 0
23 for (i = 0; i < dnt; ++i) {
24 for (j = 0; j < cnt; ++j) {
25 if (all[j] == from[i]) {
26 for (k = j + 1; k < cnt; ++k) {
27 if (all[k] == to[i]) {
28 break;
31 if (k < cnt) {
32 for (l = k - 1; l >= j; --l) {
33 all[l + 1] = all[l]
35 all[j] = to[i]
36 break;
40 if (j < cnt) {
41 moved = 1
42 break
45 } while (moved)
47 printf "sorted-subdirs = "
48 for (i = 0; i < cnt; ++i) {
49 printf "%s ", all[i];
51 printf "\n"