BSD make
errors out on my Makefile
while GNU make
mentions no problem, and I would like to know if it is possible to make it compatible with it? Not that I plan on porting the program now, but I assume anything is possible in the future. Thank you.
The exact error produced:
bmake: don't know how to make .force_rebuild. Stop
My 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)
On my testing PC, my GNU make
version is:
$ 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
And it builds my binary and runs it just fine:
$ learn-cpp
/home/vlastimil/Development/cpp/rpi4-temperature-moninor--and-fan-control
$ make
Compiling... Done.
Running program...
25.0°C
I doubt this Makefile
succeeds in GNU make. The target .force_rebuild
is missing as this is reported, and the both GNU make and BSD bmake fail. Add the target like in the referenced link in the Makefile
.
.PHONY: .force_rebuild
.force_rebuild:
$(APP_NAME): .force_rebuild