Merge branch 'keni-pending2' into NetHack-3.7

This commit is contained in:
nhkeni
2024-03-10 10:36:24 -04:00
4 changed files with 385 additions and 267 deletions

View File

@@ -9,6 +9,9 @@
# ( cd src ; make all ; cp ../sys/unix/Makefile.src ./Makefile ; \
# make depend ; cp ./Makefile ../sys/unix/Makefile.src ; \
# cd .. ; sh sys/unix/setup.sh [sys/unix/hints/FOO] )
# newer usage:
# cd sys/unix ; make -f Makefile.src updatedepend
#
# This awk program scans each file in sequence, looking for lines beginning
# with `#include "' and recording the name inside the quotes. For .h files,
@@ -32,6 +35,7 @@
#
BEGIN { FS = "\"" #for `#include "X"', $2 is X
dosort = 1
dorulesort = 1
special[++sp_cnt] = "../include/config.h"
special[++sp_cnt] = "../include/hack.h"
alt_deps["../include/extern.h"] = ""
@@ -74,7 +78,10 @@ FNR == 1 { output_dep() #finish previous file
}
deps[file] = deps[file] " " incl
}
END { output_dep() } #finish the last file
END {
output_dep() #finish the last file
output_final() #write output
}
#
@@ -82,7 +89,29 @@ END { output_dep() } #finish the last file
# don't do anything (we've just been collecting their dependencies);
# for .c files, output the `make' rule for corresponding .o file
#
function output_dep( base, targ, moc)
function output_dep(){
if(dorulesort){
worklist[++worklistctr] = file
} else {
output_final2()
}
}
function output_final( x)
{
if(dorulesort){
nhsort(worklist, 1, worklistctr-1, 1)
for(x=1;x<worklistctr;x++){
file = worklist[x]
output_final2()
}
} else {
return
}
}
function output_final2( base, targ, moc)
{
#get the file's base name (including suffix)
base = file; sub("^.+/", "", base)
@@ -144,7 +173,7 @@ function format_dep(target, source, col, n, i, list, prefix, 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)
nhsort(list, first, n, 0)
}
for (i = first; i <= n; i++) {
if (col + length(list[i]) >= (i < n ? 78 : 80) - 1) {
@@ -205,11 +234,11 @@ function depend(inout, name, skip, n, i, list)
# 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)
function nhsort(list, first, last, cmpid, i,j,temp)
{
for (i = first; i <= last-1; i++) {
for (j = i+1; j <= last; j++) {
if (list[i] > list[j]) {
if (nhcmp(list[i], list[j], cmpid)) {
temp = list[i]
list[i] = list[j]
list[j] = temp
@@ -217,4 +246,39 @@ function nhsort(list, first, last, i,j,temp)
}
}
}
function nhcmp(a,b,cmpid)
{
if(cmpid == 0){ # sort dependencies
# 2 .c or .cpp files
if (a ~ /\.c(pp)?$/ && b ~ /\.c(pp)?$/ ){ return a > b }
# a .c or .cpp file and anything else
if (a ~ /\.c(pp)?$/){ return 0 }
if (b ~ /\.c(pp)?$/){ return 1 }
# default
return a > b
} else if(cmpid == 1){ # sort rules
# 2 .h files
if (a ~ /\.h$/ && b ~ /\/.h$/){ return a > b }
# a .h and anything else
if (a ~ /\.h$/){ return 0 }
if (b ~ /\.h$/){ return 1 }
# 2 .c or .cpp files
if (a ~ /\.c(pp)?$/ && b ~ /\.c(pp)?$/ ){ return a > b }
# a .c or .cpp file and anything else
if (a ~ /\.c(pp)?$/){ return 0 }
if (b ~ /\.c(pp)?$/){ return 1 }
# 2 .moc files
if (a ~ /\.moc$/ && b ~ /\.moc$/){ return a > b }
# a .moc and anything else
if (a ~ /\.moc$/){ return 0 }
if (b ~ /\.moc$/){ return 1 }
# default
return a > b
} else {
print "internal error cmpid=" cmpid
exit 1
}
}
#depend.awk#