为什么父目录中的 Gnumake 表现不同?

发布于 2024-08-29 10:12:46 字数 3487 浏览 4 评论 0原文

我很困惑为什么当我从父目录执行 gnumake 时它的行为不正确,而如果我 cd 到子目录并执行 gnumake 则它工作正常。

在父 makefile 中,我有这样的规则:

.PHONY: zlib-1.2.5
zlib-1.2.5:
    @ echo Issuing $(MAKE) in $@ ...
    pushd zlib-1.2.5; make; popd

我也对上面的最后一行进行了类似的尝试,但出现了相同的失败:

    make -C zlib-1.2.5

这给出了与从顶层执行相同操作不同的结果

pushd zlib-1.2.5; make; popd

父 makefile 中的某些内容正在使其进入子目录 makefile 并导致其行为不正确,但我不知道如何找到它。

我看到的症状是,子目录配置为 zlib 生成的 makefile 规则缺少依赖项,并且我得到的结果直接进入 ar,而不首先生成 .o(s): 与

cd ~/src; make zlib-1.2.5
CPPFLAGS_AUTO = <  >
Issuing make in zlib-1.2.5 ...
pushd zlib-1.2.5; make; popd
~/src/zlib-1.2.5 ~/src
make[1]: Entering directory `/disk2/user/src/zlib-1.2.5'
ar rc libz.a adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o 
ar: adler32.o: No such file or directory
make[1]: *** [libz.a] Error 1
gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -o libz.so.1.2.5 adler32.lo compress.lo crc32.lo deflate.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo uncompr.lo zutil.lo  -lc -L. libz.a
gcc: adler32.lo: No such file or directory
gcc: compress.lo: No such file or directory
gcc: crc32.lo: No such file or directory
gcc: deflate.lo: No such file or directory
[...]
make[1]: *** [libz.so.1.2.5] Error 1
make[1]: Target `all' not remade because of errors.
make[1]: Leaving directory `/disk2/user/src/zlib-1.2.5'
~/src

它正常工作的 zlib 目录相比:

cd ~/src/zlib-1.2.5; make
gcc -O3 -D_LARGEFILE64_SOURCE=1   -c -o example.o example.c
gcc -O3 -D_LARGEFILE64_SOURCE=1   -c -o adler32.o adler32.c
gcc -O3 -D_LARGEFILE64_SOURCE=1   -c -o compress.o compress.c
gcc -O3 -D_LARGEFILE64_SOURCE=1   -c -o crc32.o crc32.c
[...]
gcc -O3 -D_LARGEFILE64_SOURCE=1   -c -o zutil.o zutil.c
ar rc libz.a adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o 
(ranlib libz.a || true) >/dev/null 2>&1
gcc -O3 -D_LARGEFILE64_SOURCE=1 -o example example.o -L. libz.a
gcc -O3 -D_LARGEFILE64_SOURCE=1   -c -o minigzip.o minigzip.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -o minigzip minigzip.o -L. libz.a
mkdir objs 2>/dev/null || test -d objs
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DPIC -c -o objs/adler32.o adler32.c
mv objs/adler32.o adler32.lo
mkdir objs 2>/dev/null || test -d objs
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DPIC -c -o objs/compress.o compress.c
mv objs/compress.o compress.lo
[...]
mkdir objs 2>/dev/null || test -d objs
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DPIC -c -o objs/zutil.o zutil.c
mv objs/zutil.o zutil.lo
gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -o libz.so.1.2.5 adler32.lo compress.lo crc32.lo deflate.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo uncompr.lo zutil.lo  -lc -L. libz.a
rm -f libz.so libz.so.1
ln -s libz.so.1.2.5 libz.so
ln -s libz.so.1.2.5 libz.so.1
rmdir objs
gcc -O3 -D_LARGEFILE64_SOURCE=1 -o examplesh example.o -L. libz.so.1.2.5
gcc -O3 -D_LARGEFILE64_SOURCE=1 -o minigzipsh minigzip.o -L. libz.so.1.2.5
gcc -O3 -D_LARGEFILE64_SOURCE=1 -o example64 example64.o -L. libz.a
gcc -O3 -D_LARGEFILE64_SOURCE=1 -o minigzip64 minigzip64.o -L. libz.a

I am stumped as to why when I do a gnumake from the parent directory it behaves incorrectly, whereas, if I cd to the subdirectory and do gnumake it works correctly.

In the parent makefile, I have a rule like this:

.PHONY: zlib-1.2.5
zlib-1.2.5:
    @ echo Issuing $(MAKE) in $@ ...
    pushd zlib-1.2.5; make; popd

I also tried it like this for last line above with the same failure:

    make -C zlib-1.2.5

Which gives different result than doing the same from the toplevel

pushd zlib-1.2.5; make; popd

There is a something from the parent makefile that is making its way into the subdirectory makefile and causing it to behave incorrectly, but I don't know how to find it.

The symptom I see is that the subdirectory config generated makefile rule for zlib misses the dependencies and I get this result going straight to the ar without generating the .o(s) first:

cd ~/src; make zlib-1.2.5
CPPFLAGS_AUTO = <  >
Issuing make in zlib-1.2.5 ...
pushd zlib-1.2.5; make; popd
~/src/zlib-1.2.5 ~/src
make[1]: Entering directory `/disk2/user/src/zlib-1.2.5'
ar rc libz.a adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o 
ar: adler32.o: No such file or directory
make[1]: *** [libz.a] Error 1
gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -o libz.so.1.2.5 adler32.lo compress.lo crc32.lo deflate.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo uncompr.lo zutil.lo  -lc -L. libz.a
gcc: adler32.lo: No such file or directory
gcc: compress.lo: No such file or directory
gcc: crc32.lo: No such file or directory
gcc: deflate.lo: No such file or directory
[...]
make[1]: *** [libz.so.1.2.5] Error 1
make[1]: Target `all' not remade because of errors.
make[1]: Leaving directory `/disk2/user/src/zlib-1.2.5'
~/src

Versus from the zlib directory where it works correctly:

cd ~/src/zlib-1.2.5; make
gcc -O3 -D_LARGEFILE64_SOURCE=1   -c -o example.o example.c
gcc -O3 -D_LARGEFILE64_SOURCE=1   -c -o adler32.o adler32.c
gcc -O3 -D_LARGEFILE64_SOURCE=1   -c -o compress.o compress.c
gcc -O3 -D_LARGEFILE64_SOURCE=1   -c -o crc32.o crc32.c
[...]
gcc -O3 -D_LARGEFILE64_SOURCE=1   -c -o zutil.o zutil.c
ar rc libz.a adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o 
(ranlib libz.a || true) >/dev/null 2>&1
gcc -O3 -D_LARGEFILE64_SOURCE=1 -o example example.o -L. libz.a
gcc -O3 -D_LARGEFILE64_SOURCE=1   -c -o minigzip.o minigzip.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -o minigzip minigzip.o -L. libz.a
mkdir objs 2>/dev/null || test -d objs
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DPIC -c -o objs/adler32.o adler32.c
mv objs/adler32.o adler32.lo
mkdir objs 2>/dev/null || test -d objs
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DPIC -c -o objs/compress.o compress.c
mv objs/compress.o compress.lo
[...]
mkdir objs 2>/dev/null || test -d objs
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DPIC -c -o objs/zutil.o zutil.c
mv objs/zutil.o zutil.lo
gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -o libz.so.1.2.5 adler32.lo compress.lo crc32.lo deflate.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo uncompr.lo zutil.lo  -lc -L. libz.a
rm -f libz.so libz.so.1
ln -s libz.so.1.2.5 libz.so
ln -s libz.so.1.2.5 libz.so.1
rmdir objs
gcc -O3 -D_LARGEFILE64_SOURCE=1 -o examplesh example.o -L. libz.so.1.2.5
gcc -O3 -D_LARGEFILE64_SOURCE=1 -o minigzipsh minigzip.o -L. libz.so.1.2.5
gcc -O3 -D_LARGEFILE64_SOURCE=1 -o example64 example64.o -L. libz.a
gcc -O3 -D_LARGEFILE64_SOURCE=1 -o minigzip64 minigzip64.o -L. libz.a

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

唔猫 2024-09-05 10:12:46

运行 make -D 打开调试

run make -D to turn on debug

护你周全 2024-09-05 10:12:46
pushd zlib-1.2.5; make; popd

应该是

make -C zlib-1.2.5

-C 标志/开关更改目录,类似于代码使用 pushdpopd 命令执行的操作。区别在于行为,因为此 make 过程是递归的。实际上,如果使用诸如 gmake 之类的命令而不是可能的命令,则可以使用 $(MAKE) 而不是 make BSD make(因为它是 GNU makefile)。

pushd zlib-1.2.5; make; popd

should be

make -C zlib-1.2.5

The -C flag/switch changes the directory similar to what your code does with the pushd and popd commands. The difference is in the behaviour since this make process is recursive. And actually, you might use $(MAKE) instead of make in the event that a command such as gmake is used instead of what might be BSD make (since it is a GNU makefile).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文