为什么父目录中的 Gnumake 表现不同?
我很困惑为什么当我从父目录执行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
运行 make -D 打开调试
run make -D to turn on debug
应该是
-C
标志/开关更改目录,类似于代码使用pushd
和popd
命令执行的操作。区别在于行为,因为此 make 过程是递归的。实际上,如果使用诸如gmake
之类的命令而不是可能的命令,则可以使用$(MAKE)
而不是make
BSDmake
(因为它是 GNU makefile)。should be
The
-C
flag/switch changes the directory similar to what your code does with thepushd
andpopd
commands. The difference is in the behaviour since this make process is recursive. And actually, you might use$(MAKE)
instead ofmake
in the event that a command such asgmake
is used instead of what might be BSDmake
(since it is a GNU makefile).