1

I'm generating a makefile using GO text/template The template is generated as expected (with the right content ) but the problem is that it’s not indented with tabs and I got errors while running make command after generation.

This is the output of the template:

all: app app_2

DIR = $(PWD)
.PHONY: app
app:
@echo "run module 1"

.PHONY: app_2
app_2:
@echo "run module 2”

When I run make I got error "makefile:7: *** missing separator. Stop.” (This is the line with the first echo”)

If I change the ideation to tab (after the file was generated) with Goland or vsCode, I was able to run the file successfully and see the expected output..., any idea how to make it work with go text/template ?

This is the template

all: {{- range .Load.Proc}} {{.Name}}{{end}}


{{- range .Load.Proc}}
.PHONY: {{.Name}}
{{.Name}}:
    @echo {{.Text}}
{{end}}

This is the makefile issue: makefile:4: *** missing separator. Stop but for me it's a problem since I want to generate the file without the need to manually change the indentation.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189

1 Answers1

1

Use tab characters in the template to produce tabs in the output. To fix the template in the question, replace the spaces before @echo with a tab character.

https://play.golang.org/p/c7v6eNsI2Fy

If you cannot put tabs in the template for some reason, then use {{"\t"}} to produce a tab in the output:

{{"\t"}}echo {{.Text}}

https://play.golang.org/p/3B-oIW-aCb4

Charlie Tumahai
  • 113,709
  • 12
  • 249
  • 242