在 Linux coreutils 包中编译特定的源文件

标签 c linux gcc compilation makefile

我需要从 Linux coreutils 源文件编译特定版本的 cp(复制)和 mv(移动)实用程序。而不是编译整个包:

./configure
make

这需要很长时间,我怎么能只编译cp(./src/cp.c)和mv(./src/mv.c)?

我试图删除不相关的 c 文件,但 cp.c 和 mv.c 有太多依赖项无法跟踪...我意识到这是简化我的问题的愚蠢方法。必须有一行代码或其他东西告诉 make 或 gcc 只编译 cp 和 mv!

要使用的示例源代码:http://ftp.gnu.org/gnu/coreutils/coreutils-8.21.tar.xz

提前致谢!

最佳答案

在运行 configure 之后运行 make src/cp src/mv 应该可以工作,但是 coreutils 构建系统没有正确设置依赖项。 cpmv 依赖于 Makefile 不跟踪的生成的源文件。但是,您需要的生成文件是在默认 make all 开始时创建的,因此您可以开始完整构建,并在它通过 GEN 后立即终止它行:

$ ./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.

然后运行make src/cp src/mv来构建你需要的程序:

$ 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.

关于在 Linux coreutils 包中编译特定的源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22005048/

相关文章:

c - uint32_t 的位符号 -1 而不是 C 中的 1

linux - 从 Jenkins 或 Linux 控制台运行时 Chromedriver 失败

c - 为什么 ld 没有从共享库中找到一些符号

c - 可读性与可维护性 : Condensing statements to loops

c - 尝试使用陷阱标志和陷阱信号处理程序单步执行程序,在 vsyscall 上崩溃

c - 错误 : 'type name' declared as function returning a function

android - 在 Python 和 Kivy 中使用 buildozer 时出现错误 "Unable to find Compiler"

linux - 在 Linux 中输出中的关键字后终止命令

c++ - 在类模板上使用 arm gcc 编译期间出现段错误

c++ - 为什么 const 左值引用可以引用可变右值引用?