Turn "overriding commands for target" into error - makefile

GNU make issues warning if there is more than one recipe for a single target. Is this possible to convert the warning to error to have more visible?

I ended up patching GNU make and rebuilding it from sources (GIT tag 4.1):
diff --git a/read.c b/read.c
index 6ff4bcc..f227681 100644
--- a/read.c
+++ b/read.c
## -2121,7 +2121,7 ## record_files (struct nameseq *filenames, const char *pattern,
error (&cmds->fileinfo, l,
_("warning: overriding recipe for target '%s'"),
f->name);
- error (&f->cmds->fileinfo, l,
+ fatal (&f->cmds->fileinfo, l,
_("warning: ignoring old recipe for target '%s'"),
f->name);
}

Related

`nix-env -i stack` failed on Mac OS X

Because of this problem, and some one told me that I should install stack and cabal-install using nix, so I am now trying to install haskell-stack using nix-env -i.
Whole error messages are here.
$ nix-env -i stack
...
lib/machserver.cpp:180:27: note: put the semicolon on a separate line to silence this warning
In file included from lib/alloc.cpp:32:
In file included from ./security_utilities/globalizer.h:31:
In file included from ./security_utilities/threading.h:40:
./security_utilities/threading_internal.h:67:5: warning: macro expansion producing 'defined' has undefined behavior [-Wexpansion-to-defined]
#if _HAVE_64BIT_ATOMIC
^
./security_utilities/threading_internal.h:41:29: note: expanded from macro '_HAVE_64BIT_ATOMIC'
#define _HAVE_64BIT_ATOMIC (defined(__ppc64__) || defined(__i386__) || defined(__x86_64__))
^
./security_utilities/threading_internal.h:67:5: warning: macro expansion producing 'defined' has undefined behavior [-Wexpansion-to-defined]
./security_utilities/threading_internal.h:41:51: note: expanded from macro '_HAVE_64BIT_ATOMIC'
#define _HAVE_64BIT_ATOMIC (defined(__ppc64__) || defined(__i386__) || defined(__x86_64__))
^
./security_utilities/threading_internal.h:67:5: warning: macro expansion producing 'defined' has undefined behavior [-Wexpansion-to-defined]
./security_utilities/threading_internal.h:41:72: note: expanded from macro '_HAVE_64BIT_ATOMIC'
#define _HAVE_64BIT_ATOMIC (defined(__ppc64__) || defined(__i386__) || defined(__x86_64__))
^
./security_utilities/threading_internal.h:119:50: warning: while loop has empty body [-Wempty-body]
{ while (!casb(store, value, store)) /* again */; return value; }
^
./security_utilities/threading_internal.h:119:50: note: put the semicolon on a separate line to silence this warning
4 warnings generated.
4 warnings generated.
4 warnings generated.
5 warnings generated.
make[2]: *** [/nix/store/204lvxmsigkgkdv2c0fvkqalxmg4fik5-gnustep-make-2.7.0/share/GNUstep/Makefiles/Instance/library.make:278: internal-library-all_] Error 2
make[1]: *** [/nix/store/204lvxmsigkgkdv2c0fvkqalxmg4fik5-gnustep-make-2.7.0/share/GNUstep/Makefiles/Master/rules.make:297: security_utilities.all.library.variables] Error 2
make: *** [/nix/store/204lvxmsigkgkdv2c0fvkqalxmg4fik5-gnustep-make-2.7.0/share/GNUstep/Makefiles/Master/library.make:37: internal-all] Error 2
builder for '/nix/store/xxja1zlr9xqvl4vij85lcf30h5s6yyi5-libsecurity_utilities-osx-10.7.5.drv' failed with exit code 2
cannot build derivation '/nix/store/g2i0xac4g4173561i5lsgn7pncswzmqd-SecurityTool-55115.drv': 1 dependencies couldn't be built
copying path '/nix/store/b5j4s3wmh2bji4ck8wrvizh5knfnw4mw-pem-0.2.4' from 'https://cache.nixos.org'...
cannot build derivation '/nix/store/ss179ilk0x4yb6z1dks3aa9z5b0bzih5-x509-system-1.6.6.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/7f4a2s6ri62dm37md14wxla62hygxg0z-connection-0.2.8.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/lg6k2p3v4sfj6w9kb3bapizzr8qk3i3p-http-client-tls-0.3.5.3.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/djqw65b0cnlpdfpadxhnqr344qrwdqa9-stack-1.9.1.drv': 1 dependencies couldn't be built
error: build of '/nix/store/djqw65b0cnlpdfpadxhnqr344qrwdqa9-stack-1.9.1.drv' failed
and
$ uname -a
Darwin YudeMBP.local 18.2.0 Darwin Kernel Version 18.2.0: Fri Oct 5 19:41:49 PDT 2018; root:xnu-4903.221.2~2/RELEASE_X86_64 x86_64
How to fix this?
It looks like you are trying to install stack from a Nixpkgs version with a broken dependency of stack.
You can see build age and links to their statuses in HowOldIs.
To change the channel you're installing from, use the nix-channel command.
For example:
# add the config
nix-channel --add https://nixos.org/channels/nixpkgs-18.09-darwin nixpkgs
# download the latest nix expressions
nix-channel --update

a surprising (?) behaviour of GNU Make when using ``%`` as target

Consider the following Makefile
foo:
#echo '$#'
test:
#echo '$#'
#echo '---'
# Catch-all target
%: test
#echo '+++'
#echo '$#'
When issuing make bar the following is the console output:
$ make bar
test
---
+++
Makefile
+++
bar
I would like to understand the origin of Makefile which shows it is received as argument at some point, and also how to get rid of it in such a scheme. This is using
GNU Make 4.1
Built for x86_64-apple-darwin13.4.0
GNU make treats the makefile itself as a target that needs to be updated. See How Makefiles Are Remade:
... after reading in all makefiles, make will consider each as a goal target and attempt to update it. If a makefile has a rule which says how to update it (found either in that very makefile or in another one) or if an implicit rule applies to it (see Using Implicit Rules), it will be updated if necessary...
If you know that one or more of your makefiles cannot be remade and you want to keep make from performing an implicit rule search on them, perhaps for efficiency reasons, you can use any normal method of preventing implicit rule look-up to do so. For example, you can write an explicit rule with the makefile as the target, and an empty recipe (see Using Empty Recipes).
Hence, the catch-all-target % is used to update Makefile.
Makefiles often do not have to be updated, so it is customary to add an empty rule for that:
Makefile : ;

"make: *** No targets. Stop." error

I've prepared the following makefile, to automatically clean-up all the temporary projects I want to delete:
.SUFFIXES : bye
# The default action is to
# remove the latest project, i was working at...
byebye :
rm -rf "$(ls -1dt /projects/new_* | head -n1)"
# Remove a specific project.
# Run make from the command-line as 'make new_1_bye' etc.
%_bye :
rm -rf /projects/$*
But, if I run make as:
$ make
I get:
make: *** No targets. Stop.
Why?
The .SUFFIXES line seems to cause the trouble. Suffixes normally start with a dot (.c, for example). Make appears to accept the suffix bye, but that means the line byebye: marks the start of a suffix rule, and the %_bye line is also a suffix rule. That adds up to mean there are no targets cited in the makefile, hence the error message.
If you use .SUFFIXES : .bye instead, make is then happy with the makefile.

Specifying different GNUmakefile for GNU make command

I have two GNUmakefiles in my directory as follows,
GNUmakefile &
GNUmakefile2
Could someone please let me know the command I have to use, if I have to let the "make" command to process "GNUmakefile2" instead of "GNUmakefile".
I used the below command,
make -f GNUmakefile2
but in that case, I am getting the following errors,
This is gnustep-make 2.6.1. Type 'make print-gnustep-make-help' for help.
make[1]: ** No rule to make target `internal-master-tool-all'. Stop.*
make: ** [internal-all] Error 2*
I think it is considering GNUmakefile as makefile (when I use make with -f command), so it is checking for rules in GNUmakefile.
At present what I am doing is I am renaming the required file (which I want, make command to execute) to "GNUmakefile". And I am not getting any errors while executing "make" command, but I don't think this is the correct solution.
Please let me know which command I need to use for this scenario. Thanks for your help.
After checking Beta's solution (i.e.,but that makefile is invoking Make a second time, and the second Make process is probably reading GNUmakefile) what I have done is I renamed existing "GNUmakefile" to "GNUmakefile3".
So at present in my directory the following makefiles are present:- "GNUmakefile2" & "GNUmakefile3".
And then I executed the following command:- $ make -f GNUmakefile2
I recieved the below errors,
This is gnustep-make 2.6.1. Type 'make print-gnustep-make-help' for help.
make[1]: GNUmakefile: No such file or directory
make[1]: * No rule to make target `GNUmakefile'. Stop.
make: * [internal-all] Error 2
Please let me know what is the problem here
Your makefile includes two huge makefiles from the FSF. The second, library.make, contains this rule:
ifeq ($(GNUSTEP_MAKE_PARALLEL_BUILDING), no)
# Standard building
...
else
# Parallel building. ...
internal-library-all_:: $(GNUSTEP_OBJ_INSTANCE_DIR) $(OBJ_DIRS_TO_CREATE)
$(ECHO_NOTHING_RECURSIVE_MAKE)$(MAKE) -f $(MAKEFILE_NAME) ...
endif
and the first, common.make contains this assignment:
# The default name of the makefile to be used in recursive invocations of make
ifeq ($(MAKEFILE_NAME),)
MAKEFILE_NAME = GNUmakefile
endif
So try either make -f GNUmakefile2 GNUSTEP_MAKE_PARALLEL_BUILDING=no or make -f GNUmakefile2 MAKEFILE_NAME=GNUmakefile2, and see if that solves the problem.

Double slash in Cmake add_custom_command causes "No rule to make" error

The following doesn't compile for me using CMake 2.8.3. NOte the "//" caused by a trailing slash on the "DIR" variable. It does compile if that trailing slash is removed.
Anyone know if this is this a bug in CMake or Make, or just user error?
Thanks.
CMakeLists.txt:
SET(DIR ${CMAKE_CURRENT_SOURCE_DIR}/)
FILE(MAKE_DIRECTORY ${DIR})
ADD_CUSTOM_COMMAND(
OUTPUT ${DIR}/test.cc
COMMAND echo "int main(void) { }" > ${DIR}/test.cc
VERBATIM
)
ADD_EXECUTABLE(test ${DIR}/test.cc)
Console:
-- Configuring done
-- Generating done
-- Build files have been written to: /home/sam/tmp
Scanning dependencies of target test
make[2]: *** No rule to make target `test.cc', needed by `CMakeFiles/test.dir/test.o'. Stop.
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
There are a few things wrong with this code:
You are using shell redirection (>) in add_custom_command but you have specified the VERBATIM flag which doesn't process via the shell.
You are not enclosing your paths in quotes, which will cause problems if they contain spaces, set(DIR ... should be: set(DIR "${CMAKE_CURRENT_SOURCE_DIR}/")
You are creating files within the source tree; CMake is usually used with out of source builds so temporary files should be created in the build tree
You could use file(WRITE to create the file, which will be faster than calling out to the shell
cmake_minimum_required is missing
Fixed CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
set(DIR "${CMAKE_CURRENT_BINARY_DIR}")
file(MAKE_DIRECTORY "${DIR}")
file(WRITE "${DIR}/test.cc" "int main(void) {}")
add_executable(test "${DIR}/test.cc")

Resources