aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2024-02-09 06:21:42 -0600
committerRob Landley <rob@landley.net>2024-02-09 06:21:42 -0600
commit8a2d19bf12c2bcfe250bb711df267cd5bd9e755e (patch)
treec78e5eed5792f4d19c3c615db4b0278938ca159b
parentbd6357ebe5a615a081c09fe7e53596c295a2ee23 (diff)
downloadtoybox-8a2d19bf12c2bcfe250bb711df267cd5bd9e755e.tar.gz
Rewrite globals.h generation to only call sed twice.
This version runs every time (much faster), and only includes enabled structures so the union's size is the enabled high water mark rather than pending: scripts/probes/GLOBALS now says that ps is the largest one, setting the sizeof(this) to 336 bytes.
-rwxr-xr-xscripts/make.sh34
-rw-r--r--toys/other/gpiod.c1
-rw-r--r--toys/other/i2ctools.c1
-rw-r--r--toys/other/readlink.c1
-rw-r--r--toys/pending/git.c1
5 files changed, 11 insertions, 27 deletions
diff --git a/scripts/make.sh b/scripts/make.sh
index d659e739..a1968aa9 100755
--- a/scripts/make.sh
+++ b/scripts/make.sh
@@ -204,30 +204,18 @@ fi
# Extract global structure definitions and flag definitions from toys/*/*.c
-function getglobals()
{
- for i in toys/*/*.c
- do
- NAME=${i##*/} NAME=${NAME%\.c}
- DATA="$($SED -n -e '/^GLOBALS(/,/^)/b got;b;:got' \
- -e 's/^GLOBALS(/_data {/' \
- -e 's/^)/};/' -e 'p' $i)"
- [ -n "$DATA" ] && echo -e "// $i\n\nstruct $NAME$DATA\n"
- done
-}
-
-if isnewer globals.h toys
-then
- GLOBSTRUCT="$(getglobals)"
- (
- echo "$GLOBSTRUCT"
- echo
- echo "extern union global_union {"
- echo "$GLOBSTRUCT" | \
- $SED -n 's/struct \(.*\)_data {/ struct \1_data \1;/p'
- echo "} this;"
- ) > "$GENDIR"/globals.h
-fi
+ STRUX="$($SED -ne 's/^#define[ \t]*FOR_\([^ \t]*\).*/\1/;T s1;h;:s1' \
+ -e '/^GLOBALS(/,/^)/{s/^GLOBALS(//;T s2;g;s/.*/struct &_data {/;:s2;s/^)/};\n/;p}' \
+ $TOYFILES)"
+ echo "$STRUX" &&
+ echo "extern union global_union {" &&
+ $SED -n 's/^struct \(.*\)_data .*/\1/;T;s/.*/\tstruct &_data &;/p' \
+ <<<"$STRUX" &&
+ echo "} this;"
+} > "$GENDIR"/globals.h || exit 1
+# -e 'h;y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/;H;g;s/\n/ /'\
+# -e 's/\([^ ]*\) \(.*\)/\tUSE_\2(struct \1_data \1;)/p')"
hostcomp mktags
if isnewer tags.h toys
diff --git a/toys/other/gpiod.c b/toys/other/gpiod.c
index e80452f8..3abdbc0c 100644
--- a/toys/other/gpiod.c
+++ b/toys/other/gpiod.c
@@ -58,7 +58,6 @@ config GPIOSET
*/
#define FOR_gpiodetect
-#define TT this.gpiod
#include "toys.h"
GLOBALS(
diff --git a/toys/other/i2ctools.c b/toys/other/i2ctools.c
index 21317a12..fc905ea0 100644
--- a/toys/other/i2ctools.c
+++ b/toys/other/i2ctools.c
@@ -88,7 +88,6 @@ config I2CTRANSFER
#define FOR_i2cdetect
#define FORCE_FLAGS
-#define TT this.i2ctools
#include "toys.h"
GLOBALS(
diff --git a/toys/other/readlink.c b/toys/other/readlink.c
index 6a64eca5..fb4460de 100644
--- a/toys/other/readlink.c
+++ b/toys/other/readlink.c
@@ -43,7 +43,6 @@ config REALPATH
#define FOR_realpath
#define FORCE_FLAGS
-#define TT this.readlink // workaround: first FOR_ doesn't match filename
#include "toys.h"
GLOBALS(
diff --git a/toys/pending/git.c b/toys/pending/git.c
index 82421483..4ea8a4ac 100644
--- a/toys/pending/git.c
+++ b/toys/pending/git.c
@@ -63,7 +63,6 @@ config GITCHECKOUT
A minimal git checkout.
*/
-#define TT this.git
#define FOR_gitclone
#include "toys.h"
#include "openssl/sha.h" //ToDo: borrowed from OpenSSL to not pipe or refactor the SHA1SUM in toybox