我有一个Makefile
说:
aaa:bbb
echo 456
bbb:
echo 123
bbb
当目录中 没有文件时,无论是否有aaa
文件都会执行这两条规则。
但为什么?
我有一个Makefile
说:
aaa:bbb
echo 456
bbb:
echo 123
bbb
当目录中 没有文件时,无论是否有aaa
文件都会执行这两条规则。
但为什么?
为什么当make
代码中的命令抛出错误时make: *** No targets. Stop.
代码:
NAME := program
FLAG := -std=c11 -Wall -Wextra -Werror -Wpedantic
all: $(NAME)
$(NAME): *.c
clang $(FLAG) -o $(NAME) *.c -lm
clean:
rm -rf $(NAME)
reinstall: clean all
这是我从芯片制造商那里得到的命令行:
make sunxi_defconfig ARCH=arm CROSS_COMPILE=arm-linux-
它肯定失败了,消息如下
*** Error during writing of the configuration.
make[1]: *** [scripts/kconfig/Makefile:121: nanopi_h3_defconfig] Error 1
make: *** [Makefile:479: nanopi_h3_defconfig] Error 2
我sunxi_defconfig
从文件夹中找到了configs/
。为什么配置文件sunxi_defconfig
作为命令目标放在参数列表中make
?我make
仔细研究了命令手册,没有发现将配置文件作为制作目标的情况。是不是命令行写错了?我该如何修复它?
我有这个:
.PHONY: check
check:
script-returning-nearly-always-zero
obj2.img: obj1.img check
make-obj2-from-obj1
所以,逻辑是我想重新生成obj2.img
,如果它比 obj1 更旧(或者它甚至不存在)。但是,如果“检查”目标失败,我想要一个错误。
现在我的问题是 的生成器obj2.img
总是运行。我想,可能是check
因为.PHONY
。
obj2.img
我可以以某种方式要求 make仅在obj1.img
更新时重新生成吗?
我只是在学习make。我偶然发现了关于 make 的自动删除中间文件的问题。我想更好地预测 make 如何标记文件中间(即回答“会自动删除它吗?”),所以我编写了一个像这样的虚拟项目来演示我的问题:
你好.h
#ifndef HELLO_H
#define HELLO_H
void hello(const char *name);
#endif
你好ç
#include <stdio.h>
void hello(const char *name) {
printf("Hello %s\n", name);
}
主程序
#include "hello.h"
int main() {
hello("world");
return 0;
}
生成文件
all: main
./main
clean:
rm -f *.o *.a
rm -f main
hello.o:
gcc -c hello.c
libmyhello.a: hello.o
ar -crv $@ hello.o
main: libmyhello.a
gcc -L. -o $@ [email protected] -lmyhello
.PHONY: all clean
当我制作时main
,它需要libmyhello.a
。libmyhello.a
需要hello.o
. 如果我没理解错的话,hello.o
应该是一个中间文件。但在此过程中并未被删除make main
。
为什么?如何判断 make 是否会将文件视为中间文件并将其删除?
这是我的简单 Makefile:
#create an exe file
run: link
gcc link.o -o run
#sketch link.o
link.o: main.o sum.o
ld -r main.o sum.o -o link.o
#sketch main.o
main.o: main.c
gcc -c main.c -o main.o
#sketch sum.o
sum.o: sum.c
gcc -c sum.c -o sum.o
#make clean recipie
clean:
rm *.o
rm run
这个 makefile 可能有点不成熟或薄弱。但我真正关心的是目标被击中的过程。在讲述实际问题之前,让我们先看看它的输出。
gcc -c main.c -o main.o
gcc -c sum.c -o sum.o
ld -r main.o sum.o -o link.o
cc link.o -o link
gcc link.o -o run
我的问题是:这是因为link
依赖性run
还是因为link.o
在命令部分中提到,命令run
再次寻找它是因为它make
的依赖性寻找提及依赖性或者因为在命令部分然后目标中的第一个命令是分别遇到and和?是因为依赖项中提到的文件还是命令中提到的文件?link.o
main.o
sum.o
link.o
main.o
sum.o
main.o
sum.o
link.o
我需要为 Makefile 中的多个目录创建链接。
链接(对于 中的所有文件./topdir/
)应该从./anotherdir/<file>
到./topdir/<file>
。
我试过了:
create-links: ./topdir/*/
@for f in $^; do \
echo "this is my path: [$${f}]" && \
DIR=$(shell basename $${f}) && \
echo "make link from ./anotherdir/$(DIR)" ;\
done
./topdir 中有这些文件
dir1
dir2
file1
file2
f
使用 dirs 及其相对路径(例如./topdir/dir1
)正确分配。
我只需要没有路径的目录名。这是basename
应该做的。
但 DIR 始终为空。为什么?
我正在尝试从 github repo/source 构建 opendingux。https://github.com/OpenDingux/buildroot
OpenDingux 是一款专注于(复古)游戏的嵌入式 Linux 发行版。
我克隆了 repo,然后运行下面的命令。
cd ./buildroot;
export CONFIG='gcw0'; bash ./rebuild.sh;
上述命令的输出几乎是一堵文字墙,因为它有 22301 行长,所以无法在此问题中发布。完整输出可在此处获得https://paste.ee/p/UInYW
我已经剪掉了我在下面得到的错误。
/bin/bash: line 2: 186552 Killed build/genautomata ../../gcc/common.md ../../gcc/config/mips/mips.md insn-conditions.md > tmp-automata.c
make[3]: *** [Makefile:2459: s-automata] Error 137
make[3]: *** Waiting for unfinished jobs....
rm gcc.pod
make[2]: *** [Makefile:4415: all-gcc] Error 2
make[1]: *** [package/pkg-generic.mk:270: /home/vagrant/buildroot/output/gcw0/build/host-gcc-initial-11.1.0/.stamp_built] Error 2
make: *** [Makefile:84: _all] Error 2
使 -v 返回:
GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2016 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.
在一个目录下,一个文件:makefile
ifneq ($(jobserver),T)
$(error This makefile only works with a Make program that supports $$(eval))
endif
按 make 类型调用 make
makefile:2: *** This makefile only works with a Make program that supports $(eval). Stop.
即使我尝试
ifneq ($(eval),T)
$(error This makefile only works with a Make program that supports $$(eval))
endif
仍然返回
makefile:2: *** This makefile only works with a Make program that supports $(eval). Stop.
我按照在线教程进行操作,这些 makefile 测试 make 中的功能/功能是否可用。它不应该产生错误。
我正在运行 debuild 并且 lintian 自动找到我在联机帮助页中遇到的 2 个错误。
运行 debuild 命令后的项目结构如下所示
hoseopjeong@hoseopjeong-VirtualBox:~/Documents/HoseopJeong_debian_lab9/debianlaboration9-0.0$ tree
.
├── debian
│ ├── changelog
│ ├── compat
│ ├── control
│ ├── copyright
│ ├── debhelper-build-stamp
│ ├── debianlaboration9
│ │ ├── DEBIAN
│ │ │ ├── control
│ │ │ └── md5sums
│ │ └── usr
│ │ ├── bin
│ │ │ └── electrotest_standalone
│ │ └── share
│ │ ├── doc
│ │ │ └── debianlaboration9
│ │ │ ├── changelog.Debian.gz
│ │ │ ├── copyright
│ │ │ └── README.Debian
│ │ └── man
│ │ └── electrotest_standalone.man.gz
│ ├── debianlaboration9.debhelper.log
│ ├── debianlaboration9.substvars
│ ├── files
│ ├── patches
│ │ └── series
│ ├── README.Debian
│ ├── rules
│ ├── source
│ │ ├── format
│ │ └── local-options
│ └── watch
├── electrotest_standalone
├── electrotest_standalone.man
├── Makefile
└── src
└── electrotest_standalone.c
debuild 使用的 makefile 看起来像这样
prefix = /usr/local
all: electrotest
electrotest: ./src/electrotest_standalone.c
gcc -o electrotest_standalone ./src/electrotest_standalone.c -lm
install:electrotest
install -D electrotest_standalone \
$(DESTDIR)$(prefix)/bin/electrotest_standalone
mkdir $(DESTDIR)/usr/share
mkdir $(DESTDIR)/usr/share/man
cp electrotest_standalone.man \
$(DESTDIR)/usr/share/man/
clean:
-rm -f electrotest
distclean:clean
uninstall:
-rm -f $(DESTDIR)$(prefix)/bin/electrotest_standalone
.PHONY: all install clean distclean uninstall
因此,据我了解,man 文件必须位于 usr/share/man 中。这就是为什么我使用 Makefile 手动创建 ushare/man 文件夹的原因,当我运行 debuild 命令时,我可以看到 debuild 创建了这些文件夹,并且cp electrotest_standalone.man \ $(DESTDIR)/usr/share/man/
debuild 还设法将该文件复制到由 debuild 生成的 man 文件夹中。不过,林天还是不喜欢。
当我运行 debuild 时,lintian 显示
Now running lintian...
W: debianlaboration9: improbable-bug-number-in-closes 10
E: debianlaboration9: manpage-in-wrong-directory usr/share/man/electrotest_standalone.man.gz
W: debianlaboration9: binary-without-manpage usr/bin/electrotest_standalone
它说我的 man 文件在错误的位置,并且二进制文件 electrotest_standalone 没有任何手册页。我究竟做错了什么?
目前我的手册页只有一句话
NAME: electrotest_standalone