How to get a static binary from ports

Karol Kwiatkowski karol.kwiat at gmail.com
Fri Sep 7 04:42:31 PDT 2007


Karol Kwiatkowski wrote:
> Hi all,
> 
> to keep it short:
> 
> is there any ports knob to statically link binaries?
> If not, what steps should I take to modify a port?
> 
> longer version:
> 
> I'm trying to get a static binary out of the port. I thought it should
> be straight and easy, but I'm lost right now.
> 
> The port in question is databases/rrdtool, uses libtool:15, gnu
> configure, gmake, etc.
> 
> Normally, this port builds rrdtool binary which is dynamically linked
> (full path removed for brevity):
> 
> # ldd (...)/work/rrdtool-1.2.23/src/.libs/rrdtool
> (...)/work/rrdtool-1.2.23/src/.libs/rrdtool:
>     librrd.so.2 => not found (0x0)
>     libfreetype.so.9 => /usr/local/lib/libfreetype.so.9 (0x28085000)
>     libpng.so.5 => /usr/local/lib/libpng.so.5 (0x280ef000)
>     libz.so.4 => /lib/libz.so.4 (0x28115000)
>     libart_lgpl_2.so.5 => /usr/local/lib/libart_lgpl_2.so.5 (0x28127000)
>     libm.so.5 => /lib/libm.so.5 (0x2813c000)
>     libc.so.7 => /lib/libc.so.7 (0x28151000)
> 
> With 'make CFLAGS+=-static' I get:
> 
> # ldd (...)/work/rrdtool-1.2.23/src/rrdtool
> (...)/work/rrdtool-1.2.23/src/rrdtool:
>     libfreetype.so.9 => /usr/local/lib/libfreetype.so.9 (0x280cb000)
>     libpng.so.5 => /usr/local/lib/libpng.so.5 (0x28135000)
>     libz.so.4 => /lib/libz.so.4 (0x2815b000)
>     libart_lgpl_2.so.5 => /usr/local/lib/libart_lgpl_2.so.5 (0x2816d000)
>     libm.so.5 => /lib/libm.so.5 (0x28182000)
>     libc.so.7 => /lib/libc.so.7 (0x28197000)
> 
> librrd.so.2 is now included statically, but the rest is not. I tried
> various configure options like --enable-static, --disable-shared, also
> added '-static' to CFLAGS and/or LDFLAGS in Makefile plus various
> combinations of the above but that doesn't make a difference.
> 
> How can I include the rest of the libraries in the binary?

OK, it seems it's a problem with rrdtool's build suite, and not only
I've got problems with it[1].

For the archives, in case of rrdtool's port, a simple workaround is to
patch src/Makefile (exists after 'configure' part, so those patches are
host's dependent):

# cat src_Makefile.patch
--- src/Makefile.orig   2007-09-06 14:01:07.000000000 +0200
+++ src/Makefile        2007-09-06 15:13:15.000000000 +0200
@@ -183,7 +183,7 @@
 INSTALL_PROGRAM = install  -s -o root -g wheel -m 555
 INSTALL_SCRIPT = install  -o root -g wheel -m 555
 INSTALL_STRIP_PROGRAM = ${SHELL} $(install_sh) -c -s
-LDFLAGS = -L/usr/local/lib
+LDFLAGS = -all-static -L/usr/local/lib
 LIBOBJS =
 LIBS =
 LIBTOOL = $(SHELL) /usr/local/bin/libtool


And while we're here it might be worth changing path to default font so
the binary can work as a 'standalone' (here to 'current'):

@@ -301,7 +301,7 @@
 #
 #ACLOCAL_M4       = $(top_srcdir)/config/aclocal.m4
 #AUTOHEADER = ${SHELL}
/mnt/big/FreeBSD/work/usr/ports/databases/rrdtool/work/rrdtool-1.2.23/missing
--run autoheader --localdir=$(top_srcdir)/config
-fontsdir = $(datadir)/rrdtool/fonts
+fontsdir = .
 fonts_DATA = DejaVuSansMono-Roman.ttf
 AM_CPPFLAGS = -DRRD_DEFAULT_FONT=\"$(RRD_DEFAULT_FONT)\" -DNUMVERS=1.2023
 UPD_C_FILES = \


Cheers and thanks for the pointers.

Karol

[1] http://ramblingfoo.blogspot.com/2007/08/softfloat-rrdtool-sequel.html

-- 
Karol Kwiatkowski   <karol.kwiat at gmail dot com>
OpenPGP 0x06E09309

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 542 bytes
Desc: OpenPGP digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-ports/attachments/20070907/8c38168a/signature.pgp


More information about the freebsd-ports mailing list