Files
openwrt/docs/mawk_vs_gawk_report.md
2026-03-22 00:54:57 -07:00

2.0 KiB
Executable File

Report: mawk vs gawk in OpenWRT SDK Context

Introduction

This report details the technical differences between mawk and gawk that led to the build failure of the Mosh package within the OpenWRT SDK environment.

The failure

The OpenWRT SDK build process failed with the following error:

awk: include/scan.awk: line 21: function asort never defined

This error occurred during the package scanning phase (include/scan.mk), which uses awk scripts to parse package definitions.

mawk (Mike's AWK)

  • Design Philosophy: Built for speed and strict POSIX compliance. It is significantly faster than gawk for simple text processing tasks, which is why it is the default awk provider on many Debian-based minimal installations.
  • Limitation: It generally implements only the features defined in the POSIX standard for AWK. It lacks many GNU-specific extensions.
  • Missing Feature: complex sorting functions like asort and asorti are NOT part of the POSIX standard, and thus are absent in mawk.

gawk (GNU AWK)

  • design Philosophy: The GNU implementation of AWK. It includes all POSIX features plus a vast array of extensions.
  • Key Features:
    • asort() / asorti(): Built-in functions for sorting arrays.
    • Network capabilities (/inet/tcp/...).
    • Bitwise operations (and, or, xor).
    • Time functions (mktime, strftime).
  • OpenWRT Requirement: The OpenWRT build system (scripts in include/ and scripts/) relies heavily on these GNU extensions for dependency resolution and menu construction. Specifically, asort is used to deterministically order package lists.

Conclusion

The task was blocked because the system's /usr/bin/awk pointed to mawk. The OpenWRT SDK assumes a full-featured gawk environment. Although mawk is faster, it is functionally insufficient for the complex logic contained in OpenWRT's build scripts.

Now that gawk is installed, the SDK scripts will be able to execute the asort function and proceed with the build.