From bea2d208dd44904d4064bb2c6e73cea34aa39d45 Mon Sep 17 00:00:00 2001 From: nhkeni Date: Mon, 4 Mar 2024 13:38:17 -0500 Subject: [PATCH] depend.awk: sort the dependencies Can be disabled in the BEGIN block (set dosort = 0). Blame this change on the Department of Motor Vehicles :-) --- sys/unix/depend.awk | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/sys/unix/depend.awk b/sys/unix/depend.awk index 89af26d8a..1a1a1e2f9 100644 --- a/sys/unix/depend.awk +++ b/sys/unix/depend.awk @@ -1,6 +1,6 @@ # depend.awk -- awk script used to construct makefile dependencies # for nethack's source files (`make depend' support for Makefile.src). -# $NHDT-Date: 1697316508 2023/10/14 20:48:28 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.16 $ +# $NHDT-Date: 1709577497 2024/03/04 18:38:17 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.18 $ # # usage: # awk -f depend.awk ../include/*.h list-of-.c/.cpp-files @@ -31,6 +31,7 @@ # zlib.h ditto # BEGIN { FS = "\"" #for `#include "X"', $2 is X + dosort = 1 special[++sp_cnt] = "../include/config.h" special[++sp_cnt] = "../include/hack.h" alt_deps["../include/extern.h"] = "" @@ -142,6 +143,9 @@ function format_dep(target, source, col, n, i, list, prefix, moc) #first: leading whitespace yields empty 1st element; not sure why moc #files duplicate the target as next element but we need to skip that too first = moc ? 3 : 2 + if (dosort ){ + nhsort(list, first, n) + } for (i = first; i <= n; i++) { if (col + length(list[i]) >= (i < n ? 78 : 80) - 1) { printf(" \\\n\t\t"); col = 16 #make a backslash+newline split @@ -197,4 +201,20 @@ function depend(inout, name, skip, n, i, list) return inout } +# +# sort list[first]..list[last] +# Derived from: https://www.baeldung.com/linux/awk-begin-and-end-rules +# +function nhsort(list, first, last, i,j,temp) +{ + for (i = first; i <= last-1; i++) { + for (j = i+1; j <= last; j++) { + if (list[i] > list[j]) { + temp = list[i] + list[i] = list[j] + list[j] = temp + } + } + } +} #depend.awk#