[rfc] accumulating ifdef def else def endif in usage.h [was: Re: crond usage documentation oddity (busybox v1.1.0-pre1)]

Bernhard Fischer rep.nop at aon.at
Sat Oct 15 10:40:08 PDT 2005


On Sat, Oct 15, 2005 at 05:39:12PM +0200, Cristian Ionescu-Idbohrn wrote:
>Idea for a patch attached.

[quoting a conversation from a few days ago]
me> vodz, i do not like what we currently have to do in usage.h for all the
me>      FEATURE defines. What do you think about creating a
me>      usage_feature.h which does all the #if ENABLE_FEATURE_*
me>      #define USAGE_*(a) (a)  #else #define USAGE_*(a)  #endif stuff we
me>      keep adding to usage.h?
me> vodz, that one would simply be generated depending on the .config
vodz> cow`: I more like create usage.c. ;-)
vodz> cow`: but be not urgent
me> vodz, i don't care if it is in  a header or in .c. It's not urgent,
me>       but would be nice to have in the mid-term, imho.
vodz> cow`: I like (may be my idea) #if ENABLE_FEATURE_*  #define
vodz>     USAGE_*(a) (a) #else #define USAGE_*(a) #endif :-)

I'm attaching an untested quick patchlet which does this. What do other
people think about this approach (except that someone will dislike it
using awk and do it differently, which is fine with me)?


>
>I noticed there are a lot of various DEBUG macros around.
>'find -type f -name "*.[ch]" | xargs egrep DEBUG' may give you an idea.
>Wouldn't a uniform variant provide a more maintenance friendly code?
>
>
>Cheers,
>Cristian
>--- include/usage.h.orig	2005-10-15 09:20:27.000000000 +0200
>+++ include/usage.h	2005-10-15 17:20:50.000000000 +0200
>@@ -262,11 +262,17 @@
> 	"\tu\t\tunconditional overwrite\n" \
> 	"\tF\t\tinput from file"
> 
>+#ifdef FEATURE_DEBUG_OPT
>+#define USAGE_CROND_DEBUG(a) a
>+#else
>+#define USAGE_CROND_DEBUG(a)
>+#endif
>+
> #define crond_trivial_usage \
>-	"-d[#] -c <crondir> -f -b"
>+	USAGE_CROND_DEBUG("-d [#] ") \
>+	"-l [#] -S -L logfile -f -b -c dir"
> #define crond_full_usage \
>-	"\t-d [#] -l [#] -S -L logfile -f -b -c dir\n" \
>-	"\t-d num\tdebug level\n" \
>+	USAGE_CROND_DEBUG("\t-d num\tdebug level\n") \
> 	"\t-l num\tlog level (8 - default)\n" \
> 	"\t-S\tlog to syslogd (default)\n" \
> 	"\t-L file\tlog to file\n" \

>_______________________________________________
>busybox mailing list
>busybox at busybox.net
>http://busybox.net/cgi-bin/mailman/listinfo/busybox
-------------- next part --------------
Index: Makefile
===================================================================
--- Makefile	(revision 11874)
+++ Makefile	(working copy)
@@ -295,7 +295,7 @@
 scripts/bb_mkdep: $(top_srcdir)/scripts/bb_mkdep.c
 	$(HOSTCC) $(HOSTCFLAGS) -o $@ $<
 
-DEP_INCLUDES := include/config.h include/bb_config.h
+DEP_INCLUDES := include/config.h include/bb_config.h include/_usage.h
 
 ifeq ($(strip $(CONFIG_BBCONFIG)),y)
 DEP_INCLUDES += include/bbconfigopts.h
@@ -325,13 +325,16 @@
 		< $< >> $@
 	@echo "#endif" >> $@
 
+include/_usage.h: .config
+	awk '/CONFIG/{gsub("#[[:space:]]*|=y|.*CONFIG_","");if(!/=/){print("#if ENABLE_"$$1"\n#define USAGE_"$$1"(a) a\n#else\n#define USAGE_"$$1"(a)\n#endif");}}' $(<) > $(@)
+
 clean:
 	- $(MAKE) -C scripts/config $@
 	- rm -f docs/busybox.dvi docs/busybox.ps \
 	    docs/busybox.pod docs/busybox.net/busybox.html \
 	    docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
 	    docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
-	    docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
+	    docs/busybox.net/BusyBox.html busybox.links include/_usage.h \
 	    .config.old busybox
 	- rm -rf _install testsuite/links
 	- find . -name .\*.flags -exec rm -f {} \;
Index: include/usage.h
===================================================================
--- include/usage.h	(revision 11874)
+++ include/usage.h	(working copy)
@@ -1,5 +1,6 @@
 #ifndef __BB_USAGE_H__
 #define __BB_USAGE_H__
+#include "_usage.h"
 
 #define addgroup_trivial_usage \
 	"[-g GID] group_name [user_name]"


More information about the busybox mailing list