[RFC][patch] standalone applets

Bernhard Fischer rep.nop at aon.at
Thu Feb 23 14:21:16 UTC 2006


On Wed, Feb 15, 2006 at 03:17:14PM -0500, Rob Landley wrote:
>On Wednesday 15 February 2006 9:45 am, Bernhard Fischer wrote:
>> Hi,
>>
>> The attached patch

>> - adds a (very) rough proposal for building standalone applets.
>>   See "Build options" Standalone applets.
>>   I changed coreutils/true and editors/* so you can try these as
>>   standalone.

>Overall, I need to think about whether or not I like the approach for make 
>standalone.
>
>Do you think I could I get the cleanup part and the make standalone part as 
>two separate patches?  It looks like half the lines this patch touches are 
>things like the removal of .o from names, which is separate (and nice, and 
>1.1.1 material).

The broken out patch for standalone is attached.
Just turn on building libbusybox and
make coreutils/true
or
make $(pwd)/editors/sed

As mentioned above, it is very rough and i think we'd be better off to
create an applets/standalone.c and use this instead of echoing the
needed glue to cc directly like this patchlet does (see the file foo.c
created for your convenience).

One can see that the needed infrastructure for building the standalone
stuff is only a very, very few lines (that's why i initially forgot to
put it into a separate patch. I was just touching the makefiles, so
thought i'd do it in one go. Yea, i'll try to avoid that).

This patch does not add the KConfig changes to make the applets
selectable as standalone via menuconfig.

PS: Attention:
issuing a "make standalone" will destroy your e2fsbb.h. I already
mentioned a few times that the e2fsprogs are integrated extremely badly
in busybox. *shrug*
-------------- next part --------------
diff -X excl -ru busybox/Makefile busybox.standalone/Makefile
--- busybox/Makefile	2006-02-23 12:20:03.000000000 +0100
+++ busybox.standalone/Makefile	2006-02-23 14:41:26.000000000 +0100
@@ -259,7 +259,8 @@
 endif
 $(if $($(1)_OBJ$(os)),$($(1)_OBJ$(os)): $(top_builddir)/$(2)/%$(os): $(top_srcdir)/$(2)/%.c)
 $(if $($(1)_OBJ),$($(1)_OBJ): $(top_builddir)/$(2)/%.o: $(top_srcdir)/$(2)/%.c)
-$(if $($(1)_BIN),$($(1)_BIN): $(top_builddir)/$(2)/%: $(top_srcdir)/$(2)/%.c)
+# standalone binary:
+$(if $(patsubst $(top_builddir)/%.o,%,$($(1)_OBJ)),$(patsubst $(top_builddir)/%.o,%,$($(1)_OBJ)): $(2)/%: $(top_srcdir)/$(2)/%.c)
 
 lib-obj-y+=$($(1)_OBJ) $($(1)_OBJ.o) $($(1)_OBJ.os)
 lib-mobj-y+=$($(1)_MOBJ.o) $($(1)_MOBJ.os)
@@ -269,6 +270,10 @@
 # The actual directory patterns for .o*
 $(foreach d,$(DIRS),$(eval $(call dir_pattern.o,$(subst /,_,$(d)),$(d))))
 
+bin-m+=$(patsubst $(top_srcdir)/%.c,%,$(APPLET_SRC-a))
+# make coreutils/true and $(pwd)/coreutils/true work:
+$(foreach b,$(bin-m),$(eval $(top_builddir)/$(b): $(b)))
+
 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
 # Finally pull in the dependencies (headers and other includes) of the
 # individual object files
@@ -277,7 +282,7 @@
 
 # Everything is set.
 
-all: busybox busybox.links doc ;
+all: busybox busybox.links standalone doc ;
 
 # Two modes of operation: legacy and IMA
 # Legacy mode builds each object through an individual invocation of CC
@@ -324,10 +329,11 @@
 
 endif # CONFIG_BUILD_LIBBUSYBOX
 
+BUSYBOX_SRC   := $(APPLETS_SRC)
 ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
 ifneq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
 # --combine but not linking against libbusybox, so compile lib*.c
-BUSYBOX_SRC   := $(LIBRARY_SRC)
+BUSYBOX_SRC   += $(LIBRARY_SRC)
 BUSYBOX_DEFINE:= $(LIBRARY_DEFINE)
 endif # !CONFIG_FEATURE_SHARED_BUSYBOX
 $(LIBBUSYBOX_SONAME): $(LIBRARY_SRC)
@@ -406,6 +412,47 @@
 		-f $(top_srcdir)/Makefile STRIPCMD=/bin/true
 	$(NM) --size-sort busybox
 
+# Standalone applets
+standalone: $(bin-m) ;
+
+BIN_LDFLAGS= -L$(top_builddir) -lbusybox $(LIBRARIES) -DSTANDALONE \
+ -D__usage_messages='$(shell echo "$(@F)_full_usage" | $(CPP) -include $(top_srcdir)/include/usage.h - | tail -n 1|sed "s/'/''/g")' \
+ -D__bb_msg_full_version='"BusyBox v$(VERSION) ($(BUILDTIME))"'
+
+OPTIONAL_HELP_MESSAGE:= \
+void bb_show_usage (void) {\n\
+  const char *format_string;\n\
+  const char *usage_string = usage_messages;\n\
+  format_string = \"%s\\\n\\\nUsage: %s %s\\\n\\\n\";\n\
+  if (*usage_string == '\\\b')\n\
+    format_string = \"%s\\\n\\\no help available.\\\n\\\n\";\n\
+  fprintf (stderr, format_string, bb_msg_full_version, bb_applet_name,\
+  usage_string);\n\
+  exit(bb_default_error_retval);\n\
+}\n
+
+OPTIONAL_HELP_STUFF:= \
+if (argv[1] && !strcmp(argv[1],\"--help\"))\n\
+bb_show_usage();\n
+
+$(bin-m): | $(LIBBUSYBOX_SONAME)
+	$(disp_bin)
+	$(Q)echo -e "\
+	#include <stdio.h>\n\
+	#include <stdlib.h>\n\
+	#include <string.h>\n\
+	extern int $(@F)_main(int,char*[]);\n\
+	char*bb_applet_name=\"$(@F)\";\n\
+	int bb_default_error_retval=1;\n\
+	const char*usage_messages=__usage_messages;\n\
+	const char*bb_msg_full_version=__bb_msg_full_version;\n\
+	$(OPTIONAL_HELP_MESSAGE)\
+	int main(int argc, char*argv[]) {\n\
+	$(OPTIONAL_HELP_STUFF)\
+	return $(@F)_main(argc,argv);}" \
+	| tee foo.c | $(cmd_bin) 
+	$(do_strip)
+
 # Documentation Targets
 doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html ;
 
diff -X excl -ru busybox/Rules.mak busybox.standalone/Rules.mak
--- busybox/Rules.mak	2006-02-23 11:28:37.000000000 +0100
+++ busybox.standalone/Rules.mak	2006-02-23 14:19:05.000000000 +0100
@@ -367,6 +367,11 @@
 cmd_link           = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -I$(srcdir) $(LDFLAGS)
 cmd_link.h         = $(HOSTCC) $(HOSTCFLAGS) $(HOST_LDFLAGS) $^ -o $@
 cmd_ar             = $(AR) $(ARFLAGS) $@ $^
+cmd_bin            = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(PROG_CFLAGS) \
+ $(BIN_LDFLAGS) -I$(top_srcdir)/include -o $@ $^ \
+ $(foreach f,$^,$(CFLAGS-$(notdir $(patsubst %/$,%,$(dir $(f))))-$(notdir $(f)))) \
+ $(CFLAGS-$(notdir $(@D))-$(notdir $(@F))) \
+ $(CFLAGS-$(notdir $(@D))) -x c -
 compile.c          = $(disp_compile.c) $(cmd_compile.c)
 compile.m          = $(disp_compile.c) $(cmd_compile.m)
 compile.h          = $(disp_compile.h) $(cmd_compile.h)
@@ -374,6 +379,7 @@
 do_link            = $(disp_link)      $(cmd_link)
 do_link.h          = $(disp_link.h)    $(cmd_link.h)
 do_ar              = $(disp_ar)        $(cmd_ar)
+do_bin             = $(disp_bin)       $(cmd_bin)
 
 ifdef rules-mak-rules
 .SUFFIXES: .c .S .o .os .om .osm .oS .so .a .s .i .E
diff -X excl -ru busybox/applets/Makefile.in busybox.standalone/applets/Makefile.in
--- busybox/applets/Makefile.in	2006-02-23 10:09:30.000000000 +0100
+++ busybox.standalone/applets/Makefile.in	2006-02-23 13:57:36.000000000 +0100
@@ -9,8 +9,5 @@
 
 APPLETS_SRC:= $(patsubst %,$(srcdir)/%,applets.c busybox.c version.c)
 
-APPLET_SRC-y+=$(APPLETS_SRC)
-APPLET_SRC-a+=$(APPLETS_SRC)
-
 applets_OBJ:=$(patsubst $(srcdir)/%.c,$(objdir)/%.o,$(APPLETS_SRC))
 



More information about the busybox mailing list