make: /bin/sh: Command not found - makefile

My environment:
I have recently installed MinGW and GNUWin32 on my Windows 10 pc.
I can compile with g++ successfully without using a make file.
With a makefile, make finds g++ to do compiles.
Problem:
My Clean rule is failing with:
make: /bin/sh: Command not found
make: *** [clean] Error 127
I edited my makefile to have only the following:
RM = C:\WFF\GNUWin32\bin\rm.exe
clean :
whoami
where rm
${RM} *.o *.exe
When I execute make, this is the result:
whoami
tilt
where rm
c:\WFF\GNUWin32\bin\rm.exe
C:\WFF\GNUWin32\bin\rm.exe *.o *.exe
make: /bin/sh: Command not found
make: *** [clean] Error 127
Observations:
whoami works
where works and finds rm.exe
but, through the macro substitution for ${RM}, rm.exe is not found
I tried both of the following with weird results:
executed the make file this way: make SHELL=cmd.exe
added this to the makefile: SHELL = C:\Windows\System32\cmd.exe
For each, make seems to
call cmd.exe
execute the comand whoami
and stops
I enter exit, and make continues
call cmd.exe
execute where rm
and stops
I enter exit, and make continues
etc.
If I enter exit too many times, the window is closed, which doesn't surprise me.
Question: any idea what I can do to debug this or solve it?

Related

Permission denied when running go from Makefile

I'm experiencing some weird permission denied errors that I have no idea where could be coming from.
$ go run .
Hello from go
$ make run
go run .
make: go: Permission denied
make: *** [Makefile:2: run] Error 127
$ make run2
echo "Make says hello" ; go run .
Make says hello
Hello from go
$ cat Makefile
run:
go run .
run2:
echo "Make says hello" ; go run .
$ cat main.go
package main
import "fmt"
func main() {
fmt.Println("Hello from go")
}
My terminal is bash running on Ubuntu 22.04.
What is the difference between my run target and running go directly that can cause a permission denied error?
What's the difference between run and run2 that allow it to work in one but not in the other?
EDIT: Running make with -d / --trace
$ make -d run
<...snip...>
No need to remake target 'Makefile'.
Updating goal targets....
Considering target file 'run'.
File 'run' does not exist.
Finished prerequisites of target file 'run'.
Must remake target 'run'.
go run .
make: go: Permission denied
make: *** [Makefile:2: run] Error 127
$ make --trace run
Makefile:2: target 'run' does not exist
go run .
make: go: Permission denied
make: *** [Makefile:2: run] Error 127
$ make --trace run2
Makefile:5: target 'run2' does not exist
echo "Make says hello"; go run .
Make says hello
Hello from go
This is due to a bug in GNU make (actually it's a bug in gnulib). It means that you have a directory named go, in some directory on your PATH (before the actual directory containing the go executable).
So if you have a directory /usr/bin/go/. and you have /usr/bin on your PATH, you'll see this issue.
You should check your PATH and make sure to remove any directories that contain such subdirectories. If you can't remove that directory from your PATH (it's unusual to need directories containing subdirectories on your PATH but I guess it's possible) and you can't rename the go directory to something else, you'll have to ensure that GNU make invokes a shell, by adding a special character. Just ; is good enough:
run:
go run . ;
The issue you're experiencing is likely due to different environment between your shell and shell executed by Makefile. If for example you have a shell alias for go this alias is not visible to Makefile or if you have a custom path in you're shell rc file it's not visible to Makefile. It's hard to guess where the difference might be.
You might want to try debug the issue by trying following in your Makefile:
echo $(PATH)
command -v go
and run the same commands in your shell and compare results.
Note that the default shell for Makefile is /bin/sh whereas you probably have bash or zsh.
Here's some handy defaults to configure your Makefile build:
LANG=en_US.UTF-8
SHELL=/bin/bash
.SHELLFLAGS=--norc --noprofile -e -u -o pipefail -c

Problems with command make

I want to install CD-HIT but 'make' command shows error.
I am running in cygwin (32 bits) so I installed 'make' with apt.cyg and it seems to be correctly installed. Also, I've added the path where CD-HIT are located to $PATH but I still get problems with 'make'.
Here you can see where CD-HIT files are located.
$ pwd
/home/Ale/cdhit-4.8.1
The path is in $PATH
$ $PATH
-bash: /home/Ale/cdhit-4.8.1:/home/Ale/cdhit-4.8.1:/usr/local/bin:/usr/bin:/cygdrive/c/Program: No such file or directory
When using make it shows this error.
$ make -f Makefile
g++ -fopenmp -DWITH_ZLIB -O2 cdhit-common.c++ -c
make: g++: No se encontrĂ³ el programa
make: *** [Makefile:79: cdhit-common.o] Error 127

make[1]: /usr/local/bin/bash: Command not found

I cleaned up my mac and make stopped working as it worked before. There is /bin/bash but make started looking for it in /usr/local/bin/bash. Makefile is correct, something is definitely wrong with my paths. Please help.
NYC-JDOE-MBP:jdk9 jdoe$ make
make[1]: /usr/local/bin/bash: Command not found
make[1]: /usr/local/bin/bash: Command not found
make[1]: /usr/local/bin/bash: Command not found
/Users/jdoe/dev/jdk9/make/common/Modules.gmk:65: *** No source files found for BUILD_GENMODULESLIST. Stop.
make: Nothing to be done for 'default'.
NYC-JDOE-MBP:jdk9 jdoe$ which bash
/bin/bash
create symlink for bash to local folder.
ln -s /bin/bash /usr/local/bin/bash

make[1]: exec(f77) failed (No such file or directory) on DragonFly BSD

I get this error when trying to compile html-xml-utils-6.9 on DragonFly BSD. Funny thing is, when doing grep -r f77 in the source directory, the result is empty. So no such option is in the constructed Makefile after ./configure.
This is my configure output: http://pastebin.com/4tKEXQKG
I tried to do alias f77="gfortran48", but the problem remains. gfortran48 is an installed compiler, I've checked with man gfortran48.
My full error output:
/home/olle2/Downloads/html-xml-utils-6.9$ make
make all-am
f77 -O -c html.e
make[1]: exec(f77) failed (No such file or directory)
*** Error code 1
Stop.
make[1]: stopped in /home/olle2/Downloads/html-xml-utils-6.9
*** Error code 1
Stop.
make: stopped in /home/olle2/Downloads/html-xml-utils-6.9
Any ideas?
Related thread: make: f77: No such file or directory
Aliases aren't available to non-interactive shells generally so an alias isn't the right solution to this problem.
The default FC make variable is f77 so that is likely what is in use in the makefile. This also indicates your solution.
Try make FC=gfortran48 or similar.
Solved with this line:
./configure LDFLAGS="-L/usr/local/lib -liconv" && gmake && echo $?
(gmake instead of make gives saner error messages.)
Thanks to #dragonflybsd IRC channel!

Why does make tell me "Command not found"?

I have the following simple makefile:
all:
fat_imgen.exe
Where fat_imgen.exe is an executable in the same directory as the makefile. When I try and run this however this happens:
>make
fat_imgen.exe
make: fat_imgen.exe: Command not found
make: *** [all] Error 127
If I run fat_imgen from that same command prompt then it starts as expected - why can't make find fat_imgen.exe?
This is all running under Mingw / Windows.
When using a simple commend like the name of an executable, GNU make will start the executable directly. If the directory where the executable is found is not in the PATH/path, make will fail.
If you put the directory in the path, your makefile should work normally.
Also, as suggested in a comment by #AlexFarber, by adding './' GNU make will assume a more complex command (since not all shells are created equal), and hand the command over to the configured shell. That will work, since the shell is created in the directory where the command is then found.

Resources