ascii-boxes / boxes

Command line ASCII boxes unlimited!
https://boxes.thomasjensen.com/
GNU General Public License v3.0
613 stars 75 forks source link

compilation option request (static binary) #100

Closed matteoguglielmi closed 2 years ago

matteoguglielmi commented 2 years ago

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!

tsjensen commented 2 years ago

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 commented 2 years ago

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

matteoguglielmi commented 2 years ago

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

4) download pcre2:

wget https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.40/pcre2-10.40.tar.bz2

5) clone boxes:

git clone https://github.com/ascii-boxes/boxes.git

6) compile libunistring:

./configure --enable-static --prefix=/usr
make
make install

7) compile pcre2:

./configure --enable-pcre2-16 --enable-pcre2-32 --enable-static --prefix=/usr
make
make install

8) 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

9) compile boxes:

make

or

CFLAGS_ADDTL='-std=c99' make

if you happen to have an old compiler

10) 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.

tsjensen commented 2 years ago

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

tsjensen commented 2 years ago

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!

matteoguglielmi commented 2 years ago

It is working,

Thank you.