Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 979
yy502 Avatar asked Feb 25 '14 05:02

yy502


1 Answers

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.
like image 125
andrewdotn Avatar answered Nov 03 '22 03:11

andrewdotn