coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Compiling a specific binary in this package


From: Assaf Gordon
Subject: RE: Compiling a specific binary in this package
Date: Wed, 8 Nov 2017 00:41:29 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0

(Answering a question from github:
https://github.com/coreutils/coreutils/issues/13)

alxpettit writes:
I want to use this code as a basis for my project. I am forking the mv command, since it's relatively simple (~500 lines of dedicated code), and its functions closely match the purpose of my program.

That is an inaccurate assessment.
While "mv.c" itself is about ~500 lines,
it uses "copy.c" which is ~3000 lines,
which in turn uses many gnulib modules.
Also used are "remove.c", "cp-hash.c", "selinux.c", etc.

Compiling the file 'mv.c' alone would not yield an executable with mv's functionality.

I tried doing make help and ./configure --help, but I found no option to simply compile one binary.

There is no such option at the moment.
You could run "./configure" followed by "make src/mv"
which will then compile only the required files to build the 'mv' executable, but this will still result in many compiled files.

I did a trace on the Makefile, and isolated the command that produces
the mv binary:

gcc -I. -I./lib -Ilib -I./lib -Isrc -I./src -g -O2 -MT src/mv.o -MD -MP -MF $depbase.Tpo -c -o src/mv.o src/mv.c &&\ echo " CCLD " src/mv;gcc -g -O2 -Wl,--as-needed -o src/mv src/mv.o src/remove.o src/copy.o src/cp-hash.o src/extent-scan.o src/force-link.o src/selinux.o src/libver.a lib/libcoreutils.a lib/libcoreutils.a -lacl -lattr

Of course, it doesn't work without all the object files already generated. I can't tell which lines are producing them, and after skimming the Makefile and configure.ac.

coreutils uses gnu autoconf and automake to generate the Makefiles.

The file "src/local.mk" contains the following line:

    src_mv_SOURCES = src/mv.c src/remove.c \
                     $(copy_sources) $(selinux_sources)

Which defines the needed files to build 'mv'.

To learn more about using or tweaking autotools projects
see here:
 https://en.wikipedia.org/wiki/GNU_Build_System
 https://www.lrde.epita.fr/~adl/autotools.html
 https://autotools.io/index.html

In projects that use Autotools there's little point in
modifying a "Makefile" directly.

I've concluded that I have a newfound appreciation for docker build environments. (I'm mostly a Python programmer, and don't have too much experience with the in-depth GNU toolchains.)

(the following is just my personal opinion:)

In most cases you'll find that a "docker build environment" is
just a lazy substitute for properly packaging a software project
using existing frameworks (be it autotools, cmake, ninja, waf,
Makefiles, or in python's case: a properly setuptools configuration).

In many of these cases, the developer decides that instead of spending
the time to use a build infrastructure and document the pre-requisites,
they just "freeze" their build environment and expect others to just deploy their copy.

That is a poor way to build scalable reliable systems.

Unfortunately, I can't figure out how to compile it without, y'know, compiling everything else. I don't want to have to drag 50M of source
code around just for a variation on a coreutils binary. How can I
compile just `mv.c?

There is no way to do so, because mv's functionality is spread of over
many files, and they are all needed.

(technically, you can compile 'mv.c' alone to 'mv.o', but that won't get
you the 'mv' executable, which I assume is what you need.)

GNU coreutils's mv has a lot of features, and perhaps you don't need all of them.

If you want to build something based on a minimal 'mv' functionality,
perhaps consider using the mv code from FreeBSD, which seems a lot smaller: https://github.com/freebsd/freebsd/blob/master/bin/mv/mv.c (though depending on which OS you need it for, it might have it's own difficulties to be built).

Other possible starting point would be with BusyBox ( https://busybox.net/ ) or ToyBox (http://landley.net/toybox/about.html)

Both of these projects are designed to be small and very modular,
to the point that you can build just the 'mv' executable with them.
However even when building just the 'mv' binary, many source code files are still compiled.


Lastly,
It's sometimes worth going back to the beginning and re-evaluate what functionality do you need for your program.
Is really the entire functionality of 'mv' needed?



regards,
 - Assaf





reply via email to

[Prev in Thread] Current Thread [Next in Thread]