BSDmake
出错了,Makefile
而 GNUmake
没有问题,我想知道是否可以使它与 BSD 兼容?我现在不打算移植该程序,但我认为将来一切皆有可能。谢谢。
产生的确切错误:
bmake: don't know how to make .force_rebuild. Stop
我的Makefile
:
# Use the latest version of the compiler on Debian 12 OS, arm64 platform:
CXX=g++-12
# Use the official standard;
# Optimize for speed;
# Stop on all warnings;
# Do not include debug symbols:
CXXFLAGS=-std=c++17 -O3 -Wall -Wextra -Werror -Wpedantic -pedantic-errors
# The name of the resulting executable file:
APP_NAME=auto-fan-control
# The name of the C++ source code file:
SRC_FILE=$(APP_NAME).cpp
# Possibly not doing anything when using GNU make;
# You may see this for an explanation:
# https://www.gnu.org/software/make/manual/html_node/Special-Targets.html#index-POSIX_002dconforming-mode_002c-setting
.POSIX:
# You may see this for an explanation:
# https://stackoverflow.com/a/70199176/1997354
# Force re-build work-around:
.PHONY: .force_rebuild
$(APP_NAME): .force_rebuild
$(APP_NAME): $(SRC_FILE)
@printf '%s' 'Compiling...'
@$(CXX) $(CXXFLAGS) $(SRC_FILE) -o $(APP_NAME)
@printf '%s\n' ' Done.'
@strip -s $(APP_NAME)
@printf '%s\n' 'Running program... '
@./$(APP_NAME)
在我的测试电脑上,我的 GNUmake
版本是:
$ apt-cache policy make
make:
Installed: 4.3-4.1build2
Candidate: 4.3-4.1build2
Version table:
*** 4.3-4.1build2 500
500 https://archive.ubuntu.com/ubuntu noble/main amd64 Packages
100 /var/lib/dpkg/status
它构建了我的二进制文件并运行良好:
$ learn-cpp
/home/vlastimil/Development/cpp/rpi4-temperature-moninor--and-fan-control
$ make
Compiling... Done.
Running program...
25.0°C
我怀疑这
Makefile
在 GNU make 中能否成功。正如报告的那样,缺少目标.force_rebuild
,GNU make 和 BSD bmake 都失败了。像在 中引用的链接中添加目标一样Makefile
。