yy502
yy502

Reputation: 323

compile specific source file in Linux coreutils package

I need to compile a specific version of cp (copy) and mv (move) utility from the Linux coreutils source file. Instead of compiling the whole package with:

./configure
make

which takes ages, how can I only compile cp (./src/cp.c) and mv (./src/mv.c)?

I tried to remove irrelevant c files but cp.c and mv.c have too many dependencies to trace... and I realise this is a stupid way to simplify my problem. There must be an one-liner or some thing that tells make or gcc to only compile cp and mv!

Sample source code to work with: http://ftp.gnu.org/gnu/coreutils/coreutils-8.21.tar.xz

Thanks in advance!

Upvotes: 8

Views: 4620

Answers (4)

pixelbeat
pixelbeat

Reputation: 31748

coreutils takes only a short while to compile. Note it support parallel compiles well so add the -j $(nproc) option to make.

The largest time portion is due to configure which is mandatory.

Consequently coreutils uses BUILT_SOURCES to initially generate some sources required in the build. The automake manual says that

"you cannot use BUILT_SOURCES if the ability to run ‘make foo’ on a clean tree is important to you."

Given the relative short time of the build and the unusual use case of a partial build from a clean tree, the coreutils project avoids manually specifying all dependencies, and instead uses BUILT_SOURCES as described above

Upvotes: 0

Lee Duhem
Lee Duhem

Reputation: 15121

I believe disable the features (such as support of Native Language Support) that you does not want or need, only include the absolutely necessary modules(for example gnulib), then build the whole project is still the quickest and easiest way to get what you need.

Upvotes: 0

andrewdotn
andrewdotn

Reputation: 34863

Running make src/cp src/mv after running configure should work, but the coreutils build system doesn’t have the dependencies set up correctly. cp and mv depend on generated source files that aren’t tracked by the Makefile. However the generated files you need are created right at the start of the default make all, so you can start a full build, and kill it right after it gets past the GEN lines:

$ ./configure
...
$ make
  GEN    lib/alloca.h
  GEN    lib/c++defs.h
  ...
  GEN    src/version.c
  GEN    src/version.h
make  all-recursive
make[1]: Entering directory `/home/andrew/coreutils-8.21'
Making all in po
make[2]: Entering directory `/home/andrew/coreutils-8.21/po'
make[2]: Leaving directory `/home/andrew/coreutils-8.21/po'
Making all in .
make[2]: Entering directory `/home/andrew/coreutils-8.21'
  CC     lib/set-mode-acl.o
  CC     lib/copy-acl.o
^C
make[2]: *** wait: No child processes.  Stop.
make[2]: *** Waiting for unfinished jobs....
make[2]: *** wait: No child processes.  Stop.
make[1]: *** wait: No child processes.  Stop.
make[1]: *** Waiting for unfinished jobs....
make[1]: *** wait: No child processes.  Stop.
make: *** wait: No child processes.  Stop.
make: *** Waiting for unfinished jobs....
make: *** wait: No child processes.  Stop.

Then run make src/cp src/mv to build the programs you need:

$ make src/cp src/mv
  CC     src/cp.o
  CC     src/copy.o
  CC     src/cp-hash.o
  CC     src/extent-scan.o
  CC     src/version.o
  AR     src/libver.a
  CC     lib/argmatch.o
  CC     lib/argv-iter.o
  CC     lib/backupfile.o
  ... 230 other files ...
  CC     lib/vasprintf.o
  CC     lib/vfprintf.o
  CC     lib/vprintf.o
  AR     lib/libcoreutils.a
  CCLD   src/cp
  CC     src/mv.o
  CC     src/remove.o
  CCLD   src/mv
$ src/cp --version
cp (GNU coreutils) 8.21
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Torbjörn Granlund, David MacKenzie, and Jim Meyering.

Upvotes: 8

Amit
Amit

Reputation: 91

You need to dig in to the make file which is created after ./configure. Try to find out the make command related to your source build process.

Upvotes: 0

Related Questions