Go run configuration using a Makefile

Answered

Hi,

I am running the eval copy of GoLand.  I am attempting to build some pre-existing and new projects that use a Makefile to build the executables.  These are based on the ElasticSearch beats structure for anyone familiar with them.  Is there any way to create a Run Configuration to use a Makefile rather than the Go command?

 

Thanks,

 

Jon

1
21 comments

You need to install the Makefile support plugin, https://plugins.jetbrains.com/plugin/9333-makefile-support, via Settings | Plugins which will allow you to run make configurations. If you open the makefile itself, the plugin should also be suggested.

1
Avatar
Permanently deleted user

Excellent.  Thanks Florin.  I was subsequently able to use this along with Delve to get something running within IntelliJ ultimate with the GoLand plugin

0

The Makefile plugin should also be available in GoLand standalone, if you are looking for a more streamlined Go experience. Otherwise I'm happy I could help you, feel free to ask any further questions should you need to. 

0

Does this work on Windows? I get this error when trying to run it:

 

Error running 'Makefile': Cannot run program "\usr\bin\make" (in directory "C:\Users\Brian Hechinger\Documents\projects\CR\Client\go-tools\pipelineReport"): CreateProcess error=2, The system cannot find the file specified

 

I installed the GnuWin version of make and added it to the system path but that didn't help.

 

Thanks!

0

Wonko Hello, yes, it should work for Windows. Can you please send an example of your project and configuration of the Makefile?

0

Hi, I also have similar problem with Wonko on windows.
please I really need your help.
Thank you.

0

Victorisholaoladele Hello, try installing make (choco install make) with Chocolatey and then execute a command from the file. Does it solve the problem?

0

Daniil I'm not entirely sure what you need. Would you mind providing details? Screenshots? Is there a way to get the config as text to paste here?

 

The part that throws me is it's looking for /usr/bin/make which in Windows doesn't make much sense.

0

Wonko You can attach a link to the remote repository (which contains the configuration files and some code that runs), which I can download to my device. Have you tried installing make utility with Chocolatey, as I wrote to another user earlier?

0

This is a private repo that I cannot share on the internet. I installed make via the Gnu installer and then replaced that with make installed by Chocolatey. Same error as before. It's looking for /usr/bin/make which obviously doesn't exist on windows.

0

Wonko Thanks for your answer. I found a way to run the utility on Windows.

1. Install GnuWin32 (Make for Windows).

2. Install the Makefile plugin.

3. Go to settings and specify the path to make: File | Settings | Build, Execution, Deployment | Make | Path to Make executable (by default: C:\Program Files (x86)\GnuWin32\bin\make.exe). Check "Use Cygwin" if necessary.

After that, run the make file and everything should work. Please note that you will not be able to use some utilities (for example grep) in configurations.

3

Perfect, thanks Daniil! (work with the chocolately installed make as well)

0
Avatar
Permanently deleted user

At least on vscode, I found that the "git" bash and the choco installed "make" can be made to work for many unix makefiles, which typically may have common unix shell commands embedded in them (mkdir, rm, etc), without requiring cygwin, mingw, or anything else.  For vscode, you can run bash -c "make target", or per their json, it is synthesized from something like:

{"label": "clean","type": "process","command": "bash","args": ["-c","make clean"]}

Finding a simple way to offer this kind of functionality as an option in the jetbrain makefile plugin on windows would be very nice since you don't need other things installed other than choco make, as you would already very likely have git bash for windows. Incidentally the synthesized command this produces from vscode also works fine on unix systems, too, making generic makefiles truly cross-platform. Another suggestion I could make is to embedded cmake -E based commands in makefiles instead, but installing cmake just to run simple makefiles cross-platform seems a bit much.

 

 

0

Hi @...,

Currently, you can install make via Chocolatey and specify a path to make.exe executable in the settings: File | Settings | Build, Execution, Deployment | Build Tools | Make (by default C:\ProgramData\chocolatey\bin\make.exe). GnuWin32 and other tools are not required.

I hope it helps.

0
Avatar
Permanently deleted user

Danill, you are missing what the use case is.  When Windows executes the make file, the default shell as cmd or PowerShell rather than something like bash. So the individual commands within the makefile are executed with the wrong shell.  Things like "if test ... ;" or "mkdir -p ...", so very common in unix makefiles, have no direct equivalents in windows shell or powershell and either behave differently or fail. Even echo behaves differently, as quotes becomes part of output on windows.  You can make a custom variant just for windows with a bunch of ifeq and things like that everywhere in the Makefile, but that is a lot of work to maintain. It is much simpler to run bash -c "make target" on windows because you can then often just use it as is and let it do the path and environment translations between bash & windows once as it starts. The other possibility is to have a SHELL := bash in the top makefile, but I think that invokes bash and does complex translations for each and every line as executed within in the Makefile rather than just once when make is executed. Since virtually nobody uses make on windows with windows shell commands (there is nmake which is different), I don't think this would change an "expected" behavior by anyone.

0

Thanks for the update, now it is more clear. I think it can be done via WSL2 (with specifying make executable on WSL2 mount), and we have a ticket for that, please see and follow CPP-25102.

0
Avatar
Permanently deleted user

Thanks Daniil. I think this solves a different, important, and somewhat related issue. However, in this case, one wants go.exe itself to execute under windows and produce a windows native binary.  Running make thru wsl likely means your also executing wsl's instance of go, too, which would produce a linux binary instead. This use case I am suggesting exists because with the limited nature of go tooling project level support (if only go.mod had even some of the metadata of rust's cargo toml...) one often ends up using a Makefile with go in actual real world enterprise applications and the intended result is a native binary built on the platform your developing on, not a docker image or linux binary.

0

GOOS=windows solves that for you quite nicely. You just need to set that wherever make is getting called. Simple solution.

1
Avatar
Permanently deleted user

So to build native go windows binaries, cross compile in wsl.  I am not saying it is wrong, it is entirely correct and possible, though the idea of crossing multiple platforms doesn't appeal to my sense of efficiency ;).  But this actually did suggested to me something else very simple too, which I think could work with the choco make and git bash alone.

ifeq ($(OS), Windows_NT)
SHELL := bash
endif

which avoids the need for platform crossovers...

1

I agree that building windows binaries cross-compiled on WSL is a bit silly but honestly it works and is a simple solution so it's definitely one to keep in your basket of tricks as it may come in handy one day.

0

@... it seems your trick may no longer necessary. I just added bin directory of git to the path. Later on, make command worked without any additional configuration. Adding this:

$(info ${SHELL})

into my make file printed this:

C:/Program Files/Git/bin/sh.exe

It seems make prefers sh over cmd if it can find it on the path.

TLDR; just add git bash to windows path and everything works.

0

Please sign in to leave a comment.