depend.awk: sort the dependencies

Can be disabled in the BEGIN block (set dosort = 0).

Blame this change on the Department of Motor Vehicles :-)
This commit is contained in:
nhkeni
2024-03-04 13:38:17 -05:00
parent ed5ef46109
commit bea2d208dd

View File

@@ -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#