Skip to contentSkip to conversation

Add ability to force a static BB build

Buildroot Michael S. Zick 1 participant 2 messages Nov 19, 2009

lore
Share & tools
lore
#0 lore raw

This one I find to be useful for people (like myself) that need a static linked busybox before setting up a dynamically linked system.

A1: Yes, this feature could be selected in the busybox config file; but exposing the feature in BR allows the use of "canned" BB config files without creating a custom one with only "static" changed.

"Signed-off-by" == "works for me"

package/busybox/Config.in +14 -0
index 7438a8d..90cec45 100644
@@ -56,6 +56,20 @@ config BR2_PACKAGE_BUSYBOX_FULLINSTALL
 
 	  If you wish to just install /bin/busybox, then answer N.
 
+config BR2_PACKAGE_BUSYBOX_MKSTATIC
+    bool "Build a staticly linked BusyBox"
+    depends on BR2_PACKAGE_BUSYBOX
+    default n
+    help
+        This will produce a staticly linked BusyBox.
+
+        Over-rides the selection made in the BusyBox config file.
+
+        Generates a larger BusyBox that can be run independently
+        of the rest of the system being built.
+        Useful if you need to run BusyBox before setting up for
+        a dynamically linked system.
+
 config BR2_PACKAGE_BUSYBOX_CONFIG
 	string "BusyBox configuration file to use?"
 	depends on BR2_PACKAGE_BUSYBOX
package/busybox/busybox.mk +5 -0
index eb79134..187a06a 100644
@@ -77,6 +77,11 @@ ifeq ($(BR2_INET_RPC),y)
 else
 	$(SED) "s/^.*CONFIG_FEATURE_MOUNT_NFS.*/CONFIG_FEATURE_MOUNT_NFS=n/;" $(BUSYBOX_DIR)/.config
 endif
+ifeq ($(BR2_PACKAGE_BUSYBOX_MKSTATIC),y)
+	# force static build on
+	$(SED) "s/^.*CONFIG_STATIC.*/CONFIG_STATIC=y/" $(BUSYBOX_DIR)/.config
+	$(SED) "s/^.*CONFIG_PIE.*/CONFIG_PIE=n/" $(BUSYBOX_DIR)/.config
+endif
 ifeq ($(BR2_PACKAGE_BUSYBOX_SKELETON),y)
 	# force mdev on
 	$(SED) "s/^.*CONFIG_MDEV.*/CONFIG_MDEV=y/" $(BUSYBOX_DIR)/.config
#1 lore raw

Ah, but getting it to build. . .

Add: "-static -static-libgcc" to the BusyBox menuconfig "extra cflags":

buildroot$ file output/target/bin/busybox
output/target/bin/busybox: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), statically linked, with unknown capability 0xf41 = 0x756e6700, stripped

Now to figure out where in the auto-magic build system to fix "build static" Needed:
CFLAGS+="-static -static-libgcc"
LDFLAGS+="-static"

And clean up that required "-enable-shared -enable-static" library building option. That is the correct option pair, the other variations are not required.

Mike

Quoted 59 lines · Michael S. Zick

This one I find to be useful for people (like myself) that need a static linked busybox before setting up a dynamically linked system.

A1: Yes, this feature could be selected in the busybox config file; but exposing the feature in BR allows the use of "canned" BB config files without creating a custom one with only "static" changed.

"Signed-off-by" == "works for me"

package/busybox/Config.in +14 -0
index 7438a8d..90cec45 100644
@@ -56,6 +56,20 @@ config BR2_PACKAGE_BUSYBOX_FULLINSTALL
 
 	  If you wish to just install /bin/busybox, then answer N.
 
+config BR2_PACKAGE_BUSYBOX_MKSTATIC
+    bool "Build a staticly linked BusyBox"
+    depends on BR2_PACKAGE_BUSYBOX
+    default n
+    help
+        This will produce a staticly linked BusyBox.
+
+        Over-rides the selection made in the BusyBox config file.
+
+        Generates a larger BusyBox that can be run independently
+        of the rest of the system being built.
+        Useful if you need to run BusyBox before setting up for
+        a dynamically linked system.
+
 config BR2_PACKAGE_BUSYBOX_CONFIG
 	string "BusyBox configuration file to use?"
 	depends on BR2_PACKAGE_BUSYBOX
package/busybox/busybox.mk +5 -0
index eb79134..187a06a 100644
@@ -77,6 +77,11 @@ ifeq ($(BR2_INET_RPC),y)
 else
 	$(SED) "s/^.*CONFIG_FEATURE_MOUNT_NFS.*/CONFIG_FEATURE_MOUNT_NFS=n/;" $(BUSYBOX_DIR)/.config
 endif
+ifeq ($(BR2_PACKAGE_BUSYBOX_MKSTATIC),y)
+	# force static build on
+	$(SED) "s/^.*CONFIG_STATIC.*/CONFIG_STATIC=y/" $(BUSYBOX_DIR)/.config
+	$(SED) "s/^.*CONFIG_PIE.*/CONFIG_PIE=n/" $(BUSYBOX_DIR)/.config
+endif
 ifeq ($(BR2_PACKAGE_BUSYBOX_SKELETON),y)
 	# force mdev on
 	$(SED) "s/^.*CONFIG_MDEV.*/CONFIG_MDEV=y/" $(BUSYBOX_DIR)/.config

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot