Skip to contentSkip to conversation

Add support to mkconfig for setting simple #defines in config.h

PATCH New Kumar Gala 4 participants 10 messages Aug 7, 2009 – Aug 13, 2009

lore
Share & tools
lore

Kumar Gala

author
#0 lore raw

PATCH 1/1 Add support to mkconfig for setting simple #defines in config.h

To simplify the top level makefile it useful to be able to set some #defines in config.h to express different configurations.

Added a -D option that allows us to replace:

MPC8536DS_36BIT_config \
MPC8536DS_config: unconfig

        @mkdir -p $(obj)include
        @echo "#define CONFIG_$(@:_config=) 1"  >$(obj)include/config.h
        @$(MKCONFIG) -a MPC8536DS ppc mpc85xx mpc8536ds freescale

with:

MPC8536DS_36BIT_config \
MPC8536DS_config: unconfig

	@$(MKCONFIG) -D $(@:_config=)=1 MPC8536DS ppc mpc85xx mpc8536ds freescale
---
 mkconfig |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
mkconfig +4 -0
index b0bbbd1..8d778e5 100755
@@ -10,12 +10,14 @@
 
 APPEND=no	# Default: Create new config file
 BOARD_NAME=""	# Name to print in make output
+DEFINES=""
 
 while [ $# -gt 0 ] ; do
 	case "$1" in
 	--) shift ; break ;;
 	-a) shift ; APPEND=yes ;;
 	-n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;
+	-D) shift ; DEFINES="#define ${1/=/\t}\n"${DEFINES} ; shift ;;
 	*)  break ;;
 	esac
 done
@@ -84,5 +86,7 @@ fi
 echo "/* Automatically generated - do not edit */" >>config.h
 echo "#include <configs/$1.h>" >>config.h
 echo "#include <asm/config.h>" >>config.h
+echo -e ${DEFINES} >> config.h
+
 
 exit 0
Signature · 1 line
1.6.0.6
#1 lore raw

PATCH 1/1 Add support to mkconfig for setting simple #defines in config.h

mkconfig line 20

Quoted 6 lines · Kumar Gala

while [ $# -gt 0 ] ; do

mkconfig +1 -0
 	case "$1" in
 	--) shift ; break ;;
 	-a) shift ; APPEND=yes ;;
 	-n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;
+	-D) shift ; DEFINES="#define ${1/=/\t}\n"${DEFINES} ; shift ;;

How about something like:

-D) shift ; DEFINES="${1//_/ } ${DEFINES}"; shift ;;

...

for i in ${DEFINES}; do

	echo "#define CONFIG_${i}" >> config.h

done

?

This would allow multiple underscore-separated booleans in the target name.

If we really need values on the options, we could change CONFIG_${i} to CONFIG_${i/=/\t} similar to what you do above, and embed the "=value" in the target name (MPC83536DS_NAND_FOO=2_36BIT_BAR=blah ends up defining NAND, FOO as 2, 36BIT, and BAR as blah). I think simple bools (MPC8536DS_NAND_36BIT) will be enough until we get kconfig, though.

-Scott

#2 lore raw

PATCH 1/1 Add support to mkconfig for setting simple #defines in config.h

Quoted 11 lines · On Friday 07 August 2009 15:22:15 Scott Wood wrote:

mkconfig line 20

Quoted 6 lines · Kumar Gala

while [ $# -gt 0 ] ; do

mkconfig +1 -0
 	case "$1" in
 	--) shift ; break ;;
 	-a) shift ; APPEND=yes ;;
 	-n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;
+	-D) shift ; DEFINES="#define ${1/=/\t}\n"${DEFINES} ; shift ;;

How about something like:

-D) shift ; DEFINES="${1//_/ } ${DEFINES}"; shift ;;

mkconfig's interpreter is /bin/sh, so if you want to use the string replace bashism, you'll have to change it to /bin/bash. or use the POSIX:
"#define ${1%%=*}\t${1#*=}\n${DEFINES}"
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090813/e5fb49f9/attachment.pgp

#3 lore raw

PATCH 1/1 Add support to mkconfig for setting simple #defines in config.h

Quoted 10 lines · Mike Frysinger
Quoted 9 lines · On Friday 07 August 2009 15:22:15 Scott Wood wrote:

mkconfig line 20

Quoted 6 lines · Kumar Gala

while [ $# -gt 0 ] ; do

mkconfig +1 -0
 	case "$1" in
 	--) shift ; break ;;
 	-a) shift ; APPEND=yes ;;
 	-n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;
+	-D) shift ; DEFINES="#define ${1/=/\t}\n"${DEFINES} ; shift ;;

How about something like:

Quoted 5 lines
Quoted 1 line

-D) shift ; DEFINES="${1//_/ } ${DEFINES}"; shift ;;

mkconfig's interpreter is /bin/sh, so if you want to use the string replace bashism, you'll have to change it to /bin/bash. or use the POSIX:
"#define ${1%%=*}\t${1#*=}\n${DEFINES}"

Do you have a non-bash version of my alternative (which handles multiple symbols rather than one symbol/value pair per -D)? Or do we need to invoke sed to be portable?

Or can we just use bash? :-)

-Scott

#4 lore raw

PATCH 1/1 Add support to mkconfig for setting simple #defines in config.h

Quoted 12 lines · On Thursday 13 August 2009 11:28:09 Scott Wood wrote:
Quoted 11 lines · Mike Frysinger
Quoted 10 lines · On Friday 07 August 2009 15:22:15 Scott Wood wrote:

mkconfig line 20

Quoted 6 lines · Kumar Gala

while [ $# -gt 0 ] ; do

mkconfig +1 -0
 	case "$1" in
 	--) shift ; break ;;
 	-a) shift ; APPEND=yes ;;
 	-n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;
+	-D) shift ; DEFINES="#define ${1/=/\t}\n"${DEFINES} ; shift ;;

How about something like:

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

-D) shift ; DEFINES="${1//_/ } ${DEFINES}"; shift ;;

mkconfig's interpreter is /bin/sh, so if you want to use the string replace bashism, you'll have to change it to /bin/bash. or use the
POSIX: "#define ${1%%=*}\t${1#*=}\n${DEFINES}"

Do you have a non-bash version of my alternative (which handles multiple symbols rather than one symbol/value pair per -D)?

i dont know what you mean by one symbol/value pair per -D. i assume that the -D option here has the exact same behavior as that of gcc. do you have an example invocation of mkconfig to show what you mean ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090813/d961574c/attachment.pgp

#5 lore raw

PATCH 1/1 Add support to mkconfig for setting simple #defines in config.h

Quoted 13 lines · Mike Frysinger
Quoted 12 lines · On Thursday 13 August 2009 11:28:09 Scott Wood wrote:
Quoted 11 lines · Mike Frysinger
Quoted 10 lines · On Friday 07 August 2009 15:22:15 Scott Wood wrote:

mkconfig line 20

Quoted 6 lines · Kumar Gala

while [ $# -gt 0 ] ; do

mkconfig +1 -0
 	case "$1" in
 	--) shift ; break ;;
 	-a) shift ; APPEND=yes ;;
 	-n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;
+	-D) shift ; DEFINES="#define ${1/=/\t}\n"${DEFINES} ; shift ;;

How about something like:

-D) shift ; DEFINES="${1//_/ } ${DEFINES}"; shift ;;

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

mkconfig's interpreter is /bin/sh, so if you want to use the string replace bashism, you'll have to change it to /bin/bash. or use the
POSIX: "#define ${1%%=*}\t${1#*=}\n${DEFINES}"

Do you have a non-bash version of my alternative (which handles multiple symbols rather than one symbol/value pair per -D)?

i dont know what you mean by one symbol/value pair per -D. i assume that the -D option here has the exact same behavior as that of gcc.

That's what Kumar's patch has it do, but I'm not sure that it's the most useful thing to expose to the makefile. Maybe we should use a different option letter (-d?) and implement the GCC-like symbol/value semantics later if we end up needing it.

Hopefully kconfig is merged before then. :-)

Quoted 1 line

do you have an example invocation of mkconfig to show what you mean ?

Consider a target such as BOARDNAME_66MHz_NANDBOOT_PCISLAVE.

It could then invoke "$(MKCONFIG) -D $@ -a configname arch cpu board". mkconfig would break up the -D argument into:

#define CONFIG_BOARDNAME
#define CONFIG_66MHz
#define CONFIG_NANDBOOT
#define CONFIG_PCISLAVE

-Scott

#6 lore raw

PATCH 1/1 Add support to mkconfig for setting simple #defines in config.h

Quoted 23 lines · On Thursday 13 August 2009 14:38:45 Scott Wood wrote:
Quoted 22 lines · Mike Frysinger
Quoted 20 lines · On Thursday 13 August 2009 11:28:09 Scott Wood wrote:
Quoted 11 lines · Mike Frysinger
Quoted 10 lines · On Friday 07 August 2009 15:22:15 Scott Wood wrote:

mkconfig line 20

Quoted 6 lines · Kumar Gala

while [ $# -gt 0 ] ; do

mkconfig +1 -0
 	case "$1" in
 	--) shift ; break ;;
 	-a) shift ; APPEND=yes ;;
 	-n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;
+	-D) shift ; DEFINES="#define ${1/=/\t}\n"${DEFINES} ; shift ;;

How about something like:

Quoted 5 lines
Quoted 1 line

-D) shift ; DEFINES="${1//_/ } ${DEFINES}"; shift ;;

mkconfig's interpreter is /bin/sh, so if you want to use the string replace bashism, you'll have to change it to /bin/bash. or use the
POSIX: "#define ${1%%=*}\t${1#*=}\n${DEFINES}"

Do you have a non-bash version of my alternative (which handles multiple symbols rather than one symbol/value pair per -D)?

Quoted 7 lines
Quoted 2 lines

i dont know what you mean by one symbol/value pair per -D. i assume that the -D option here has the exact same behavior as that of gcc.

That's what Kumar's patch has it do, but I'm not sure that it's the most useful thing to expose to the makefile. Maybe we should use a different option letter (-d?) and implement the GCC-like symbol/value semantics later if we end up needing it.

if the proposed mkconfig -D isnt like gcc's -D, then a new letter should be picked i think to avoid confusion

Quoted 11 lines
Quoted 1 line

do you have an example invocation of mkconfig to show what you mean ?

Consider a target such as BOARDNAME_66MHz_NANDBOOT_PCISLAVE.

It could then invoke "$(MKCONFIG) -D $@ -a configname arch cpu board". mkconfig would break up the -D argument into:

#define CONFIG_BOARDNAME
#define CONFIG_66MHz
#define CONFIG_NANDBOOT
#define CONFIG_PCISLAVE

then yes, a sed would have to be used. maybe something like:
DEFINES="echo "_$*" | sed 's:_:\n#define CONFIG_:g'${DEFINES}" ; shift ;; -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090813/61280f37/attachment.pgp

#7 lore raw

PATCH 1/1 Add support to mkconfig for setting simple #defines in config.h

Dear Mike Frysinger,

Quoted 6 lines · In message <[email protected]> you wrote:
Quoted 6 lines

Consider a target such as BOARDNAME_66MHz_NANDBOOT_PCISLAVE.

It could then invoke "$(MKCONFIG) -D $@ -a configname arch cpu board". mkconfig would break up the -D argument into:

Quoted 7 lines
Quoted 4 lines

#define CONFIG_BOARDNAME
#define CONFIG_66MHz
#define CONFIG_NANDBOOT
#define CONFIG_PCISLAVE

then yes, a sed would have to be used. maybe something like:
DEFINES="echo "_$*" | sed 's:_:\n#define CONFIG_:g'${DEFINES}" ; shift > ;;

Nope, this doesn't work.

We have many names with more than one underscore in it (all the CONFIG_CMD_* and CONFIG_SYS_* and CONFIG_BOOTP_* and ...).

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Chapter 1 -- The story so  far:
In the beginning the Universe was created. This has  made  a  lot  of
people very angry and been widely regarded as a bad move.
#8 lore raw

PATCH 1/1 Add support to mkconfig for setting simple #defines in config.h

Quoted 11 lines · On Thursday 13 August 2009 16:15:11 Wolfgang Denk wrote:
Quoted 10 lines · Mike Frysinger
Quoted 9 lines

Consider a target such as BOARDNAME_66MHz_NANDBOOT_PCISLAVE.

It could then invoke "$(MKCONFIG) -D $@ -a configname arch cpu board". mkconfig would break up the -D argument into:

#define CONFIG_BOARDNAME
#define CONFIG_66MHz
#define CONFIG_NANDBOOT
#define CONFIG_PCISLAVE

Quoted 8 lines
Quoted 3 lines

then yes, a sed would have to be used. maybe something like:
DEFINES="echo "_$*" | sed 's:_:\n#define CONFIG_:g'${DEFINES}" ; shift

Quoted 1 line

;;

Nope, this doesn't work.

We have many names with more than one underscore in it (all the CONFIG_CMD_* and CONFIG_SYS_* and CONFIG_BOOTP_* and ...).

i'm only giving POSIX compliant versions of proposed code. the issue you raised i dont care about -- that's for the OP to handle.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090813/94a9ea16/attachment.pgp

#9 lore raw

PATCH 1/1 Add support to mkconfig for setting simple #defines in config.h

In reply to Wolfgang Denk
Quoted 4 lines · Wolfgang Denk

Nope, this doesn't work.

We have many names with more than one underscore in it (all the CONFIG_CMD_* and CONFIG_SYS_* and CONFIG_BOOTP_* and ...).

So? Let the board config file translate from the target names into the real names. We can put the former in a CONFIG_OPT_* namespace if you prefer. There certainly should never be any CONFIG_SYS_ being defined by this mechanism -- it's explicitly for things the user is specifying.

This is an interim measure until we get kconfig (not a replacement for it) and is made necessary by your refusal to accept the status quo of target handling until then. Kumar's version does not handle targets with more than one orthogonal option.

-Scott