i'm fairly new to using Makefiles to write commands for me.
I have made a Makefile to run and format a Flask app.
The contents are
run:
.\venv\Scripts\python.exe app.py
format:
prettier -w .\templates\
prettier -w .\static\
autopep8 --in-place --aggressive --aggressive .\app.py
make run works as expected probably because I have the virutal environment in the same directory.
Running make format
❯ make format
prettier -w .\templates\
prettier -w .\static\
autopep8 --in-place --aggressive --aggressive .\app.py
[warn] Ignored unknown option --in-place.
[warn] Ignored unknown option --aggressive=.\app.py.
[error] No files matching the pattern were found: ".\templatesprettier".
[error] No files matching the pattern were found: ".\staticautopep8".
Makefile:4: recipe for target 'format' failed
make: *** [format] Error 2
But executing the contents of format manually works perfectly fine. So I'm guessing it is some sort of issue from the makefile not having access to these global scrips?
How would I go about fixing this, and is there perhaps an alternative way I can do this (w/o makefile) which is better suited to my task
Related
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
Been pulling out my hairs on this one, it must be so simple but for some reason I can't get it to work..
I'm using go1.15, on Ubuntu 18.04, trying to build lnd from source off of github.
I run sudo make install after all the preliminaries but keep getting error
GO111MODULE=on go install -v -tags="" -ldflags " -s -w -X github.com/lightningnetwork/lnd/build.Commit=v0.11.0-beta-199-g98da919bf1c421dd4a976506761e626e39384a8d -X github.com/lightningnetwork/lnd/build.CommitHash=98da919bf1c421dd4a976506761e626e39384a8d -X github.com/lightningnetwork/lnd/build.GoVersion= -X github.com/lightningnetwork/lnd/build.RawTags=" github.com/lightningnetwork/lnd/cmd/lnd
/bin/sh: 1: go: not found
Makefile:139: recipe for target 'install' failed
make: *** [install] Error 127
i have GOPATH=/usr/local/go and have added /usr/local/go/bin to my PATH variable
can't understand what i am doing wrong
go version returns normally
I'm an intermediate programmer, but been using Linux for many years and do not understand what is going on.
Just in case somebody finds this the answer is that the golang installation instructions say to update your PATH variable in ~/.profile but this only applies to interactive shells, not scripts. So if you want to properly update this for scripts you'll have to find another way. My quick fix was just inserting a PATH update into the script itself.
Link for solution is:
Bash script can't execute Go command
I am trying to build a project that requires two include paths.
My command is:
./autogen.sh --prefix /usr/ --libdir /usr/lib/x86_64-linux-gnu/ CXXFLAGS="-I${TensorflowPath} -I${TensorflowPath}/tensorflow/lite/tools/make/downloads/flatbuffers/include" --enable-tflite
and I have set TensorflowPath to the correct path for my tensorflow source directory.
but the error I get is:
configure: error: unrecognized option: `-I/home/aaron/src/tensorflow/tensorflow/lite/tools/make/downloads/flatbuffers/include'
This is really maddening! The second or third option is always erroring out. Please advise !!
This autogen.sh script appears to be broken both conceptually by unifying two very distinct steps (generating configure with its related files and running configure) into one without good reason, and by the actual implementation of that broken concept using a broken way of passing command line arguments to the child configure process.
If you can replace the call to autogen.sh with a call to autoreconf -vis ., just do that and ignore the broken autogen.sh:
autoreconf -vis .
./configure CXXFLAGS="-Ifoo -Ibar" --prefix=/what/ever --and-so-on
make
make install
If you absolutely need to use that autogen.sh script and cannot just replace it with a call to autoreconf -vis ., call autogen.sh with the single parameter --help to prevent it from running configure with any consequences.
The single --help argument contains no spaces and thus even an autogen.sh script with shell quoting bugs should pass it on correctly to configure. Now autogen.sh should do its buildsystem setup first, and then run configure --help which does nothing but print a bunch of messages to the console.
Then you can run your actual configure command with the correct parameters afterwards:
./autogen.sh --help
./configure CXXFLAGS="-Ifoo -Ibar" --prefix=/what/ever --and-so-on
make
make install
When I try to run ./configure.ac file with MSYS .sh from the command line with mingw64 compiler, I get the following Error from the ./configure file.
Error:
./configure.ac: line 11: syntax error near unexpected token `[svnversion],'
./configure.ac: line 11: `define([svnversion], esyscmd([sh -c "C:\trunk\bin\run_svnversion_if_it_exists.bash|tr -d '\n'"]))dnl'
sh-4.3$
From this Code:
define([svnversion], esyscmd([sh -c "C:\trunk\bin\run_svnversion_if_it_exists.bash|tr -d '\n'"]))dnl
AC_INIT([oomph-lib],[1.0.svnversion],[***#contact])
Is there another way to define SVN version or call it from the bash file?
No, configure.ac is a not a Bash script. Note that configure.ac is different from configure because it ends with .ac. If whatever project you are trying to compile has a configure script, that should be a Bash script that you can run. If it only has configure.ac, you have to run some arcane series of GNU autotools commands to generate a configure script from it (e.g. autoconf, autoreconf). Look at the documentation for your that project to figure out what commands to run.
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.