Hi Rich. I changed the sole print statement in the script to printf and was able to achieve a small but real increase in speed.
Also, I discovered that adding a set of parenthesis around the concatenation operation at the getline step is required for the script to work with gawk.
So here is the final version of the script:
#!/usr/bin/awk -f
# treegen.awk v1.2 (April 7, 2026)
# usage example: $ treegen.awk labwc.tcz
BEGIN {
LEVEL = 0
LINUX_VERSION = "6.18.2-tinycore64"
MIRROR_PATH = "/path/to/your/local/mirror/tinycorelinux/17.x/x86_64/tcz/"
get_dependencies(ARGV[1])
}
function get_dependencies(app, depapp) {
gsub(/KERNEL/,LINUX_VERSION,app)
for (i = 0; i < LEVEL; i++)
printf(" ")
printf("%s\n", app)
while (getline depapp <(MIRROR_PATH app ".dep") > 0) {
if (depapp ~ /\.tcz/) { # because some .dep files have blank lines
LEVEL++
get_dependencies(depapp)
}
}
close(MIRROR_PATH app ".dep")
LEVEL--
}
To use GNU awk rather than Busybox awk, one simply needs to load gawk and change the shebang from #!/usr/bin/awk -f to #!/usr/local/bin/gawk -f
I don't have a lot of time to tinker today, so for the Busybox awk vs. GNU awk benchmarking I simply ran this command 10 times for each awk version:
$ time treegen.awk vlc-dev.tcz
then took the mean of the real time shown in the output. Here is the somewhat surprising result:
Busybox awk: 1.52 sec
GNU awk: 1.61 sec
I'm not sure whether the difference is statistically significant. I generally prefer to do as much as possible with just what's included in the base system, so I'm happy that Busybox is at least as fast as GNU awk if not slightly faster for this particular task!
P.S. treegen.awk is now in the public domain. It would be trivial to use a variable to count the number of times the get_dependencies function has been called, and bail out if that variable exceeds some appropriately large number. This could be used as a poor man's test for circular dependencies.