boxes icon indicating copy to clipboard operation
boxes copied to clipboard

compilation option request (static binary)

Open matteoguglielmi opened this issue 2 years ago • 4 comments

Hello,

I need to run a pre-compiled binary of boxes (latest version) on many different linux distributions and would need to have a compilation option (e.g. make -static) to generate a static binary that is the most portable one (would run across the largest number of Linux flavors and releases).

For instance,

boxes compiled on CentOS 7 does not run on Redhat Enterprise Linux 7 (without subscription - dvd only packages) because of libunistring/libpcre2 version mismatch.

Also,

boxes cannot be compiled on Redhat Enterprise Linux 7 because of the lack of libunistring/libpcre2 development packages.

So,

is there a way to get a static binary of boxes that would run "hopefully" anywhere?

Thank you!

matteoguglielmi avatar Jun 07 '22 04:06 matteoguglielmi

Good question, and this seems a reasonable request.

is there a way to get a static binary of boxes that would run (almost) anywhere?

Unfortunately, I honestly don't know how to do that. But if you were to offer an implementation of such an option in a pull request, I would be in favor.

You can already pass additional options to the build via the CFLAGS_ADDTL and LDFLAGS_ADDTL variables. Would that help?

tsjensen avatar Jun 07 '22 09:06 tsjensen

Closed because of no feedback. Feel free to reopen if you have new information.

tsjensen avatar Jun 29 '22 12:06 tsjensen

Steps to statically compile boxes against libunistring and pcre2:

  1. install a bare minimum linux distribution of your choice using virtualbox

  2. install wget, gcc, flex and bison packages

  3. download libunistring:

wget https://ftp.gnu.org/gnu/libunistring/libunistring-1.0.tar.gz
  1. download pcre2:
wget https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.40/pcre2-10.40.tar.bz2
  1. clone boxes:
git clone https://github.com/ascii-boxes/boxes.git
  1. compile libunistring:
./configure --enable-static --prefix=/usr
make
make install
  1. compile pcre2:
./configure --enable-pcre2-16 --enable-pcre2-32 --enable-static --prefix=/usr
make
make install
  1. edit boxes Makefile:
vim src/Makefile

change this:

boxes: $(ALL_OBJ) | check_dir
       $(CC) $(LDFLAGS) $^ -o $@ -lunistring -lpcre2-32
       if [ "$(STRIP)" = "true" ] ; then strip $@ ; fi

into this:

boxes: $(ALL_OBJ) | check_dir
        $(CC) $(LDFLAGS) $^ -o $@ -l:libunistring.a -l:libpcre2-32.a
        if [ "$(STRIP)" = "true" ] ; then strip $@ ; fi
  1. compile boxes:
make

or

CFLAGS_ADDTL='-std=c99' make

if you happen to have an old compiler

  1. check boxes binary:
ldd out/boxes

linux-vdso.so.1 =>  (0x00007ffc5f97b000)
libc.so.6 => /lib64/libc.so.6 (0x00007fcfd7221000)
/lib64/ld-linux-x86-64.so.2 (0x00007fcfd75ef000)

where libunistring and pcre2 must not be listed i.e. were statically linked.

matteoguglielmi avatar Jul 25 '22 05:07 matteoguglielmi

Thanks! I'll check that out. Please be a little patient, conflicting priorities at the moment.

tsjensen avatar Jul 25 '22 11:07 tsjensen

Ok, this seemed to be quite straightforward. One can now make static to have make download and compile both libunistring and pcre2, then create a statically linked binary.

Do check it out and let us know if it helped!

tsjensen avatar Sep 23 '22 20:09 tsjensen

It is working,

Thank you.

matteoguglielmi avatar Sep 26 '22 11:09 matteoguglielmi