scripts/carray: change to using single .awk script to generate .c
PATCH 1/1 scripts/carray: change to using single .awk script to generate .c
The shell script makes multiple call-outs to awk to get information from the configuration file. It would be easier to just write the whole thing in one .awk script and have the makefile altered to call that instead.
There should be no functional difference other than the script type and has been tested with PLATFORM=generic build. This should be both quicker and easier to understand.
---
v2:
- updated with the new bits from Samuel Holland's changes
- minor tweaks to the awk script to fix the output spacings
--- Makefile | 9 ++-- scripts/carray.awk | 121 +++++++++++++++++++++++++++++++++++++++++++++ scripts/carray.sh | 84 ------------------------------- 3 files changed, 125 insertions(+), 89 deletions(-) create mode 100755 scripts/carray.awk delete mode 100755 scripts/carray.sh
Makefile +4 -5
@@ -501,8 +501,7 @@ compile_d2c = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ $(src_dir)/scripts/d2c.sh -i $(6) -a $(D2C_ALIGN_BYTES) -p $(D2C_NAME_PREFIX) -t $(D2C_PADDING_BYTES) > $(1) compile_carray = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " CARRAY $(subst $(build_dir)/,,$(1))"; \ - $(eval CARRAY_VAR_LIST := $(carray-$(subst .carray.c,,$(shell basename $(1)))-y)) \ - $(src_dir)/scripts/carray.sh -i $(2) -l "$(CARRAY_VAR_LIST)" > $(1) + $(src_dir)/scripts/carray.awk -v "SCRIPT_NAME=scripts/carray.awk" -v "CONFIG_FILE=$(shell basename $(2))" -- -l "$(CARRAY_VAR_LIST)" < $(2) > $(1) compile_gen_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " GEN-DEP $(subst $(build_dir)/,,$(1))"; \ echo "$(1:.dep=$(2)): $(3)" >> $(1)
@@ -531,7 +530,7 @@ $(build_dir)/%.dep: $(src_dir)/%.carray $(KCONFIG_AUTOHEADER) $(call compile_gen_dep,$@,.c,$< $(KCONFIG_AUTOHEADER)) $(call compile_gen_dep,$@,.o,$(@:.dep=.c)) -$(build_dir)/%.carray.c: $(src_dir)/%.carray $(src_dir)/scripts/carray.sh +$(build_dir)/%.carray.c: $(src_dir)/%.carray $(src_dir)/scripts/carray.awk $(call compile_carray,$@,$<) $(build_dir)/%.dep: $(src_dir)/%.c $(KCONFIG_AUTOHEADER)
@@ -559,7 +558,7 @@ $(platform_build_dir)/%.dep: $(platform_src_dir)/%.carray $(KCONFIG_AUTOHEADER) $(call compile_gen_dep,$@,.c,$< $(KCONFIG_AUTOHEADER)) $(call compile_gen_dep,$@,.o,$(@:.dep=.c)) -$(platform_build_dir)/%.carray.c: $(platform_src_dir)/%.carray $(src_dir)/scripts/carray.sh +$(platform_build_dir)/%.carray.c: $(platform_src_dir)/%.carray $(src_dir)/scripts/carray.awk $(call compile_carray,$@,$<) $(platform_build_dir)/%.dep: $(platform_src_dir)/%.c $(KCONFIG_AUTOHEADER)
@@ -602,7 +601,7 @@ $(platform_build_dir)/%.dep: $(src_dir)/%.carray $(KCONFIG_AUTOHEADER) $(call compile_gen_dep,$@,.c,$< $(KCONFIG_AUTOHEADER)) $(call compile_gen_dep,$@,.o,$(@:.dep=.c)) -$(platform_build_dir)/%.carray.c: $(src_dir)/%.carray $(src_dir)/scripts/carray.sh +$(platform_build_dir)/%.carray.c: $(src_dir)/%.carray $(src_dir)/scripts/carray.awk $(call compile_carray,$@,$<) $(platform_build_dir)/%.dep: $(src_dir)/%.c $(KCONFIG_AUTOHEADER)
scripts/carray.awk new file +121 -0
121 lines not on this page · raw message
scripts/carray.sh deleted +0 -84
84 lines not on this page · raw message
Signature · 1 line
2.37.2.352.g3c44437643
PATCH 1/1 scripts/carray: change to using single .awk script to generate .c
Quoted 11 lines · Ben Dooks
The shell script makes multiple call-outs to awk to get information from the configuration file. It would be easier to just write the whole thing in one .awk script and have the makefile altered to call that instead.
There should be no functional difference other than the script type and has been tested with PLATFORM=generic build. This should be both quicker and easier to understand.
Signed-off-by Ben Dooks <[email protected]>---
This seems to have made it to patchwork but not the list archives?
Quoted 269 lines
v2:
- updated with the new bits from Samuel Holland's changes
- minor tweaks to the awk script to fix the output spacings--- Makefile | 9 ++-- scripts/carray.awk | 121 +++++++++++++++++++++++++++++++++++++++++++++ scripts/carray.sh | 84 ------------------------------- 3 files changed, 125 insertions(+), 89 deletions(-)create mode 100755
scripts/carray.awk
delete mode 100755scripts/carray.shMakefile +4
-5@@ -501,8 +501,7 @@ compile_d2c = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ $(src_dir)/scripts/d2c.sh -i $(6) -a $(D2C_ALIGN_BYTES) -p $(D2C_NAME_PREFIX) -t $(D2C_PADDING_BYTES) > $(1) compile_carray = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " CARRAY $(subst $(build_dir)/,,$(1))"; \ - $(eval CARRAY_VAR_LIST := $(carray-$(subst .carray.c,,$(shell basename $(1)))-y)) \ - $(src_dir)/scripts/carray.sh -i $(2) -l "$(CARRAY_VAR_LIST)" > $(1) + $(src_dir)/scripts/carray.awk -v "SCRIPT_NAME=scripts/carray.awk" -v "CONFIG_FILE=$(shell basename $(2))" -- -l "$(CARRAY_VAR_LIST)" < $(2) > $(1) compile_gen_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " GEN-DEP $(subst $(build_dir)/,,$(1))"; \ echo "$(1:.dep=$(2)): $(3)" >> $(1)@@ -531,7 +530,7 @@ $(build_dir)/%.dep: $(src_dir)/%.carray $(KCONFIG_AUTOHEADER) $(call compile_gen_dep,$@,.c,$< $(KCONFIG_AUTOHEADER)) $(call compile_gen_dep,$@,.o,$(@:.dep=.c)) -$(build_dir)/%.carray.c: $(src_dir)/%.carray $(src_dir)/scripts/carray.sh +$(build_dir)/%.carray.c: $(src_dir)/%.carray $(src_dir)/scripts/carray.awk $(call compile_carray,$@,$<) $(build_dir)/%.dep: $(src_dir)/%.c $(KCONFIG_AUTOHEADER)@@ -559,7 +558,7 @@ $(platform_build_dir)/%.dep: $(platform_src_dir)/%.carray $(KCONFIG_AUTOHEADER) $(call compile_gen_dep,$@,.c,$< $(KCONFIG_AUTOHEADER)) $(call compile_gen_dep,$@,.o,$(@:.dep=.c)) -$(platform_build_dir)/%.carray.c: $(platform_src_dir)/%.carray $(src_dir)/scripts/carray.sh +$(platform_build_dir)/%.carray.c: $(platform_src_dir)/%.carray $(src_dir)/scripts/carray.awk $(call compile_carray,$@,$<) $(platform_build_dir)/%.dep: $(platform_src_dir)/%.c $(KCONFIG_AUTOHEADER)@@ -602,7 +601,7 @@ $(platform_build_dir)/%.dep: $(src_dir)/%.carray $(KCONFIG_AUTOHEADER) $(call compile_gen_dep,$@,.c,$< $(KCONFIG_AUTOHEADER)) $(call compile_gen_dep,$@,.o,$(@:.dep=.c)) -$(platform_build_dir)/%.carray.c: $(src_dir)/%.carray $(src_dir)/scripts/carray.sh +$(platform_build_dir)/%.carray.c: $(src_dir)/%.carray $(src_dir)/scripts/carray.awk $(call compile_carray,$@,$<) $(platform_build_dir)/%.dep: $(src_dir)/%.c $(KCONFIG_AUTOHEADER)scripts/carray.awk new file +121
-0@@ -0,0 +1,121 @@ +#!/usr/bin/awk -f + +function usage() +{ + echo "Usage:" + echo " $0 [options]" + echo "Options:" + echo " -h Display help or usage" + echo " -l <variable_list> List of variables in the array (Optional)" + exit 1; +} + +function get_fields(start, end) +{ + result = $start; + + for (nr = start+1; nr <= end; nr++) { + result = result " " $nr + } + return result; +} + +BEGIN { + VAR_LIST[0] = ""; delete VAR_LIST[0] + + for (ArgIndex = 1; ArgIndex < ARGC; ArgIndex++) { + Arg = ARGV[ArgIndex]; + + if (Arg !~ /^-./) { continue; } + ARGV[ArgIndex] = ""; + + if (Arg == "-h") { + usage(); + } else if (Arg == "-l") { + ArgIndex++; + split(ARGV[ArgIndex], Args," ") + for (A in Args) { + VAR_LIST[length(VAR_LIST)] = Args[A]; + } + ARGV[ArgIndex] = ""; + } else { + usage() > "/dev/stderr" + } + } +} + +# process items from the config file +xs +/^HEADER:/ { TYPE_HEADER = $2 } + +/^TYPE:/ { TYPE_NAME = get_fields(2, NF); } + +/^NAME:/ { ARRAY_NAME = $2} + +/^MEMBER-NAME:/ { MEMBER_NAME = $2 } + +/^MEMBER-TYPE:/ { MEMBER_TYPE = get_fields(2, NF); } + +# code to dump the generated .c file once config file is processed + +END { + # enable for debug + if (0 == 1) { + print "ARRAY_NAME " ARRAY_NAME + print "TYPE_HEADER " TYPE_HEADER + print "TYPE_NAME " TYPE_NAME + + print length(VAR_LIST) + for (v in VAR_LIST) { + print "VAR_LIST " v " = " VAR_LIST[v] + } + } + + if (length(ARRAY_NAME) == 0) { + print "Must specify NAME: in input config file" > "/dev/stderr" + usage() > "/dev/stderr" + } + + if (length(TYPE_NAME) == 0) { + print "Must specify TYPE: in input config file" > "/dev/stderr" + usage() > "/dev/stderr" + } + + if (length(TYPE_HEADER) == 0) { + print "Must specify HEADER: in input config file" > "/dev/stderr" + usage() > "/dev/stderr" + } + + if (length(MEMBER_NAME) > 0 && length(MEMBER_TYPE) == 0) { + print "Must specify MEMBER-TYPE: when using MEMBER-NAME:" < "/dev/stderr" + usage() > "/dev/stderr" + } + + printf "// Generated with %s from %s\n", SCRIPT_NAME, CONFIG_FILE + printf "// DO NOT EDIT THIS FILE DIRECTLY\n" + printf "\n" + printf("#include <%s>\n\n", TYPE_HEADER) + + for (v in VAR_LIST) { + printf("extern %s %s;\n", TYPE_NAME, VAR_LIST[v]) + } + print "" + + if (length(MEMBER_TYPE) > 0) { + TYPE_NAME = MEMBER_TYPE; + } + + if (length(MEMBER_NAME) > 0) { + VAR_SUFFIX = "." MEMBER_NAME; + } else { + VAR_SUFFIX = "" + } + + printf("%s *const %s[] = {\n", TYPE_NAME, ARRAY_NAME) + for (v in VAR_LIST) { + printf("\t&%s%s,\n", VAR_LIST[v], VAR_SUFFIX) + } + printf("\tNULL\n"); + + printf("};\n"); +}scripts/carray.sh deleted +0
-84@@ -1,84 +0,0 @@ -#!/usr/bin/env bash - -function usage() -{ - echo "Usage:" - echo " $0 [options]" - echo "Options:" - echo " -h Display help or usage" - echo " -i <input_config> Input config file" - echo " -l <variable_list> List of variables in the array (Optional)" - exit 1; -} - -# Command line options -CONFIG_FILE="" -VAR_LIST="" - -while getopts "hi:l:" o; do - case "${o}" in - h) - usage - ;; - i) - CONFIG_FILE=${OPTARG} - ;; - l) - VAR_LIST=${OPTARG} - ;; - *) - usage - ;; - esac -done -shift $((OPTIND-1)) - -if [ -z "${CONFIG_FILE}" ]; then - echo "Must specify input config file" - usage -fi - -if [ ! -f "${CONFIG_FILE}" ]; then - echo "The input config file should be a present" - usage -fi - -TYPE_HEADER=$(awk '{ if ($1 == "HEADER:") { printf $2; exit 0; } }' "${CONFIG_FILE}") -if [ -z "${TYPE_HEADER}" ]; then - echo "Must specify HEADER: in input config file" - usage -fi - -TYPE_NAME=$(awk '{ if ($1 == "TYPE:") { printf $2; for (i=3; i<=NF; i++) printf " %s", $i; exit 0; } }' "${CONFIG_FILE}") -if [ -z "${TYPE_NAME}" ]; then - echo "Must specify TYPE: in input config file" - usage -fi - -ARRAY_NAME=$(awk '{ if ($1 == "NAME:") { printf $2; exit 0; } }' "${CONFIG_FILE}") -if [ -z "${ARRAY_NAME}" ]; then - echo "Must specify NAME: in input config file" - usage -fi - -MEMBER_NAME=$(awk '{ if ($1 == "MEMBER-NAME:") { printf $2; exit 0; } }' "${CONFIG_FILE}") -MEMBER_TYPE=$(awk '{ if ($1 == "MEMBER-TYPE:") { printf $2; for (i=3; i<=NF; i++) printf " %s", $i; exit 0; } }' "${CONFIG_FILE}") -if [ -n "${MEMBER_NAME}" ] && [ -z "${MEMBER_TYPE}" ]; then - echo "Must specify MEMBER-TYPE: when using MEMBER-NAME:" - usage -fi - -printf "// Generated with $(basename $0) from $(basename ${CONFIG_FILE})\n" -printf "#include <%s>\n\n" "${TYPE_HEADER}" - -for VAR in ${VAR_LIST}; do - printf "extern %s %s;\n" "${TYPE_NAME}" "${VAR}" -done -printf "\n" - -printf "%s *const %s[] = {\n" "${MEMBER_TYPE:-${TYPE_NAME}}" "${ARRAY_NAME}" -for VAR in ${VAR_LIST}; do - printf "\t&%s,\n" "${VAR}${MEMBER_NAME:+.}${MEMBER_NAME}" -done - printf "\tNULL\n" -printf "};\n"
Signature · 4 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius https://www.codethink.co.uk/privacy.html
PATCH 1/1 scripts/carray: change to using single .awk script to generate .c
In reply to Ben DooksQuoted 10 lines · On Fri, Nov 29, 2024 at 3:39?PM Ben Dooks <[email protected]> wrote:
The shell script makes multiple call-outs to awk to get information from the configuration file. It would be easier to just write the whole thing in one .awk script and have the makefile altered to call that instead.
There should be no functional difference other than the script type and has been tested with PLATFORM=generic build. This should be both quicker and easier to understand.
Quoted 5 lines
Signed-off-by Ben Dooks <[email protected]>---
v2:
- updated with the new bits from Samuel Holland's changes
- minor tweaks to the awk script to fix the output spacing
The "./scripts/carray.awk -h" is not showing the help text.
Also, I tried compiling OpenSBI with this patch on Ubuntu 24.04 but it does not boot because the generated C arrays are empty.
Quoted 65 lines
--- Makefile | 9 ++-- scripts/carray.awk | 121 +++++++++++++++++++++++++++++++++++++++++++++ scripts/carray.sh | 84 ------------------------------- 3 files changed, 125 insertions(+), 89 deletions(-) create mode 100755 scripts/carray.awk delete mode 100755 scripts/carray.shMakefile +4
-5@@ -501,8 +501,7 @@ compile_d2c = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ $(src_dir)/scripts/d2c.sh -i $(6) -a $(D2C_ALIGN_BYTES) -p $(D2C_NAME_PREFIX) -t $(D2C_PADDING_BYTES) > $(1) compile_carray = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " CARRAY $(subst $(build_dir)/,,$(1))"; \ - $(eval CARRAY_VAR_LIST := $(carray-$(subst .carray.c,,$(shell basename $(1)))-y)) \ - $(src_dir)/scripts/carray.sh -i $(2) -l "$(CARRAY_VAR_LIST)" > $(1) + $(src_dir)/scripts/carray.awk -v "SCRIPT_NAME=scripts/carray.awk" -v "CONFIG_FILE=$(shell basename $(2))" -- -l "$(CARRAY_VAR_LIST)" < $(2) > $(1) compile_gen_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " GEN-DEP $(subst $(build_dir)/,,$(1))"; \ echo "$(1:.dep=$(2)): $(3)" >> $(1)@@ -531,7 +530,7 @@ $(build_dir)/%.dep: $(src_dir)/%.carray $(KCONFIG_AUTOHEADER) $(call compile_gen_dep,$@,.c,$< $(KCONFIG_AUTOHEADER)) $(call compile_gen_dep,$@,.o,$(@:.dep=.c)) -$(build_dir)/%.carray.c: $(src_dir)/%.carray $(src_dir)/scripts/carray.sh +$(build_dir)/%.carray.c: $(src_dir)/%.carray $(src_dir)/scripts/carray.awk $(call compile_carray,$@,$<) $(build_dir)/%.dep: $(src_dir)/%.c $(KCONFIG_AUTOHEADER)@@ -559,7 +558,7 @@ $(platform_build_dir)/%.dep: $(platform_src_dir)/%.carray $(KCONFIG_AUTOHEADER) $(call compile_gen_dep,$@,.c,$< $(KCONFIG_AUTOHEADER)) $(call compile_gen_dep,$@,.o,$(@:.dep=.c)) -$(platform_build_dir)/%.carray.c: $(platform_src_dir)/%.carray $(src_dir)/scripts/carray.sh +$(platform_build_dir)/%.carray.c: $(platform_src_dir)/%.carray $(src_dir)/scripts/carray.awk $(call compile_carray,$@,$<) $(platform_build_dir)/%.dep: $(platform_src_dir)/%.c $(KCONFIG_AUTOHEADER)@@ -602,7 +601,7 @@ $(platform_build_dir)/%.dep: $(src_dir)/%.carray $(KCONFIG_AUTOHEADER) $(call compile_gen_dep,$@,.c,$< $(KCONFIG_AUTOHEADER)) $(call compile_gen_dep,$@,.o,$(@:.dep=.c)) -$(platform_build_dir)/%.carray.c: $(src_dir)/%.carray $(src_dir)/scripts/carray.sh +$(platform_build_dir)/%.carray.c: $(src_dir)/%.carray $(src_dir)/scripts/carray.awk $(call compile_carray,$@,$<) $(platform_build_dir)/%.dep: $(src_dir)/%.c $(KCONFIG_AUTOHEADER)scripts/carray.awk new file +10
-0@@ -0,0 +1,121 @@ +#!/usr/bin/awk -f + +function usage() +{ + echo "Usage:" + echo " $0 [options]" + echo "Options:" + echo " -h Display help or usage" + echo " -l <variable_list> List of variables in the array (Optional)" + exit 1;
scripts/carray.awk line 20
Quoted 10 lines
scripts/carray.awk new file +10
-0+} + +function get_fields(start, end) +{ + result = $start; + + for (nr = start+1; nr <= end; nr++) { + result = result " " $nr + } + return result;
This script has a mix of spaces and tabs for indentation. Let's be consistent with the type of indentation.
Quoted 192 lines
scripts/carray.awk new file +101
-0+} + +BEGIN { + VAR_LIST[0] = ""; delete VAR_LIST[0] + + for (ArgIndex = 1; ArgIndex < ARGC; ArgIndex++) { + Arg = ARGV[ArgIndex]; + + if (Arg !~ /^-./) { continue; } + ARGV[ArgIndex] = ""; + + if (Arg == "-h") { + usage(); + } else if (Arg == "-l") { + ArgIndex++; + split(ARGV[ArgIndex], Args," ") + for (A in Args) { + VAR_LIST[length(VAR_LIST)] = Args[A]; + } + ARGV[ArgIndex] = ""; + } else { + usage() > "/dev/stderr" + } + } +} + +# process items from the config file +xs +/^HEADER:/ { TYPE_HEADER = $2 } + +/^TYPE:/ { TYPE_NAME = get_fields(2, NF); } + +/^NAME:/ { ARRAY_NAME = $2} + +/^MEMBER-NAME:/ { MEMBER_NAME = $2 } + +/^MEMBER-TYPE:/ { MEMBER_TYPE = get_fields(2, NF); } + +# code to dump the generated .c file once config file is processed + +END { + # enable for debug + if (0 == 1) { + print "ARRAY_NAME " ARRAY_NAME + print "TYPE_HEADER " TYPE_HEADER + print "TYPE_NAME " TYPE_NAME + + print length(VAR_LIST) + for (v in VAR_LIST) { + print "VAR_LIST " v " = " VAR_LIST[v] + } + } + + if (length(ARRAY_NAME) == 0) { + print "Must specify NAME: in input config file" > "/dev/stderr" + usage() > "/dev/stderr" + } + + if (length(TYPE_NAME) == 0) { + print "Must specify TYPE: in input config file" > "/dev/stderr" + usage() > "/dev/stderr" + } + + if (length(TYPE_HEADER) == 0) { + print "Must specify HEADER: in input config file" > "/dev/stderr" + usage() > "/dev/stderr" + } + + if (length(MEMBER_NAME) > 0 && length(MEMBER_TYPE) == 0) { + print "Must specify MEMBER-TYPE: when using MEMBER-NAME:" < "/dev/stderr" + usage() > "/dev/stderr" + } + + printf "// Generated with %s from %s\n", SCRIPT_NAME, CONFIG_FILE + printf "// DO NOT EDIT THIS FILE DIRECTLY\n" + printf "\n" + printf("#include <%s>\n\n", TYPE_HEADER) + + for (v in VAR_LIST) { + printf("extern %s %s;\n", TYPE_NAME, VAR_LIST[v]) + } + print "" + + if (length(MEMBER_TYPE) > 0) { + TYPE_NAME = MEMBER_TYPE; + } + + if (length(MEMBER_NAME) > 0) { + VAR_SUFFIX = "." MEMBER_NAME; + } else { + VAR_SUFFIX = "" + } + + printf("%s *const %s[] = {\n", TYPE_NAME, ARRAY_NAME) + for (v in VAR_LIST) { + printf("\t&%s%s,\n", VAR_LIST[v], VAR_SUFFIX) + } + printf("\tNULL\n"); + + printf("};\n"); +}scripts/carray.sh deleted +0
-85@@ -1,84 +0,0 @@ -#!/usr/bin/env bash - -function usage() -{ - echo "Usage:" - echo " $0 [options]" - echo "Options:" - echo " -h Display help or usage" - echo " -i <input_config> Input config file" - echo " -l <variable_list> List of variables in the array (Optional)" - exit 1; -} - -# Command line options -CONFIG_FILE="" -VAR_LIST="" - -while getopts "hi:l:" o; do - case "${o}" in - h) - usage - ;; - i) - CONFIG_FILE=${OPTARG} - ;; - l) - VAR_LIST=${OPTARG} - ;; - *) - usage - ;; - esac -done -shift $((OPTIND-1)) - -if [ -z "${CONFIG_FILE}" ]; then - echo "Must specify input config file" - usage -fi - -if [ ! -f "${CONFIG_FILE}" ]; then - echo "The input config file should be a present" - usage -fi - -TYPE_HEADER=$(awk '{ if ($1 == "HEADER:") { printf $2; exit 0; } }' "${CONFIG_FILE}") -if [ -z "${TYPE_HEADER}" ]; then - echo "Must specify HEADER: in input config file" - usage -fi - -TYPE_NAME=$(awk '{ if ($1 == "TYPE:") { printf $2; for (i=3; i<=NF; i++) printf " %s", $i; exit 0; } }' "${CONFIG_FILE}") -if [ -z "${TYPE_NAME}" ]; then - echo "Must specify TYPE: in input config file" - usage -fi - -ARRAY_NAME=$(awk '{ if ($1 == "NAME:") { printf $2; exit 0; } }' "${CONFIG_FILE}") -if [ -z "${ARRAY_NAME}" ]; then - echo "Must specify NAME: in input config file" - usage -fi - -MEMBER_NAME=$(awk '{ if ($1 == "MEMBER-NAME:") { printf $2; exit 0; } }' "${CONFIG_FILE}") -MEMBER_TYPE=$(awk '{ if ($1 == "MEMBER-TYPE:") { printf $2; for (i=3; i<=NF; i++) printf " %s", $i; exit 0; } }' "${CONFIG_FILE}") -if [ -n "${MEMBER_NAME}" ] && [ -z "${MEMBER_TYPE}" ]; then - echo "Must specify MEMBER-TYPE: when using MEMBER-NAME:" - usage -fi - -printf "// Generated with $(basename $0) from $(basename ${CONFIG_FILE})\n" -printf "#include <%s>\n\n" "${TYPE_HEADER}" - -for VAR in ${VAR_LIST}; do - printf "extern %s %s;\n" "${TYPE_NAME}" "${VAR}" -done -printf "\n" - -printf "%s *const %s[] = {\n" "${MEMBER_TYPE:-${TYPE_NAME}}" "${ARRAY_NAME}" -for VAR in ${VAR_LIST}; do - printf "\t&%s,\n" "${VAR}${MEMBER_NAME:+.}${MEMBER_NAME}" -done - printf "\tNULL\n" -printf "};\n" --
Quoted 2 lines
2.37.2.352.g3c44437643
Regards,
Anup
PATCH 1/1 scripts/carray: change to using single .awk script to generate .c
Quoted 17 lines · Anup Patel
Quoted 10 lines · On Fri, Nov 29, 2024 at 3:39?PM Ben Dooks <[email protected]> wrote:
The shell script makes multiple call-outs to awk to get information from the configuration file. It would be easier to just write the whole thing in one .awk script and have the makefile altered to call that instead.
There should be no functional difference other than the script type and has been tested with PLATFORM=generic build. This should be both quicker and easier to understand.
Quoted 5 lines
Signed-off-by Ben Dooks <[email protected]>---
v2:
- updated with the new bits from Samuel Holland's changes
- minor tweaks to the awk script to fix the output spacing
Quoted 4 lines
The "
./scripts/carray.awk-h" is not showing the help text.Also, I tried compiling OpenSBI with this patch on Ubuntu 24.04 but it does not boot because the generated C arrays are empty.
Hmm, it might be worth adding an option to warn if the lists are zero length?
I seem to have forgotten to add -h
I'll try running it under standard awk, I think my debian install maybe using gawk by default.
Does anyone know if awk has some way of deal with options? I couldn't find anything that shows anything like getopt() library.
Thanks.
Signature · 4 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius https://www.codethink.co.uk/privacy.html
PATCH 1/1 scripts/carray: change to using single .awk script to generate .c
Quoted 29 lines · Ben Dooks
Quoted 18 lines · Anup Patel
Quoted 10 lines · On Fri, Nov 29, 2024 at 3:39?PM Ben Dooks <[email protected]> wrote:
The shell script makes multiple call-outs to awk to get information from the configuration file. It would be easier to just write the whole thing in one .awk script and have the makefile altered to call that instead.
There should be no functional difference other than the script type and has been tested with PLATFORM=generic build. This should be both quicker and easier to understand.
Quoted 5 lines
Signed-off-by Ben Dooks <[email protected]>---
v2:
?? - updated with the new bits from Samuel Holland's changes ?? - minor tweaks to the awk script to fix the output spacingQuoted 4 lines
The "
./scripts/carray.awk-h" is not showing the help text.Also, I tried compiling OpenSBI with this patch on Ubuntu 24.04 but it does not boot because the generated C arrays are empty.
Hmm, it might be worth adding an option to warn if the lists are zero length?
I seem to have forgotten to add -h
Quoted 8 lines
I'll try running it under standard awk, I think my debian install maybe using gawk by default.
Does anyone know if awk has some way of deal with options? I couldn't find anything that shows anything like
getopt()library.Thanks.
I found an issue with -h is that (g)awk takes this as an argument for itself.
I am considering moving to wrapping the awk in bash and having bash sort the arguments out and then invoking the awk directly from the bash script. I'll look at this for v3.
Signature · 4 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius https://www.codethink.co.uk/privacy.html